{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tw-progress-indicator",
  "type": "registry:ui",
  "title": "react-tw/progress-indicator.tsx",
  "description": "Carbon `ProgressIndicator` / `ProgressStep` as React + Tailwind components, the look and rules of Copied from @purpurabog/ui 2.3.0; the package is the maintained source, this copy is yours to change. Icons from the Carbon Design System (Apache-2.0, © IBM Corp.; see THIRD-PARTY-NOTICES.md in the package).",
  "dependencies": [
    "@purpurabog/ui@^2.3.0"
  ],
  "registryDependencies": [
    "@kanok-ui/tw-i18n",
    "@kanok-ui/tw-theme",
    "@kanok-ui/tw-utils"
  ],
  "files": [
    {
      "path": "src/react-tw/progress-indicator.tsx",
      "type": "registry:ui",
      "target": "components/ui/react-tw/progress-indicator.tsx",
      "content": "import { createContext, useContext, useMemo, type ReactNode, type ComponentProps } from 'react';\nimport { ProgressIndicator as ProgressIndicatorPrimitive } from '@purpurabog/ui/headless';\nimport { useTranslation } from './lib/i18n.ts';\nimport { cn } from './lib/utils.ts';\n\n/**\n * Carbon `ProgressIndicator` / `ProgressStep` as React + Tailwind components, the look and rules of\n * `<ui-progress-indicator>`: an ordered list of steps — before `currentIndex` complete, at it\n * current, after it incomplete (a step's own `complete` wins). `vertical` stacks them,\n * `spaceEqually` stretches them across the width, `interactive` lets the user jump to another\n * step (`onChange`; the current and disabled steps don't react).\n */\nexport type ProgressStepState = ProgressIndicatorPrimitive.StepState;\n\n/** The state of the step at `index` (Carbon): its own `complete`, else before / at / after the current index. */\nexport const stepState = ProgressIndicatorPrimitive.stepState;\n\n/** What the styled steps need to look right; the state (current index, clicks, Tab stops) is the primitive's. */\ninterface IndicatorLook {\n    vertical: boolean;\n    spaceEqually: boolean;\n}\n\nconst IndicatorContext = createContext<IndicatorLook | null>(null);\n\nexport interface ProgressIndicatorProps extends Omit<ComponentProps<'ol'>, 'currentIndex' | 'defaultCurrentIndex' | 'onChange' | 'vertical' | 'spaceEqually' | 'interactive' | 'className' | 'children'> {\n    currentIndex?: number;\n    defaultCurrentIndex?: number;\n    onChange?: (index: number) => void;\n    vertical?: boolean;\n    /** Stretch the steps to share the width (horizontal only). */\n    spaceEqually?: boolean;\n    /** The user can jump between steps. */\n    interactive?: boolean;\n    className?: string;\n    /** `<ProgressStep>`s. */\n    children: ReactNode;\n}\n\nexport function ProgressIndicator({ currentIndex, defaultCurrentIndex = 0, onChange, vertical = false, spaceEqually = false, interactive = false, className, children, ...rest }: Readonly<ProgressIndicatorProps>) {\n    const look = useMemo<IndicatorLook>(() => ({ vertical, spaceEqually: spaceEqually && !vertical }), [vertical, spaceEqually]);\n    return (\n        <IndicatorContext.Provider value={look}>\n            <ProgressIndicatorPrimitive.Root\n                {...rest}\n                currentIndex={currentIndex}\n                defaultCurrentIndex={defaultCurrentIndex}\n                onChange={onChange}\n                vertical={vertical}\n                interactive={interactive}\n                className={cn('m-0 flex list-none flex-wrap p-0 font-sans', vertical ? 'flex-col' : 'flex-row', className)}\n            >\n                {children}\n            </ProgressIndicatorPrimitive.Root>\n        </IndicatorContext.Provider>\n    );\n}\n\nconst ICONS: Record<ProgressStepState | 'invalid', ReactNode> = {\n    complete: (\n        <>\n            <path d=\"M8 1a7 7 0 1 0 0 14A7 7 0 0 0 8 1Zm0 13a6 6 0 1 1 0-12 6 6 0 0 1 0 12Z\" />\n            <path d=\"m7 11.4-2.7-2.7.7-.7L7 10l4-4 .7.7z\" />\n        </>\n    ),\n    current: <path d=\"M8 1a7 7 0 1 0 0 14A7 7 0 0 0 8 1Zm0 13a6 6 0 0 1 0-12z\" />,\n    incomplete: <path d=\"M8 2a6 6 0 1 1 0 12A6 6 0 0 1 8 2m0-1a7 7 0 1 0 0 14A7 7 0 0 0 8 1Z\" />,\n    invalid: <path d=\"M8 1 1 14h14L8 1Zm0 2.2L13.3 13H2.7L8 3.2ZM7.4 6h1.2v4H7.4zM8 12.4a.8.8 0 1 1 0-1.6.8.8 0 0 1 0 1.6Z\" />,\n};\n\nexport interface ProgressStepProps extends Omit<ComponentProps<'li'>, 'label' | 'secondaryLabel' | 'complete' | 'invalid' | 'disabled' | 'lang' | 'className'> {\n    label: ReactNode;\n    /** Smaller text under the label (Carbon `secondaryLabel`). */\n    secondaryLabel?: ReactNode;\n    /** Done regardless of `currentIndex`. */\n    complete?: boolean;\n    invalid?: boolean;\n    disabled?: boolean;\n    lang?: string;\n    className?: string;\n}\n\n/** What a screen reader hears after the step's label. */\nfunction stepMessage(t: ReturnType<typeof useTranslation>['common'], state: ProgressStepState, invalid: boolean) {\n    if (invalid) return t.stepInvalid;\n    if (state === 'complete') return t.stepComplete;\n    return state === 'current' ? t.stepCurrent : t.stepIncomplete;\n}\n\n/** The 16px status icon: blue (complete, current), ink (incomplete), red (invalid), grey (disabled). */\nfunction StepIcon({ state, invalid, disabled }: Readonly<{ state: ProgressStepState; invalid: boolean; disabled: boolean }>) {\n    return (\n        <svg\n            viewBox=\"0 0 16 16\"\n            aria-hidden=\"true\"\n            className={cn(\n                'mt-[10px] me-2 size-4 shrink-0 rounded-[50%]',\n                state === 'incomplete' ? 'fill-ink' : 'fill-primary',\n                invalid && 'fill-error',\n                disabled && 'fill-ink-disabled',\n                'forced-colors:fill-[CanvasText]',\n                state === 'current' && 'forced-colors:fill-[Highlight]',\n            )}\n        >\n            {ICONS[invalid ? 'invalid' : state]}\n        </svg>\n    );\n}\n\ninterface StepLabelsProps {\n    label: ReactNode;\n    secondaryLabel?: ReactNode;\n    spaceEqually: boolean;\n    vertical: boolean;\n    clickable: boolean;\n    disabled: boolean;\n}\n\n/** The label (88px wide, focus outline on the text) and the optional secondary line under it. */\nfunction StepLabels({ label, secondaryLabel, spaceEqually, vertical, clickable, disabled }: Readonly<StepLabelsProps>) {\n    return (\n        <span className=\"flex min-w-0 flex-col\">\n            <span\n                className={cn(\n                    'm-0 mt-2 text-ink type-body-sm [overflow-wrap:break-word] transition-[color] duration-(--ui-duration-moderate) ease-carbon',\n                    'group-focus-visible/step:text-focus group-focus-visible/step:rounded-[var(--ui-link-focus-radius,0px)] group-focus-visible/step:outline-1 group-focus-visible/step:outline-solid group-focus-visible/step:outline-focus',\n                    // a design can keep each label on one line, ending in an ellipsis (--ui-progress-label-*)\n                    'me-[var(--ui-progress-label-gap,0px)] max-w-[var(--ui-progress-label-max-width,88px)]',\n                    !vertical && '[overflow:var(--ui-progress-label-overflow,visible)] [white-space:var(--ui-progress-label-white-space,normal)] [text-overflow:var(--ui-progress-label-text-overflow,clip)]',\n                    spaceEqually && 'me-3 max-w-full',\n                    vertical && 'max-w-[160px] whitespace-normal',\n                    clickable && 'group-hover/step:text-link-hover',\n                    disabled && 'text-ink-disabled',\n                )}\n            >\n                {label}\n            </span>\n            {secondaryLabel ? <span className={cn('mt-1 text-ink-muted type-caption', disabled && 'text-ink-disabled')}>{secondaryLabel}</span> : null}\n        </span>\n    );\n}\n\n/** The step's button: the primitive's (state, Tab stop, click) with the icon, labels, screen-reader words and line. */\nfunction StepButton({ label, secondaryLabel, lang, look }: Readonly<{ label: ReactNode; secondaryLabel?: ReactNode; lang?: string; look: IndicatorLook }>) {\n    const { state, invalid, disabled, clickable } = ProgressIndicatorPrimitive.useStepContext('<ProgressStep>');\n    const t = useTranslation(lang).common;\n    const { vertical, spaceEqually } = look;\n    const message = stepMessage(t, state, invalid);\n    return (\n        <ProgressIndicatorPrimitive.StepButton\n            className={cn(\n                'group/step m-0 box-border flex min-h-8 w-full cursor-default flex-row border-0 bg-none p-0 text-start text-inherit [font:inherit] outline-none',\n                clickable && 'cursor-pointer',\n                disabled && 'cursor-not-allowed',\n                vertical && 'min-h-[58px] items-start ps-4',\n                'forced-colors:focus-visible:outline-[length:var(--ui-focus-width,2px)] forced-colors:focus-visible:outline-solid forced-colors:focus-visible:outline-[Highlight]',\n            )}\n        >\n            <StepIcon state={state} invalid={invalid} disabled={disabled} />\n            <StepLabels label={label} secondaryLabel={secondaryLabel} spaceEqually={spaceEqually} vertical={vertical} clickable={clickable} disabled={disabled} />\n            <span className=\"sr-only\">{message}</span>\n            <span className={cn('absolute start-0 top-0 h-0.5 w-full', state === 'incomplete' ? 'bg-hairline' : 'bg-primary', spaceEqually && 'min-w-32', vertical && 'h-full w-0.5')} />\n        </ProgressIndicatorPrimitive.StepButton>\n    );\n}\n\nexport function ProgressStep({ label, secondaryLabel, complete = false, invalid = false, disabled = false, lang, className, ...rest }: Readonly<ProgressStepProps>) {\n    const look = useContext(IndicatorContext);\n    if (!look) throw new Error('<ProgressStep> goes inside <ProgressIndicator>');\n    const { vertical, spaceEqually } = look;\n\n    return (\n        <ProgressIndicatorPrimitive.Step {...rest}\n            complete={complete}\n            invalid={invalid}\n            disabled={disabled}\n            className={cn(\n                'relative box-border inline-flex w-32 flex-row overflow-visible font-sans',\n                // Carbon: 128px steps (112px at the least); a design can share the row out (--ui-progress-step-*)\n                !vertical && 'flex-[var(--ui-progress-step-flex,0_1_auto)] min-w-[var(--ui-progress-step-min-width,112px)]',\n                spaceEqually && 'min-w-32 flex-[1_1_0]',\n                vertical && 'flex min-h-[58px] w-auto min-w-0',\n                className,\n            )}\n        >\n            <StepButton label={label} secondaryLabel={secondaryLabel} lang={lang} look={look} />\n        </ProgressIndicatorPrimitive.Step>\n    );\n}\n\n\n/** Carbon `ProgressIndicatorSkeleton`: `steps` incomplete steps (128px in a row, or stacked with `vertical`): the subtle line, the empty circle and a 40×14 label bar. Hidden from assistive tech. */\nexport function ProgressIndicatorSkeleton({ steps = 4, vertical = false, className, ...rest }: Readonly<ComponentProps<'div'> & { steps?: number; vertical?: boolean }>) {\n    return (\n        <div {...rest} aria-hidden=\"true\" className={cn('flex flex-wrap', vertical && 'flex-col', className)}>\n            {Array.from({ length: Math.max(1, steps) }, (_, i) => (\n                <div key={i} className={cn('relative flex shrink-0', vertical ? 'min-h-[58px] ps-4' : 'w-32 min-w-28')}>\n                    <span className={cn('absolute start-0 top-0 block bg-hairline', vertical ? 'h-full w-0.5' : 'h-0.5 w-full')} />\n                    {/* the incomplete step's empty circle, as ProgressStep */}\n                    <svg viewBox=\"0 0 16 16\" aria-hidden=\"true\" className=\"me-2 mt-2.5 size-4 shrink-0 fill-ink\">\n                        <path d=\"M8 2a6 6 0 1 1 0 12A6 6 0 0 1 8 2m0-1a7 7 0 1 0 0 14A7 7 0 0 0 8 1Z\" />\n                    </svg>\n                    <span className={cn('skeleton block h-3.5 w-10', vertical ? 'mt-[11px]' : 'mt-2.5')} />\n                </div>\n            ))}\n        </div>\n    );\n}\n"
    }
  ]
}
