From 208a2cd3b5eef329aaff5cde3581f0cb5a29a3db Mon Sep 17 00:00:00 2001 From: Kia King Ishii Date: Thu, 26 Oct 2023 16:42:10 +0900 Subject: [PATCH] feat(input-segments): add `` --- docs/.vitepress/config.mts | 1 + docs/components/input-segments.md | 413 ++++++++++++++++++ lib/components/SInputSegments.vue | 132 ++++++ lib/components/SInputSegmentsOption.vue | 150 +++++++ .../SInputSegments.01_Playground.story.vue | 90 ++++ .../SInputSegments.02_Modes.story.vue | 29 ++ ...SInputSegments.03_Disable_Option.story.vue | 26 ++ 7 files changed, 841 insertions(+) create mode 100644 docs/components/input-segments.md create mode 100644 lib/components/SInputSegments.vue create mode 100644 lib/components/SInputSegmentsOption.vue create mode 100644 stories/components/SInputSegments.01_Playground.story.vue create mode 100644 stories/components/SInputSegments.02_Modes.story.vue create mode 100644 stories/components/SInputSegments.03_Disable_Option.story.vue diff --git a/docs/.vitepress/config.mts b/docs/.vitepress/config.mts index cec7eeb9..9de9e934 100644 --- a/docs/.vitepress/config.mts +++ b/docs/.vitepress/config.mts @@ -65,6 +65,7 @@ function sidebar(): DefaultTheme.SidebarItem[] { { text: 'SInputNumber', link: '/components/input-number' }, { text: 'SInputRadios', link: '/components/input-radios' }, { text: 'SInputSelect', link: '/components/input-select' }, + { text: 'SInputSegments', link: '/components/input-segments' }, { text: 'SInputSwitch', link: '/components/input-switch' }, { text: 'SInputTextarea', link: '/components/input-textarea' }, { text: 'SInputYMD', link: '/components/input-ymd' }, diff --git a/docs/components/input-segments.md b/docs/components/input-segments.md new file mode 100644 index 00000000..12f73064 --- /dev/null +++ b/docs/components/input-segments.md @@ -0,0 +1,413 @@ + + +# SInputSegments + +`` is used to pick one choice from a linear set of closely related choices. + + + + + +## Usage + +Define options and set value. `` requires an option to be selected. If you do not define either `:value` or `v-model`, it will throw an error. + +```vue + + + +``` + +## Props + +Here are the list of props you may pass to the component. + +### `:size` + +Defines the size of the input. The default is `small`. + +```ts +interface Props { + size?: 'mini' | 'small' | 'medium' +} +``` + +```vue-html + +``` + +### `:label` + +Defines the label text of the input. + +```ts +interface Props { + label?: string +} +``` + +```vue-html + +``` + +### `:info` + +Shows help icon after the label and shows info in a tooltip when the user hovers the label. + +```ts +interface Props { + info?: string +} +``` + +```vue-html + +``` + +### `:note` + +Adds small help text after the label. Best used along with `label` prop. + +```ts +interface Props { + note?: string +} +``` + +```vue-html + +``` + +### `:check-icon` + +Icon to display at corner right of label. Useful to show the status of a particular input. + +```ts +import { IconifyIcon } from '@iconify/vue/dist/offline' + +interface Props { + checkIcon?: IconifyIcon +} +``` + +```vue-html + +``` + +### `:check-text` + +Text to display alongside `check-icon`. + +```ts +interface Props { + checkText?: string +} +``` + +```vue-html + +``` + +### `:check-color` + +Defines the color of `check-icon` and `check-text`. The default is `neutral`. + +```ts +interface Props { + checkColor?: Color +} + +type Color = + | 'neutral' + | 'mute' + | 'info' + | 'success' + | 'warning' + | 'danger' +``` + +```vue-html + +``` + +### `:options` + +The list of selectable options for the input. + +```ts +interface Props { + options?: Option[] +} + +interface Option { + label: string + value: T + mode?: Mode + disabled?: boolean +} + +type Mode = + | 'neutral' + | 'mute' + | 'info' + | 'success' + | 'warning' + | 'danger' +``` + +```vue-html + +``` + +### `:block` + +stretch each button evenly to fill the width of the control's parent. This option is intended to make the input easier to adapt into different layouts. + +```ts +interface Props { + block?: boolean +} +``` + +```vue-html + +``` + +### `:disabled` + +Mark all options as disabled. You may also set `disabled` property on each option to disable specific options. + +When this prop is set, users may not be able to focus the element not trigger any events. + +```ts +interface Props { + disabled?: boolean +} +``` + +```vue-html + +``` + +### `:value` + +Sets the input value. When `model-value` prop is set (e.g. via `v-model` directive), this prop gets ignored. + +```ts +interface Props { + value?: T +} +``` + +```vue-html + +``` + +### `:model-value` + +The `v-model` binding for the input. + +```ts +interface Props { + modelValue?: T +} +``` + +```vue-html + +``` + +### `:validation` + +The validation object for the input. It accepts [Vuelidate](https://vuelidate-next.netlify.app/) like validation object and displays error if there're any. + +```ts +import { Ref } from 'vue' + +interface Props { + validation?: Validatable +} + +interface Validatable { + readonly $dirty: boolean + readonly $invalid: boolean + readonly $errors: ValidatableError[] + readonly $touch: () => void +} + +interface ValidatableError { + readonly $message: string | Ref +} +``` + +```vue-html + +``` + +### `:hide-error` + +Stop showing validation error message even when there are errors. This prop will not prevent the error color from appearing. + +```ts +interface Props { + hideError?: boolean +} +``` + +```vue-html + +``` + +## Slots + +Here are the list of slots you may define within the component. + +### `#info` {#info-slot} + +Same as `info` prop. When `info` prop and this slot are defined at the same time, this slot will take precedence. + +```vue-html + + + +``` + +## Events + +Here are the list of events the component may emit. + +### `@update:model-value` + +Emits when the user selects the item. This event is always emitted together with `change` event. + +```ts +interface Emits { + (e: 'update:model-value', value: T): void +} +``` + +### `@change` + +Emits when the user selects the item. This event is always emitted together with `update:model-value` event. + +```ts +interface Emits { + (e: 'change', value: T): void +} +``` + +## Styles + +You may customize the styles by overriding `--input` prefixed CSS variables. + +### Global input styles + +You may customize the various styles of the component via global input related CSS variables. Please refer to [Styles: Input Styles](../styles/input-styles) page. + +### Button styles + +Each option styles shares the style of ``. Here are the list of all available variables. Note that `neutral` mode of `` uses `mute` variant of ``. + +```css + --button-fill-mute-border-color: var(--c-divider-1); + --button-fill-mute-text-color: var(--c-text-1); + --button-fill-mute-bg-color: var(--c-mute); + + --button-fill-info-border-color: var(--c-info-light); + --button-fill-info-text-color: var(--c-text-dark-1); + --button-fill-info-bg-color: var(--c-info-bg); + + --button-fill-success-border-color: var(--c-success-light); + --button-fill-success-text-color: var(--c-text-dark-1); + --button-fill-success-bg-color: var(--c-success-bg); + + --button-fill-warning-border-color: var(--c-warning-light); + --button-fill-warning-text-color: var(--c-text-dark-1); + --button-fill-warning-bg-color: var(--c-warning-bg); + + --button-fill-danger-border-color: var(--c-danger-light); + --button-fill-danger-text-color: var(--c-text-dark-1); + --button-fill-danger-bg-color: var(--c-danger-bg); +``` diff --git a/lib/components/SInputSegments.vue b/lib/components/SInputSegments.vue new file mode 100644 index 00000000..72013128 --- /dev/null +++ b/lib/components/SInputSegments.vue @@ -0,0 +1,132 @@ + + + + + diff --git a/lib/components/SInputSegmentsOption.vue b/lib/components/SInputSegmentsOption.vue new file mode 100644 index 00000000..bbdd5a78 --- /dev/null +++ b/lib/components/SInputSegmentsOption.vue @@ -0,0 +1,150 @@ + + + + + diff --git a/stories/components/SInputSegments.01_Playground.story.vue b/stories/components/SInputSegments.01_Playground.story.vue new file mode 100644 index 00000000..8f1c5efc --- /dev/null +++ b/stories/components/SInputSegments.01_Playground.story.vue @@ -0,0 +1,90 @@ + + + diff --git a/stories/components/SInputSegments.02_Modes.story.vue b/stories/components/SInputSegments.02_Modes.story.vue new file mode 100644 index 00000000..4f88ba2e --- /dev/null +++ b/stories/components/SInputSegments.02_Modes.story.vue @@ -0,0 +1,29 @@ + + + diff --git a/stories/components/SInputSegments.03_Disable_Option.story.vue b/stories/components/SInputSegments.03_Disable_Option.story.vue new file mode 100644 index 00000000..e09fb18c --- /dev/null +++ b/stories/components/SInputSegments.03_Disable_Option.story.vue @@ -0,0 +1,26 @@ + + +