UNPKG

2.04 kBTypeScriptView Raw
1import { ComponentType } from 'react'
2import { StandardProps, CommonEventFunction, FormItemProps } from './common'
3
4interface SwitchProps extends StandardProps, FormItemProps {
5 /** 是否选中
6 * @default false
7 * @supported weapp, h5, rn, swan, alipay, tt
8 */
9 checked?: boolean
10
11 /** 是否禁用
12 * @default false
13 * @supported weapp, rn, tt
14 */
15 disabled?: boolean
16
17 /** 样式,有效值:switch, checkbox
18 * @default "switch"
19 * @supported weapp, h5, rn, swan, alipay, tt
20 */
21 type?: 'switch' | 'checkbox'
22
23 /** switch 的颜色,同 css 的 color
24 * @default "#04BE02"
25 * @supported weapp, h5, rn, swan, alipay, tt
26 */
27 color?: string
28
29 /** checked 改变时触发 change 事件
30 * @supported weapp, rn, tt
31 */
32 onChange?: CommonEventFunction<SwitchProps.onChangeEventDetail>
33
34 /** 用于透传 `WebComponents` 上的属性到内部 H5 标签上
35 * @supported h5
36 */
37 nativeProps?: Record<string, unknown>
38}
39
40declare namespace SwitchProps {
41 interface onChangeEventDetail {
42 value: boolean
43 }
44}
45
46/** 开关选择器
47 * @classification forms
48 * @example_react
49 * ```tsx
50 * export default class PageView extends Component {
51 * constructor() {
52 * super(...arguments)
53 * }
54 *
55 * render() {
56 * return (
57 * <View className='components-page'>
58 * <Text>默认样式</Text>
59 * <Switch checked/>
60 * <Switch/>
61 * <Text>推荐展示样式</Text>
62 * <Switch checked/>
63 * <Switch/>
64 * </View>
65 * )
66 * }
67 * }
68 * ```
69 * @example_vue
70 * ```html
71 * <template>
72 * <view class='components-page'>
73 * <text>默认样式</text>
74 * <switch :checked="true" />
75 * <switch />
76 * <text>推荐展示样式</text>
77 * <switch :checked="true" />
78 * <switch />
79 * </view>
80 * </template>
81 * ```
82 * @supported weapp, h5, rn, swan, alipay, tt
83 * @see https://developers.weixin.qq.com/miniprogram/dev/component/switch.html
84 */
85declare const Switch: ComponentType<SwitchProps>
86
87export { Switch, SwitchProps }