1 | import { ComponentType } from 'react'
|
2 | import { StyleProp, TextStyle, ViewStyle } from 'react-native'
|
3 | import { StandardProps, CommonEventFunction, FormItemProps } from './common'
|
4 | /** 选择器通用参数 */
|
5 | interface PickerStandardProps extends StandardProps, FormItemProps {
|
6 | /**
|
7 | * 选择器的标题,微信小程序中仅安卓可用
|
8 | * @supported weapp
|
9 | */
|
10 | headerText?: string
|
11 | /**
|
12 | * 选择器类型,默认是普通选择器
|
13 | * @default "selector"
|
14 | * @supported weapp, h5, rn, harmony, harmony_hybrid
|
15 | */
|
16 | mode?: keyof PickerStandardProps.Mode
|
17 | /**
|
18 | * 是否禁用
|
19 | * @default false
|
20 | * @supported weapp, h5, rn, harmony_hybrid
|
21 | */
|
22 | disabled?: boolean
|
23 | /**
|
24 | * 取消选择或点遮罩层收起 picker 时触发
|
25 | * @supported weapp, h5, rn, harmony, harmony_hybrid
|
26 | */
|
27 | onCancel?: CommonEventFunction
|
28 | }
|
29 | declare namespace PickerStandardProps {
|
30 | /** 选择器类型 */
|
31 | interface Mode {
|
32 | /** 普通选择器 */
|
33 | selector
|
34 | /** 多列选择器 */
|
35 | multiSelector
|
36 | /** 时间选择器 */
|
37 | time
|
38 | /** 日期选择器 */
|
39 | date
|
40 | /** 省市区选择器 */
|
41 | region
|
42 | }
|
43 | interface PickerText {
|
44 | okText?: string
|
45 | cancelText?: string
|
46 | }
|
47 | }
|
48 | /** 普通选择器:mode = selector */
|
49 | interface PickerSelectorProps extends PickerStandardProps {
|
50 | /** 选择器类型 */
|
51 | mode?: 'selector'
|
52 | /**
|
53 | * mode为 selector 或 multiSelector 时,range 有效
|
54 | * @supported weapp, h5, rn, harmony, harmony_hybrid
|
55 | * @default []
|
56 | */
|
57 | range: string[] | number[] | Record<string, any>[]
|
58 | /**
|
59 | * 当 range 是一个 Object Array 时,通过 rangeKey 来指定 Object 中 key 的值作为选择器显示内容
|
60 | * @supported weapp, h5, rn, harmony, harmony_hybrid
|
61 | */
|
62 | rangeKey?: string
|
63 | /**
|
64 | * 表示选择了 range 中的第几个(下标从 0 开始)
|
65 | * @supported weapp, h5, rn, harmony, harmony_hybrid
|
66 | * @default 0
|
67 | */
|
68 | value?: number
|
69 | /** 设置 React 非受控状态下的初始取值
|
70 | * @supported weapp, h5, rn, harmony_hybrid
|
71 | */
|
72 | defaultValue?: number
|
73 | /**
|
74 | * mode为 selector 或 multiSelector 时 itemStyle 有效
|
75 | * @supported rn
|
76 | * @default {}
|
77 | */
|
78 | itemStyle?: StyleProp<TextStyle>
|
79 | /**
|
80 | * mode为 selector 或 multiSelector 时 indicatorStyle 有效
|
81 | * @supported rn
|
82 | * @default {}
|
83 | */
|
84 | indicatorStyle?: StyleProp<ViewStyle>
|
85 | /**
|
86 | * value 改变时触发 change 事件
|
87 | * @supported weapp, h5, rn, harmony, harmony_hybrid
|
88 | */
|
89 | onChange?: CommonEventFunction<PickerSelectorProps.ChangeEventDetail>
|
90 | /**
|
91 | * 用于替换组件内部文本
|
92 | * @supported h5, harmony, harmony_hybrid
|
93 | */
|
94 | textProps?: PickerStandardProps.PickerText
|
95 | }
|
96 | declare namespace PickerSelectorProps {
|
97 | interface ChangeEventDetail {
|
98 | /** 表示变更值的下标 */
|
99 | value: string | number
|
100 | }
|
101 | }
|
102 | /** 多列选择器:mode = multiSelector */
|
103 | interface PickerMultiSelectorProps extends PickerStandardProps {
|
104 | /** 选择器类型 */
|
105 | mode: 'multiSelector'
|
106 | /**
|
107 | * mode为 selector 或 multiSelector 时,range 有效
|
108 | * @supported weapp, h5, rn, harmony, harmony_hybrid
|
109 | * @default []
|
110 | */
|
111 | range: Array<string[]> | Array<number[]> | Array<Record<string, any>[]>
|
112 | /**
|
113 | * 当 range 是一个 Object Array 时,通过 rangeKey 来指定 Object 中 key 的值作为选择器显示内容
|
114 | * @supported weapp, h5, rn, harmony, harmony_hybrid
|
115 | */
|
116 | rangeKey?: string
|
117 | /**
|
118 | * 表示选择了 range 中的第几个(下标从 0 开始)
|
119 | * @supported weapp, h5, rn, harmony, harmony_hybrid
|
120 | * @default []
|
121 | */
|
122 | value: number[] | string[] | Record<string, any>[]
|
123 | /**
|
124 | * mode为 selector 或 multiSelector 时 itemStyle 有效
|
125 | * @supported rn
|
126 | * @default {}
|
127 | */
|
128 | itemStyle?: StyleProp<TextStyle>
|
129 | /**
|
130 | * mode为 selector 或 multiSelector 时 indicatorStyle 有效
|
131 | * @supported rn
|
132 | * @default {}
|
133 | */
|
134 | indicatorStyle?: StyleProp<ViewStyle>
|
135 | /**
|
136 | * 当 value 改变时触发 change 事件
|
137 | * @supported weapp, h5, rn, harmony, harmony_hybrid
|
138 | */
|
139 | onChange: CommonEventFunction<PickerMultiSelectorProps.ChangeEventDetail>
|
140 | /**
|
141 | * 列改变时触发
|
142 | * @supported weapp, h5, rn, harmony, harmony_hybrid
|
143 | */
|
144 | onColumnChange?: CommonEventFunction<PickerMultiSelectorProps.ColumnChangeEventDetail>
|
145 | }
|
146 | declare namespace PickerMultiSelectorProps {
|
147 | interface ChangeEventDetail {
|
148 | /** 表示变更值的下标 */
|
149 | value: number[]
|
150 | }
|
151 | interface ColumnChangeEventDetail {
|
152 | /** 表示改变了第几列(下标从0开始) */
|
153 | column: number
|
154 | /** 表示变更值的下标 */
|
155 | value: number
|
156 | }
|
157 | }
|
158 | /** 时间选择器:mode = time */
|
159 | interface PickerTimeProps extends PickerStandardProps {
|
160 | /** 选择器类型 */
|
161 | mode: 'time'
|
162 | /**
|
163 | * value 的值表示选择了 range 中的第几个(下标从 0 开始)
|
164 | * @supported weapp, h5, rn, harmony, harmony_hybrid
|
165 | */
|
166 | value?: string
|
167 | /** 设置 React 非受控状态下的初始取值
|
168 | * @supported weapp, h5, rn
|
169 | */
|
170 | defaultValue?: string
|
171 | /**
|
172 | * 仅当 mode 为 "time" 或 "date" 时有效,表示有效时间范围的开始,字符串格式为"hh:mm"
|
173 | * @supported weapp, h5, rn, harmony, harmony_hybrid
|
174 | */
|
175 | start?: string
|
176 | /**
|
177 | * 仅当 mode 为 "time" 或 "date" 时有效,表示有效时间范围的结束,字符串格式为"hh:mm"
|
178 | * @supported weapp, h5, rn, harmony, harmony_hybrid
|
179 | */
|
180 | end?: string
|
181 | /**
|
182 | * value 改变时触发 change 事件
|
183 | * @supported weapp, h5, rn, harmony, harmony_hybrid
|
184 | */
|
185 | onChange: CommonEventFunction<PickerTimeProps.ChangeEventDetail>
|
186 | }
|
187 | declare namespace PickerTimeProps {
|
188 | interface ChangeEventDetail {
|
189 | /** 表示选中的时间 */
|
190 | value: string
|
191 | }
|
192 | }
|
193 | /** 日期选择器:mode = date */
|
194 | interface PickerDateProps extends PickerStandardProps {
|
195 | /** 选择器类型 */
|
196 | mode: 'date'
|
197 | /**
|
198 | * 表示选中的日期,格式为"YYYY-MM-DD"
|
199 | * @supported weapp, h5, rn, harmony, harmony_hybrid
|
200 | * @default 0
|
201 | */
|
202 | value: string
|
203 | /** 设置 React 非受控状态下的初始取值
|
204 | * @supported weapp, h5, rn
|
205 | */
|
206 | defaultValue?: string
|
207 | /**
|
208 | * 仅当 mode 为 "time" 或 "date" 时有效,表示有效时间范围的开始,字符串格式为"YYYY-MM-DD"
|
209 | * @supported weapp, h5, rn, harmony, harmony_hybrid
|
210 | */
|
211 | start?: string
|
212 | /**
|
213 | * 仅当 mode 为 "time" 或 "date" 时有效,表示有效时间范围的结束,字符串格式为"YYYY-MM-DD"
|
214 | * @supported weapp, h5, rn, harmony, harmony_hybrid
|
215 | */
|
216 | end?: string
|
217 | /**
|
218 | * 有效值 year, month, day,表示选择器的粒度
|
219 | * @supported weapp, h5, rn, harmony_hybrid
|
220 | * @default "day"
|
221 | */
|
222 | fields?: keyof PickerDateProps.Fields
|
223 | /**
|
224 | * value 改变时触发 change 事件
|
225 | * @supported weapp, h5, rn, harmony, harmony_hybrid
|
226 | */
|
227 | onChange: CommonEventFunction<PickerDateProps.ChangeEventDetail>
|
228 | }
|
229 | declare namespace PickerDateProps {
|
230 | interface Fields {
|
231 | /** 选择器粒度为年 */
|
232 | year
|
233 | /** 选择器粒度为月份 */
|
234 | month
|
235 | /** 选择器粒度为天 */
|
236 | day
|
237 | }
|
238 | interface ChangeEventDetail {
|
239 | /** 表示选中的日期 */
|
240 | value: string
|
241 | }
|
242 | }
|
243 | /** 省市区选择器:mode = region */
|
244 | interface PickerRegionProps extends PickerStandardProps {
|
245 | /** 选择器类型 */
|
246 | mode: 'region'
|
247 | /**
|
248 | * 表示选中的省市区,默认选中每一列的第一个值
|
249 | * @supported weapp, h5, rn, harmony_hybrid
|
250 | * @default []
|
251 | */
|
252 | value?: string[]
|
253 | /** 设置 React 非受控状态下的初始取值
|
254 | * @supported weapp, h5, rn
|
255 | */
|
256 | defaultValue?: string[]
|
257 | /**
|
258 | * 可为每一列的顶部添加一个自定义的项
|
259 | * @supported weapp, h5, rn, harmony_hybrid
|
260 | */
|
261 | customItem?: string
|
262 | /**
|
263 | * 选择器层级
|
264 | * @supported weapp
|
265 | * @default "region"
|
266 | */
|
267 | level?: keyof PickerRegionProps.Level
|
268 | /**
|
269 | * 自定义省市区数据
|
270 | * @supported rn
|
271 | */
|
272 | regionData?: PickerRegionProps.RegionData[]
|
273 | /**
|
274 | * value 改变时触发 change 事件
|
275 | * @supported weapp, h5, rn, harmony_hybrid
|
276 | */
|
277 | onChange: CommonEventFunction<PickerRegionProps.ChangeEventDetail>
|
278 | }
|
279 | declare namespace PickerRegionProps {
|
280 | interface ChangeEventDetail {
|
281 | /** 表示选中的省市区 */
|
282 | value: string[]
|
283 | /** 统计用区划代码 */
|
284 | code: string[]
|
285 | /** 邮政编码 */
|
286 | postcode?: string
|
287 | }
|
288 | interface RegionData {
|
289 | value: string
|
290 | code: string
|
291 | postcode?: string
|
292 | children?: RegionData[]
|
293 | }
|
294 | interface Level {
|
295 | /** 省级选择器 */
|
296 | province
|
297 | /** 市级选择器 */
|
298 | city
|
299 | /** 区级选择器 */
|
300 | region
|
301 | /** 街道选择器 */
|
302 | 'sub-district'
|
303 | }
|
304 | }
|
305 | /**
|
306 | * 从底部弹起的滚动选择器
|
307 | * @classification forms
|
308 | * @supported weapp, swan, alipay, tt, h5, rn, harmony, harmony_hybrid
|
309 | * @example_react
|
310 | * ```tsx
|
311 | * export default class PagePicker extends Component {
|
312 | * state = {
|
313 | * selector: ['美国', '中国', '巴西', '日本'],
|
314 | * selectorChecked: '美国',
|
315 | * timeSel: '12:01',
|
316 | * dateSel: '2018-04-22'
|
317 | * }
|
318 | *
|
319 | * onChange = e => {
|
320 | * this.setState({
|
321 | * selectorChecked: this.state.selector[e.detail.value]
|
322 | * })
|
323 | * }
|
324 | *
|
325 | * onTimeChange = e => {
|
326 | * this.setState({
|
327 | * timeSel: e.detail.value
|
328 | * })
|
329 | * }
|
330 | * onDateChange = e => {
|
331 | * this.setState({
|
332 | * dateSel: e.detail.value
|
333 | * })
|
334 | * }
|
335 | *
|
336 | * render () {
|
337 | * return (
|
338 | * <View className='container'>
|
339 | * <View className='page-body'>
|
340 | * <View className='page-section'>
|
341 | * <Text>地区选择器</Text>
|
342 | * <View>
|
343 | * <Picker mode='selector' range={this.state.selector} onChange={this.onChange}>
|
344 | * <View className='picker'>
|
345 | * 当前选择:{this.state.selectorChecked}
|
346 | * </View>
|
347 | * </Picker>
|
348 | * </View>
|
349 | * </View>
|
350 | * <View className='page-section'>
|
351 | * <Text>时间选择器</Text>
|
352 | * <View>
|
353 | * <Picker mode='time' onChange={this.onTimeChange}>
|
354 | * <View className='picker'>
|
355 | * 当前选择:{this.state.timeSel}
|
356 | * </View>
|
357 | * </Picker>
|
358 | * </View>
|
359 | * </View>
|
360 | * <View className='page-section'>
|
361 | * <Text>日期选择器</Text>
|
362 | * <View>
|
363 | * <Picker mode='date' onChange={this.onDateChange}>
|
364 | * <View className='picker'>
|
365 | * 当前选择:{this.state.dateSel}
|
366 | * </View>
|
367 | * </Picker>
|
368 | * </View>
|
369 | * </View>
|
370 | * </View>
|
371 | * </View>
|
372 | * )
|
373 | * }
|
374 | * }
|
375 | * ```
|
376 | * @example_vue
|
377 | * ```html
|
378 | * <template>
|
379 | * <view class="page-body">
|
380 | * <view class="page-section">
|
381 | * <text>地区选择器</text>
|
382 | * <view>
|
383 | * <picker mode="selector" :range="selector" `@change="onChange">
|
384 | * <view class="picker">
|
385 | * 当前选择:{{selectorChecked}}
|
386 | * </view>
|
387 | * </picker>
|
388 | * </view>
|
389 | * </view>
|
390 | * <view class="page-section">
|
391 | * <text>时间选择器</text>
|
392 | * <view>
|
393 | * <picker mode="time" `@change="onTimeChange">
|
394 | * <view class="picker">
|
395 | * 当前选择:{{timeSel}}
|
396 | * </view>
|
397 | * </picker>
|
398 | * </view>
|
399 | * </view>
|
400 | * <view class="page-section">
|
401 | * <text>日期选择器</text>
|
402 | * <view>
|
403 | * <picker mode="date" `@change="onDateChange">
|
404 | * <view class="picker">
|
405 | * 当前选择:{{dateSel}}
|
406 | * </view>
|
407 | * </picker>
|
408 | * </view>
|
409 | * </view>
|
410 | * </view>
|
411 | * </template>
|
412 | *
|
413 | * <script>
|
414 | * export default {
|
415 | * data() {
|
416 | * return {
|
417 | * selector: ['美国', '中国', '巴西', '日本'],
|
418 | * selectorChecked: '美国',
|
419 | * timeSel: '12:01',
|
420 | * dateSel: '2018-04-22'
|
421 | * }
|
422 | * },
|
423 | * methods: {
|
424 | * onChange: function(e) {
|
425 | * this.selectorChecked = this.selector[e.detail.value]
|
426 | * },
|
427 | *
|
428 | * onTimeChange: function(e) {
|
429 | * this.timeSel = e.detail.value
|
430 | * },
|
431 | *
|
432 | * onDateChange: function(e) {
|
433 | * this.dateSel = e.detail.value
|
434 | * }
|
435 | * }
|
436 | * }
|
437 | * </script>
|
438 | * ```
|
439 | * @see https://developers.weixin.qq.com/miniprogram/dev/component/picker.html
|
440 | */
|
441 | declare const Picker: ComponentType<
|
442 | PickerMultiSelectorProps | PickerTimeProps | PickerDateProps | PickerRegionProps | PickerSelectorProps
|
443 | >
|
444 | export {
|
445 | Picker,
|
446 | PickerStandardProps,
|
447 | PickerSelectorProps,
|
448 | PickerMultiSelectorProps,
|
449 | PickerTimeProps,
|
450 | PickerDateProps,
|
451 | PickerRegionProps,
|
452 | }
|