{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tw-contained-list",
  "type": "registry:ui",
  "title": "react-tw/contained-list.tsx",
  "description": "Carbon `ContainedList` as a React + Tailwind component, the look of `<ui-contained-list>`: a titled 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/tw-theme",
    "@kanok-ui/tw-utils"
  ],
  "files": [
    {
      "path": "src/react-tw/contained-list.tsx",
      "type": "registry:ui",
      "target": "components/ui/react-tw/contained-list.tsx",
      "content": "import { createContext, useContext, useId, useMemo, type ReactNode, type ComponentProps } from 'react';\nimport { cn } from './lib/utils.ts';\n\nexport type ContainedListKind = 'on-page' | 'disclosed';\nexport type ContainedListSize = 'sm' | 'md' | 'lg' | 'xl';\n\n/** Beyond Carbon: the side nav's current-page bar on the start edge (--ui-nav-current-*; Kanok hides it, forced colours still show it). */\nconst CURRENT_MARK =\n    \"before:absolute before:inset-y-(--ui-nav-current-mark-inset,0px) before:start-0 before:w-(--ui-nav-current-mark-width,3px) before:rounded-(--ui-nav-current-mark-radius,0px) before:bg-[color:var(--ui-nav-current-mark,var(--ui-primary))] before:content-[''] forced-colors:before:w-[3px] forced-colors:before:bg-[Highlight]\";\n\nconst ListContext = createContext<{ size: ContainedListSize; inset: boolean }>({ size: 'lg', inset: false });\n\n/** The row height (`--_h`) per size; literal class names, so Tailwind generates them. */\nconst ROW_HEIGHT: Record<ContainedListSize, string> = {\n    sm: '[--_h:32px]',\n    md: '[--_h:40px]',\n    lg: '[--_h:var(--ui-field-height-lg,48px)]',\n    xl: '[--_h:64px]',\n};\n\nexport interface ContainedListProps extends Omit<ComponentProps<'div'>, 'label' | 'kind' | 'size' | 'inset' | 'action' | 'className' | 'children'> {\n    /** The header label (it also names the list). */\n    label?: ReactNode;\n    /** `on-page`: a 48px heading header on the page; `disclosed`: a 32px label header on the layer. */\n    kind?: ContainedListKind;\n    /** Row height: sm 32 / md 40 / lg 48 / xl 64. */\n    size?: ContainedListSize;\n    /** The rules stop at the row padding (Carbon `isInset`). */\n    inset?: boolean;\n    /** A header control (search, icon button). */\n    action?: ReactNode;\n    /** Beyond Carbon: the list the user is on, among several (`aria-current=\"true\"` on the list, the side nav's fill and bar on the header). */\n    current?: boolean;\n    className?: string;\n    /** `<ContainedListItem>`s. */\n    children?: ReactNode;\n}\n\n/**\n * Carbon `ContainedList` as a React + Tailwind component, the look of `<ui-contained-list>`: a titled\n * list of rows separated by 1px rules, for settings, side panels and tiles. An on-page list right\n * after another on-page list sits 16px below it.\n */\nexport function ContainedList({ label, kind = 'on-page', size = 'lg', inset = false, action, current = false, className, children, ...rest }: Readonly<ContainedListProps>) {\n    const id = useId();\n    const context = useMemo(() => ({ size, inset }), [size, inset]);\n    const disclosed = kind === 'disclosed';\n    return (\n        <div {...rest} data-contained-list={kind} className={cn('block font-sans', ROW_HEIGHT[size], !disclosed && '[[data-contained-list=on-page]+&]:mt-4', className)}>\n            {label || action ? (\n                <div\n                    className={cn(\n                        'sticky top-0 z-1 box-border flex h-(--_h) items-center border-b border-solid border-hairline bg-layer-background px-4 text-ink type-body-emphasis leading-[18px]!',\n                        disclosed && 'h-8 border-b-0 bg-surface-1 text-ink-muted type-caption leading-4!',\n                        current && ['bg-[color:var(--ui-nav-current-background,var(--ui-canvas-selected))]', CURRENT_MARK],\n                    )}\n                >\n                    <div id={`${id}-label`} className=\"w-full\">\n                        {label}\n                    </div>\n                    <div className=\"-me-4 flex items-center\">{action}</div>\n                </div>\n            ) : null}\n            <ul aria-labelledby={label ? `${id}-label` : undefined} aria-current={current || undefined} className=\"m-0 list-none p-0\">\n                <ListContext.Provider value={context}>{children}</ListContext.Provider>\n            </ul>\n        </div>\n    );\n}\n\nexport interface ContainedListItemProps extends Omit<ComponentProps<'li'>, 'onClick' | 'disabled' | 'icon' | 'action' | 'className' | 'children'> {\n    /** Makes the row a button. */\n    onClick?: () => void;\n    disabled?: boolean;\n    /** A 16px leading icon. */\n    icon?: ReactNode;\n    /** A trailing control (e.g. an IconButton) that stays interactive on its own. */\n    action?: ReactNode;\n    /** Beyond Carbon: the row the user is on (`aria-current=\"true\"` on its button, else on the row; the side nav's current-page look). */\n    current?: boolean;\n    className?: string;\n    children?: ReactNode;\n}\n\n/**\n * A row of a ContainedList (Carbon `ContainedListItem`): `onClick` makes it a button (`disabled`\n * greys it out), `icon` adds a 16px leading icon and `action` a trailing control.\n */\nexport function ContainedListItem({ onClick, disabled = false, icon, action, current = false, className, children, ...rest }: Readonly<ContainedListItemProps>) {\n    const { inset } = useContext(ListContext);\n    const inner = (\n        <span className={cn('grid grid-cols-[1fr] gap-x-3', icon && 'grid-cols-[1rem_1fr]')}>\n            {icon ? <span className=\"inline-flex pt-0.5 [&>svg]:size-4 [&>svg]:fill-icon-primary\">{icon}</span> : <span className=\"hidden\" />}\n            <span>{children}</span>\n        </span>\n    );\n    const content = cn(\n        'm-0 box-border block min-h-(--_h) w-full border-0 bg-transparent px-4 py-[calc((var(--_h)-20px)/2)] text-start text-ink type-body-sm leading-5! transition-[background-color] duration-(--ui-duration-moderate-01) ease-carbon',\n        action && 'pe-12',\n        // the side nav's current page: a fill (kept under the pointer, as there) and the start bar\n        current && ['bg-[color:var(--ui-nav-current-background,var(--ui-canvas-selected))]', CURRENT_MARK],\n    );\n    return (\n        <li aria-current={current && !onClick ? true : undefined} {...rest}\n            className={cn(\n                'relative list-item list-none [&:not(:first-of-type)>:first-child]:-mt-px',\n                \"not-last-of-type:before:absolute not-last-of-type:before:inset-x-0 not-last-of-type:before:bottom-0 not-last-of-type:before:h-px not-last-of-type:before:bg-hairline not-last-of-type:before:content-[''] forced-colors:not-last-of-type:before:bg-[CanvasText]\",\n                inset && 'not-last-of-type:before:inset-x-4',\n                className,\n            )}\n        >\n            {onClick ? (\n                <button\n                    type=\"button\"\n                    disabled={disabled}\n                    aria-current={current || undefined}\n                    onClick={onClick}\n                    className={cn(\n                        content,\n                        'cursor-pointer outline-none disabled:cursor-not-allowed disabled:text-ink-disabled',\n                        !current && 'hover:not-disabled:bg-ghost-hover active:not-disabled:bg-ghost-active',\n                        \"focus-visible:after:absolute focus-visible:after:inset-0 focus-visible:after:rounded-[var(--ui-focus-radius,0px)] focus-visible:after:outline-[length:var(--ui-focus-width,2px)] focus-visible:after:-outline-offset-2 focus-visible:after:outline-focus focus-visible:after:outline-solid focus-visible:after:content-['']\",\n                    )}\n                >\n                    {inner}\n                </button>\n            ) : (\n                <div className={content}>{inner}</div>\n            )}\n            {action ? <div className=\"pointer-events-none absolute inset-x-0 top-0 flex h-(--_h) items-center justify-end [&>*]:pointer-events-auto\">{action}</div> : null}\n        </li>\n    );\n}\n"
    }
  ]
}
