Skip to content

Commit 4554951

Browse files
authored
feat(PickerItem): add icon prop (#3930)
* feat(PickerItem): add icon prop * fix(PickerItem): fix console alarm * chore: update demo
1 parent 250a705 commit 4554951

File tree

11 files changed

+25
-10
lines changed

11 files changed

+25
-10
lines changed
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
"component": true,
33
"styleIsolation": "apply-shared",
4-
"usingComponents": {}
4+
"usingComponents": {
5+
"t-icon": "../icon/icon"
6+
}
57
}

packages/components/picker-item/picker-item.less

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
color: @picker-item-color;
3232
font-size: @picker-item-font-size;
3333

34+
&-icon {
35+
font-size: 36rpx;
36+
margin-right: @spacer;
37+
}
38+
3439
&-label {
3540
white-space: nowrap;
3641
text-overflow: ellipsis;

packages/components/picker-item/picker-item.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export default class PickerItem extends SuperComponent {
3939
if (keys === null || JSON.stringify(this.data.pickerKeys) === JSON.stringify(keys)) return;
4040

4141
this.setData({
42-
pickerKeys: keys,
42+
pickerKeys: { ...this.data.pickerKeys, ...keys },
4343
});
4444
}
4545
},
@@ -68,7 +68,7 @@ export default class PickerItem extends SuperComponent {
6868
value: '',
6969
curIndex: 0,
7070
columnIndex: 0,
71-
pickerKeys: { value: 'value', label: 'label' },
71+
pickerKeys: { value: 'value', label: 'label', icon: 'icon' },
7272
formatOptions: props.options.value,
7373
};
7474

packages/components/picker-item/picker-item.wxml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,16 @@
1616
class="{{_.cls(classPrefix + '__item', [['active', curIndex == index]])}}"
1717
style="height: {{pickItemHeight}}px"
1818
wx:for="{{formatOptions}}"
19-
wx:key="index"
19+
wx:key="value"
2020
wx:for-item="option"
2121
data-index="{{ index }}"
2222
bind:tap="onClickItem"
2323
>
24+
<t-icon
25+
wx:if="{{option[pickerKeys.icon]}}"
26+
class="{{classPrefix}}__item-icon"
27+
name="{{option[pickerKeys.icon]}}"
28+
/>
2429
<text class="{{classPrefix}}__item-label">{{option[pickerKeys.label]}}</text>
2530
<slot name="label-suffix--{{index}}"></slot>
2631
</view>

packages/components/picker-item/type.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ export interface TdPickerItemProps {
2525
export interface PickerItemOption {
2626
label: string;
2727
value: string | number;
28+
icon?: string;
2829
}

packages/components/picker/README.en-US.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ name | type | default | description | required
4141
style | Object | - | CSS(Cascading Style Sheets) | N
4242
custom-style | Object | - | CSS(Cascading Style Sheets),used to set style on virtual component | N
4343
format | Function | - | Typescript:`(option: PickerItemOption, columnIndex: number) => PickerItemOption` | N
44-
options | Array | [] | Typescript:`PickerItemOption[]` `interface PickerItemOption { label: string; value: string \| number }`[see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/packages/components/picker-item/type.ts) | N
44+
options | Array | [] | Typescript:`PickerItemOption[]` `interface PickerItemOption { label: string; value: string \| number; icon?: string }`[see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/packages/components/picker-item/type.ts) | N
4545

4646
### CSS Variables
4747

packages/components/picker/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ confirm-btn | String / Boolean | true | 确定按钮文字。TS 类型:`boolea
5959
footer | Slot | - | 底部内容。[通用类型定义](https://github.com/Tencent/tdesign-miniprogram/blob/develop/packages/components/common/common.ts) | N
6060
header | Boolean / Slot | true | 头部内容。值为 true 显示空白头部,值为 false 不显示任何内容。[通用类型定义](https://github.com/Tencent/tdesign-miniprogram/blob/develop/packages/components/common/common.ts) | N
6161
item-height | Number | 80 | PickerItem 的子项高度,单位 rpx | N
62-
keys | Object | - | 用来定义 value / label 在 `options` 中对应的字段别名。TS 类型:`KeysType`[通用类型定义](https://github.com/Tencent/tdesign-miniprogram/blob/develop/packages/components/common/common.ts) | N
62+
keys | Object | - | 用来定义 value / label / icon `options` 中对应的字段别名。TS 类型:`KeysType`[通用类型定义](https://github.com/Tencent/tdesign-miniprogram/blob/develop/packages/components/common/common.ts) | N
6363
popup-props | Object | {} | 透传 Popup 组件全部属性。TS 类型:`PopupProps`[Popup API Documents](./popup?tab=api)[详细类型定义](https://github.com/Tencent/tdesign-miniprogram/blob/develop/packages/components/picker/type.ts) | N
6464
title | String | '' | 标题 | N
6565
use-popup | Boolean | true | 是否使用弹出层包裹 | N
@@ -86,7 +86,7 @@ pick | `(value: Array<PickerValue>, label: string, column: number, index: number
8686
style | Object | - | 样式 | N
8787
custom-style | Object | - | 样式,一般用于开启虚拟化组件节点场景 | N
8888
format | Function | - | 格式化标签。TS 类型:`(option: PickerItemOption, columnIndex: number) => PickerItemOption` | N
89-
options | Array | [] | 数据源。TS 类型:`PickerItemOption[]` `interface PickerItemOption { label: string; value: string \| number }`[详细类型定义](https://github.com/Tencent/tdesign-miniprogram/blob/develop/packages/components/picker-item/type.ts) | N
89+
options | Array | [] | 数据源。TS 类型:`PickerItemOption[]` `interface PickerItemOption { label: string; value: string \| number; icon?: string }`[详细类型定义](https://github.com/Tencent/tdesign-miniprogram/blob/develop/packages/components/picker-item/type.ts) | N
9090

9191
### CSS Variables
9292

packages/components/picker/__test__/__snapshots__/demo.test.js.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ exports[`Picker Picker base demo works fine 1`] = `
153153
options="{{
154154
Array [
155155
Object {
156+
"icon": "home",
156157
"label": "北京市",
157158
"tag": "",
158159
"value": "北京市",

packages/components/picker/_example/base/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Component({
55
dateText: '',
66
dateValue: [],
77
citys: [
8-
{ label: '北京市', value: '北京市', tag: '合' },
8+
{ label: '北京市', value: '北京市', icon: 'home', tag: '合' },
99
{ label: '上海市', value: '上海市', tag: '合' },
1010
{ label: '广州市', value: '广州市' },
1111
{ label: '深圳市', value: '深圳市' },
@@ -26,6 +26,7 @@ Component({
2626
const { value, label } = item;
2727
if (value === '北京市') {
2828
return {
29+
...item,
2930
value,
3031
label: label.substring(0, 2),
3132
};

packages/components/picker/props.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const props: TdPickerProps = {
3131
type: Number,
3232
value: 80,
3333
},
34-
/** 用来定义 value / label 在 `options` 中对应的字段别名 */
34+
/** 用来定义 value / label / icon 在 `options` 中对应的字段别名 */
3535
keys: {
3636
type: Object,
3737
},

0 commit comments

Comments
 (0)