Skip to content

Commit

Permalink
feat(RadioGroup): configurable label size (#881)
Browse files Browse the repository at this point in the history
  • Loading branch information
connerblanton committed Oct 27, 2023
1 parent 327c776 commit 5a2644b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
4 changes: 4 additions & 0 deletions docs/content/3.forms/6.radio-group.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ Alternatively, you can use individual Radio components:

:component-example{component="radio-example"}

::callout{icon="i-heroicons-light-bulb"}
If using the RadioGroup component, you can customize the Radio options by using the `uiRadio` prop.
::

### Legend

Use the `legend` prop to add a legend to the RadioGroup.
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/components/forms/Radio.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
v-bind="attrs"
>
</div>
<div v-if="label || $slots.label" class="ms-3 text-sm">
<div v-if="label || $slots.label" class="ms-3 inline-flex items-center">
<label :for="id" :class="ui.label">
<slot name="label">{{ label }}</slot>
<span v-if="required" :class="ui.required">*</span>
Expand Down
13 changes: 11 additions & 2 deletions src/runtime/components/forms/RadioGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
:model-value="modelValue"
:value="option.value"
:disabled="disabled"
:ui="uiRadio"
@change="onUpdate(option.value)"
>
<template #label>
Expand All @@ -33,10 +34,11 @@ import { mergeConfig, get } from '../../utils'
import type { Strategy } from '../../types'
// @ts-expect-error
import appConfig from '#build/app.config'
import { radioGroup } from '#ui/ui.config'
import { radioGroup, radio } from '#ui/ui.config'
import colors from '#ui-colors'
const config = mergeConfig<typeof radioGroup>(appConfig.ui.strategy, appConfig.ui.select, radioGroup)
const config = mergeConfig<typeof radioGroup>(appConfig.ui.strategy, appConfig.ui.radioGroup, radioGroup)
const configRadio = mergeConfig<typeof radio>(appConfig.ui.strategy, appConfig.ui.radio, radio)
export default defineComponent({
components: {
Expand Down Expand Up @@ -86,11 +88,16 @@ export default defineComponent({
ui: {
type: Object as PropType<Partial<typeof config & { strategy?: Strategy }>>,
default: undefined
},
uiRadio: {
type: Object as PropType<Partial<typeof configRadio & { strategy?: Strategy }>>,
default: undefined
}
},
emits: ['update:modelValue', 'change'],
setup (props, { emit }) {
const { ui, attrs } = useUI('radioGroup', toRef(props, 'ui'), config, toRef(props, 'class'))
const { ui: uiRadio } = useUI('radio', toRef(props, 'uiRadio'), configRadio)
const { emitFormChange, color, name } = useFormGroup(props, config)
provide('radio-group', { color, name })
Expand Down Expand Up @@ -131,6 +138,8 @@ export default defineComponent({
return {
// eslint-disable-next-line vue/no-dupe-keys
ui,
// eslint-disable-next-line vue/no-dupe-keys
uiRadio,
attrs,
normalizedOptions,
// eslint-disable-next-line vue/no-dupe-keys
Expand Down
6 changes: 3 additions & 3 deletions src/runtime/ui.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -777,9 +777,9 @@ export const radio = {
background: 'bg-white dark:bg-gray-900',
border: 'border border-gray-300 dark:border-gray-700',
ring: 'focus-visible:ring-2 focus-visible:ring-{color}-500 dark:focus-visible:ring-{color}-400 focus-visible:ring-offset-2 focus-visible:ring-offset-white dark:focus-visible:ring-offset-gray-900',
label: 'font-medium text-gray-700 dark:text-gray-200',
required: 'text-red-500 dark:text-red-400',
help: 'text-gray-500 dark:text-gray-400',
label: 'text-sm font-medium text-gray-700 dark:text-gray-200',
required: 'text-sm text-red-500 dark:text-red-400',
help: 'text-sm text-gray-500 dark:text-gray-400',
default: {
color: 'primary'
}
Expand Down

1 comment on commit 5a2644b

@vercel
Copy link

@vercel vercel bot commented on 5a2644b Oct 27, 2023

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-git-dev-nuxt-js.vercel.app
ui.nuxt.com
ui-nuxt-js.vercel.app

Please sign in to comment.