-
Notifications
You must be signed in to change notification settings - Fork 462
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(RadioGroup): new component (#730)
Co-authored-by: Benjamin Canac <canacb1@gmail.com>
- Loading branch information
1 parent
f785ecd
commit 23d5dc7
Showing
11 changed files
with
369 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,15 @@ | ||
<script setup> | ||
const methods = [{ | ||
name: 'email', | ||
value: 'email', | ||
label: 'Email' | ||
}, { | ||
name: 'sms', | ||
value: 'sms', | ||
label: 'Phone (SMS)' | ||
}, { | ||
name: 'push', | ||
value: 'push', | ||
label: 'Push notification' | ||
}] | ||
const methods = [ | ||
{ value: 'email', label: 'Email' }, | ||
{ value: 'sms', label: 'Phone (SMS)' }, | ||
{ value: 'push', label: 'Push notification' } | ||
] | ||
const selected = ref('sms') | ||
</script> | ||
|
||
<template> | ||
<div class="space-y-1"> | ||
<URadio v-for="method of methods" :key="method.name" v-model="selected" v-bind="method" /> | ||
<URadio v-for="method of methods" :key="method.value" v-model="selected" v-bind="method" /> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<script setup> | ||
const options = [{ | ||
value: 'email', | ||
label: 'Email' | ||
}, { | ||
value: 'sms', | ||
label: 'Phone (SMS)' | ||
}, { | ||
value: 'push', | ||
label: 'Push notification' | ||
}] | ||
const selected = ref('sms') | ||
</script> | ||
|
||
<template> | ||
<URadioGroup v-model="selected" legend="Choose something" :options="options" /> | ||
</template> |
20 changes: 20 additions & 0 deletions
20
docs/components/content/examples/RadioGroupLabelExample.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<script setup> | ||
const options = [ | ||
{ value: 'email', label: 'Email', icon: 'i-heroicons-at-symbol' }, | ||
{ value: 'sms', label: 'Phone (SMS)', icon: 'i-heroicons-phone' }, | ||
{ value: 'push', label: 'Push notification', icon: 'i-heroicons-bell' } | ||
] | ||
const selected = ref('sms') | ||
</script> | ||
|
||
<template> | ||
<URadioGroup v-model="selected" :options="options"> | ||
<template #label="{ option }"> | ||
<p class="italic"> | ||
<UIcon :name="option.icon" /> | ||
{{ option.label }} | ||
</p> | ||
</template> | ||
</URadioGroup> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
--- | ||
title: RadioGroup | ||
description: Display a set of radio buttons. | ||
navigation: | ||
badge: New | ||
links: | ||
- label: GitHub | ||
icon: i-simple-icons-github | ||
to: https://github.com/nuxt/ui/blob/dev/src/runtime/components/forms/RadioGroup.vue | ||
--- | ||
|
||
## Usage | ||
|
||
Use a `v-model` to make the RadioGroup reactive. | ||
|
||
:component-example{component="radio-group-example"} | ||
|
||
Alternatively, you can use individual Radio components: | ||
|
||
:component-example{component="radio-example"} | ||
|
||
### Legend | ||
|
||
Use the `legend` prop to add a legend to the RadioGroup. | ||
|
||
::component-card | ||
--- | ||
baseProps: | ||
options: [{ value: 'email', label: 'Email' }, { value: 'sms', label: 'Phone (SMS)' }, { value: 'push', label: 'Push notification' }] | ||
modelValue: 'sms' | ||
props: | ||
legend: 'Legend' | ||
--- | ||
:: | ||
|
||
### Style | ||
|
||
Use the `color` prop to change the style of the RadioGroup. | ||
|
||
::component-card | ||
--- | ||
baseProps: | ||
options: [{ value: 'email', label: 'Email' }, { value: 'sms', label: 'Phone (SMS)' }, { value: 'push', label: 'Push notification' }] | ||
modelValue: 'sms' | ||
props: | ||
color: 'primary' | ||
--- | ||
:: | ||
|
||
::callout{icon="i-heroicons-light-bulb"} | ||
This prop also work on the Radio component. | ||
:: | ||
|
||
### Disabled | ||
|
||
Use the `disabled` prop to disable the RadioGroup. | ||
|
||
::component-card | ||
--- | ||
baseProps: | ||
options: [{ value: 'email', label: 'Email' }, { value: 'sms', label: 'Phone (SMS)' }, { value: 'push', label: 'Push notification' }] | ||
modelValue: 'sms' | ||
props: | ||
disabled: true | ||
--- | ||
:: | ||
|
||
::callout{icon="i-heroicons-light-bulb"} | ||
This prop also work on the Radio component. | ||
:: | ||
|
||
### Label | ||
|
||
Use the `label` prop to display a label on the right of the Radio. | ||
|
||
::component-card{slug="radio"} | ||
--- | ||
props: | ||
label: 'Label' | ||
--- | ||
:: | ||
|
||
### Required | ||
|
||
Use the `required` prop to display a red star next to the label of the Radio. | ||
|
||
::component-card{slug="radio"} | ||
--- | ||
props: | ||
label: 'Label' | ||
required: true | ||
--- | ||
:: | ||
|
||
### Help | ||
|
||
Use the `help` prop to display some text under the Radio. | ||
|
||
::component-card{slug="radio"} | ||
--- | ||
props: | ||
label: 'Label' | ||
help: 'Please choose one' | ||
--- | ||
:: | ||
|
||
## Slots | ||
|
||
### `label` | ||
|
||
Use the `#label` slot to override the label of each option. | ||
|
||
:component-example{component="radio-group-label-example"} | ||
|
||
Alternatively, you can do the same with individual Radio: | ||
|
||
::component-card{slug="radio"} | ||
--- | ||
slots: | ||
label: <span class="italic">Label</span> | ||
--- | ||
|
||
#label | ||
[Label]{.italic} | ||
:: | ||
|
||
### `legend` | ||
|
||
Use the `#legend` slot to override the content of the legend. | ||
|
||
::component-card | ||
--- | ||
baseProps: | ||
options: [{ value: 'email', label: 'Email' }, { value: 'sms', label: 'Phone (SMS)' }, { value: 'push', label: 'Push notification' }] | ||
modelValue: 'sms' | ||
slots: | ||
legend: <span class="italic">Legend</span> | ||
--- | ||
|
||
#legend | ||
[Legend]{.italic} | ||
:: | ||
|
||
## Props | ||
|
||
:component-props | ||
|
||
:u-divider{label="Radio" type="dashed" class="my-12"} | ||
|
||
:component-props{slug="radio"} | ||
|
||
## Preset | ||
|
||
:component-preset | ||
|
||
:component-preset{slug="radio"} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
23d5dc7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
ui – ./
ui-nuxt-js.vercel.app
ui-git-dev-nuxt-js.vercel.app
ui.nuxt.com