Skip to content

Commit 2dd3bf8

Browse files
committed
docs(TimePicker): add descriptions for time range
1 parent 4dfd1fa commit 2dd3bf8

File tree

5 files changed

+808
-790
lines changed

5 files changed

+808
-790
lines changed

packages/vant/src/time-picker/README.md

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ export default {
7171

7272
### Time Range
7373

74+
You can use props like `min-hour` and `max-hour` to limit the range of hours, `min-minute` and `max-minute` to limit the range of minutes, and `min-second` and `max-second` to limit the range of seconds.
75+
76+
For example, in the following example, users can only select hours between `10` and `20`, and minutes between `30` and `40`.
77+
7478
```html
7579
<van-time-picker
7680
v-model="currentTime"
@@ -93,6 +97,36 @@ export default {
9397
};
9498
```
9599

100+
### Overall Time Range
101+
102+
You can use `min-time` and `max-time` attributes to limit the overall time range, with the format `10:00:00`.
103+
104+
- When `min-time` is set, attributes like `min-hour`, `min-minute`, and `min-second` will not take effect.
105+
- When `max-time` is set, attributes like `max-hour`, `max-minute`, and `max-second` will not take effect.
106+
107+
For example, in the following example, users can select any time between `09:40:10` and `20:20:50`.
108+
109+
```html
110+
<van-time-picker
111+
v-model="currentTime"
112+
title="Choose Time"
113+
:columns-type="['hour', 'minute', 'second']"
114+
min-time="09:40:10"
115+
max-time="20:20:50"
116+
/>
117+
```
118+
119+
```js
120+
import { ref } from 'vue';
121+
122+
export default {
123+
setup() {
124+
const currentTime = ref(['12', '00', '00']);
125+
return { currentTime };
126+
},
127+
};
128+
```
129+
96130
### Options Formatter
97131

98132
Using `formatter` prop to format option text.
@@ -159,31 +193,6 @@ export default {
159193
};
160194
```
161195

162-
### Limit Time Range
163-
164-
Using `min-time` and `max-time` props to limit the time range, Convention format `10:00:00`.
165-
166-
```html
167-
<van-time-picker
168-
v-model="currentTime"
169-
title="Choose Time"
170-
:columns-type="['hour', 'minute', 'second']"
171-
min-time="09:40:10"
172-
max-time="20:20:50"
173-
/>
174-
```
175-
176-
```js
177-
import { ref } from 'vue';
178-
179-
export default {
180-
setup() {
181-
const currentTime = ref(['12', '00', '00']);
182-
return { currentTime };
183-
},
184-
};
185-
```
186-
187196
### Advanced Usage
188197

189198
The third parameter of the `filter` function can get the currently selected time, which can be used to filter unwanted times more flexibly when using the uncontrolled mode.

packages/vant/src/time-picker/README.zh-CN.md

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ export default {
7373

7474
### 时间范围
7575

76+
你可以使用 `min-hour``max-hour` 等属性来限制小时(hour)范围、分钟(minute)范围和秒(second)范围。
77+
78+
比如以下示例,用户可以选择的小时是 `10 ~ 20` ,分钟是 `30 ~ 40`
79+
7680
```html
7781
<van-time-picker
7882
v-model="currentTime"
@@ -95,6 +99,36 @@ export default {
9599
};
96100
```
97101

102+
### 整体时间范围
103+
104+
你可以使用 `min-time``max-time` 属性来限制整体时间范围,约定格式 `10:00:00`
105+
106+
- 设置 `min-time` 后,`min-hour``min-minute``min-second` 属性将不会生效。
107+
- 设置 `max-time` 后,`max-hour``max-minute``max-second` 属性将不会生效。
108+
109+
比如以下示例,用户可以选择从 `09:40:10``20:20:50` 的任意时间。
110+
111+
```html
112+
<van-time-picker
113+
v-model="currentTime"
114+
title="选择时间"
115+
:columns-type="['hour', 'minute', 'second']"
116+
min-time="09:40:10"
117+
max-time="20:20:50"
118+
/>
119+
```
120+
121+
```js
122+
import { ref } from 'vue';
123+
124+
export default {
125+
setup() {
126+
const currentTime = ref(['12', '00', '00']);
127+
return { currentTime };
128+
},
129+
};
130+
```
131+
98132
### 格式化选项
99133

100134
通过传入 `formatter` 函数,可以对选项的文字进行格式化。
@@ -160,31 +194,6 @@ export default {
160194
};
161195
```
162196

163-
### 限制时间范围
164-
165-
使用 `min-time``max-time` 来限制时间范围,约定格式 `10:00:00`
166-
167-
```html
168-
<van-time-picker
169-
v-model="currentTime"
170-
title="选择时间"
171-
:columns-type="['hour', 'minute', 'second']"
172-
min-time="09:40:10"
173-
max-time="20:20:50"
174-
/>
175-
```
176-
177-
```js
178-
import { ref } from 'vue';
179-
180-
export default {
181-
setup() {
182-
const currentTime = ref(['12', '00', '00']);
183-
return { currentTime };
184-
},
185-
};
186-
```
187-
188197
### 高级用法
189198

190199
`filter` 函数的第三个参数能获取到当前选择的时间,这在使用非受控模式时,可以更灵活地过滤掉不需要的时间。
@@ -241,8 +250,8 @@ export default {
241250
| max-minute | 可选的最大分钟 | _number \| string_ | `59` |
242251
| min-second | 可选的最小秒数 | _number \| string_ | `0` |
243252
| max-second | 可选的最大秒数 | _number \| string_ | `59` |
244-
| min-time `v4.5.0` | 可选的最小时间,格式参考 `07:40:00`,使用时 `min-hour` `min-minute` `min-second` 无效 | _string_ | - |
245-
| max-time `v4.5.0` | 可选的最大时间,格式参考 `10:20:00`,使用时 `max-hour` `max-minute` `max-second` 无效 | _string_ | - |
253+
| min-time `v4.5.0` | 可选的最小时间,格式参考 `07:40:00`,使用时 `min-hour` `min-minute` `min-second` 不会生效 | _string_ | - |
254+
| max-time `v4.5.0` | 可选的最大时间,格式参考 `10:20:00`,使用时 `max-hour` `max-minute` `max-second` 不会生效 | _string_ | - |
246255
| title | 顶部栏标题 | _string_ | `''` |
247256
| confirm-button-text | 确认按钮文字 | _string_ | `确认` |
248257
| cancel-button-text | 取消按钮文字 | _string_ | `取消` |

packages/vant/src/time-picker/demo/index.vue

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const t = useTranslate({
1414
columnsType: '选项类型',
1515
optionsFilter: '过滤选项',
1616
optionsFormatter: '格式化选项',
17-
timeUniteRange: '时分时间范围',
17+
overallTimeRange: '整体时间范围',
1818
},
1919
'en-US': {
2020
hour: 'h',
@@ -24,7 +24,7 @@ const t = useTranslate({
2424
columnsType: 'Columns Type',
2525
optionsFilter: 'Options Filter',
2626
optionsFormatter: 'Options Formatter',
27-
timeUniteRange: 'Hour Minute Range',
27+
overallTimeRange: 'Overall Time Range',
2828
},
2929
});
3030
@@ -107,6 +107,16 @@ const formatter = (type: string, option: PickerOption) => {
107107
/>
108108
</demo-block>
109109

110+
<demo-block card :title="t('overallTimeRange')">
111+
<van-time-picker
112+
v-model="hourMinuteTime"
113+
:title="t('chooseTime')"
114+
:columns-type="['hour', 'minute', 'second']"
115+
min-time="09:40:10"
116+
max-time="20:20:50"
117+
/>
118+
</demo-block>
119+
110120
<demo-block card :title="t('optionsFormatter')">
111121
<van-time-picker
112122
v-model="formatterTime"
@@ -123,16 +133,6 @@ const formatter = (type: string, option: PickerOption) => {
123133
/>
124134
</demo-block>
125135

126-
<demo-block card :title="t('timeUniteRange')">
127-
<van-time-picker
128-
v-model="hourMinuteTime"
129-
:title="t('chooseTime')"
130-
:columns-type="['hour', 'minute', 'second']"
131-
min-time="09:40:10"
132-
max-time="20:20:50"
133-
/>
134-
</demo-block>
135-
136136
<demo-block card :title="t('advancedUsage')">
137137
<van-time-picker :title="t('chooseTime')" :filter="timeFilter" />
138138
</demo-block>

0 commit comments

Comments
 (0)