// AlignUI VerticalStepper v0.0.0 import * as React from 'react'; import { tv, type VariantProps } from '@/utils/tv'; import type { PolymorphicComponentProps } from '@/utils/polymorphic'; import { recursiveCloneChildren } from '@/utils/recursive-clone-children'; import { cn } from '@/utils/cn'; import { ChevronRight } from 'lucide-react'; import { Slot } from '@radix-ui/react-slot'; const VERTICAL_STEPPER_ROOT_NAME = 'VerticalStepperRoot'; const VERTICAL_STEPPER_ARROW_NAME = 'VerticalStepperArrow'; const VERTICAL_STEPPER_ITEM_NAME = 'VerticalStepperItem'; const VERTICAL_STEPPER_ITEM_INDICATOR_NAME = 'VerticalStepperItemIndicator'; function VerticalStepperRoot({ asChild, children, className, ...rest }: React.HTMLAttributes & { asChild?: boolean; }) { const Component = asChild ? Slot : 'div'; return ( {children} ); } VerticalStepperRoot.displayName = VERTICAL_STEPPER_ROOT_NAME; function VerticalStepperArrow({ className, as, ...rest }: PolymorphicComponentProps) { const Component = as || ChevronRight; return ( ); } VerticalStepperArrow.displayName = VERTICAL_STEPPER_ARROW_NAME; const verticalStepperItemVariants = tv({ slots: { root: [ // base 'grid w-full auto-cols-auto grid-flow-col grid-cols-[auto,minmax(0,1fr)] items-center gap-2.5 rounded-10 p-2 text-left text-paragraph-sm', ], indicator: [ // base 'flex size-5 shrink-0 items-center justify-center rounded-full text-label-xs', ], }, variants: { state: { completed: { root: 'bg-bg-weak-50 text-text-sub-600', indicator: 'bg-success-base text-static-white', }, active: { root: 'bg-bg-white-0 text-text-strong-950 shadow-regular-xs', indicator: 'bg-primary-base text-static-white', }, default: { root: 'bg-bg-weak-50 text-text-sub-600', indicator: 'bg-bg-white-0 text-text-sub-600 shadow-regular-xs', }, }, }, defaultVariants: { state: 'default', }, }); type VerticalStepperItemSharedProps = VariantProps< typeof verticalStepperItemVariants >; type VerticalStepperItemProps = React.ButtonHTMLAttributes & VariantProps & { asChild?: boolean; }; const VerticalStepperItem = React.forwardRef< HTMLButtonElement, VerticalStepperItemProps >(({ asChild, children, state, className, ...rest }, forwardedRef) => { const uniqueId = React.useId(); const Component = asChild ? Slot : 'button'; const { root } = verticalStepperItemVariants({ state }); const sharedProps: VerticalStepperItemSharedProps = { state, }; const extendedChildren = recursiveCloneChildren( children as React.ReactElement[], sharedProps, [VERTICAL_STEPPER_ITEM_INDICATOR_NAME], uniqueId, asChild, ); return ( {extendedChildren} ); }); VerticalStepperItem.displayName = VERTICAL_STEPPER_ITEM_NAME; function VerticalStepperItemIndicator({ state, className, children, ...rest }: React.HTMLAttributes & VerticalStepperItemSharedProps) { const { indicator } = verticalStepperItemVariants({ state }); if (state === 'completed') { return (
); } return (
{children}
); } VerticalStepperItemIndicator.displayName = VERTICAL_STEPPER_ITEM_INDICATOR_NAME; export { VerticalStepperRoot as Root, VerticalStepperArrow as Arrow, VerticalStepperItem as Item, VerticalStepperItemIndicator as ItemIndicator, };