From 898b30e047b81b9df5eb83106b6e7e673c89ac38 Mon Sep 17 00:00:00 2001 From: soykje Date: Thu, 7 Dec 2023 20:49:53 +0100 Subject: [PATCH] feat(progress-tracker): add orientation prop --- .../src/ProgressTracker.doc.mdx | 10 +- .../src/ProgressTracker.stories.tsx | 25 +++++ .../src/ProgressTracker.styles.ts | 13 +++ .../progress-tracker/src/ProgressTracker.tsx | 8 +- .../src/ProgressTrackerContext.ts | 2 +- .../src/ProgressTrackerStep.styles.ts | 99 +++++++++++++------ .../src/ProgressTrackerStep.tsx | 20 ++-- .../progress-tracker/src/variants/disabled.ts | 21 ++++ .../progress-tracker/src/variants/index.ts | 2 + .../progress-tracker/src/variants/size.ts | 34 +++++++ 10 files changed, 192 insertions(+), 42 deletions(-) create mode 100644 packages/components/progress-tracker/src/ProgressTracker.styles.ts create mode 100644 packages/components/progress-tracker/src/variants/disabled.ts create mode 100644 packages/components/progress-tracker/src/variants/index.ts create mode 100644 packages/components/progress-tracker/src/variants/size.ts diff --git a/packages/components/progress-tracker/src/ProgressTracker.doc.mdx b/packages/components/progress-tracker/src/ProgressTracker.doc.mdx index f2667b9cf..c19a8e964 100644 --- a/packages/components/progress-tracker/src/ProgressTracker.doc.mdx +++ b/packages/components/progress-tracker/src/ProgressTracker.doc.mdx @@ -61,6 +61,12 @@ Use `size` prop to set the size of the progress indicators. Smallest size doesn' +### Orientation + +Use `orientation` prop to set `horizontal|vertical` orientation. + + + ### Intent Use `intent` prop to set the color. @@ -69,10 +75,6 @@ Use `intent` prop to set the color. Use `design` prop to set the look and feel. -### Orientation - -Use `orientation` prop to set `horizontal|vertical` orientation. - ## Accessibility ### Keyboard Interactions diff --git a/packages/components/progress-tracker/src/ProgressTracker.stories.tsx b/packages/components/progress-tracker/src/ProgressTracker.stories.tsx index 65e8ee72f..b1d5c9c07 100644 --- a/packages/components/progress-tracker/src/ProgressTracker.stories.tsx +++ b/packages/components/progress-tracker/src/ProgressTracker.stories.tsx @@ -11,6 +11,7 @@ const meta: Meta = { export default meta const sizes: ProgressTrackerProps['size'][] = ['sm', 'md', 'lg'] +const orientations: ProgressTrackerProps['orientation'][] = ['horizontal', 'vertical'] export const Default: StoryFn = _args => ( console.log('Clicked on', id)}> @@ -50,3 +51,27 @@ export const Size: StoryFn = _args => ( ))} ) + +export const Orientation: StoryFn = _args => ( +
+ {orientations.map(orientation => ( +
+ {`${orientation}${ + orientation === 'horizontal' ? ' (default)' : '' + }`} + + + + + + +
+ ))} +
+) diff --git a/packages/components/progress-tracker/src/ProgressTracker.styles.ts b/packages/components/progress-tracker/src/ProgressTracker.styles.ts new file mode 100644 index 000000000..3698810eb --- /dev/null +++ b/packages/components/progress-tracker/src/ProgressTracker.styles.ts @@ -0,0 +1,13 @@ +import { cva } from 'class-variance-authority' + +export const progressListVariant = cva(['flex flex-nowrap'], { + variants: { + orientation: { + horizontal: 'flex-row w-full', + vertical: 'flex-col', + }, + }, + defaultVariants: { + orientation: 'horizontal', + }, +}) diff --git a/packages/components/progress-tracker/src/ProgressTracker.tsx b/packages/components/progress-tracker/src/ProgressTracker.tsx index 88b36839a..c9ee0ecb4 100644 --- a/packages/components/progress-tracker/src/ProgressTracker.tsx +++ b/packages/components/progress-tracker/src/ProgressTracker.tsx @@ -1,6 +1,7 @@ import { cx } from 'class-variance-authority' import { type ComponentPropsWithoutRef, forwardRef, type PropsWithChildren, useState } from 'react' +import { progressListVariant } from './ProgressTracker.styles' import { ProgressTrackerContext, type ProgressTrackerContextInterface, @@ -9,7 +10,7 @@ import type { ProgressTrackerStepVariantsProps } from './ProgressTrackerStep.sty export interface ProgressTrackerProps extends ComponentPropsWithoutRef<'div'>, - Pick { + Pick { /** * The index of the current step. * @default 0 @@ -33,6 +34,7 @@ export const ProgressTracker = forwardRef -
    +
      {children}
    diff --git a/packages/components/progress-tracker/src/ProgressTrackerContext.ts b/packages/components/progress-tracker/src/ProgressTrackerContext.ts index ae3bad778..d42caeedb 100644 --- a/packages/components/progress-tracker/src/ProgressTrackerContext.ts +++ b/packages/components/progress-tracker/src/ProgressTrackerContext.ts @@ -8,7 +8,7 @@ interface Step { } export type ProgressTrackerContextInterface = Required< - Pick + Pick > & { steps: Set setSteps: Dispatch>> diff --git a/packages/components/progress-tracker/src/ProgressTrackerStep.styles.ts b/packages/components/progress-tracker/src/ProgressTrackerStep.styles.ts index a351875f5..f6851cf85 100644 --- a/packages/components/progress-tracker/src/ProgressTrackerStep.styles.ts +++ b/packages/components/progress-tracker/src/ProgressTrackerStep.styles.ts @@ -2,64 +2,93 @@ import { cva, type VariantProps } from 'class-variance-authority' export const stepItemVariant = cva( [ - 'relative inline-flex flex-auto first:grow-0 justify-center', + 'relative inline-flex flex-auto first:grow-0 justify-center group', // Progress Track - 'before:absolute after:absolute before:z-base after:z-base', - 'before:h-[1px] after:h-[1px]', - 'before:bg-basic after:bg-basic', - 'before:left-none after:right-none', - 'first:before:content-none last:after:content-none', + 'after:absolute after:z-base', + 'after:bg-basic', + 'last:after:content-none', ], { variants: { size: { - sm: [ - 'pt-[calc(16px+theme("spacing.md"))]', + sm: '', + md: '', + lg: '', + }, + disabled: { + true: 'before:opacity-dim-3', + false: '', + }, + disabledAfter: { + true: 'after:opacity-dim-3', + false: '', + }, + orientation: { + vertical: ['after:w-[1px]', 'after:bottom-none'], + horizontal: [ + 'before:h-[1px] after:h-[1px]', + 'before:bg-basic before:absolute before:z-base', + 'before:left-none after:right-none', + 'first:before:content-none', + ], + }, + }, + compoundVariants: [ + { + size: 'sm', + orientation: 'horizontal', + class: [ 'before:top-[8px] after:top-[8px]', 'before:right-[calc(50%+12px)] after:left-[calc(50%+12px)]', ], - md: [ - 'pt-[calc(24px+theme("spacing.md"))]', + }, + { + size: 'md', + orientation: 'horizontal', + class: [ 'before:top-[12px] after:top-[12px]', 'before:right-[calc(50%+16px)] after:left-[calc(50%+16px)]', ], - lg: [ - 'pt-[calc(32px+theme("spacing.md"))]', + }, + { + size: 'lg', + orientation: 'horizontal', + class: [ 'before:top-[16px] after:top-[16px]', 'before:right-[calc(50%+20px)] after:left-[calc(50%+20px)]', ], }, - disabled: { - true: 'before:opacity-dim-3 after:opacity-dim-3', - false: '', + { + size: 'sm', + orientation: 'vertical', + class: ['after:left-[8px]', 'after:top-[24px]'], }, - disabledBefore: { - true: 'before:opacity-dim-3', - false: '', + { + size: 'md', + orientation: 'vertical', + class: ['after:left-[12px]', 'after:top-[32px]'], }, - disabledAfter: { - true: 'after:opacity-dim-3', - false: '', + { + size: 'lg', + orientation: 'vertical', + class: ['after:left-[16px]', 'after:top-[40px]'], }, - }, + ], defaultVariants: { disabled: false, - disabledBefore: false, disabledAfter: false, size: 'lg', + orientation: 'horizontal', }, } ) -// eslint-disable-next-line tailwindcss/no-custom-classname export const stepButtonVariant = cva( [ - 'block mx-sm mb-auto', - 'border-x-sm border-x-transparent', + 'flex gap-md', // Progress Indicator 'before:[counter-increment:step] before:content-[counter(step)]', - 'before:absolute before:z-raised before:top-none before:left-[50%] before:translate-x-[-50%]', - 'before:flex before:items-center before:justify-center before:rounded-full', + 'before:flex before:shrink-0 before:items-center before:justify-center before:rounded-full before:mx-auto', 'before:border-sm before:text-on-basic-container', 'before:text-body-2 before:font-bold', ], @@ -89,6 +118,19 @@ export const stepButtonVariant = cva( true: ['cursor-default'], false: '', }, + orientation: { + vertical: [ + 'flex-row items-baseline', + 'my-sm mr-auto group-first:mt-none group-last:mb-none', + 'border-y-sm border-y-transparent', + 'text-left', + ], + horizontal: [ + 'flex-col items-center', + 'mx-sm mb-auto group-first:ml-none group-last:mr-none', + 'border-x-sm border-x-transparent', + ], + }, }, compoundVariants: [ { @@ -105,6 +147,7 @@ export const stepButtonVariant = cva( active: false, complete: false, size: 'lg', + orientation: 'horizontal', }, } ) diff --git a/packages/components/progress-tracker/src/ProgressTrackerStep.tsx b/packages/components/progress-tracker/src/ProgressTrackerStep.tsx index 25bdb259a..97c376a60 100644 --- a/packages/components/progress-tracker/src/ProgressTrackerStep.tsx +++ b/packages/components/progress-tracker/src/ProgressTrackerStep.tsx @@ -1,10 +1,17 @@ -import { type ComponentPropsWithoutRef, forwardRef, useEffect, useId, useState } from 'react' +import { + type ComponentPropsWithoutRef, + forwardRef, + type ReactNode, + useEffect, + useId, + useState, +} from 'react' import { useProgressTrackerContext } from './ProgressTrackerContext' import { stepButtonVariant, stepItemVariant } from './ProgressTrackerStep.styles' export type ProgressTrackerStepProps = ComponentPropsWithoutRef<'li'> & { - label?: string + label?: ReactNode disabled?: boolean } @@ -16,6 +23,7 @@ export const ProgressTrackerStep = forwardRef ) diff --git a/packages/components/progress-tracker/src/variants/disabled.ts b/packages/components/progress-tracker/src/variants/disabled.ts new file mode 100644 index 000000000..5eb6c5626 --- /dev/null +++ b/packages/components/progress-tracker/src/variants/disabled.ts @@ -0,0 +1,21 @@ +export const disabledItemVariants = { + disabled: { + true: 'before:opacity-dim-3 after:opacity-dim-3', + false: '', + }, + disabledBefore: { + true: 'before:opacity-dim-3', + false: '', + }, + disabledAfter: { + true: 'after:opacity-dim-3', + false: '', + }, +} + +export const disabledButtonVariants = { + disabled: { + true: 'before:opacity-dim-3', + false: '', + }, +} diff --git a/packages/components/progress-tracker/src/variants/index.ts b/packages/components/progress-tracker/src/variants/index.ts new file mode 100644 index 000000000..ebc78fbf2 --- /dev/null +++ b/packages/components/progress-tracker/src/variants/index.ts @@ -0,0 +1,2 @@ +export * from './size' +export * from './disabled' diff --git a/packages/components/progress-tracker/src/variants/size.ts b/packages/components/progress-tracker/src/variants/size.ts new file mode 100644 index 000000000..653a9ba44 --- /dev/null +++ b/packages/components/progress-tracker/src/variants/size.ts @@ -0,0 +1,34 @@ +export const sizeItemVariants = [ + { + size: 'sm', + orientation: ['horizontal', 'vertical'], + class: [ + 'before:top-[8px] after:top-[8px]', + 'before:right-[calc(50%+12px)] after:left-[calc(50%+12px)]', + ], + }, + { + size: 'md', + orientation: ['horizontal', 'vertical'], + class: [ + 'before:top-[12px] after:top-[12px]', + 'before:right-[calc(50%+16px)] after:left-[calc(50%+16px)]', + ], + }, + { + size: 'lg', + orientation: ['horizontal', 'vertical'], + class: [ + 'before:top-[16px] after:top-[16px]', + 'before:right-[calc(50%+20px)] after:left-[calc(50%+20px)]', + ], + }, +] as const + +export const sizeButtonVariants = { + size: { + sm: ['before:w-sz-16 before:h-sz-16', 'before:!content-["_"]'], + md: 'before:w-sz-24 before:h-sz-24', + lg: 'before:w-sz-32 before:h-sz-32', + }, +}