Skip to content

Commit

Permalink
Merge pull request #669 from Tencent/docs/swiper
Browse files Browse the repository at this point in the history
feat(Swiper): support pagination-position
  • Loading branch information
LeeJim authored Jul 29, 2022
2 parents ef2a351 + 1ca3e46 commit 8d7100f
Show file tree
Hide file tree
Showing 31 changed files with 620 additions and 402 deletions.
113 changes: 50 additions & 63 deletions src/swiper/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,84 +21,71 @@ isComponent: true

swiper 必须配合 swiper-item 使用,swiper-item 作为轮播条目组件,宽高默认 100%。

## 代码演示

### 基础轮播图
### 主题定制
CSS 变量名|说明
--|--
--td-swiper-nav-dot-color | 点状导航器颜色
--td-swiper-nav-dot-active-color | 点状导航器激活态颜色
--td-swiper-nav-fraction-color | 分式导航器颜色
--td-swiper-nav-fraction-bg-color | 分式导航器背景颜色
--td-swiper-nav-btn-color | 按钮导航器颜色
--td-swiper-nav-btn-bg-color | 按钮导航器背景颜色


## 代码演示

多种轮播样式,通过 `navigation` 设置导航样式,没有值则不显示,也可以自定义 `nav` 组件

<img src="https://tdesign.gtimg.com/miniprogram/readme/swiper.gif" width="375px" height="50%">

```html
<!-- 默认样式 -->
<t-swiper t-class="swiper-wrap" current="{{current}}" bindchange="onChange" navigation>
<t-swiper-item wx:for="{{items}}" wx:key="index">
<view class="item {{item.cls}}">{{index}}<image src="{{item.image}}" class="img" /></view>
</t-swiper-item>
</t-swiper>

<!-- 使用插槽组合 自定义nav组件 -->
<t-swiper current="{{1}}" autoplay="{{true}}" duration="{{500}}" interval="{{5000}}">
<t-swiper-item wx:for="{{items}}" wx:key="index">
<view class="item {{item.cls}}">{{index}}<image src="{{item.image}}" class="img" /></view>
</t-swiper-item>
<t-swiper-nav slot="nav" type="dots-bar" />
</t-swiper>
```

```js
data: {
current: 1,
items: [
{
cls: 'item0',
image: `01.png`,
},
{
cls: 'item1',
image: `02.png`,
},
{
cls: 'item2',
image: `03.png`,
},
{
cls: 'item3',
image: `04.png`,
},
{
cls: 'item4',
image: `05.png`,
},
],
},

onChange(e) {
const {
detail: { current, source },
} = e;
console.log(current, source)
},
```
### 点状(dots)轮播图
{{ base }}

## API
### 分式(fraction)导航器轮播图

{{ fraction }}

### 插槽自定义导航器轮播图

{{ custom }}

### 按钮导航器轮播图

{{ nav-btn }}

### 轮播图垂直样式

{{ vertical }}

## API
### Swiper Props

| 名称 | 类型 | 默认值 | 说明 | 必传 |
| ---------- | ------- | ---------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---- |
| animation | String | slide | 轮播切换动画效果类型。可选项:slide | N |
| autoplay | Boolean | true | 是否自动播放 | N |
| current | Number | 0 | 当前轮播在哪一项(下标) | N |
| direction | String | horizontal | 轮播滑动方向,包括横向滑动和纵向滑动两个方向。可选项:horizontal/vertical | N |
| duration | Number | 300 | 滑动动画时长 | N |
| height | Number | - | 当使用垂直方向滚动时的高度 | N |
| interval | Number | 5000 | 轮播间隔时间 | N |
| navigation | Object | - | 导航配置。`navigation.type` 表示导航器风格,圆点/分式等,没有值则不显示。`navigation.minShowNum` 表示小于这个数字不会显示导航器。`navigation.showSlideBtn` 表示是否显示两侧的滑动控制按钮。TS 类型:`Navigation`[详细类型定义](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/swiper/type.ts) | N |
名称 | 类型 | 默认值 | 说明 | 必传
-- | -- | -- | -- | --
animation | String | slide | 轮播切换动画效果类型。可选项:slide | N
autoplay | Boolean | true | 是否自动播放 | N
current | Number | 0 | 当前轮播在哪一项(下标) | N
default-current | Number | undefined | 当前轮播在哪一项(下标)。非受控属性 | N
direction | String | horizontal | 轮播滑动方向,包括横向滑动和纵向滑动两个方向。可选项:horizontal/vertical | N
duration | Number | 300 | 滑动动画时长 | N
height | Number | - | 当使用垂直方向滚动时的高度 | N
interval | Number | 5000 | 轮播间隔时间 | N
loop | Boolean | true | 【开发中】是否循环播放 | N
navigation | Object / Slot | - | 导航器全部配置 | N
pagination-position | String | bottom-right | 页码信息展示位置。可选项:top-left/top/top-right/bottom-left/bottom/bottom-right | N

### Swiper Events

名称 | 参数 | 描述
-- | -- | --
change | `(current: number, source: SwiperChangeSource)` | 轮播切换时触发。[详细类型定义](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/swiper/type.ts)。<br/>`type SwiperChangeSource = 'autoplay' | 'touch' | ''`<br/>

### SwiperNavigation

名称 | 类型 | 默认值 | 说明 | 必传
-- | -- | -- | -- | --
min-show-num | Number | - | 小于这个数字不会显示导航器 | N
show-slide-btn | Boolean | - | 表示是否显示两侧的滑动控制按钮 | N
type | String | - | 导航器类型,点状(dots)、点条状(dots-bar)、分式(fraction)等。TS 类型:`SwiperNavigationType` `type SwiperNavigationType = 'dots' | 'dots-bar' | 'fraction'`[详细类型定义](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/swiper/type.ts) | N
37 changes: 37 additions & 0 deletions src/swiper/_example/base/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const imageCdn = 'https://tdesign.gtimg.com/site/swiper';
const swiperList = [
{
image: `${imageCdn}/01.png`,
},
{
image: `${imageCdn}/02.png`,
},
{
image: `${imageCdn}/03.png`,
},
{
image: `${imageCdn}/04.png`,
},
{
image: `${imageCdn}/05.png`,
},
];

Component({
data: {
current: 1,
autoplay: true,
duration: 500,
interval: 5000,
swiperList,
},

methods: {
onChange(e) {
const {
detail: { current, source },
} = e;
console.log(current, source);
},
},
});
7 changes: 7 additions & 0 deletions src/swiper/_example/base/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"component": true,
"usingComponents": {
"t-swiper": "tdesign-miniprogram/swiper/swiper",
"t-swiper-item": "tdesign-miniprogram/swiper/swiper-item"
}
}
12 changes: 12 additions & 0 deletions src/swiper/_example/base/index.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<t-swiper
current="{{current}}"
autoplay="{{autoplay}}"
duration="{{duration}}"
interval="{{interval}}"
bindchange="onChange"
navigation
>
<t-swiper-item wx:for="{{swiperList}}" wx:key="index">
<image src="{{item.image}}" class="img" />
</t-swiper-item>
</t-swiper>
4 changes: 4 additions & 0 deletions src/swiper/_example/base/index.wxss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.img {
width: 100%;
height: 100%;
}
28 changes: 28 additions & 0 deletions src/swiper/_example/custom/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const imageCdn = 'https://tdesign.gtimg.com/site/swiper';
const swiperList = [
{
image: `${imageCdn}/01.png`,
},
{
image: `${imageCdn}/02.png`,
},
{
image: `${imageCdn}/03.png`,
},
{
image: `${imageCdn}/04.png`,
},
{
image: `${imageCdn}/05.png`,
},
];

Component({
data: {
current: 1,
autoplay: true,
duration: 500,
interval: 5000,
swiperList,
},
});
8 changes: 8 additions & 0 deletions src/swiper/_example/custom/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"component": true,
"usingComponents": {
"t-swiper": "tdesign-miniprogram/swiper/swiper",
"t-swiper-item": "tdesign-miniprogram/swiper/swiper-item",
"t-swiper-nav": "tdesign-miniprogram/swiper/swiper-nav"
}
}
7 changes: 7 additions & 0 deletions src/swiper/_example/custom/index.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<t-swiper current="{{current}}" autoplay="{{autoplay}}" duration="{{duration}}" interval="{{interval}}">
<t-swiper-item wx:for="{{swiperList}}" wx:key="index">
<image src="{{item.image}}" class="img" />
</t-swiper-item>
<!-- 使用插槽组合,可自定义nav组件 -->
<t-swiper-nav slot="nav" type="dots-bar" />
</t-swiper>
4 changes: 4 additions & 0 deletions src/swiper/_example/custom/index.wxss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.img {
width: 100%;
height: 100%;
}
30 changes: 30 additions & 0 deletions src/swiper/_example/fraction/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const imageCdn = 'https://tdesign.gtimg.com/site/swiper';
const swiperList = [
{
image: `${imageCdn}/01.png`,
},
{
image: `${imageCdn}/02.png`,
},
{
image: `${imageCdn}/03.png`,
},
{
image: `${imageCdn}/04.png`,
},
{
image: `${imageCdn}/05.png`,
},
];

Component({
data: {
current: 2,
autoplay: true,
duration: 500,
interval: 5000,
paginationPosition: 'bottom-right',
swiperList,
navigation: { type: 'fraction' },
},
});
7 changes: 7 additions & 0 deletions src/swiper/_example/fraction/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"component": true,
"usingComponents": {
"t-swiper": "tdesign-miniprogram/swiper/swiper",
"t-swiper-item": "tdesign-miniprogram/swiper/swiper-item"
}
}
12 changes: 12 additions & 0 deletions src/swiper/_example/fraction/index.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<t-swiper
current="{{current}}"
autoplay="{{autoplay}}"
duration="{{duration}}"
interval="{{interval}}"
navigation="{{navigation}}"
paginationPosition="{{paginationPosition}}"
>
<t-swiper-item wx:for="{{swiperList}}" wx:key="index">
<image src="{{item.image}}" class="img" />
</t-swiper-item>
</t-swiper>
4 changes: 4 additions & 0 deletions src/swiper/_example/fraction/index.wxss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.img {
width: 100%;
height: 100%;
}
29 changes: 29 additions & 0 deletions src/swiper/_example/nav-btn/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const imageCdn = 'https://tdesign.gtimg.com/site/swiper';
const swiperList = [
{
image: `${imageCdn}/01.png`,
},
{
image: `${imageCdn}/02.png`,
},
{
image: `${imageCdn}/03.png`,
},
{
image: `${imageCdn}/04.png`,
},
{
image: `${imageCdn}/05.png`,
},
];

Component({
data: {
current: 3,
autoplay: true,
duration: 500,
interval: 5000,
swiperList,
navigation: { type: '', hasNavBtn: true },
},
});
7 changes: 7 additions & 0 deletions src/swiper/_example/nav-btn/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"component": true,
"usingComponents": {
"t-swiper": "tdesign-miniprogram/swiper/swiper",
"t-swiper-item": "tdesign-miniprogram/swiper/swiper-item"
}
}
11 changes: 11 additions & 0 deletions src/swiper/_example/nav-btn/index.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<t-swiper
current="{{current}}"
autoplay="{{autoplay}}"
duration="{{duration}}"
interval="{{interval}}"
navigation="{{navigation}}"
>
<t-swiper-item wx:for="{{swiperList}}" wx:key="index">
<image src="{{item.image}}" class="img" />
</t-swiper-item>
</t-swiper>
4 changes: 4 additions & 0 deletions src/swiper/_example/nav-btn/index.wxss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.img {
width: 100%;
height: 100%;
}
7 changes: 6 additions & 1 deletion src/swiper/_example/swiper.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
"navigationBarBackgroundColor": "#fff",
"backgroundColor": "#fff",
"usingComponents": {
"t-demo": "../../components/demo-block/index"
"t-demo": "../../components/demo-block/index",
"base": "./base",
"fraction": "./fraction",
"nav-btn": "./nav-btn",
"custom": "./custom",
"vertical": "./vertical"
}
}
Loading

0 comments on commit 8d7100f

Please sign in to comment.