{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "stepper",
  "title": "Stepper",
  "description": "Where a person is in a flow of steps, such as a checkout or a setup, horizontal or vertical. Steps already reached can be gone back to. When the current step moves, the lines between fill one after another and the current step’s tile lights once its line arrives; a done step’s tick wipes in, and an error has a mark of its own.",
  "dependencies": [
    "@ui-sdk/react",
    "@ui-sdk/core"
  ],
  "registryDependencies": [
    "https://kinoui.com/r/step.json",
    "https://kinoui.com/r/refs.json",
    "https://kinoui.com/r/theme.json"
  ],
  "files": [
    {
      "path": "registry/components/kino/stepper.tsx",
      "content": "'use client'\n\nimport { mergeRefs } from '@/registry/lib/refs'\nimport {\n  type StepStatus as AnyStepStatus,\n  stepLineClassName,\n  stepLineFillClassName,\n  stepStatusText,\n  StepMark,\n  stepTiming,\n} from '@/registry/lib/step'\nimport { Button as ButtonPrimitive } from '@ui-sdk/react/button'\nimport { mergeProps, type PartProps, renderElement } from '@ui-sdk/react/primitive'\nimport {\n  type ComponentProps,\n  type CSSProperties,\n  createContext,\n  type ReactNode,\n  useContext,\n  useEffect,\n  useLayoutEffect,\n  useRef,\n  useState,\n} from 'react'\n\nimport { cn } from '@/lib/utils'\n\n/** A Stepper's step is never skipped: a wizard's steps are each done, current or to come. */\ntype StepperStatus = Exclude<AnyStepStatus, 'skipped'>\n\n/*\n * Where a person is in a flow of steps, such as a checkout or a setup: each\n * step a marker on a line, with its title beside it. The markers and lines\n * are the Timeline's: a done step's tile takes a tick that wipes in, the\n * current one is solid, an upcoming one is faint and an error takes the\n * destructive colour with a mark of its own.\n *\n * When the current step moves, the line out of each step passed fills along\n * its length on `draw` (or empties, going back) and each marker on the way\n * changes once the line reaching it has arrived, so the current step lights\n * in its turn. A move of several steps takes as long as one.\n *\n * A horizontal stepper puts each title beside its marker; in a box narrower\n * than 42rem the titles go under the markers, so every one stays readable,\n * and below 28rem the descriptions are left to screen readers.\n */\n\ntype StepperOrientation = 'horizontal' | 'vertical'\n\ninterface StepperContextValue {\n  value: number\n  from: number\n  orientation: StepperOrientation\n  linear: boolean\n  select: (step: number) => void\n}\n\nconst StepperContext = createContext<StepperContextValue | null>(null)\n\nfunction useStepper() {\n  const context = useContext(StepperContext)\n  if (!context) throw new Error('Stepper parts go inside a Stepper.')\n  return context\n}\n\ninterface StepperItemContextValue {\n  step: number\n  status: StepperStatus\n  setHasTrigger: (has: boolean) => void\n}\n\nconst StepperItemContext = createContext<StepperItemContextValue | null>(null)\n\nfunction useStepperItem() {\n  const context = useContext(StepperItemContext)\n  if (!context) throw new Error('A step’s parts go inside a StepperItem.')\n  return context\n}\n\n/**\n * `value` is the current step, counted from 0: the steps before it are\n * complete and the ones after it upcoming, and one past the last marks every\n * step complete. `className` is for the list itself, as `<ol>`'s;\n * `containerClassName` for the box around it. Name it with `aria-label` or\n * `aria-labelledby`.\n */\nfunction Stepper({\n  className,\n  containerClassName,\n  value: valueProp,\n  defaultValue = 0,\n  onValueChange,\n  orientation = 'horizontal',\n  linear = true,\n  ref,\n  ...props\n}: Omit<ComponentProps<'ol'>, 'defaultValue'> & {\n  containerClassName?: string\n  value?: number\n  defaultValue?: number\n  onValueChange?: (value: number) => void\n  orientation?: StepperOrientation\n  /**\n   * In a linear flow a `StepperTrigger` goes back to a step already reached\n   * but not on to an upcoming one; `false` lets every step be picked.\n   */\n  linear?: boolean\n}) {\n  const [own, setOwn] = useState(defaultValue)\n  const value = valueProp ?? own\n  // The step it last moved from, so the lines and markers between the two\n  // take their turns. A move that starts while the last still runs takes no\n  // turns, so everything turns back from where it is.\n  const [move, setMove] = useState({ from: value, to: value })\n  const [busy, setBusy] = useState(false)\n  if (move.to !== value) setMove({ from: busy ? value : move.to, to: value })\n  const list = useRef<HTMLOListElement>(null)\n  useEffect(() => {\n    const element = list.current\n    if (!element) return\n    const running = new Map<EventTarget, Set<string>>()\n    const run = (event: TransitionEvent) => {\n      if (!(event.target instanceof Element)) return\n      if (!event.target.closest('[data-slot=stepper-line],[data-slot=stepper-marker]'))\n        return\n      const properties = running.get(event.target) ?? new Set<string>()\n      properties.add(event.propertyName)\n      running.set(event.target, properties)\n      setBusy(true)\n    }\n    const end = (event: TransitionEvent) => {\n      const properties = running.get(event.target as EventTarget)\n      properties?.delete(event.propertyName)\n      if (properties?.size === 0) running.delete(event.target as EventTarget)\n      if (running.size === 0) setBusy(false)\n    }\n    element.addEventListener('transitionrun', run)\n    element.addEventListener('transitionend', end)\n    element.addEventListener('transitioncancel', end)\n    return () => {\n      element.removeEventListener('transitionrun', run)\n      element.removeEventListener('transitionend', end)\n      element.removeEventListener('transitioncancel', end)\n    }\n  }, [])\n\n  const select = (step: number) => {\n    if (step === value) return\n    setOwn(step)\n    onValueChange?.(step)\n  }\n\n  return (\n    <StepperContext.Provider\n      value={{ value, from: move.from, orientation, linear, select }}\n    >\n      <div\n        data-slot='stepper'\n        className={cn(\n          // Horizontal reads its own width, so it fills its parent's.\n          orientation === 'horizontal' && '@container/stepper w-full',\n          containerClassName,\n        )}\n      >\n        <ol\n          ref={mergeRefs(list, ref)}\n          data-slot='stepper-list'\n          data-orientation={orientation}\n          className={cn(\n            'group/stepper flex [--stepper-gap:var(--control-padding)] [--stepper-marker:var(--control-height-xs)]',\n            orientation === 'horizontal'\n              ? 'items-start gap-(--stepper-gap)'\n              : 'flex-col gap-(--stepper-gap) [--stepper-gap:var(--surface-gap)]',\n            className,\n          )}\n          {...props}\n        />\n      </div>\n    </StepperContext.Provider>\n  )\n}\n\n/** Its colours wait (`--stepper-wait`) and its line fills (`--stepper-line-*`) in its turn of a move, as fractions of `draw`. */\nfunction timingStyle(step: number, from: number, to: number) {\n  const timing = stepTiming(step, from, to)\n  return {\n    '--stepper-wait': timing.markerWait,\n    '--stepper-line-delay': timing.lineDelay,\n    '--stepper-line-span': timing.lineSpan,\n  } as CSSProperties\n}\n\n/**\n * One step, numbered by `step` from 0. Its status follows the Stepper's\n * `value`; `status` sets it instead, such as `error` on a step that needs\n * another look. Hold the marker and content in a `StepperTrigger` to make the\n * step one a person can go to, or put them straight in for a stepper that\n * only shows where they are.\n */\nfunction StepperItem({\n  className,\n  step,\n  status: statusProp,\n  style,\n  render,\n  children,\n  ...props\n}: Omit<PartProps<'li'>, 'className' | 'style'> & {\n  className?: string\n  style?: CSSProperties\n  step: number\n  status?: StepperStatus\n}) {\n  const { value, from, orientation } = useStepper()\n  const status: StepperStatus =\n    statusProp ?? (step < value ? 'complete' : step === value ? 'current' : 'upcoming')\n  const [hasTrigger, setHasTrigger] = useState(false)\n  const horizontal = orientation === 'horizontal'\n  const element = renderElement(\n    'li',\n    mergeProps(\n      {\n        'data-slot': 'stepper-item',\n        'data-status': status,\n        'data-passed': step < value ? '' : undefined,\n        // A trigger carries it instead, where a screen reader meets it.\n        'aria-current': step === value && !hasTrigger ? 'step' : undefined,\n        style: { ...timingStyle(step, from, value), ...style },\n        className: cn(\n          'group/step relative flex min-w-0 motion-safe:[--step-wait:calc(var(--motion-draw-duration)*var(--stepper-wait))]',\n          horizontal\n            ? 'flex-1 basis-0 flex-col items-center gap-y-1.5 text-center @2xl/stepper:flex-row @2xl/stepper:items-start @2xl/stepper:gap-x-(--control-padding) @2xl/stepper:text-start @2xl/stepper:last:flex-none'\n            : 'items-start gap-x-(--control-padding)',\n          className,\n        ),\n        children: (\n          <>\n            {children}\n            <StepperLine passed={step < value} horizontal={horizontal} />\n          </>\n        ),\n      },\n      props,\n    ),\n    render,\n  )\n  return (\n    <StepperItemContext.Provider value={{ step, status, setHasTrigger }}>\n      {element}\n    </StepperItemContext.Provider>\n  )\n}\n\n/**\n * The line to the next step, 4px clear of both markers. Once its step is\n * passed it fills from the start on `draw`, in its turn of a move.\n */\nfunction StepperLine({ passed, horizontal }: { passed: boolean; horizontal: boolean }) {\n  return (\n    <span\n      aria-hidden\n      data-slot='stepper-line'\n      data-passed={passed || undefined}\n      className={cn(\n        stepLineClassName,\n        'group-last/step:hidden',\n        horizontal\n          ? // Under the titles, it runs from this marker's centre to the next\n            // one's, across the gap between the steps; beside them, it takes\n            // the room left after this title.\n            'absolute start-[calc(50%+var(--stepper-marker)/2+0.25rem)] top-[calc(var(--stepper-marker)/2-0.5px)] h-px w-[calc(100%+var(--stepper-gap)-var(--stepper-marker)-0.5rem)] @2xl/stepper:relative @2xl/stepper:start-auto @2xl/stepper:top-auto @2xl/stepper:mt-[calc(var(--stepper-marker)/2-0.5px)] @2xl/stepper:w-auto @2xl/stepper:min-w-4 @2xl/stepper:flex-1'\n          : 'absolute start-[calc(var(--stepper-marker)/2-0.5px)] top-[calc(var(--stepper-marker)+0.25rem)] -bottom-[calc(var(--stepper-gap)-0.25rem)] w-px',\n      )}\n    >\n      <span\n        className={cn(\n          stepLineFillClassName,\n          'delay-[calc(var(--motion-draw-duration)*var(--stepper-line-delay))] duration-[calc(var(--motion-draw-duration)*var(--stepper-line-span))]',\n          horizontal\n            ? 'origin-left scale-x-0 rtl:origin-right [[data-passed]>&]:scale-x-100'\n            : 'origin-top scale-y-0 [[data-passed]>&]:scale-y-100',\n        )}\n      />\n    </span>\n  )\n}\n\n/**\n * The step's mark: its number, or the icon given as its children. A done\n * step shows the Checkbox's tick, which wipes in on `draw`, and an error a\n * cross in an octagon, so neither leans on colour alone. Decorative: the title\n * and the status a screen reader hears say what it is.\n */\nfunction StepperMarker({\n  className,\n  render,\n  children,\n  ...props\n}: Omit<PartProps<'span'>, 'className' | 'children'> & {\n  className?: string\n  children?: ReactNode\n}) {\n  const { step, status } = useStepperItem()\n  return renderElement(\n    'span',\n    mergeProps(\n      {\n        'data-slot': 'stepper-marker',\n        'aria-hidden': true,\n        className: cn(\n          'relative z-10 flex size-(--stepper-marker) shrink-0 items-center justify-center',\n          className,\n        ),\n        children: <StepMark status={status}>{children ?? step + 1}</StepMark>,\n      },\n      props,\n    ),\n    render,\n  )\n}\n\n/**\n * Makes a step one a person can go to: a `<button>`, or a link with\n * `render={<a href='…' />}`. It picks its step\n * (`onValueChange`); in a `linear` stepper an upcoming step's trigger is\n * disabled, so it leaves the tab order.\n */\nfunction StepperTrigger({\n  className,\n  disabled,\n  onClick,\n  ...props\n}: Omit<ComponentProps<typeof ButtonPrimitive>, 'className'> & {\n  className?: string\n}) {\n  const { value, linear, select, orientation } = useStepper()\n  const { step, setHasTrigger } = useStepperItem()\n  useLayoutEffect(() => {\n    setHasTrigger(true)\n    return () => setHasTrigger(false)\n  }, [setHasTrigger])\n  return (\n    <ButtonPrimitive\n      data-slot='stepper-trigger'\n      aria-current={step === value ? 'step' : undefined}\n      disabled={disabled ?? (linear && step > value)}\n      onClick={(event, details) => {\n        onClick?.(event, details)\n        select(step)\n      }}\n      className={cn(\n        // Its backdrop reaches 4px past the marker and title, where it can't\n        // move them, and over a line that runs under a title below its marker.\n        'relative z-10 -m-1 flex min-w-0 rounded-(--control-radius-capped) p-1 transition-colors duration-(--motion-press-duration) ease-(--motion-press-fade-easing) outline-offset-2 focus-visible:ring-3 focus-visible:ring-ring/50 focus-visible:outline-hidden not-data-disabled:hover:bg-accent/70 not-data-disabled:active:bg-accent data-disabled:cursor-default',\n        orientation === 'horizontal'\n          ? 'flex-col items-center gap-y-1.5 text-center @2xl/stepper:flex-row @2xl/stepper:items-start @2xl/stepper:gap-x-(--control-padding) @2xl/stepper:text-start'\n          : 'items-start gap-x-(--control-padding) text-start',\n        className,\n      )}\n      {...props}\n    />\n  )\n}\n\n/** The title and any description, its first line level with the marker beside it. */\nfunction StepperContent({\n  className,\n  render,\n  children,\n  ...props\n}: Omit<PartProps<'div'>, 'className'> & { className?: string }) {\n  const { status } = useStepperItem()\n  const { orientation } = useStepper()\n  return renderElement(\n    'div',\n    mergeProps(\n      {\n        'data-slot': 'stepper-content',\n        className: cn(\n          'flex min-w-0 flex-col gap-0.5',\n          orientation === 'horizontal'\n            ? 'max-w-full @2xl/stepper:py-[calc((var(--stepper-marker)-1.25rem)/2)]'\n            : 'py-[calc((var(--stepper-marker)-1.25rem)/2)]',\n          className,\n        ),\n        children: (\n          <>\n            {stepStatusText[status] ? (\n              <span className='sr-only'>{stepStatusText[status]}: </span>\n            ) : null}\n            {children}\n          </>\n        ),\n      },\n      props,\n    ),\n    render,\n  )\n}\n\n/**\n * Muted while upcoming, destructive on an error. A long unbroken word breaks\n * rather than run out of the box. Under the markers of a narrow horizontal\n * stepper it is a size smaller.\n */\nfunction StepperTitle({\n  className,\n  render,\n  ...props\n}: Omit<PartProps<'div'>, 'className'> & { className?: string }) {\n  return renderElement(\n    'div',\n    mergeProps(\n      {\n        'data-slot': 'stepper-title',\n        className: cn(\n          'text-sm leading-5 font-medium wrap-anywhere transition-colors @max-md/stepper:group-data-[orientation=horizontal]/stepper:text-xs @max-md/stepper:group-data-[orientation=horizontal]/stepper:leading-4 duration-(--motion-morph-duration) ease-(--motion-morph-fade-easing) [transition-delay:var(--step-wait,0s)] group-data-[status=error]/step:text-destructive group-data-[status=upcoming]/step:text-muted-foreground',\n          className,\n        ),\n      },\n      props,\n    ),\n    render,\n  )\n}\n\n/**\n * A line under the title: what the step asks for, or that it's optional.\n * Under the markers of a narrow horizontal stepper only a screen reader\n * reads it, since the columns are too narrow for it.\n */\nfunction StepperDescription({\n  className,\n  render,\n  ...props\n}: Omit<PartProps<'div'>, 'className'> & { className?: string }) {\n  return renderElement(\n    'div',\n    mergeProps(\n      {\n        'data-slot': 'stepper-description',\n        className: cn(\n          'text-muted-foreground text-sm leading-5 text-pretty wrap-anywhere @max-md/stepper:group-data-[orientation=horizontal]/stepper:sr-only',\n          className,\n        ),\n      },\n      props,\n    ),\n    render,\n  )\n}\n\nexport {\n  Stepper,\n  StepperContent,\n  StepperDescription,\n  StepperItem,\n  StepperMarker,\n  StepperTitle,\n  StepperTrigger,\n}\nexport type { StepperOrientation, StepperStatus }\n",
      "type": "registry:component",
      "target": "@components/kino/stepper.tsx"
    }
  ],
  "type": "registry:component"
}