Skip to content

Commit

Permalink
feat(SwipeCell): support icon
Browse files Browse the repository at this point in the history
  • Loading branch information
anlyyao committed Dec 9, 2022
1 parent b7e2d3f commit 6841547
Show file tree
Hide file tree
Showing 23 changed files with 417 additions and 100 deletions.
2 changes: 1 addition & 1 deletion src/swipe-cell/README.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ custom-style | String | - | \- | N
disabled | Boolean | - | \- | N
opened | Boolean / Array | false | \- | N
left | Array / Slot | - | Typescript:`Array<SwipeActionItem>` | N
right | Array / Slot | - | Typescript:`Array<SwipeActionItem>` `interface SwipeActionItem {text: string; className?: string; style?: string; onClick?: () => void; [key: string]: any }`[see more ts definition](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/swipe-cell/type.ts) | N
right | Array / Slot | - | Typescript:`Array<SwipeActionItem>` `interface SwipeActionItem {text?: string; icon?: string | object; className?: string; style?: string; onClick?: () => void; [key: string]: any }`[see more ts definition](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/swipe-cell/type.ts) | N

### SwipeCell Events

Expand Down
18 changes: 12 additions & 6 deletions src/swipe-cell/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,24 @@ isComponent: true
}
```

## 代码演示
### 组件类型

<img src="https://tdesign.gtimg.com/miniprogram/readme/swipeout-1.png" width="375px" height="50%">

### 往左滑动
左滑单操作

{{ left }}

### 往右滑动
右滑单操作

{{ right }}

左右滑操作

{{ double }}

带图标的滑动操作

{{ icon }}

## API
### SwipeCell Props

Expand All @@ -37,7 +43,7 @@ custom-style | String | - | 自定义组件样式 | N
disabled | Boolean | - | 是否禁用滑动 | N
opened | Boolean / Array | false | 操作项是否呈现为打开态,值为数组时表示分别控制左右滑动的展开和收起状态。TS 类型:`boolean| Array<boolean>` | N |
left | Array / Slot | - | 左侧滑动操作项。所有行为同 `right`。TS 类型:`Array<SwipeActionItem>` | N
right | Array / Slot | - | 右侧滑动操作项。有两种定义方式,一种是使用数组,二种是使用插槽。`right.text` 表示操作文本,`right.className` 表示操作项类名,`right.style` 表示操作项样式,`right.onClick` 表示点击操作项后执行的回调函数。示例:`[{ text: '删除', style: 'background-color: red', onClick: () => {} }]`。TS 类型:`Array<SwipeActionItem>` `interface SwipeActionItem {text: string; className?: string; style?: string; onClick?: () => void; [key: string]: any }`[详细类型定义](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/swipe-cell/type.ts) | N
right | Array / Slot | - | 右侧滑动操作项。有两种定义方式,一种是使用数组,二种是使用插槽。`right.text` 表示操作文本,`right.className` 表示操作项类名,`right.style` 表示操作项样式,`right.onClick` 表示点击操作项后执行的回调函数。示例:`[{ text: '删除', icon: 'delete', style: 'background-color: red', onClick: () => {} }]`。TS 类型:`Array<SwipeActionItem>` `interface SwipeActionItem {text?: string; icon?: string | object, className?: string; style?: string; onClick?: () => void; [key: string]: any }`[详细类型定义](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/swipe-cell/type.ts) | N

### SwipeCell Events

Expand Down
188 changes: 155 additions & 33 deletions src/swipe-cell/__test__/__snapshots__/demo.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,32 +1,54 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`SwipeCell SwipeCell left demo works fine 1`] = `
<left>
exports[`SwipeCell SwipeCell double demo works fine 1`] = `
<double>
<t-swipe-cell
tClass="test-class-123"
left="{{
Array [
Object {
"className": "btn favor-btn",
"text": "选择",
},
]
}}"
right="{{
Array [
Object {
"className": "btn delete-btn",
"text": "删除",
},
]
}}"
bind:click="onActionClick"
>
<t-cell
bordered="{{false}}"
note="辅助信息"
title="列表-左滑单操作"
title="左右滑操作"
/>
<wx-view
class="t-swipe-cell-demo-btn delete-btn"
slot="right"
bind:tap="onDelete"
>
删除
</wx-view>
</t-swipe-cell>
</double>
`;

exports[`SwipeCell SwipeCell icon demo works fine 1`] = `
<wx-icon>
<t-swipe-cell
right="{{
Array [
Object {
"className": "t-swipe-cell-demo-btn edit-btn",
"className": "btn edit-btn",
"icon": Object {
"name": "edit",
"size": 16,
},
"text": "编辑",
},
Object {
"className": "t-swipe-cell-demo-btn delete-btn",
"className": "btn delete-btn",
"icon": Object {
"name": "delete",
"size": 16,
},
"text": "删除",
},
]
Expand All @@ -35,56 +57,156 @@ exports[`SwipeCell SwipeCell left demo works fine 1`] = `
>
<t-cell
bordered="{{false}}"
note="双操作"
title="列表-左滑双操作"
note="辅助信息"
title="左滑-带图标文本双操作"
/>
</t-swipe-cell>
<t-swipe-cell
right="{{
Array [
Object {
"className": "btn edit-btn",
"icon": "edit",
},
Object {
"className": "btn delete-btn",
"icon": "delete",
},
]
}}"
>
<t-cell
bordered="{{false}}"
note="辅助信息"
title="左滑-仅带图标双操作"
/>
</t-swipe-cell>
<t-swipe-cell>
<t-cell
bordered="{{false}}"
note="多操作"
title="列表-左滑多操作"
description="一段很长很长的内容文字"
image="https://we-retail-static-1300977798.cos.ap-guangzhou.myqcloud.com/retail-ui/components-exp/placeholder/quartet.svg"
note="辅助信息"
title="左滑大列表-仅带图标双操作"
/>
<wx-view
class="t-swipe-cell-demo-btn-wrapper"
class="btn-wrapper"
slot="right"
>
<wx-view
class="t-swipe-cell-demo-btn favor-btn"
bind:tap="onFavor"
>
收藏
</wx-view>
<wx-view
class="t-swipe-cell-demo-btn edit-btn"
class="btn edit-btn column"
bind:tap="onEdit"
>
编辑
<t-icon
class="padding-bottom"
name="edit"
size="32rpx"
/>
编辑
</wx-view>
<wx-view
class="t-swipe-cell-demo-btn delete-btn"
class="btn delete-btn column"
bind:tap="onDelete"
>
删除
<t-icon
class="padding-bottom"
name="delete"
size="32rpx"
/>
删除
</wx-view>
</wx-view>
</t-swipe-cell>
</wx-icon>
`;

exports[`SwipeCell SwipeCell left demo works fine 1`] = `
<left>
<t-swipe-cell>
<t-cell
bordered="{{false}}"
description="一段很长很长的内容文字一段很长很长的内容文字一段很长很长的内容文字"
note="辅助信息"
title="左滑单操作"
/>
<wx-view
class="btn delete-btn"
slot="right"
bind:tap="onDelete"
>
删除
</wx-view>
</t-swipe-cell>
<t-swipe-cell>
<t-cell
bordered="{{false}}"
description="一段很长很长的内容文字"
image="https://we-retail-static-1300977798.cos.ap-guangzhou.myqcloud.com/retail-ui/components-exp/placeholder/quartet.svg"
tClassImage="title-image-large"
note="辅助信息"
title="左滑大列表"
/>
<wx-view
class="t-swipe-cell-demo-btn delete-btn"
class="btn delete-btn"
slot="right"
bind:tap="onDelete"
>
删除
</wx-view>
</t-swipe-cell>
<t-swipe-cell
right="{{
Array [
Object {
"className": "btn edit-btn",
"text": "编辑",
},
Object {
"className": "btn delete-btn",
"text": "删除",
},
]
}}"
bind:click="onActionClick"
>
<t-cell
bordered="{{false}}"
note="辅助信息"
title="左滑双操作"
/>
</t-swipe-cell>
<t-swipe-cell>
<t-cell
bordered="{{false}}"
note="辅助信息"
title="左滑多操作"
/>
<wx-view
class="btn-wrapper"
slot="right"
>
<wx-view
class="btn favor-btn"
bind:tap="onFavor"
>
收藏
</wx-view>
<wx-view
class="btn edit-btn"
bind:tap="onEdit"
>
编辑
</wx-view>
<wx-view
class="btn delete-btn"
bind:tap="onDelete"
>
删除
</wx-view>
</wx-view>
</t-swipe-cell>
</left>
`;

Expand All @@ -94,10 +216,10 @@ exports[`SwipeCell SwipeCell right demo works fine 1`] = `
<t-cell
bordered="{{false}}"
note="辅助信息"
title="列表-右滑单操作"
title="右滑单操作"
/>
<wx-view
class="t-swipe-cell-demo-btn favor-btn"
class="btn favor-btn"
slot="left"
bind:tap="onChoice"
>
Expand Down
2 changes: 1 addition & 1 deletion src/swipe-cell/__test__/demo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import simulate from 'miniprogram-simulate';
import path from 'path';

const mapper = ['left', 'right'];
const mapper = ['double', 'icon', 'left', 'right'];

describe('SwipeCell', () => {
mapper.forEach((demoName) => {
Expand Down
22 changes: 22 additions & 0 deletions src/swipe-cell/_example/double/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Component({
data: {
right: [
{
text: '删除',
className: 'btn delete-btn',
},
],
left: [
{
text: '选择',
className: 'btn favor-btn',
},
],
},

methods: {
onActionClick({ detail }) {
wx.showToast({ title: `你点击了${detail.text}`, icon: 'none' });
},
},
});
7 changes: 7 additions & 0 deletions src/swipe-cell/_example/double/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"component": true,
"usingComponents": {
"t-cell": "tdesign-miniprogram/cell/cell",
"t-swipe-cell": "tdesign-miniprogram/swipe-cell/swipe-cell"
}
}
3 changes: 3 additions & 0 deletions src/swipe-cell/_example/double/index.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<t-swipe-cell right="{{right}}" left="{{left}}" bind:click="onActionClick">
<t-cell title="左右滑操作" note="辅助信息" bordered="{{false}}" />
</t-swipe-cell>
16 changes: 16 additions & 0 deletions src/swipe-cell/_example/double/index.wxss
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.btn {
display: inline-flex;
justify-content: center;
align-items: center;
width: 120rpx;
height: 100%;
color: white;
}

.favor-btn {
background-color: #0052d9;
}

.delete-btn {
background-color: #e34d59;
}
Loading

0 comments on commit 6841547

Please sign in to comment.