Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(RadioGroup): new component #730

Merged
merged 16 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/components/content/ComponentPreset.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const name = `U${upperFirst(camelName)}`
const preset = config[camelName]

const { data: ast } = await useAsyncData(`${name}-preset`, () => transformContent('content:_markdown.md', `
\`\`\`json
\`\`\`json [${name}.vue]
${JSON.stringify(preset, null, 2)}
\`\`\`\
`, {
Expand Down
8 changes: 8 additions & 0 deletions docs/components/content/examples/FormExampleElements.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const state = reactive({
checkbox: undefined,
toggle: undefined,
radio: undefined,
radioGroup: undefined,
switch: undefined,
range: undefined
})
Expand All @@ -38,6 +39,9 @@ const schema = z.object({
radio: z.string().refine(value => value === 'option-2', {
message: 'Select Option 2'
}),
radioGroup: z.string().refine(value => value === 'option-2', {
message: 'Select Option 2'
}),
range: z.number().max(20, { message: 'Must be less than 20' })
})

Expand Down Expand Up @@ -77,6 +81,10 @@ async function onSubmit (event: FormSubmitEvent<Schema>) {
<UCheckbox v-model="state.checkbox" label="Check me" />
</UFormGroup>

<UFormGroup name="radioGroup" label="Radio Group">
<URadioGroup v-model="state.radioGroup" :options="options" />
</UFormGroup>

<UFormGroup name="radio" label="Radio">
<URadio v-for="option in options" :key="option.value" v-model="state.radio" v-bind="option">
{{ option.label }}
Expand Down
20 changes: 6 additions & 14 deletions docs/components/content/examples/RadioExample.vue
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>
18 changes: 18 additions & 0 deletions docs/components/content/examples/RadioGroupExample.vue
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 docs/components/content/examples/RadioGroupLabelExample.vue
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>
2 changes: 1 addition & 1 deletion docs/content/3.forms/5.checkbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ props:

### Required

Use the `required` prop to display a red star next to the label.
Use the `required` prop to display a red star next to the label of the Checkbox.

::component-card
---
Expand Down
156 changes: 156 additions & 0 deletions docs/content/3.forms/6.radio-group.md
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"}
98 changes: 0 additions & 98 deletions docs/content/3.forms/6.radio.md

This file was deleted.

Loading