{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tw-accordion",
  "type": "registry:ui",
  "title": "react-tw/accordion.tsx",
  "description": "Carbon `Accordion` as React + Tailwind components, the look of `<ui-accordion>`: a list of items 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-theme",
    "@kanok-ui/tw-utils"
  ],
  "files": [
    {
      "path": "src/react-tw/accordion.tsx",
      "type": "registry:ui",
      "target": "components/ui/react-tw/accordion.tsx",
      "content": "import { createContext, useContext, useMemo, type ReactNode, type ComponentProps } from 'react';\nimport { Accordion as AccordionPrimitive } from '@purpurabog/ui/headless';\nimport { cn } from './lib/utils.ts';\n\n/**\n * Carbon `Accordion` as React + Tailwind components, the look of `<ui-accordion>`: a list of items\n * with 1px dividers, each a heading button (sm 32 / md 40 / lg 48px) that shows or hides its content;\n * the chevron at the end (default) or the start, `flush` swaps the outer dividers for 16px-inset lines.\n * Several items may be open at once, as in Carbon.\n */\nexport type AccordionSize = 'sm' | 'md' | 'lg';\n\n/** What the styled parts need to look right; the state (open, disabled) is the primitive's. */\ninterface AccordionLookValue {\n    size: AccordionSize;\n    align: 'start' | 'end';\n    flush: boolean;\n}\n\nconst AccordionContext = createContext<AccordionLookValue>({ size: 'md', align: 'end', flush: false });\n\nexport interface AccordionProps extends Omit<ComponentProps<'ul'>, 'size' | 'align' | 'flush' | 'disabled' | 'children' | 'className'> {\n    size?: AccordionSize;\n    /** Chevron before the title instead of after it. */\n    align?: 'start' | 'end';\n    /** No outer dividers, an inset line between items (Carbon `isFlush`; ignored with `align=\"start\"`). */\n    flush?: boolean;\n    /** Disables every item. */\n    disabled?: boolean;\n    children: ReactNode;\n    className?: string;\n}\n\nexport function Accordion({ size = 'md', align = 'end', flush = false, disabled = false, children, className, ...rest }: Readonly<AccordionProps>) {\n    const context = useMemo(() => ({ size, align, flush: flush && align !== 'start' }), [size, align, flush]);\n    return (\n        <AccordionContext.Provider value={context}>\n            <AccordionPrimitive.Root {...rest} disabled={disabled} className={cn('m-0 block w-full list-none p-0 font-sans', className)}>\n                {children}\n            </AccordionPrimitive.Root>\n        </AccordionContext.Provider>\n    );\n}\n\nexport interface AccordionItemProps extends Omit<ComponentProps<'li'>, 'title' | 'open' | 'defaultOpen' | 'onOpenChange' | 'disabled' | 'children' | 'className'> {\n    title: ReactNode;\n    open?: boolean;\n    defaultOpen?: boolean;\n    /** After the user opened or closed it. */\n    onOpenChange?: (open: boolean) => void;\n    disabled?: boolean;\n    children?: ReactNode;\n    className?: string;\n}\n\n/** The field heights (--ui-field-height-*, as <ui-accordion>): the chevron and the one-line title centred in them. */\nconst HEIGHT = {\n    sm: { heading: 'min-h-field-sm', arrow: 'mt-[calc((var(--ui-field-height-sm)-16px)/2)]', title: 'py-[calc((var(--ui-field-height-sm)-20px)/2)]' },\n    md: { heading: 'min-h-field-md', arrow: 'mt-[calc((var(--ui-field-height-md)-16px)/2)]', title: 'py-[calc((var(--ui-field-height-md)-20px)/2)]' },\n    lg: { heading: 'min-h-field-lg', arrow: 'mt-[calc((var(--ui-field-height-lg)-16px)/2)]', title: 'py-[calc((var(--ui-field-height-lg)-20px)/2)]' },\n} as const;\n/** With the chevron at the start Carbon drops it 2px lower. */\nconst ARROW_START = { sm: 'mt-[calc((var(--ui-field-height-sm)-16px)/2+2px)]', md: 'mt-[calc((var(--ui-field-height-md)-16px)/2+2px)]', lg: 'mt-[calc((var(--ui-field-height-lg)-16px)/2+2px)]' } as const;\n\nexport function AccordionItem({ title, open, defaultOpen = false, onOpenChange, disabled, children, className, ...rest }: Readonly<AccordionItemProps>) {\n    const { flush } = useContext(AccordionContext);\n    return (\n        <AccordionPrimitive.Item\n            {...rest}\n            open={open}\n            defaultOpen={defaultOpen}\n            onOpenChange={onOpenChange}\n            disabled={disabled}\n            className={cn(\n                'block border-0 border-t border-solid border-hairline transition-[border-color] duration-(--ui-duration-moderate) ease-carbon last:border-b',\n                flush && \"border-transparent before:mx-4 before:block before:h-px before:bg-hairline before:content-['']\",\n                className,\n            )}\n        >\n            <AccordionItemBody title={title}>{children}</AccordionItemBody>\n        </AccordionPrimitive.Item>\n    );\n}\n\n/** The heading button and the content of an item, inside its primitive (they follow its open state). */\nfunction AccordionItemBody({ title, children }: Readonly<{ title: ReactNode; children?: ReactNode }>) {\n    const { size, align } = useContext(AccordionContext);\n    const isOpen = AccordionPrimitive.useItemContext().open;\n    const start = align === 'start';\n    return (\n        <>\n            <AccordionPrimitive.Trigger\n                className={cn(\n                    'relative m-0 box-border flex w-full cursor-pointer items-start justify-start border-0 bg-transparent p-0 pe-4 text-start text-ink',\n                    start ? 'flex-row' : 'flex-row-reverse',\n                    HEIGHT[size].heading,\n                    'transition-[background-color] duration-(--ui-duration-moderate) ease-carbon hover:bg-ghost-hover',\n                    // a row: the ring inside, in rounded corners (--ui-accordion-focus-radius; Carbon: square)\n                    'outline-none focus-visible:outline-[length:var(--ui-focus-width,2px)] focus-visible:outline-solid focus-visible:-outline-offset-2 focus-visible:outline-focus focus-visible:rounded-[var(--ui-accordion-focus-radius,0px)] forced-colors:focus-visible:outline-[Highlight]',\n                    'disabled:cursor-not-allowed disabled:text-ink-disabled disabled:hover:bg-transparent',\n                )}\n            >\n                <svg\n                    viewBox=\"0 0 16 16\"\n                    aria-hidden=\"true\"\n                    className={cn(\n                        'size-4 flex-[0_0_16px] fill-current transition-transform duration-(--ui-duration-moderate) ease-carbon',\n                        start ? cn(ARROW_START[size], 'ms-4') : HEIGHT[size].arrow,\n                        isOpen ? '[transform:rotate(-90deg)]' : '[transform:rotate(-270deg)]',\n                    )}\n                >\n                    <path d=\"M11 8 6 13l-.7-.7L9.6 8 5.3 3.7 6 3z\" />\n                </svg>\n                <span className={cn('ms-4 flex-1 type-body-sm leading-5! [word-break:break-word]', HEIGHT[size].title, start && 'me-4')}>{title}</span>\n            </AccordionPrimitive.Trigger>\n            {/* Carbon .cds--accordion__wrapper: everything (display too) moves for 110ms with the entrance easing, opening from @starting-style */}\n            <AccordionPrimitive.Panel\n                className={cn(\n                    'transition-all transition-discrete duration-(--ui-duration-moderate) ease-(--ui-easing-entrance)',\n                    isOpen ? 'block max-h-none overflow-visible pt-2 pb-6 opacity-100 starting:max-h-0 starting:p-0 starting:opacity-0' : 'hidden max-h-0 overflow-hidden p-0 opacity-0',\n                )}\n            >\n                <div className={cn('px-4 type-body-sm leading-5! min-[672px]:pe-12 min-[1056px]:pe-[25%]', start && 'ms-8')}>{children}</div>\n            </AccordionPrimitive.Panel>\n        </>\n    );\n}\n\n/** Carbon `AccordionSkeleton`: `count` headings (a title bar and the chevron), the first open with three lines unless `open` is false; `align=\"start\"` puts the chevron first. Hidden from assistive tech. */\nexport function AccordionSkeleton({ count = 4, open = true, align = 'end', className, ...rest }: Readonly<ComponentProps<'div'> & { count?: number; open?: boolean; align?: 'start' | 'end' }>) {\n    return (\n        <div {...rest} aria-hidden=\"true\" className={cn('block', className)}>\n            {Array.from({ length: Math.max(1, count) }, (_, i) => {\n                const expanded = open && i === 0;\n                return (\n                    <div key={i} className=\"border-0 border-t border-solid border-hairline last:border-b\">\n                        <div className={cn('flex h-10 items-center gap-4 px-4', align === 'start' && 'flex-row-reverse')}>\n                            <span className=\"skeleton block h-4 flex-1\" />\n                            {/* as AccordionItem: pointing down, up when open */}\n                            <svg viewBox=\"0 0 16 16\" aria-hidden=\"true\" className={cn('size-4 shrink-0 fill-icon-primary', expanded ? '[transform:rotate(-90deg)]' : '[transform:rotate(90deg)]')}>\n                                <path d=\"M11 8 6 13l-.7-.7L9.6 8 5.3 3.7 6 3z\" />\n                            </svg>\n                        </div>\n                        {expanded ? (\n                            <div className=\"flex flex-col gap-2 ps-4 pe-[25%] pb-2\">\n                                <span className=\"skeleton block h-4 w-[90%]\" />\n                                <span className=\"skeleton block h-4 w-[80%]\" />\n                                <span className=\"skeleton block h-4 w-[95%]\" />\n                            </div>\n                        ) : null}\n                    </div>\n                );\n            })}\n        </div>\n    );\n}\n"
    }
  ]
}
