2020-08-13 11:47:56 +08:00
# ButtonGroup
## Demos
### Stylistic variants
2021-10-20 01:11:27 +08:00
Available style variants for the [`ui` ](#props-ui ) prop: `primary` / `strong` / `basic` .
2020-08-13 11:47:56 +08:00
[[ demo src="/demo/button-group/style.vue" ]]
### Size variants
2021-10-20 01:11:27 +08:00
Available size variants for the [`ui` ](#props-ui ) prop: `xs` / `s` / `m` / `l` / `xl` .
2020-08-13 11:47:56 +08:00
[[ demo src="/demo/button-group/size.vue" ]]
2021-11-05 11:47:31 +08:00
### Using datasource
2020-08-13 11:47:56 +08:00
2021-10-20 01:11:27 +08:00
Use the [`items` ](#props-items ) prop to provide content with a datasource.
2020-08-13 11:47:56 +08:00
[[ demo src="/demo/button-group/items.vue" ]]
### Disabled state
2021-10-20 01:11:27 +08:00
Use the [`disabled` ](#props-disabled ) prop to set the button group to disabled state.
2020-08-13 11:47:56 +08:00
[[ demo src="/demo/button-group/disabled.vue" ]]
## API
### Props
| Name | Type | Default | Description |
| -- | -- | -- | -- |
2021-10-20 01:11:27 +08:00
| ``ui`` | `string=` | - | [^ui] |
| ``items`` | `Array<Object>` | - | [^items] |
| ``disabled`` | `boolean=` | `false` | Whether the button is disabled. |
2020-08-13 11:47:56 +08:00
^^^ui
Style variants. A space-separated list of enum values.
+++Enum values
| Value | Description |
| -- | -- |
| `primary` | Primary buttons. |
| `strong` | Strong buttons. |
2020-09-22 11:06:13 +08:00
| `basic` | Basic buttons. |
2020-08-13 11:47:56 +08:00
| `xs` | Extra small. |
| `s` | Small. |
| `m` | Medium. |
| `l` | Large. |
| `xl` | Extra large. |
+++
^^^
^^^items
The datasource array for buttons in the group. The type of each item is `{label, value}` .
+++Properties
| Name | Type | Description |
| -- | -- | -- |
| `label` | `string` | The label text of the button. |
| `value` | `*=` | Will emit an event with the same name when given a string value. |
+++
^^^
### Slots
| Name | Description |
| -- | -- |
2021-10-20 01:11:27 +08:00
| ``default`` | Button group's content. |
| ``item`` | [^slot-item] |
2020-08-13 11:47:56 +08:00
2020-12-22 16:33:30 +08:00
^^^slot-item
2020-08-13 11:47:56 +08:00
The content of each button.
2021-10-20 01:11:27 +08:00
Shows the text specified by the `label` property by default.
2020-08-13 11:47:56 +08:00
+++Scope properties
| Name | Type | Description |
| -- | -- | -- |
| `label` | `string` | The label text of the button. |
| `value` | `*=` | The value of button item. |
| `index` | `number` | The index of the button within `items` . |
| `disabled` | `boolean=` | Whether the button is disabled. |
+++
Additionally, custom properties apart from the listed ones will also be passes into the scope object via `v-bind` .
^^^
### Events
| Name | Description |
| -- | -- |
2021-10-20 01:11:27 +08:00
| ``click`` | [^click-event] |
2020-08-13 11:47:56 +08:00
| < var > < value> < / var > | [^value-var-event] |
^^^click-event
Triggered upon clicks. The callback parameter list is `(item, index)` .
+++Parameters
| Name | Type | Description |
| -- | -- | -- |
| `item` | `{label: string, value: *=, ...}` | Datasource item. |
| `index` | `number` | The index of the button within `items` . |
+++
^^^
^^^value-var-event
2021-10-20 01:11:27 +08:00
If the corresponding item has a string `value` property, an event with the name of `value` value will be emitted each time the button is clicked. It shares the same parameters with the [`click` ](#events-click ) event.
2020-08-13 11:47:56 +08:00
^^^