Skip to content

Commit 11fcb72

Browse files
committed
feat(DateTimePicker): support formatter props
1 parent 60d58b3 commit 11fcb72

File tree

8 files changed

+53
-14
lines changed

8 files changed

+53
-14
lines changed

src/date-time-picker/README.en-US.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ end | String / Number | - | \- | N
1616
filter | Function | - | Typescript:`(type: TimeModeValues, columns: DateTimePickerColumn) => DateTimePickerColumn` `type DateTimePickerColumn = DateTimePickerColumnItem[]` `interface DateTimePickerColumnItem { label: string,value: string}`[see more ts definition](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/date-time-picker/type.ts) | N
1717
footer | Slot | - | [see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/src/common/common.ts) | N
1818
format | String | 'YYYY-MM-DD HH:mm:ss' | \- | N
19+
formatter | Function | - | Typescript:`(option: DateTimePickerColumnItem, columnIndex: number) => DateTimePickerColumnItem` | N
1920
header | Boolean / Slot | true | [see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/src/common/common.ts) | N
2021
mode | String / Array | 'date' | Typescript:`DateTimePickerMode` `type DateTimePickerMode = TimeModeValues \| Array<TimeModeValues> ` `type TimeModeValues = 'year' \| 'month' \| 'date' \| 'hour' \| 'minute' \| 'second'`[see more ts definition](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/date-time-picker/type.ts) | N
2122
popup-props | Object | {} | popup properties。Typescript:`PopupProps`[Popup API Documents](./popup?tab=api)[see more ts definition](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/date-time-picker/type.ts) | N

src/date-time-picker/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,10 @@ end | String / Number | - | 选择器的最大可选时间,默认为当前时
7070
filter | Function | - | 列选项过滤函数,支持自定义列内容。(type 值可为: year, month, date, hour, minute, second)。TS 类型:`(type: TimeModeValues, columns: DateTimePickerColumn) => DateTimePickerColumn` `type DateTimePickerColumn = DateTimePickerColumnItem[]` `interface DateTimePickerColumnItem { label: string,value: string}`[详细类型定义](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/date-time-picker/type.ts) | N
7171
footer | Slot | - | 底部内容。[通用类型定义](https://github.com/Tencent/tdesign-miniprogram/blob/develop/src/common/common.ts) | N
7272
format | String | 'YYYY-MM-DD HH:mm:ss' | 用于格式化 pick、change、confirm 事件返回的值,[详细文档](https://day.js.org/docs/en/display/format) | N
73+
formatter | Function | - | 格式化标签。TS 类型:`(option: DateTimePickerColumnItem, columnIndex: number) => DateTimePickerColumnItem` | N
7374
header | Boolean / Slot | true | 头部内容。值为 true 显示空白头部,值为 false 不显示任何内容。[通用类型定义](https://github.com/Tencent/tdesign-miniprogram/blob/develop/src/common/common.ts) | N
7475
mode | String / Array | 'date' | year = 年;month = 年月;date = 年月日;hour = 年月日时; minute = 年月日时分;当类型为数组时,第一个值控制年月日,第二个值控制时分秒。TS 类型:`DateTimePickerMode` `type DateTimePickerMode = TimeModeValues \| Array<TimeModeValues> ` `type TimeModeValues = 'year' \| 'month' \| 'date' \| 'hour' \| 'minute' \| 'second'`[详细类型定义](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/date-time-picker/type.ts) | N
75-
popup-props | Object | {} | 透传 `Popup` 组件全部属性。TS 类型:`PopupProps`[Popup API Documents](./popup?tab=api)[详细类型定义](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/date-time-picker/type.ts) | N
76+
popup-props | Object | {} | 透传 Popup 组件全部属性。TS 类型:`PopupProps`[Popup API Documents](./popup?tab=api)[详细类型定义](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/date-time-picker/type.ts) | N
7677
show-week | Boolean | false | 【开发中】是否在日期旁边显示周几(如周一,周二,周日等) | N
7778
start | String / Number | - | 选择器的最小可选时间,默认为当前时间-10年 | N
7879
steps | Object | - | 时间间隔步数,示例:`{ minute: 5 }` | N

src/date-time-picker/__test__/__snapshots__/demo.test.js.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ exports[`DateTimePicker DateTimePicker year-month-date demo works fine 1`] = `
182182
end="2030-09-09 12:12:12"
183183
filter="{{[Function]}}"
184184
format="YYYY-MM-DD"
185+
formatter="{{[Function]}}"
185186
mode="date"
186187
popupProps="{{
187188
Object {

src/date-time-picker/_example/year-month-date/index.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
const calendarMonth = [
2+
'January',
3+
'February',
4+
'March',
5+
'April',
6+
'May',
7+
'June',
8+
'July',
9+
'August',
10+
'September',
11+
'October',
12+
'November',
13+
'December',
14+
];
15+
116
Page({
217
data: {
318
mode: '',
@@ -17,6 +32,25 @@ Page({
1732
popupProps: {
1833
usingCustomNavbar: true,
1934
},
35+
36+
formatter(item, index) {
37+
let label = item.label.slice(0, -1);
38+
if (index === 1) {
39+
label = calendarMonth[Number(label) - 1];
40+
}
41+
if (index === 2) {
42+
const suffixes = {
43+
1: 'st',
44+
2: 'nd',
45+
3: 'rd',
46+
};
47+
label = `${label}${suffixes[label] || 'th'}`;
48+
}
49+
return {
50+
value: item.value,
51+
label,
52+
};
53+
},
2054
},
2155
showPicker(e) {
2256
const { mode } = e.currentTarget.dataset;

src/date-time-picker/_example/year-month-date/index.wxml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
start="{{start}}"
2121
end="{{end}}"
2222
filter="{{filter}}"
23+
formatter="{{formatter}}"
2324
popup-props="{{popupProps}}"
2425
bindchange="onConfirm"
2526
bindpick="onColumnChange"

src/date-time-picker/date-time-picker.wxml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
class="{{_.cls(classPrefix + '__item', [['roomly', columns.length > 5 && index == 0]])}}"
2525
options="{{item}}"
2626
index="index"
27+
format="{{formatter}}"
2728
/>
2829
<slot slot="footer" name="footer" />
2930
</t-picker>

src/date-time-picker/props.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ const props: TdDateTimePickerProps = {
3030
end: {
3131
type: null,
3232
},
33-
/** 组件类名,分别用于设置组件外层元素、确认按钮、取消按钮、标题等元素类名 */
34-
externalClasses: {
35-
type: Array,
36-
},
3733
/** 列选项过滤函数,支持自定义列内容。(type 值可为: year, month, date, hour, minute, second) */
3834
filter: {
3935
type: null,
@@ -43,6 +39,10 @@ const props: TdDateTimePickerProps = {
4339
type: String,
4440
value: 'YYYY-MM-DD HH:mm:ss',
4541
},
42+
/** 格式化标签 */
43+
formatter: {
44+
type: null,
45+
},
4646
/** 头部内容。值为 true 显示空白头部,值为 false 不显示任何内容 */
4747
header: {
4848
type: Boolean,
@@ -53,7 +53,7 @@ const props: TdDateTimePickerProps = {
5353
type: null,
5454
value: 'date',
5555
},
56-
/** 透传 `Popup` 组件全部属性 */
56+
/** 透传 Popup 组件全部属性 */
5757
popupProps: {
5858
type: Object,
5959
value: {},

src/date-time-picker/type.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,6 @@ export interface TdDateTimePickerProps {
4646
type: null;
4747
value?: string | number;
4848
};
49-
/**
50-
* 组件类名,分别用于设置组件外层元素、确认按钮、取消按钮、标题等元素类名
51-
*/
52-
externalClasses?: {
53-
type: ArrayConstructor;
54-
value?: ['t-class', 't-class-confirm', 't-class-cancel', 't-class-title'];
55-
};
5649
/**
5750
* 列选项过滤函数,支持自定义列内容。(type 值可为: year, month, date, hour, minute, second)
5851
*/
@@ -68,6 +61,13 @@ export interface TdDateTimePickerProps {
6861
type: StringConstructor;
6962
value?: string;
7063
};
64+
/**
65+
* 格式化标签
66+
*/
67+
formatter?: {
68+
type: undefined;
69+
value?: (option: DateTimePickerColumnItem, columnIndex: number) => DateTimePickerColumnItem;
70+
};
7171
/**
7272
* 头部内容。值为 true 显示空白头部,值为 false 不显示任何内容
7373
* @default true
@@ -85,7 +85,7 @@ export interface TdDateTimePickerProps {
8585
value?: DateTimePickerMode;
8686
};
8787
/**
88-
* 透传 `Popup` 组件全部属性
88+
* 透传 Popup 组件全部属性
8989
* @default {}
9090
*/
9191
popupProps?: {

0 commit comments

Comments
 (0)