From cff504a0075f6d43c0133e73250c581e6b3a4265 Mon Sep 17 00:00:00 2001 From: Italo Israel Baeza Cabrera Date: Thu, 16 Nov 2023 01:11:07 -0300 Subject: [PATCH 1/7] feat(Ladder): new component --- .../examples/LadderExampleStepObjects.vue | 13 + docs/content/2.elements/12.ladder.md | 149 +++++++++++ src/runtime/components/elements/Ladder.vue | 236 ++++++++++++++++++ src/runtime/types/index.d.ts | 1 + src/runtime/types/ladder.d.ts | 19 ++ src/runtime/ui.config.ts | 71 ++++++ 6 files changed, 489 insertions(+) create mode 100644 docs/components/content/examples/LadderExampleStepObjects.vue create mode 100644 docs/content/2.elements/12.ladder.md create mode 100644 src/runtime/components/elements/Ladder.vue create mode 100644 src/runtime/types/ladder.d.ts diff --git a/docs/components/content/examples/LadderExampleStepObjects.vue b/docs/components/content/examples/LadderExampleStepObjects.vue new file mode 100644 index 0000000000..d036e0cdba --- /dev/null +++ b/docs/components/content/examples/LadderExampleStepObjects.vue @@ -0,0 +1,13 @@ + + + diff --git a/docs/content/2.elements/12.ladder.md b/docs/content/2.elements/12.ladder.md new file mode 100644 index 0000000000..73b797e221 --- /dev/null +++ b/docs/content/2.elements/12.ladder.md @@ -0,0 +1,149 @@ +--- +description: 'Display a progress as a list of ordered steps.' +links: + - label: GitHub + icon: i-simple-icons-github + to: https://github.com/nuxt/ui/blob/dev/src/runtime/components/data/Table.vue +--- + +## Usage + +Pass the step index as `v-model`, an array of steps as strings to the `steps` prop of the Ladder component. + +::component-card +--- +baseProps: + steps: + - Address + - Shipping + - Trade-in + - Payment + - Checkout +props: + modelValue: 3 +options: + - name: modelValue + restriction: only + values: + - 0 + - 1 + - 2 + - 3 + - 4 +--- +:: + +You may also pass an array of objects with following properties: + +- `label` - The label of the step. +- `icon` - The icon of the step. +- `disabled` - Whether the step is disabled. +- `click` - The click handler of the step. +- `to` - Execute navigation to the set destination. + +:component-example{component="ladder-example-step-objects"} + +::callout{icon="i-heroicons-exclamation-triangle"} +The `click` handler will take precedence over the navigation handler. If `click` is set to `false`, the navigation handler is disabled, even if `to` is declared. +:: + +## Click + +Steps don't change when the user clicks on it. To enable this behaviour, you can either set the `click` prop to `true`, or on each step setting `click` to `true`. + +::component-card +--- +baseProps: + modelValue: 0 + steps: + - Address + - Shipping + - Trade-in + - Payment + - Checkout +props: + click: true +--- +:: + +## Separators + +The steps are separated with horizontal lines that can be disabled by setting `separators` to `false`. + +::component-card +--- +baseProps: + steps: + - Address + - Shipping + - Trade-in + - Payment + - Checkout +props: + separators: false +--- +:: + +## Style + +Steps can be either active or inactive. You may change the color of each state using the corresponding prop: + +- `color` for an active step +- `inactiveColor` for an inactive step + +Besides all the colors from the `ui.colors` object, you can also use the `gray`. + +::component-card +--- +baseProps: + steps: + - Address + - Shipping + - Trade-in + - Payment + - Checkout +props: + color: red + inactiveColor: blue +--- +:: + +::callout{icon="i-heroicons-exclamation-triangle"} +The inactive color also affects the separator colors. +:: + +## Size + +Use the `size` prop to change the size of the ladder. + +::component-card +--- +baseProps: + steps: + - Address + - Shipping + - Trade-in + - Payment + - Checkout +props: + size: md +options: + - name: size + restriction: included + values: + - 2xs + - xs + - sm + - md + - lg + - xl +--- +:: + +## Props + +:component-props + +## Config + +:component-preset diff --git a/src/runtime/components/elements/Ladder.vue b/src/runtime/components/elements/Ladder.vue new file mode 100644 index 0000000000..4cbe17f8ee --- /dev/null +++ b/src/runtime/components/elements/Ladder.vue @@ -0,0 +1,236 @@ + + + diff --git a/src/runtime/types/index.d.ts b/src/runtime/types/index.d.ts index e274f25e92..3d9ef82487 100644 --- a/src/runtime/types/index.d.ts +++ b/src/runtime/types/index.d.ts @@ -7,6 +7,7 @@ export * from './clipboard' export * from './command-palette' export * from './dropdown' export * from './form' +export * from './ladder' export * from './link' export * from './meter' export * from './notification' diff --git a/src/runtime/types/ladder.d.ts b/src/runtime/types/ladder.d.ts new file mode 100644 index 0000000000..bb20ab769d --- /dev/null +++ b/src/runtime/types/ladder.d.ts @@ -0,0 +1,19 @@ +import { RouteParams } from 'vue-router' +import { ladder } from '../ui.config' +import colors from '#ui-colors' + +export type LadderSize = keyof typeof ladder.icon.size +export type LadderStepColor = 'gray' | typeof colors[number] + +export interface LadderStep { + label: string, + to?: RouteParams | string, + click?: Function | boolean, + icon?: string, + disabled?: boolean +} + +export interface LadderStepWrapper { + step: LadderStep, + isActive: boolean, +} diff --git a/src/runtime/ui.config.ts b/src/runtime/ui.config.ts index 1fac6cd84b..bd9bbf6c78 100644 --- a/src/runtime/ui.config.ts +++ b/src/runtime/ui.config.ts @@ -550,6 +550,77 @@ export const meterGroup = { } } +export const ladder = { + base: 'w-full flex', + container: 'grow flex flex-items-center', + step: 'grow space-y-1', + indicator: 'w-full grid', + separator: { + wrapper: 'row-start-1 col-start-1 flex items-center', + base: 'grow w-1/2', + color: 'bg-{color}-200 dark:bg-{color}-700', + shadow: '', + size: { + '2xs': 'h-px', + xs: 'h-1', + sm: 'h-2', + md: 'h-2', + lg: 'h-2', + xl: 'h-3', + '2xl': 'h-3' + } + }, + icon: { + wrapper: 'row-start-1 col-start-1 flex justify-center', + base: 'flex items-center justify-center transition-all disabled:cursor-not-allowed', + rounded: 'rounded-full', + shadow: '', + size: { + '2xs': 'text-xs h-5 w-5 ring-1', + xs: 'text-xs h-6 w-6 ring-1', + sm: 'text-sm h-7 w-7 ring-2', + md: 'text-md h-8 w-8 ring-2', + lg: 'text-lg h-9 w-9 ring-2', + xl: 'text-xl h-10 w-10 ring-4', + '2xl': 'text-2xl h-12 w-12 ring-4' + }, + active: { + background: 'bg-white dark:bg-gray-900', + ring: 'ring-{color}-500', + color: '', + shadow: '' + }, + inactive: { + background: 'bg-{color}-200 dark:bg-{color}-700', + ring: 'ring-transparent', + color: '', + shadow: '' + } + }, + label: { + base: 'px-2 text-center truncate transition-colors', + size: { + '2xs': 'text-xs', + xs: 'text-xs', + sm: 'text-sm', + md: 'text-md', + lg: 'text-lg', + xl: 'text-xl', + '2xl': 'text-2xl' + }, + active: 'text-{color}-500', + inactive: 'text-{color}-500' + }, + colors: { + gray: '' + }, + default: { + size: 'md', + color: 'primary', + inactiveColor: 'gray' + } +} + // Forms export const input = { From 42d9c04af9133294e92b31b9b902e5541370b80b Mon Sep 17 00:00:00 2001 From: Italo Israel Baeza Cabrera Date: Thu, 16 Nov 2023 01:33:52 -0300 Subject: [PATCH 2/7] Adds safe list colors --- src/colors.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/colors.ts b/src/colors.ts index 2e853d5615..28d73f3b3a 100644 --- a/src/colors.ts +++ b/src/colors.ts @@ -177,6 +177,15 @@ const safelistByComponent = { }, { pattern: new RegExp(`text-(${colorsAsRegex})-500`) }], + ladder: (colorsAsRegex) => [{ + pattern: new RegExp(`bg-(${colorsAsRegex})-200`) + }, { + pattern: new RegExp(`bg-(${colorsAsRegex})-700`), + variants: ['dark'] + }, { + pattern: new RegExp(`bg-(${colorsAsRegex})-900`), + variants: ['dark'] + }], meter: (colorsAsRegex) => [{ pattern: new RegExp(`bg-(${colorsAsRegex})-400`), variants: ['dark'] From 8a15097de7665f13ff239b006aa4086eec3c8be1 Mon Sep 17 00:00:00 2001 From: Italo Israel Baeza Cabrera Date: Thu, 16 Nov 2023 01:34:24 -0300 Subject: [PATCH 3/7] Removes unnecessary size select --- docs/content/2.elements/12.ladder.md | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/docs/content/2.elements/12.ladder.md b/docs/content/2.elements/12.ladder.md index 73b797e221..2a81a4cfe9 100644 --- a/docs/content/2.elements/12.ladder.md +++ b/docs/content/2.elements/12.ladder.md @@ -127,16 +127,6 @@ baseProps: - Checkout props: size: md -options: - - name: size - restriction: included - values: - - 2xs - - xs - - sm - - md - - lg - - xl --- :: From 5e0e2090b0e20968050ac881866c4b0300eeb19c Mon Sep 17 00:00:00 2001 From: Italo Israel Baeza Cabrera Date: Thu, 16 Nov 2023 01:40:18 -0300 Subject: [PATCH 4/7] Minor style fix [skip ci] --- docs/components/content/examples/LadderExampleStepObjects.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/components/content/examples/LadderExampleStepObjects.vue b/docs/components/content/examples/LadderExampleStepObjects.vue index d036e0cdba..403ae333ff 100644 --- a/docs/components/content/examples/LadderExampleStepObjects.vue +++ b/docs/components/content/examples/LadderExampleStepObjects.vue @@ -7,7 +7,7 @@ const steps = [ { label: 'Address', icon: 'i-heroicons-home' }, { label: 'Shipping', icon: 'i-heroicons-truck' }, { label: 'Trade-in', icon: 'i-heroicons-arrow-path', disabled: true }, - { label: 'Payment', icon: 'i-heroicons-banknotes', click: () => alert('You clicked Payment!')}, + { label: 'Payment', icon: 'i-heroicons-banknotes', click: () => alert('You clicked Payment!') }, { label: 'Checkout', icon: 'i-heroicons-check' } ] From 84643c9dacf5d684250be2b6007cb3caa6714e1b Mon Sep 17 00:00:00 2001 From: Italo Israel Baeza Cabrera Date: Fri, 17 Nov 2023 18:53:43 -0300 Subject: [PATCH 5/7] Simplified behavior, code --- .../examples/LadderExampleStepObjects.vue | 4 +- docs/content/2.elements/12.ladder.md | 25 +--- src/colors.ts | 3 - src/runtime/components/elements/Ladder.vue | 141 ++++++------------ src/runtime/ui.config.ts | 42 ++---- 5 files changed, 59 insertions(+), 156 deletions(-) diff --git a/docs/components/content/examples/LadderExampleStepObjects.vue b/docs/components/content/examples/LadderExampleStepObjects.vue index 403ae333ff..ae54c1563f 100644 --- a/docs/components/content/examples/LadderExampleStepObjects.vue +++ b/docs/components/content/examples/LadderExampleStepObjects.vue @@ -4,8 +4,8 @@