// AlignUI HorizontalStepper 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 HORIZONTAL_STEPPER_ROOT_NAME = 'HorizontalStepperRoot'; const HORIZONTAL_STEPPER_SEPARATOR_NAME = 'HorizontalStepperSeparator'; const HORIZONTAL_STEPPER_ITEM_NAME = 'HorizontalStepperItem'; const HORIZONTAL_STEPPER_ITEM_INDICATOR_NAME = 'HorizontalStepperItemIndicator'; function HorizontalStepperRoot({ asChild, children, className, ...rest }: React.HTMLAttributes & { asChild?: boolean; }) { const Component = asChild ? Slot : 'div'; return ( {children} ); } HorizontalStepperRoot.displayName = HORIZONTAL_STEPPER_ROOT_NAME; function HorizontalStepperSeparatorIcon({ className, as, ...rest }: PolymorphicComponentProps) { const Component = as || ChevronRight; return ( ); } HorizontalStepperSeparatorIcon.displayName = HORIZONTAL_STEPPER_SEPARATOR_NAME; const horizontalStepperItemVariants = tv({ slots: { root: [ // base 'flex items-center gap-2 text-paragraph-sm', ], indicator: [ // base 'flex size-5 shrink-0 items-center justify-center rounded-full text-label-xs', ], }, variants: { state: { completed: { root: 'text-text-strong-950', indicator: 'bg-success-base text-static-white', }, active: { root: 'text-text-strong-950', indicator: 'bg-primary-base text-static-white', }, default: { root: 'text-text-sub-600', indicator: 'bg-bg-white-0 text-text-sub-600 ring-1 ring-inset ring-stroke-soft-200', }, }, }, defaultVariants: { state: 'default', }, }); type HorizontalStepperItemSharedProps = VariantProps< typeof horizontalStepperItemVariants >; type HorizontalStepperItemProps = React.ButtonHTMLAttributes & VariantProps & { asChild?: boolean; }; const HorizontalStepperItem = React.forwardRef< HTMLButtonElement, HorizontalStepperItemProps >(({ asChild, children, state, className, ...rest }, forwardedRef) => { const uniqueId = React.useId(); const Component = asChild ? Slot : 'button'; const { root } = horizontalStepperItemVariants({ state }); const sharedProps: HorizontalStepperItemSharedProps = { state, }; const extendedChildren = recursiveCloneChildren( children as React.ReactElement[], sharedProps, [HORIZONTAL_STEPPER_ITEM_INDICATOR_NAME], uniqueId, asChild, ); return ( {extendedChildren} ); }); HorizontalStepperItem.displayName = HORIZONTAL_STEPPER_ITEM_NAME; function HorizontalStepperItemIndicator({ state, className, children, ...rest }: React.HTMLAttributes & HorizontalStepperItemSharedProps) { const { indicator } = horizontalStepperItemVariants({ state }); if (state === 'completed') { return (
); } return (
{children}
); } HorizontalStepperItemIndicator.displayName = HORIZONTAL_STEPPER_ITEM_INDICATOR_NAME; export { HorizontalStepperRoot as Root, HorizontalStepperSeparatorIcon as SeparatorIcon, HorizontalStepperItem as Item, HorizontalStepperItemIndicator as ItemIndicator, };