UNPKG

6.02 kBTypeScriptView Raw
1import { ComponentType } from 'react'
2import { StandardProps, CommonEventFunction } from './common'
3interface PickerViewProps extends StandardProps {
4 /** 数组中的数字依次表示 picker-view 内的 picker-view-column 选择的第几项(下标从 0 开始),数字大于 picker-view-column 可选项长度时,选择最后一项。
5 * @supported weapp, alipay, swan, tt, qq, jd, rn
6 */
7 value?: number[]
8
9 /** 设置选择器中间选中框的样式
10 * @supported weapp, alipay, swan, tt, qq, jd, rn
11 */
12 indicatorStyle?: string
13
14 /** 设置选择器中间选中框的类名
15 * @supported weapp, alipay, swan, tt, qq, jd
16 */
17 indicatorClass?: string
18
19 /** 设置蒙层的样式
20 * @supported weapp, alipay, swan, tt, qq, jd
21 */
22 maskStyle?: string
23
24 /** 设置蒙层的类名
25 * @supported weapp, alipay, swan, tt, qq, jd
26 */
27 maskClass?: string
28
29 /** 是否在手指松开时立即触发 change 事件。若不开启则会在滚动动画结束后触发 change 事件。
30 * @supported weapp, tt
31 * @default false
32 */
33 immediateChange?: boolean
34
35 /** 选择器标题,建议标题控制在 12 个中文汉字长度内,避免出现截断现象, 截断部分将以 ... 形式展示
36 * @supported swan
37 */
38 title?: string
39
40 /** 无障碍访问,(属性)元素的额外描述
41 * @supported qq
42 */
43 ariaLabel?: string
44
45 /** 当滚动选择,value 改变时触发 change 事件,event.detail = {value: value};value为数组,表示 picker-view 内的 picker-view-column 当前选择的是第几项(下标从 0 开始)
46 * @supported weapp, alipay, swan, tt, qq, jd, rn
47 */
48 onChange?: CommonEventFunction<PickerViewProps.onChangeEventDetail>
49
50 /** 当滚动选择开始时候触发事件
51 * @supported weapp, alipay, tt, qq
52 */
53 onPickStart?: CommonEventFunction
54
55 /** 当滚动选择结束时候触发事件
56 * @supported weapp, alipay, tt, qq
57 */
58 onPickEnd?: CommonEventFunction
59}
60declare namespace PickerViewProps {
61 interface onChangeEventDetail {
62 value: number[]
63 }
64}
65
66/** 嵌入页面的滚动选择器
67 * 其中只可放置 picker-view-column 组件,其它节点不会显示
68 * @classification forms
69 * @supported weapp, alipay, swan, tt, qq, jd, h5, rn, harmony
70 * @example_react
71 * ```tsx
72 * export default class Picks extends Component {
73 *
74 * constructor () {
75 * super(...arguments)
76 * const date = new Date()
77 * const years = []
78 * const months = []
79 * const days = []
80 * for (let i = 1990; i <= date.getFullYear(); i++) {
81 * years.push(i)
82 * }
83 * for (let i = 1; i <= 12; i++) {
84 * months.push(i)
85 * }
86 * for (let i = 1; i <= 31; i++) {
87 * days.push(i)
88 * }
89 * this.state = {
90 * years: years,
91 * year: date.getFullYear(),
92 * months: months,
93 * month: 2,
94 * days: days,
95 * day: 2,
96 * value: [9999, 1, 1]
97 * }
98 * }
99 *
100 * onChange = e => {
101 * const val = e.detail.value
102 * this.setState({
103 * year: this.state.years[val[0]],
104 * month: this.state.months[val[1]],
105 * day: this.state.days[val[2]],
106 * value: val
107 * })
108 * }
109 *
110 * render() {
111 * return (
112 * <View>
113 * <View>{this.state.year}年{this.state.month}月{this.state.day}日</View>
114 * <PickerView indicatorStyle='height: 50px;' style='width: 100%; height: 300px;' value={this.state.value} onChange={this.onChange}>
115 * <PickerViewColumn>
116 * {this.state.years.map(item => {
117 * return (
118 * <View>{item}年</View>
119 * );
120 * })}
121 * </PickerViewColumn>
122 * <PickerViewColumn>
123 * {this.state.months.map(item => {
124 * return (
125 * <View>{item}月</View>
126 * )
127 * })}
128 * </PickerViewColumn>
129 * <PickerViewColumn>
130 * {this.state.days.map(item => {
131 * return (
132 * <View>{item}日</View>
133 * )
134 * })}
135 * </PickerViewColumn>
136 * </PickerView>
137 * </View>
138 * )
139 * }
140 * }
141 * ```
142 * @example_vue
143 * ```html
144 * <template>
145 * <view class="taro-example">
146 * <view>{{year}}年{{month}}月{{day}}日</view>
147 * <picker-view indicator-style="height: 30px;" style="width: 100%; height: 300px;" :value="value" `@change="onChange">
148 * <picker-view-column>
149 * <view v-for="(item, index) in years" :key="index">{{item}}年</view>
150 * </picker-view-column>
151 * <picker-view-column>
152 * <view v-for="(item, index) in months" :key="index">{{item}}月</view>
153 * </picker-view-column>
154 * <picker-view-column>
155 * <view v-for="(item, index) in days" :key="index">{{item}}日</view>
156 * </picker-view-column>
157 * </picker-view>
158 * </view>
159 * </template>
160 *
161 * <script>
162 * export default {
163 * name: "Index",
164 * data() {
165 * const date = new Date()
166 * const years = []
167 * const months = []
168 * const days = []
169 * for (let i = 1990; i <= date.getFullYear(); i++) {
170 * years.push(i)
171 * }
172 * for (let i = 1; i <= 12; i++) {
173 * months.push(i)
174 * }
175 * for (let i = 1; i <= 31; i++) {
176 * days.push(i)
177 * }
178 * return {
179 * years: years,
180 * year: date.getFullYear(),
181 * months: months,
182 * month: 2,
183 * days: days,
184 * day: 2,
185 * value: [3, 1, 1]
186 * }
187 * },
188 *
189 * methods: {
190 * onChange: function(e) {
191 * const val = e.detail.value
192 * console.log(val)
193 * this.year = this.years[val[0]]
194 * this.month = this.months[val[1]]
195 * this.day = this.days[val[2]]
196 * }
197 * }
198 * }
199 * </script>
200 * ```
201 * @see https://developers.weixin.qq.com/miniprogram/dev/component/picker-view.html
202 */
203declare const PickerView: ComponentType<PickerViewProps>
204export { PickerView, PickerViewProps }