|
| 1 | +## Radio |
| 2 | + |
| 3 | +Radio component. You could set the options and the position of the radio's icon. |
| 4 | + |
| 5 | +### Example |
| 6 | + |
| 7 | +- Basic usage |
| 8 | + |
| 9 | + ```html |
| 10 | + <cube-radio v-model="selected" :options="options" /> |
| 11 | + ``` |
| 12 | + ```js |
| 13 | + export default { |
| 14 | + data() { |
| 15 | + return { |
| 16 | + selected: '', |
| 17 | + options: ['Option1', 'Option2'] |
| 18 | + } |
| 19 | + } |
| 20 | + } |
| 21 | + ``` |
| 22 | + |
| 23 | + The value of `options` is an array. The default `selected` value is `''`, which means no option will be selected by defaut. If you clicked one radio option, the `selected` will be set as the value of this option. |
| 24 | + |
| 25 | +- Configure the label, value, disabled state of options and the position of icon. |
| 26 | + |
| 27 | + ```html |
| 28 | + <cube-radio v-model="selected2" :options="options2" position="right" /> |
| 29 | + ``` |
| 30 | + ```js |
| 31 | + export default { |
| 32 | + data() { |
| 33 | + return { |
| 34 | + selected2: '3', |
| 35 | + options2: [ |
| 36 | + { |
| 37 | + label: 'Option1', |
| 38 | + value: '1' |
| 39 | + }, |
| 40 | + { |
| 41 | + label: 'Option2', |
| 42 | + value: '2' |
| 43 | + }, |
| 44 | + { |
| 45 | + label: 'Option3', |
| 46 | + value: '3', |
| 47 | + disabled: true |
| 48 | + } |
| 49 | + ] |
| 50 | + } |
| 51 | + } |
| 52 | + } |
| 53 | + ``` |
| 54 | + |
| 55 | + The `options` value can be an array which has some object items. You can set `label` and `value` in each item, and use `disabled` to configure whether the radio item's state is disabled. |
| 56 | + |
| 57 | + If the `position` is set as `'right'`, the radio's icon will be posited at the right of the label. |
| 58 | + |
| 59 | +- Horizontal order |
| 60 | + |
| 61 | + ```html |
| 62 | + <cube-radio v-model="selected3" :options="options3" :horizontal="true" /> |
| 63 | + ``` |
| 64 | + ```js |
| 65 | + export default { |
| 66 | + data() { |
| 67 | + return { |
| 68 | + selected3: '3', |
| 69 | + options3: [ |
| 70 | + { |
| 71 | + label: '1', |
| 72 | + value: '1' |
| 73 | + }, |
| 74 | + { |
| 75 | + label: '2', |
| 76 | + value: '2' |
| 77 | + }, |
| 78 | + { |
| 79 | + label: '3', |
| 80 | + value: '3', |
| 81 | + disabled: true |
| 82 | + } |
| 83 | + ] |
| 84 | + } |
| 85 | + } |
| 86 | + } |
| 87 | + ``` |
| 88 | + |
| 89 | + You can use `horizontal` to configure the style to horizontal layout. |
| 90 | + |
| 91 | +### Props configuration |
| 92 | + |
| 93 | +| Attribute | Description | Type | Accepted Values | Default | |
| 94 | +| - | - | - | - | - | |
| 95 | +| options | the array of radio options | Array | - | - | |
| 96 | +| position | icon position | String | left/right | left | |
| 97 | +| horizontal | whether use horizontal layout | Boolean | true/false | false | |
| 98 | + |
| 99 | +* `options` sub configuration |
| 100 | + |
| 101 | +| Attribute | Description | Type | |
| 102 | +| - | - | - | |
| 103 | +| label | the text of label | String | |
| 104 | +| value | the value of radio item | String/Number | |
| 105 | +| disabled | whether the item is disabled | Boolean | |
| 106 | + |
| 107 | +Note: Each item of `options` can be an string, Which means both the `label` and `value` will be set as this string. |
0 commit comments