{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tw-loading",
  "type": "registry:ui",
  "title": "react-tw/loading.tsx",
  "description": "Carbon `Loading` and `InlineLoading` 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/core-status-indicator",
    "@kanok-ui/tw-i18n",
    "@kanok-ui/tw-theme",
    "@kanok-ui/tw-utils"
  ],
  "files": [
    {
      "path": "src/react-tw/loading.tsx",
      "type": "registry:ui",
      "target": "components/ui/react-tw/loading.tsx",
      "content": "import { useEffect, useLayoutEffect, useRef, type ReactNode, type ComponentProps } from 'react';\nimport { Loading as LoadingPrimitive } from '@purpurabog/ui/headless';\nimport { CHECKMARK_FILLED, ERROR_FILLED } from '../core/status-indicator.ts';\nimport { useTranslation } from './lib/i18n.ts';\nimport { cn } from './lib/utils.ts';\n\n/**\n * Carbon `Loading` and `InlineLoading` as React + Tailwind components, the look and rules of\n * `<ui-loading>` / `<ui-inline-loading>`.\n */\n\nexport interface LoadingProps extends Omit<ComponentProps<'div'>, 'active' | 'small' | 'overlay' | 'contained' | 'delay' | 'minDuration' | 'description' | 'lang' | 'className'> {\n    /** On by default; false stops and hides it. */\n    active?: boolean;\n    /** 16px with a grey track. */\n    small?: boolean;\n    /** Cover the page and hold focus while active, giving it back afterwards. */\n    overlay?: boolean;\n    /** Cover just `children` instead of the page; they are inert and busy while active (no Carbon counterpart). */\n    contained?: boolean;\n    /** Milliseconds `active` must last before the spinner shows (default 0, as Carbon). */\n    delay?: number;\n    /** Once shown, the least milliseconds it stays (default 0). */\n    minDuration?: number;\n    /** Accessible description (default: the translation's \"Loading\"). */\n    description?: string;\n    lang?: string;\n    className?: string;\n}\n\n/**\n * Carbon `Loading`: the 88px spinner (`small`: 16px with a grey track), announced assertively. With\n * `overlay` it covers the page in the overlay colour and holds focus (Tab, clicks elsewhere) until\n * it stops — modals layered above it are left alone — then focus goes back where it was. Beyond\n * Carbon, as `<ui-loading>`: `contained` covers just its `children` (inert and busy meanwhile) and\n * `delay` / `minDuration` keep quick work from flashing a spinner.\n */\nexport function Loading({ active = true, delay = 0, minDuration = 0, description, lang, ...rest }: Readonly<LoadingProps>) {\n    const t = useTranslation(lang).common;\n    return (\n        <LoadingPrimitive.Root active={active} delay={delay} minDuration={minDuration} modal={!!rest.overlay && !rest.contained}>\n            <LoadingView {...rest} text={description || t.loading} />\n        </LoadingPrimitive.Root>\n    );\n}\n\ntype LoadingViewProps = Omit<LoadingProps, 'active' | 'delay' | 'minDuration' | 'description' | 'lang'> & { text: string };\n\n/** The spinner inline, over the page, or over just `children`; the overlay shows while the Root's `shown`. */\nfunction LoadingView({ small = false, overlay = false, contained = false, text, className, children, ...rest }: Readonly<LoadingViewProps>) {\n    const { shown } = LoadingPrimitive.useLoadingContext();\n    const spinner = <Spinner small={small} text={text} />;\n    if (contained)\n        return (\n            <div {...rest} className={cn('relative block', className)}>\n                <LoadingPrimitive.Area>{children}</LoadingPrimitive.Area>\n                <div className={cn('absolute inset-0 z-1', OVERLAY, !shown && 'hidden')}>\n                    <LoadingPrimitive.Indicator aria-label={text} className=\"outline-none\">\n                        {spinner}\n                    </LoadingPrimitive.Indicator>\n                </div>\n            </div>\n        );\n    if (!overlay)\n        return (\n            <div {...rest} className={cn('inline-block', className)}>\n                {spinner}\n            </div>\n        );\n    return (\n        <div {...rest} /* NOSONAR: the overlay layer has no meaning of its own; the dialog inside is announced */ role=\"presentation\" className={cn('fixed inset-0 z-[6000]', OVERLAY, !shown && 'hidden', className)}>\n            <LoadingPrimitive.Indicator aria-label={text} className=\"outline-none\">\n                {spinner}\n            </LoadingPrimitive.Indicator>\n        </div>\n    );\n}\n\n/** The overlay colour around a centred spinner (the page's or an area's); Carbon .cds--loading-overlay: slow-02 (700ms), expressive standard easing. */\nconst OVERLAY = 'flex items-center justify-center bg-overlay transition-[background-color] duration-700 ease-[cubic-bezier(0.4,0.14,0.3,1)] motion-reduce:transition-none forced-colors:bg-[Canvas] forced-colors:opacity-80';\n\n/** Carbon's 88px spinner (`small`: 16px with a grey track), announced assertively while shown. */\nfunction Spinner({ small, text }: Readonly<{ small: boolean; text: string }>) {\n    const { shown } = LoadingPrimitive.useLoadingContext();\n    return (\n        <LoadingPrimitive.Spinner className={cn('animate-spin [animation-duration:690ms] motion-reduce:[animation-duration:2s]', small ? 'size-4 leading-4' : 'size-[88px]', !shown && 'hidden')}>\n            <svg viewBox=\"0 0 100 100\" role=\"img\" aria-label={text} className=\"block size-full fill-transparent\">\n                <title>{text}</title>\n                {small ? <circle cx=\"50%\" cy=\"50%\" r=\"42\" className=\"stroke-layer-accent [stroke-dasharray:276.46_276.46] [stroke-dashoffset:-22] [stroke-linecap:butt] [stroke-width:16] forced-colors:stroke-[GrayText]\" /> : null}\n                <circle\n                    cx=\"50%\"\n                    cy=\"50%\"\n                    r={small ? 42 : 44}\n                    className={cn(\n                        'stroke-interactive [stroke-dasharray:276.46_276.46] [stroke-linecap:butt] forced-colors:stroke-[CanvasText]',\n                        small ? '[stroke-dashoffset:143.76] [stroke-width:16]' : '[stroke-dashoffset:52.53] [stroke-width:10]',\n                    )}\n                />\n            </svg>\n        </LoadingPrimitive.Spinner>\n    );\n}\n\nexport type InlineLoadingStatus = 'inactive' | 'active' | 'finished' | 'error';\n\nexport interface InlineLoadingProps extends Omit<ComponentProps<'div'>, 'status' | 'successDelay' | 'onSuccess' | 'iconLabel' | 'children' | 'lang' | 'className'> {\n    status?: InlineLoadingStatus;\n    /** Milliseconds after `finished` before `onSuccess` (Carbon `successDelay`). */\n    successDelay?: number;\n    onSuccess?: () => void;\n    /** Accessible name of the icon (default: the status). */\n    iconLabel?: string;\n    /** The status text (Carbon `description`). */\n    children?: ReactNode;\n    lang?: string;\n    className?: string;\n}\n\n/**\n * Carbon `InlineLoading`: a 16px spinner with a text beside it, for in-place progress. `status`\n * moves through `active` → `finished` (a check mark, then `onSuccess` after\n * `successDelay`) or `error`; `inactive` shows no icon. The whole row is a polite live region, so\n * the icon's name is announced with the text (Carbon).\n */\nexport function InlineLoading({ status = 'active', successDelay = 1500, onSuccess, iconLabel, children, lang, className, ...rest }: Readonly<InlineLoadingProps>) {\n    const t = useTranslation(lang).common;\n    const label = iconLabel || { active: t.loading, finished: t.loadingFinished, error: t.loadingError, inactive: '' }[status];\n    const success = useRef(onSuccess);\n    useLayoutEffect(() => {\n        success.current = onSuccess;\n    });\n    useEffect(() => {\n        if (status !== 'finished') return;\n        const timer = setTimeout(() => success.current?.(), successDelay);\n        return () => clearTimeout(timer);\n    }, [status, successDelay]);\n\n    let icon: ReactNode = null;\n    if (status === 'active') {\n        icon = (\n            <svg viewBox=\"0 0 100 100\" role=\"img\" aria-label={label} className=\"block size-4 animate-spin [animation-duration:690ms] motion-reduce:[animation-duration:0s]\">\n                <circle cx=\"50%\" cy=\"50%\" r=\"42\" className=\"fill-none stroke-layer-accent [stroke-dasharray:276.46_276.46] [stroke-dashoffset:-22] [stroke-linecap:butt] [stroke-width:16] forced-colors:stroke-[GrayText]\" />\n                <circle cx=\"50%\" cy=\"50%\" r=\"42\" className=\"fill-none stroke-interactive [stroke-dasharray:276.46_276.46] [stroke-dashoffset:143.76] [stroke-linecap:butt] [stroke-width:16] forced-colors:stroke-[CanvasText]\" />\n            </svg>\n        );\n    } else if (status === 'finished') {\n        icon = (\n            <svg viewBox=\"0 0 16 16\" role=\"img\" aria-label={label} className=\"block size-4 fill-success forced-colors:fill-[CanvasText]\">\n                <path d={CHECKMARK_FILLED[16].paths[0].d} />\n            </svg>\n        );\n    } else if (status === 'error') {\n        icon = (\n            <svg viewBox=\"0 0 16 16\" role=\"img\" aria-label={label} className=\"block size-4 fill-error\">\n                <path d={ERROR_FILLED[16].paths[0].d} />\n            </svg>\n        );\n    }\n    return (\n        <div {...rest} aria-live=\"polite\" className={cn('flex min-h-8 w-full items-center font-sans text-ink-muted', className)}>\n            <span className=\"relative me-2 flex size-4 items-center justify-center\">{icon}</span>\n            <span className=\"type-body-sm\">{children}</span>\n        </div>\n    );\n}\n"
    }
  ]
}
