UNPKG

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