UNPKG

5.02 kBTypeScriptView Raw
1import { ComponentType } from 'react'
2import { StandardProps, CommonEventFunction, FormItemProps } from './common'
3interface RadioProps extends StandardProps {
4 /** `<Radio/>` 标识。当该`<Radio/>` 选中时,`<RadioGroup/>`的 change 事件会携带`<Radio/>`的 value
5 * @supported weapp, alipay, swan, tt, qq, rn
6 */
7 value?: string
8
9 /** 当前是否选中
10 * @default false
11 * @supported weapp, alipay, swan, tt, qq, h5, rn
12 */
13 checked?: boolean
14
15 /** 是否禁用
16 * @default false
17 * @supported weapp, alipay, swan, tt, qq, h5, rn
18 */
19 disabled?: boolean
20
21 /** Radio 的颜色,同 css 的 color
22 * @default "#09BB07"
23 * @supported weapp, alipay, swan, tt, qq, rn
24 */
25 color?: string
26
27 /** 用于透传 `WebComponents` 上的属性到内部 H5 标签上
28 * @supported h5
29 */
30 nativeProps?: Record<string, unknown>
31
32 /** 无障碍访问,(属性)元素的额外描述
33 * @supported qq
34 */
35 ariaLabel?: string
36
37 /** <radio-group/> 中的选中项发生变化时触发 change 事件,event.detail = {value: 选中项radio的value}
38 * @supported jd
39 */
40 onChange?: CommonEventFunction<{
41 value?: string
42 }>
43}
44
45/** 单选项目
46 * @classification forms
47 * @supported weapp, alipay, swan, tt, qq, h5, rn, harmony
48 * @example_react
49 * ```tsx
50 * export default class PageRadio extends Component {
51 * state = {
52 * list: [
53 * {
54 * value: '美国',
55 * text: '美国',
56 * checked: false
57 * },
58 * {
59 * value: '中国',
60 * text: '中国',
61 * checked: true
62 * },
63 * {
64 * value: '巴西',
65 * text: '巴西',
66 * checked: false
67 * },
68 * {
69 * value: '日本',
70 * text: '日本',
71 * checked: false
72 * },
73 * {
74 * value: '英国',
75 * text: '英国',
76 * checked: false
77 * },
78 * {
79 * value: '法国',
80 * text: '法国',
81 * checked: false
82 * }
83 * ]
84 * }
85 * render () {
86 * return (
87 * <View className='container'>
88 * <Head title='Radio' />
89 * <View className='page-body'>
90 * <View className='page-section'>
91 * <Text>默认样式</Text>
92 * <Radio value='选中' checked>选中</Radio>
93 * <Radio style='margin-left: 20rpx' value='未选中'>未选中</Radio>
94 * </View>
95 * <View className='page-section'>
96 * <Text>推荐展示样式</Text>
97 * <View className='radio-list'>
98 * <RadioGroup>
99 * {this.state.list.map((item, i) => {
100 * return (
101 * <Label className='radio-list__label' for={i} key={i}>
102 * <Radio className='radio-list__radio' value={item.value} checked={item.checked}>{item.text}</Radio>
103 * </Label>
104 * )
105 * })}
106 * </RadioGroup>
107 * </View>
108 * </View>
109 * </View>
110 * </View>
111 * )
112 * }
113 * }
114 * ```
115 * @example_vue
116 * ```html
117 * <template>
118 * <view class="container">
119 * <view class="page-section">
120 * <text>默认样式</text>
121 * <radio value="选中" :checked="true">选中</radio>
122 * <radio style="margin-left: 20rpx;" value="未选中">未选中</radio>
123 * </view>
124 * <view class="page-section">
125 * <text>推荐展示样式(Taro 团队成员):</text>
126 * <radio-group `@change="onChange">
127 * <label v-for="item in list" class="checkbox-list__label">
128 * <radio class="checkbox-list__checkbox" :value="item.value" :checked="item.checked">{{ item.text }}</radio>
129 * </label>
130 * </radio-group>
131 * </view>
132 * </view>
133 * </template>
134 *
135 * <script>
136 * export default {
137 * data() {
138 * return {
139 * list: [
140 * {
141 * value: 'yuche',
142 * text: 'yuche',
143 * checked: false
144 * },
145 * {
146 * value: 'cjj',
147 * text: 'cjj',
148 * checked: false
149 * },
150 * {
151 * value: 'xiexiaoli',
152 * text: 'xiexiaoli',
153 * checked: false
154 * },
155 * {
156 * value: 'honly',
157 * text: 'honly',
158 * checked: false
159 * },
160 * {
161 * value: 'cs',
162 * text: 'cs',
163 * checked: false
164 * },
165 * {
166 * value: 'zhutianjian',
167 * text: 'zhutianjian',
168 * checked: false
169 * },
170 * {
171 * value: '隔壁老李',
172 * text: '隔壁老李',
173 * checked: true
174 * }
175 * ]
176 * }
177 * },
178 * methods: {
179 * onChange: function(e) {
180 * console.log(e.detail.value)
181 * }
182 * }
183 * }
184 * </script>
185 * ```
186 * @see https://developers.weixin.qq.com/miniprogram/dev/component/radio.html
187 */
188declare const Radio: ComponentType<RadioProps>
189export { Radio, RadioProps }