diff --git a/docs/content/2.components/radio-group.md b/docs/content/2.components/radio-group.md index e8cbc7b5..be5790f5 100644 --- a/docs/content/2.components/radio-group.md +++ b/docs/content/2.components/radio-group.md @@ -53,6 +53,20 @@ props: This prop also work on the Radio component. :: +### Orientation + +You can change the orientation of the divider by setting the `orientation` prop to `horizontal` or `vertical`. Defaults to `vertical`. + +::component-card +--- +baseProps: + options: [{ value: 'email', label: 'Email' }, { value: 'sms', label: 'Phone (SMS)' }, { value: 'push', label: 'Push notification' }] + modelValue: 'sms' +props: + orientation: 'horizontal' +--- +:: + ### Disabled Use the `disabled` prop to disable the RadioGroup. diff --git a/playground/pages/radio-group.vue b/playground/pages/radio-group.vue index 175df8a2..e1310798 100644 --- a/playground/pages/radio-group.vue +++ b/playground/pages/radio-group.vue @@ -55,5 +55,6 @@ const optionsWithDescription = [ + diff --git a/src/runtime/components/RadioGroup.vue b/src/runtime/components/RadioGroup.vue index e12419f7..7099f3d8 100644 --- a/src/runtime/components/RadioGroup.vue +++ b/src/runtime/components/RadioGroup.vue @@ -43,7 +43,7 @@ import { RadioGroupRoot, RadioGroupItem, RadioGroupIndicator, Label, useForwardP import { reactivePick } from '@vueuse/core' import { useId, useFormField } from '#imports' -const props = defineProps>() +const props = withDefaults(defineProps>(), { orientation: 'vertical' }) const emits = defineEmits() defineSlots>() @@ -56,7 +56,8 @@ const ui = computed(() => tv({ extend: radioGroup, slots: props.ui })({ size: size.value, color: color.value, disabled: disabled.value, - required: props.required + required: props.required, + orientation: props.orientation })) function normalizeOption(option: any) { diff --git a/src/theme/radio-group.ts b/src/theme/radio-group.ts index 450c0e10..82765b76 100644 --- a/src/theme/radio-group.ts +++ b/src/theme/radio-group.ts @@ -1,7 +1,7 @@ export default (config: { colors: string[] }) => ({ slots: { root: 'relative', - fieldset: 'flex flex-col', + fieldset: 'flex', legend: 'mb-1 block font-medium text-gray-700 dark:text-gray-200', option: 'flex items-start', base: 'rounded-full ring ring-inset ring-gray-300 dark:ring-gray-700 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-offset-white dark:focus-visible:outline-offset-gray-900', @@ -16,6 +16,15 @@ export default (config: { colors: string[] }) => ({ base: `focus-visible:outline-${color}-500 dark:focus-visible:outline-${color}-400`, indicator: `bg-${color}-500 dark:bg-${color}-400` }])), + orientation: { + horizontal: { + fieldset: 'flex-row', + wrapper: 'me-2' + }, + vertical: { + fieldset: 'flex-col' + } + }, size: { xs: { fieldset: 'gap-0.5', diff --git a/test/components/RadioGroup.spec.ts b/test/components/RadioGroup.spec.ts index 24928e87..4ecd646f 100644 --- a/test/components/RadioGroup.spec.ts +++ b/test/components/RadioGroup.spec.ts @@ -23,6 +23,7 @@ describe('RadioGroup', () => { ...colors.map((color: string) => [`with color ${color}`, { props: { options, color } }]), ['with class', { props: { options, class: 'absolute' } }], ['with ui', { props: { ui: { options, wrapper: 'ms-4' } } }], + ['with orientation', { props: { options, orientation: 'horizontal' } }], // Slots ['with legend slot', { props: { options }, slots: { label: () => 'Legend slot' } }], ['with label slot', { props: { options }, slots: { label: () => 'Label slot' } }], diff --git a/test/components/__snapshots__/RadioGroup.spec.ts.snap b/test/components/__snapshots__/RadioGroup.spec.ts.snap index 360e9e8d..364073bc 100644 --- a/test/components/__snapshots__/RadioGroup.spec.ts.snap +++ b/test/components/__snapshots__/RadioGroup.spec.ts.snap @@ -1,11 +1,11 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html exports[`RadioGroup > renders with class correctly 1`] = ` -"
+"
-
@@ -14,7 +14,7 @@ exports[`RadioGroup > renders with class correctly 1`] = `
-
@@ -23,7 +23,7 @@ exports[`RadioGroup > renders with class correctly 1`] = `
-
@@ -36,11 +36,11 @@ exports[`RadioGroup > renders with class correctly 1`] = ` `; exports[`RadioGroup > renders with color green correctly 1`] = ` -"
+"
-
@@ -49,7 +49,7 @@ exports[`RadioGroup > renders with color green correctly 1`] = `
-
@@ -58,7 +58,7 @@ exports[`RadioGroup > renders with color green correctly 1`] = `
-
@@ -71,11 +71,11 @@ exports[`RadioGroup > renders with color green correctly 1`] = ` `; exports[`RadioGroup > renders with color primary correctly 1`] = ` -"
+"
-
@@ -84,7 +84,7 @@ exports[`RadioGroup > renders with color primary correctly 1`] = `
-
@@ -93,7 +93,7 @@ exports[`RadioGroup > renders with color primary correctly 1`] = `
-
@@ -106,11 +106,11 @@ exports[`RadioGroup > renders with color primary correctly 1`] = ` `; exports[`RadioGroup > renders with color red correctly 1`] = ` -"
+"
-
@@ -119,7 +119,7 @@ exports[`RadioGroup > renders with color red correctly 1`] = `
-
@@ -128,7 +128,7 @@ exports[`RadioGroup > renders with color red correctly 1`] = `
-
@@ -141,11 +141,11 @@ exports[`RadioGroup > renders with color red correctly 1`] = ` `; exports[`RadioGroup > renders with defaultValue correctly 1`] = ` -"
+"
-
@@ -153,7 +153,7 @@ exports[`RadioGroup > renders with defaultValue correctly 1`] = `
-
@@ -162,7 +162,7 @@ exports[`RadioGroup > renders with defaultValue correctly 1`] = `
-
@@ -175,11 +175,11 @@ exports[`RadioGroup > renders with defaultValue correctly 1`] = ` `; exports[`RadioGroup > renders with description correctly 1`] = ` -"
+"
-
@@ -188,7 +188,7 @@ exports[`RadioGroup > renders with description correctly 1`] = `
-
@@ -197,7 +197,7 @@ exports[`RadioGroup > renders with description correctly 1`] = `
-
@@ -210,7 +210,7 @@ exports[`RadioGroup > renders with description correctly 1`] = ` `; exports[`RadioGroup > renders with description slot correctly 1`] = ` -"
+"
@@ -218,11 +218,11 @@ exports[`RadioGroup > renders with description slot correctly 1`] = ` `; exports[`RadioGroup > renders with disabled correctly 1`] = ` -"
+"
-
@@ -231,7 +231,7 @@ exports[`RadioGroup > renders with disabled correctly 1`] = `
-
@@ -240,7 +240,7 @@ exports[`RadioGroup > renders with disabled correctly 1`] = `
-
@@ -253,33 +253,33 @@ exports[`RadioGroup > renders with disabled correctly 1`] = ` `; exports[`RadioGroup > renders with label slot correctly 1`] = ` -"
+"
-
-
+
-
-
+
-
-
+
@@ -288,33 +288,33 @@ exports[`RadioGroup > renders with label slot correctly 1`] = ` `; exports[`RadioGroup > renders with legend slot correctly 1`] = ` -"
+"
-
-
+
-
-
+
-
-
+
@@ -323,11 +323,11 @@ exports[`RadioGroup > renders with legend slot correctly 1`] = ` `; exports[`RadioGroup > renders with options correctly 1`] = ` -"
+"
-
@@ -336,7 +336,7 @@ exports[`RadioGroup > renders with options correctly 1`] = `
-
@@ -345,7 +345,7 @@ exports[`RadioGroup > renders with options correctly 1`] = `
-
@@ -357,12 +357,47 @@ exports[`RadioGroup > renders with options correctly 1`] = `
" `; +exports[`RadioGroup > renders with orientation correctly 1`] = ` +"
+
+ +
+
+
+ +
+
+
+
+
+ +
+
+
+
+
+ +
+
+
+
" +`; + exports[`RadioGroup > renders with required correctly 1`] = ` -"
+"
Legend
-
@@ -371,7 +406,7 @@ exports[`RadioGroup > renders with required correctly 1`] = `
-
@@ -380,7 +415,7 @@ exports[`RadioGroup > renders with required correctly 1`] = `
-
@@ -393,11 +428,11 @@ exports[`RadioGroup > renders with required correctly 1`] = ` `; exports[`RadioGroup > renders with size lg correctly 1`] = ` -"
+"
-
@@ -406,7 +441,7 @@ exports[`RadioGroup > renders with size lg correctly 1`] = `
-
@@ -415,7 +450,7 @@ exports[`RadioGroup > renders with size lg correctly 1`] = `
-
@@ -428,11 +463,11 @@ exports[`RadioGroup > renders with size lg correctly 1`] = ` `; exports[`RadioGroup > renders with size md correctly 1`] = ` -"
+"
-
@@ -441,7 +476,7 @@ exports[`RadioGroup > renders with size md correctly 1`] = `
-
@@ -450,7 +485,7 @@ exports[`RadioGroup > renders with size md correctly 1`] = `
-
@@ -463,11 +498,11 @@ exports[`RadioGroup > renders with size md correctly 1`] = ` `; exports[`RadioGroup > renders with size sm correctly 1`] = ` -"
+"
-
@@ -476,7 +511,7 @@ exports[`RadioGroup > renders with size sm correctly 1`] = `
-
@@ -485,7 +520,7 @@ exports[`RadioGroup > renders with size sm correctly 1`] = `
-
@@ -498,11 +533,11 @@ exports[`RadioGroup > renders with size sm correctly 1`] = ` `; exports[`RadioGroup > renders with size xl correctly 1`] = ` -"
+"
-
@@ -511,7 +546,7 @@ exports[`RadioGroup > renders with size xl correctly 1`] = `
-
@@ -520,7 +555,7 @@ exports[`RadioGroup > renders with size xl correctly 1`] = `
-
@@ -533,11 +568,11 @@ exports[`RadioGroup > renders with size xl correctly 1`] = ` `; exports[`RadioGroup > renders with size xs correctly 1`] = ` -"
+"
-
@@ -546,7 +581,7 @@ exports[`RadioGroup > renders with size xs correctly 1`] = `
-
@@ -555,7 +590,7 @@ exports[`RadioGroup > renders with size xs correctly 1`] = `
-
@@ -568,7 +603,7 @@ exports[`RadioGroup > renders with size xs correctly 1`] = ` `; exports[`RadioGroup > renders with ui correctly 1`] = ` -"
+"