diff --git a/docs/components/content/ComponentPreset.vue b/docs/components/content/ComponentPreset.vue index 1d6bf46c64..ae030292b4 100644 --- a/docs/components/content/ComponentPreset.vue +++ b/docs/components/content/ComponentPreset.vue @@ -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)} \`\`\`\ `, { diff --git a/docs/components/content/examples/FormExampleElements.vue b/docs/components/content/examples/FormExampleElements.vue index 69ad917a9d..3c5c7cbb5a 100644 --- a/docs/components/content/examples/FormExampleElements.vue +++ b/docs/components/content/examples/FormExampleElements.vue @@ -16,6 +16,7 @@ const state = reactive({ checkbox: undefined, toggle: undefined, radio: undefined, + radioGroup: undefined, switch: undefined, range: undefined }) @@ -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' }) }) @@ -77,6 +81,10 @@ async function onSubmit (event: FormSubmitEvent) { + + + + {{ option.label }} diff --git a/docs/components/content/examples/RadioExample.vue b/docs/components/content/examples/RadioExample.vue index 157026f574..36ae7223f8 100644 --- a/docs/components/content/examples/RadioExample.vue +++ b/docs/components/content/examples/RadioExample.vue @@ -1,23 +1,15 @@ diff --git a/docs/components/content/examples/RadioGroupExample.vue b/docs/components/content/examples/RadioGroupExample.vue new file mode 100644 index 0000000000..24747f72b0 --- /dev/null +++ b/docs/components/content/examples/RadioGroupExample.vue @@ -0,0 +1,18 @@ + + + diff --git a/docs/components/content/examples/RadioGroupLabelExample.vue b/docs/components/content/examples/RadioGroupLabelExample.vue new file mode 100644 index 0000000000..6861ebeeb0 --- /dev/null +++ b/docs/components/content/examples/RadioGroupLabelExample.vue @@ -0,0 +1,20 @@ + + + diff --git a/docs/content/3.forms/5.checkbox.md b/docs/content/3.forms/5.checkbox.md index d6c90d2654..8fadda91fb 100644 --- a/docs/content/3.forms/5.checkbox.md +++ b/docs/content/3.forms/5.checkbox.md @@ -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 --- diff --git a/docs/content/3.forms/6.radio-group.md b/docs/content/3.forms/6.radio-group.md new file mode 100644 index 0000000000..adca095316 --- /dev/null +++ b/docs/content/3.forms/6.radio-group.md @@ -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: Label +--- + +#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: Legend +--- + +#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"} diff --git a/docs/content/3.forms/6.radio.md b/docs/content/3.forms/6.radio.md deleted file mode 100644 index ba6ad0d484..0000000000 --- a/docs/content/3.forms/6.radio.md +++ /dev/null @@ -1,98 +0,0 @@ ---- -description: Display a radio field. -links: - - label: GitHub - icon: i-simple-icons-github - to: https://github.com/nuxt/ui/blob/dev/src/runtime/components/forms/Radio.vue ---- - -## Usage - -Use a `v-model` to make the Radio reactive. - -:component-example{component="radio-example"} - -### Label - -Use the `label` prop to display a label on the right. - -::component-card ---- -props: - label: 'Label' ---- -:: - -### Style - -Use the `color` prop to change the style of the Radio. - -::component-card ---- -baseProps: - label: 'Label' -props: - color: 'primary' ---- -:: - -### Required - -Use the `required` prop to display a red star next to the label. - -::component-card ---- -props: - label: 'Label' - required: true ---- -:: - -### Help - -Use the `help` prop to display some text under the Radio. - -::component-card ---- -props: - label: 'Label' - help: 'Please choose one' ---- -:: - -### Disabled - -Use the `disabled` prop to disable the Radio. - -::component-card ---- -baseProps: - label: 'Label' -props: - disabled: true ---- -:: - -## Slots - -### `label` - -Use the `#label` slot to override the content of the label. - -::component-card ---- -slots: - label: Label ---- - -#label - [Label]{.italic} -:: - -## Props - -:component-props - -## Preset - -:component-preset diff --git a/src/runtime/components/forms/Radio.vue b/src/runtime/components/forms/Radio.vue index 1b559cabaa..71767e2b91 100644 --- a/src/runtime/components/forms/Radio.vue +++ b/src/runtime/components/forms/Radio.vue @@ -2,7 +2,7 @@
-