diff --git a/docs/app/components/content/ComponentCode.vue b/docs/app/components/content/ComponentCode.vue index 5aac82bf..0641bf24 100644 --- a/docs/app/components/content/ComponentCode.vue +++ b/docs/app/components/content/ComponentCode.vue @@ -153,7 +153,8 @@ const options = computed(() => { const items = propItems.length ? propItems.map((item: any) => ({ value: item, - label: String(item) + label: String(item), + chip: key.toLowerCase().endsWith('color') ? { color: item } : undefined })) : prop?.type === 'boolean' || prop?.type === 'boolean | undefined' ? [{ value: true, label: 'true' }, { value: false, label: 'false' }] diff --git a/docs/app/components/content/examples/form/FormExampleElements.vue b/docs/app/components/content/examples/form/FormExampleElements.vue index a841fce1..4ab598da 100644 --- a/docs/app/components/content/examples/form/FormExampleElements.vue +++ b/docs/app/components/content/examples/form/FormExampleElements.vue @@ -30,6 +30,9 @@ const schema = z.object({ radioGroup: z.string().refine(value => value === 'option-2', { message: 'Select Option 2' }), + checkboxGroup: z.any().refine(values => !!values?.find((option: any) => option === 'option-2'), { + message: 'Include Option 2' + }), slider: z.number().max(20, { message: 'Must be less than 20' }), pin: z.string().regex(/^\d$/).array().length(5) }) @@ -101,11 +104,14 @@ async function onSubmit(event: FormSubmitEvent) { - - - - - +
+ + + + + + +
diff --git a/docs/content/3.components/checkbox-group.md b/docs/content/3.components/checkbox-group.md new file mode 100644 index 00000000..cd103877 --- /dev/null +++ b/docs/content/3.components/checkbox-group.md @@ -0,0 +1,349 @@ +--- +title: CheckboxGroup +description: A set of checklist buttons to select multiple option from a list. +category: form +links: + - label: CheckboxGroup + icon: i-custom-reka-ui + to: https://reka-ui.com/docs/components/checkbox#group-root + - label: GitHub + icon: i-simple-icons-github + to: https://github.com/nuxt/ui/tree/v3/src/runtime/components/CheckboxGroup.vue +navigation.badge: Soon +--- + + +## Usage + +Use the `v-model` directive to control the value of the CheckboxGroup or the `default-value` prop to set the initial value when you do not need to control its state. + +### Items + +Use the `items` prop as an array of strings or numbers: + +::component-code +--- +prettier: true +ignore: + - modelValue + - items +external: + - items + - modelValue +externalTypes: + - CheckboxGroupItem[] + - CheckboxGroupValue[] +props: + modelValue: + - 'System' + items: + - 'System' + - 'Light' + - 'Dark' +--- +:: + +You can also pass an array of objects with the following properties: + +- `label?: string`{lang="ts-type"} +- `description?: string`{lang="ts-type"} +- [`value?: string`{lang="ts-type"}](#value-key) +- `disabled?: boolean`{lang="ts-type"} + +::component-code +--- +ignore: + - modelValue + - items +external: + - items + - modelValue +externalTypes: + - CheckboxGroupItem[] + - CheckboxGroupValue[] +props: + modelValue: + - 'system' + items: + - label: 'System' + description: 'This is the first option.' + value: 'system' + - label: 'Light' + description: 'This is the second option.' + value: 'light' + - label: 'Dark' + description: 'This is the third option.' + value: 'dark' +--- +:: + +::caution +When using objects, you need to reference the `value` property of the object in the `v-model` directive or the `default-value` prop. +:: + +### Value Key + +You can change the property that is used to set the value by using the `value-key` prop. Defaults to `value`. + +::component-code +--- +ignore: + - modelValue + - items + - valueKey +external: + - items + - modelValue +externalTypes: + - CheckboxGroupItem[] + - CheckboxGroupValue[] +props: + modelValue: + - 'light' + valueKey: 'id' + items: + - label: 'System' + description: 'This is the first option.' + id: 'system' + - label: 'Light' + description: 'This is the second option.' + id: 'light' + - label: 'Dark' + description: 'This is the third option.' + id: 'dark' +--- +:: + +### Legend + +Use the `legend` prop to set the legend of the CheckboxGroup. + +::component-code +--- +prettier: true +ignore: + - defaultValue + - items +external: + - items +externalTypes: + - CheckboxGroupItem[] +props: + legend: 'Theme' + defaultValue: + - 'System' + items: + - 'System' + - 'Light' + - 'Dark' +--- +:: + +### Color + +Use the `color` prop to change the color of the CheckboxGroup. + +::component-code +--- +prettier: true +ignore: + - defaultValue + - items +external: + - items +externalTypes: + - CheckboxGroupItem[] +items: + color: + - primary + - secondary + - success + - info + - warning + - error + - neutral +props: + color: neutral + defaultValue: + - 'System' + items: + - 'System' + - 'Light' + - 'Dark' +--- +:: + +### Variant + +Use the `variant` prop to change the variant of the CheckboxGroup. + +::component-code +--- +prettier: true +ignore: + - defaultValue + - items +external: + - items +externalTypes: + - CheckboxGroupItem[] +items: + color: + - primary + - secondary + - success + - info + - warning + - error + - neutral + variant: + - list + - card +props: + color: 'primary' + variant: 'card' + defaultValue: + - 'System' + items: + - 'System' + - 'Light' + - 'Dark' +--- +:: + +### Size + +Use the `size` prop to change the size of the CheckboxGroup. + +::component-code +--- +prettier: true +ignore: + - defaultValue + - items +external: + - items +externalTypes: + - CheckboxGroupItem[] +items: + variant: + - list + - card +props: + size: 'xl' + variant: 'list' + defaultValue: + - 'System' + items: + - 'System' + - 'Light' + - 'Dark' +--- +:: + +### Orientation + +Use the `orientation` prop to change the orientation of the CheckboxGroup. Defaults to `vertical`. + +::component-code +--- +prettier: true +ignore: + - defaultValue + - items +external: + - items +externalTypes: + - CheckboxGroupItem[] +items: + variant: + - list + - card +props: + orientation: 'horizontal' + variant: 'list' + defaultValue: + - 'System' + items: + - 'System' + - 'Light' + - 'Dark' +--- +:: + +### Indicator + +Use the `indicator` prop to change the position or hide the indicator. Defaults to `start`. + +::component-code +--- +prettier: true +ignore: + - defaultValue + - items +external: + - items +externalTypes: + - CheckboxGroupItem[] +items: + indicator: + - start + - end + - hidden + variant: + - list + - card +props: + indicator: 'end' + variant: 'card' + defaultValue: + - 'System' + items: + - 'System' + - 'Light' + - 'Dark' +--- +:: + +### Disabled + +Use the `disabled` prop to disable the CheckboxGroup. + +::component-code +--- +prettier: true +ignore: + - defaultValue + - items +external: + - items +externalTypes: + - CheckboxGroupItem[] +props: + disabled: true + defaultValue: + - 'System' + items: + - 'System' + - 'Light' + - 'Dark' +--- +:: + +## API + +### Props + +:component-props + +### Slots + +:component-slots + +### Emits + +:component-emits + +## Theme + +:component-theme diff --git a/docs/content/3.components/checkbox.md b/docs/content/3.components/checkbox.md index da514df0..2412148c 100644 --- a/docs/content/3.components/checkbox.md +++ b/docs/content/3.components/checkbox.md @@ -156,6 +156,23 @@ props: --- :: +### Variant :badge{label="Not released" class="align-text-top"} + +Use the `variant` prop to change the variant of the Checkbox. + +::component-code +--- +ignore: + - label + - defaultValue +props: + color: 'primary' + variant: 'card' + defaultValue: true + label: Check me +--- +:: + ### Size Use the `size` prop to change the size of the Checkbox. @@ -167,6 +184,24 @@ ignore: - defaultValue props: size: xl + variant: list + defaultValue: true + label: Check me +--- +:: + +### Indicator :badge{label="Not released" class="align-text-top"} + +Use the `indicator` prop to change the position or hide the indicator. Defaults to `start`. + +::component-code +--- +ignore: + - label + - defaultValue +props: + indicator: 'end' + variant: 'card' defaultValue: true label: Check me --- diff --git a/package.json b/package.json index 09e022ae..93c5b863 100644 --- a/package.json +++ b/package.json @@ -213,6 +213,7 @@ "pnpm": { "onlyBuiltDependencies": [ "better-sqlite3", + "puppeteer", "sharp" ], "ignoredBuiltDependencies": [ diff --git a/playground-vue/src/app.vue b/playground-vue/src/app.vue index 5358ba32..caaf932a 100644 --- a/playground-vue/src/app.vue +++ b/playground-vue/src/app.vue @@ -27,6 +27,7 @@ const components = [ 'calendar', 'carousel', 'checkbox', + 'checkbox-group', 'chip', 'collapsible', 'color-picker', diff --git a/playground/app/app.vue b/playground/app/app.vue index 8aa32801..5bfd8576 100644 --- a/playground/app/app.vue +++ b/playground/app/app.vue @@ -27,6 +27,7 @@ const components = [ 'calendar', 'carousel', 'checkbox', + 'checkbox-group', 'chip', 'collapsible', 'color-picker', diff --git a/playground/app/pages/components/checkbox-group.vue b/playground/app/pages/components/checkbox-group.vue new file mode 100644 index 00000000..edac0bb2 --- /dev/null +++ b/playground/app/pages/components/checkbox-group.vue @@ -0,0 +1,73 @@ + + + diff --git a/playground/app/pages/components/checkbox.vue b/playground/app/pages/components/checkbox.vue index 22d0115a..ddbe82d7 100644 --- a/playground/app/pages/components/checkbox.vue +++ b/playground/app/pages/components/checkbox.vue @@ -2,27 +2,51 @@ import theme from '#build/ui/checkbox' const sizes = Object.keys(theme.variants.size) as Array +const variants = Object.keys(theme.variants.variant) +const variant = ref('list' as const) +const indicators = Object.keys(theme.variants.indicator) as Array +const indicator = ref('start' as const) const checked = ref(true) diff --git a/src/runtime/components/Checkbox.vue b/src/runtime/components/Checkbox.vue index 50786d40..41795223 100644 --- a/src/runtime/components/Checkbox.vue +++ b/src/runtime/components/Checkbox.vue @@ -18,10 +18,19 @@ export interface CheckboxProps extends Pick tv({ extend: tv(theme), ...(appConfig.ui?.checkbox || {}) })({ size: size.value, color: color.value, + variant: props.variant, + indicator: props.indicator, required: props.required, - disabled: disabled.value, - checked: Boolean(modelValue.value ?? props.defaultValue) + disabled: disabled.value })) function onUpdate(value: any) { @@ -91,7 +101,7 @@ function onUpdate(value: any) {