From 9ce531a06f1a972bc003876162e0503c1bbbdbd8 Mon Sep 17 00:00:00 2001 From: Benjamin Canac Date: Fri, 26 May 2023 22:07:49 +0200 Subject: [PATCH] feat!: handle color states on form elements (#234) --- docs/components/ThemeSelect.vue | 4 +- docs/components/content/ComponentCard.vue | 13 +- docs/content/2.elements/1.avatar.md | 2 + docs/content/3.forms/1.input.md | 97 ++++++------ docs/content/3.forms/2.textarea.md | 62 ++++++-- docs/content/3.forms/3.select.md | 84 ++++++++--- docs/content/3.forms/4.select-menu.md | 9 +- docs/content/3.forms/8.form-group.md | 140 ++++++++++++++++++ docs/content/5.overlays/6.notification.md | 2 + src/module.ts | 82 +++++----- src/runtime/app.config.ts | 52 ++++--- .../components/elements/AvatarGroup.ts | 17 +-- .../components/elements/ButtonGroup.ts | 16 +- src/runtime/components/forms/FormGroup.ts | 82 ++++++++++ src/runtime/components/forms/Input.vue | 29 +++- src/runtime/components/forms/InputGroup.vue | 78 ---------- src/runtime/components/forms/Select.vue | 29 +++- src/runtime/components/forms/SelectMenu.vue | 29 +++- src/runtime/components/forms/Textarea.vue | 28 +++- .../components/overlays/Notification.vue | 2 +- src/runtime/utils/index.ts | 15 ++ 21 files changed, 598 insertions(+), 274 deletions(-) create mode 100644 docs/content/3.forms/8.form-group.md create mode 100644 src/runtime/components/forms/FormGroup.ts delete mode 100644 src/runtime/components/forms/InputGroup.vue diff --git a/docs/components/ThemeSelect.vue b/docs/components/ThemeSelect.vue index d6c82d31..7b0d3247 100644 --- a/docs/components/ThemeSelect.vue +++ b/docs/components/ThemeSelect.vue @@ -5,7 +5,7 @@ v-model="primary" name="primary" class="w-full [&>div>button]:!rounded-r-none" - appearance="gray" + color="gray" :ui="{ width: 'w-[194px]' }" :popper="{ placement: 'bottom-start' }" :options="primaryOptions" @@ -29,7 +29,7 @@ v-model="gray" name="gray" class="w-full [&>div>button]:!rounded-l-none [&>div>button]:-ml-px" - appearance="gray" + color="gray" :ui="{ width: 'w-[194px]' }" :popper="{ placement: 'bottom-end' }" :options="grayOptions" diff --git a/docs/components/content/ComponentCard.vue b/docs/components/content/ComponentCard.vue index 9a0da5c6..8d6ea4b2 100644 --- a/docs/components/content/ComponentCard.vue +++ b/docs/components/content/ComponentCard.vue @@ -7,7 +7,7 @@ v-if="prop.type === 'boolean'" v-model="componentProps[prop.name]" :name="prop.name" - appearance="none" + variant="none" class="justify-center" /> [] }, + extraColors: { + type: Array, + default: () => [] + }, backgroundClass: { type: String, default: 'bg-white dark:bg-gray-900' @@ -121,7 +125,8 @@ const propsToSelect = computed(() => Object.keys(componentProps).map((key) => { const keys = useGet(ui.value, dottedKey, {}) let options = typeof keys === 'object' && Object.keys(keys) if (key.toLowerCase().endsWith('color')) { - options = appConfig.ui.colors + // @ts-ignore + options = [...appConfig.ui.colors, ...props.extraColors] } return { diff --git a/docs/content/2.elements/1.avatar.md b/docs/content/2.elements/1.avatar.md index b322f867..7d81f140 100644 --- a/docs/content/2.elements/1.avatar.md +++ b/docs/content/2.elements/1.avatar.md @@ -36,6 +36,8 @@ Use the `chip-color` and `chip-position` props to display a chip on the Avatar. props: chipColor: 'primary' chipPosition: 'top-right' +extraColors: + - gray baseProps: src: 'https://avatars.githubusercontent.com/u/739984?v=4' alt: 'Avatar' diff --git a/docs/content/3.forms/1.input.md b/docs/content/3.forms/1.input.md index 7d6121a3..c966d6ae 100644 --- a/docs/content/3.forms/1.input.md +++ b/docs/content/3.forms/1.input.md @@ -12,6 +12,53 @@ baseProps: --- :: +### Style + +Use the `color` and `variant` props to change the visual style of the Input. + +::component-card +--- +baseProps: + name: 'input' + placeholder: 'Search...' +props: + color: 'primary' + variant: 'outline' +--- +:: + +Besides all the colors from the `ui.colors` object, you can also use the `white` (default) and `gray` colors with their pre-defined variants. + +#### White + +::component-card +--- +baseProps: + name: 'input' + placeholder: 'Search...' +props: + color: 'white' + variant: 'outline' +excludedProps: + - color +--- +:: + +#### Gray + +::component-card +--- +baseProps: + name: 'input' + placeholder: 'Search...' +props: + color: 'gray' + variant: 'outline' +excludedProps: + - color +--- +:: + ### Size Use the `size` prop to change the size of the Input. @@ -38,20 +85,6 @@ props: --- :: -### Appearance - -Use the `appearance` prop to change the style of the Input. - -::component-card ---- -baseProps: - name: 'input' - placeholder: 'Search...' -props: - appearance: 'white' ---- -:: - ### Icon Use any icon from [Iconify](https://icones.js.org) by setting the `icon` prop by using this pattern: `i-{collection_name}-{icon_name}`. @@ -65,9 +98,12 @@ baseProps: placeholder: 'Search...' props: icon: 'i-heroicons-magnifying-glass-20-solid' - appearance: 'white' size: 'sm' + color: 'white' trailing: false +extraColors: + - white + - gray excludedProps: - icon --- @@ -81,12 +117,9 @@ Use the `disabled` prop to disable the Input. --- baseProps: name: 'input' -props: placeholder: 'Search...' - appearance: 'white' +props: disabled: true -excludedProps: - - placeholder --- :: @@ -109,32 +142,6 @@ excludedProps: --- :: -### Group - -You can use the `InputGroup` component to add a label and additional informations to a form element. - -::component-card{slug="InputGroup"} ---- -baseProps: - name: 'group' -props: - label: 'Email' - help: "We'll only use this for spam." - hint: 'Required' - required: true -code: >- - - ---- - -#default -:u-input{name="group" placeholder="you@example.com" icon="i-heroicons-envelope"} -:: - -::alert{icon="i-heroicons-light-bulb"} -This also works with `Textarea`, `Select` and `SelectMenu` components. -:: - ## Props :component-props diff --git a/docs/content/3.forms/2.textarea.md b/docs/content/3.forms/2.textarea.md index eda1e3c4..a6461e5b 100644 --- a/docs/content/3.forms/2.textarea.md +++ b/docs/content/3.forms/2.textarea.md @@ -12,6 +12,53 @@ baseProps: --- :: +### Style + +Use the `color` and `variant` props to change the visual style of the Textarea. + +::component-card +--- +baseProps: + name: 'textarea' + placeholder: 'Search...' +props: + color: 'primary' + variant: 'outline' +--- +:: + +Besides all the colors from the `ui.colors` object, you can also use the `white` (default) and `gray` colors with their pre-defined variants. + +#### White + +::component-card +--- +baseProps: + name: 'textarea' + placeholder: 'Search...' +props: + color: 'white' + variant: 'outline' +excludedProps: + - color +--- +:: + +#### Gray + +::component-card +--- +baseProps: + name: 'textarea' + placeholder: 'Search...' +props: + color: 'gray' + variant: 'outline' +excludedProps: + - color +--- +:: + ### Size Use the `size` prop to change the size of the Textarea. @@ -38,20 +85,6 @@ props: --- :: -### Appearance - -Use the `appearance` prop to change the style of the Textarea. - -::component-card ---- -baseProps: - name: 'textarea' - placeholder: 'Search...' -props: - appearance: 'white' ---- -:: - ### Disabled Use the `disabled` prop to disable the Textarea. @@ -62,7 +95,6 @@ baseProps: name: 'input' placeholder: 'Search...' props: - appearance: 'white' disabled: true --- :: diff --git a/docs/content/3.forms/3.select.md b/docs/content/3.forms/3.select.md index e2c1faef..854f4d8d 100644 --- a/docs/content/3.forms/3.select.md +++ b/docs/content/3.forms/3.select.md @@ -22,9 +22,65 @@ excludedProps: --- :: +### Style + +Use the `color` and `variant` props to change the visual style of the Select. + +::component-card +--- +baseProps: + name: 'select' + options: + - 'United States' + - 'Canada' + - 'Mexico' +props: + color: 'primary' + variant: 'outline' +--- +:: + +Besides all the colors from the `ui.colors` object, you can also use the `white` (default) and `gray` colors with their pre-defined variants. + +#### White + +::component-card +--- +baseProps: + name: 'select' + options: + - 'United States' + - 'Canada' + - 'Mexico' +props: + color: 'white' + variant: 'outline' +excludedProps: + - color +--- +:: + +#### Gray + +::component-card +--- +baseProps: + name: 'select' + options: + - 'United States' + - 'Canada' + - 'Mexico' +props: + color: 'gray' + variant: 'outline' +excludedProps: + - color +--- +:: + ### Size -Use the `size` prop to change the size of the Input. +Use the `size` prop to change the size of the Select. ::component-card --- @@ -56,24 +112,6 @@ props: --- :: -### Appearance - -Use the `appearance` prop to change the style of the Select. - -::component-card ---- -baseProps: - name: 'select' - options: - - 'United States' - - 'Canada' - - 'Mexico' - placeholder: 'Search...' -props: - appearance: 'white' ---- -:: - ### Icon Use any icon from [Iconify](https://icones.js.org) by setting the `icon` prop by using this pattern: `i-{collection_name}-{icon_name}`. @@ -91,8 +129,11 @@ baseProps: placeholder: 'Search...' props: icon: 'i-heroicons-magnifying-glass-20-solid' - appearance: 'white' + color: 'white' size: 'sm' +extraColors: + - white + - gray excludedProps: - icon --- @@ -100,7 +141,7 @@ excludedProps: ### Disabled -Use the `disabled` prop to disable the Input. +Use the `disabled` prop to disable the Select. ::component-card --- @@ -112,7 +153,6 @@ baseProps: - 'Mexico' placeholder: 'Search...' props: - appearance: 'white' disabled: true --- :: diff --git a/docs/content/3.forms/4.select-menu.md b/docs/content/3.forms/4.select-menu.md index c1583ffd..e2da7b5f 100644 --- a/docs/content/3.forms/4.select-menu.md +++ b/docs/content/3.forms/4.select-menu.md @@ -8,7 +8,7 @@ headlessui: ## Usage -The SelectMenu component renders by default a [Select](/forms/select) component and is based on the `ui.select` preset. You can use most of the Select props to configure the display if you don't want to override the default slot such as [size](/forms/select#size), [placeholder](/forms/select#placeholder), [appearance](/forms/select#appearance), [icon](/forms/select#icon), [disabled](/forms/select#disabled), etc. +The SelectMenu component renders by default a [Select](/forms/select) component and is based on the `ui.select` preset. You can use most of the Select props to configure the display if you don't want to override the default slot such as [color](/forms/select#style), [variant](/forms/select#style), [size](/forms/select#size), [placeholder](/forms/select#placeholder), [icon](/forms/select#icon), [disabled](/forms/select#disabled), etc. Like the Select component, you can use the `options` prop to pass an array of strings or objects. @@ -148,6 +148,10 @@ baseProps: options: ['Wade Cooper', 'Arlene Mccoy', 'Devon Webb', 'Tom Cook', 'Tanya Fox', 'Hellen Schmidt', 'Caroline Schultz', 'Mason Heaney', 'Claudie Smitham', 'Emil Schaefer'] props: icon: 'i-heroicons-magnifying-glass-20-solid' + color: 'white' +extraColors: + - white + - gray excludedProps: - icon --- @@ -157,6 +161,8 @@ excludedProps: Use the `searchable` prop to enable search. +Use the `searchable-placeholder` prop to set a different placeholder. + This will use Headless UI [Combobox](https://headlessui.com/vue/combobox) component instead of [Listbox](https://headlessui.com/vue/listbox). ::component-card @@ -167,6 +173,7 @@ baseProps: options: ['Wade Cooper', 'Arlene Mccoy', 'Devon Webb', 'Tom Cook', 'Tanya Fox', 'Hellen Schmidt', 'Caroline Schultz', 'Mason Heaney', 'Claudie Smitham', 'Emil Schaefer'] props: searchable: true + searchablePlaceholder: 'Search a person...' --- :: diff --git a/docs/content/3.forms/8.form-group.md b/docs/content/3.forms/8.form-group.md new file mode 100644 index 00000000..6336a276 --- /dev/null +++ b/docs/content/3.forms/8.form-group.md @@ -0,0 +1,140 @@ +--- +github: true +description: Display a label and additional informations around a form element. +--- + + +## Usage + +Use the FormGroup component around an [Input](/forms/input), [Textarea](/forms/textarea), [Select](/forms/select) or a [SelectMenu](/forms/select-menu) with the `name` prop to automatically associate a `