{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tw-progress-bar",
  "type": "registry:ui",
  "title": "react-tw/progress-bar.tsx",
  "description": "Carbon `ProgressBar` as a React + Tailwind component, the look and rules of `<ui-progress-bar>`: 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": [],
  "registryDependencies": [
    "@kanok-ui/core-progress-bar",
    "@kanok-ui/tw-i18n",
    "@kanok-ui/tw-theme",
    "@kanok-ui/tw-utils"
  ],
  "files": [
    {
      "path": "src/react-tw/progress-bar.tsx",
      "type": "registry:ui",
      "target": "components/ui/react-tw/progress-bar.tsx",
      "content": "import { useId, type ReactNode, type ComponentProps } from 'react';\nimport { progressRatio, progressValue, type ProgressBarStatus } from '../core/progress-bar.ts';\nimport { useTranslation } from './lib/i18n.ts';\nimport { cn } from './lib/utils.ts';\n\nexport type { ProgressBarStatus } from '../core/progress-bar.ts';\nexport type ProgressBarType = 'default' | 'inline' | 'indented';\n\nexport interface ProgressBarProps extends Omit<ComponentProps<'div'>, 'label' | 'hideLabel' | 'helperText' | 'value' | 'max' | 'size' | 'status' | 'type' | 'lang' | 'className'> {\n    /** Required: what is progressing; shown above (or beside) the track and read as the bar's name. */\n    label: ReactNode;\n    /** Visually hides the label (it still names the bar). */\n    hideLabel?: boolean;\n    helperText?: ReactNode;\n    /** Current progress; leave it out for an indeterminate bar. */\n    value?: number;\n    max?: number;\n    /** `md`: Carbon `big` (8px track), `sm`: Carbon `small` (4px). */\n    size?: 'sm' | 'md';\n    status?: ProgressBarStatus;\n    /** `inline`: label and track on one row (helper text for screen readers only); `indented`: label and helper text 16px in. */\n    type?: ProgressBarType;\n    lang?: string;\n    className?: string;\n}\n\n// Carbon CheckmarkFilled / ErrorFilled (20px glyphs drawn at 16px)\nconst STATUS_ICON = {\n    finished: <path d=\"M10 1a9 9 0 1 0 0 18 9 9 0 0 0 0-18ZM8.5 14 4.4 9.9l1.4-1.4 2.7 2.7 5.7-5.7 1.4 1.4z\" />,\n    error: <path d=\"M10 1a9 9 0 1 0 0 18 9 9 0 0 0 0-18Zm3.5 13.5L10 11l-3.5 3.5L5 13l3.5-3.5L5 6l1.5-1.5L10 8l3.5-3.5L15 6l-3.5 3.5L15 13z\" />,\n};\n\n/**\n * Carbon `ProgressBar` as a React + Tailwind component, the look and rules of `<ui-progress-bar>`:\n * a labelled track that fills to `value / max`, or sweeps when `value` is left out (indeterminate).\n * `status=\"finished\"` fills it green with a check mark, `status=\"error\"` turns label icon, bar and\n * helper text red. The track is the `progressbar`: `aria-valuemin/max/now` when determinate,\n * `aria-busy` until finished, named by the label (with \"Error\" for screen readers on error) and described by the helper text.\n */\ninterface BarLook {\n    inline: boolean;\n    indented: boolean;\n    /** Finished or failed: the bar is full and the status icon shows. */\n    done: boolean;\n}\n\nfunction labelClasses({ inline, indented, done }: BarLook, hidden: boolean) {\n    return cn('mb-2 flex min-w-12 justify-between type-body-sm leading-[18px]!', inline && 'me-4 mb-0 shrink-0', inline && done && 'me-0 shrink justify-start', indented && 'px-4', hidden && 'sr-only');\n}\n\n/** The track; inline and done it's for screen readers only. Indeterminate, a 12.5% stripe sweeps across it. */\nfunction trackClasses({ inline, done }: BarLook, size: ProgressBarProps['size'], indeterminate: boolean) {\n    return cn(\n        // Carbon: a square track in the layer colour; a design can tint and round it (the bar is clipped to it)\n        'relative h-2 w-full min-w-12 rounded-[var(--ui-progress-radius)] bg-[var(--ui-progress-track,var(--ui-surface-1))] [clip-path:inset(0_round_var(--ui-progress-radius))]',\n        size === 'sm' && 'h-1',\n        inline && 'flex-[1_1_0]',\n        inline && done && 'absolute -m-px h-px w-px min-w-0 overflow-hidden [clip-path:inset(50%)]',\n        indeterminate &&\n            \"after:absolute after:inset-0 after:bg-[linear-gradient(90deg,var(--ui-interactive)_12.5%,transparent_12.5%)] after:bg-size-[200%_100%] after:animate-ui-progress after:content-[''] motion-reduce:after:[animation-duration:4s] rtl:after:animate-ui-progress-rtl\",\n        'forced-colors:border forced-colors:border-solid forced-colors:border-[CanvasText]',\n    );\n}\n\n/** The filled part: interactive blue, green and full when finished, red and full on error. */\nfunction barClasses(status: ProgressBarStatus) {\n    return cn(\n        'block h-full w-full origin-left bg-current text-interactive [transform:scaleX(0)] transition-transform duration-(--ui-duration-moderate) ease-carbon rtl:origin-right',\n        status === 'finished' && 'text-success [transform:scaleX(1)]',\n        status === 'error' && 'text-error-text [transform:scaleX(1)]',\n        'forced-colors:bg-[Highlight]',\n    );\n}\n\nexport function ProgressBar({ label, hideLabel = false, helperText, value, max = 100, size = 'md', status = 'active', type = 'default', lang, className, ...rest }: Readonly<ProgressBarProps>) {\n    const id = useId();\n    const t = useTranslation(lang).common;\n    const finished = status === 'finished';\n    const error = status === 'error';\n    const done = finished || error;\n    const capped = progressValue(value, max, status);\n    const indeterminate = capped === undefined;\n    const inline = type === 'inline';\n    const indented = type === 'indented';\n    const look = { inline, indented, done };\n\n    return (\n        <div {...rest} className={cn('block font-sans text-ink', inline && 'flex items-center', className)}>\n            <div\n                id={`${id}-label`}\n                className={labelClasses(look, hideLabel)}\n            >\n                <span className=\"truncate\">{label}</span>\n                {error ? <span className=\"sr-only\">, {t.loadingError}</span> : null}\n                {done ? (\n                    <svg viewBox=\"0 0 20 20\" aria-hidden=\"true\" className={cn('ms-4 size-4 shrink-0 fill-current', finished ? 'text-success' : 'text-error-text')}>\n                        {STATUS_ICON[status]}\n                    </svg>\n                ) : null}\n            </div>\n            <div /* NOSONAR: Carbon ProgressBar: a styled progressbar; <progress> can't take this look */\n                role=\"progressbar\"\n                aria-busy={!finished}\n                aria-labelledby={`${id}-label`}\n                aria-describedby={helperText ? `${id}-helper` : undefined}\n                aria-valuemin={indeterminate ? undefined : 0}\n                aria-valuemax={indeterminate ? undefined : max}\n                aria-valuenow={capped}\n                className={trackClasses(look, size, indeterminate)}\n            >\n                <div\n                    style={indeterminate || done ? undefined : { transform: `scaleX(${progressRatio(capped, max)})` }}\n                    className={barClasses(status)}\n                />\n            </div>\n            {helperText ? (\n                <div id={`${id}-helper`} className={cn('mt-2 text-ink-muted type-caption leading-4!', error && 'text-error-text', indented && 'px-4')}>\n                    {helperText}\n                </div>\n            ) : null}\n        </div>\n    );\n}\n"
    }
  ]
}
