{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "accordion",
  "type": "registry:ui",
  "title": "<ui-accordion>",
  "description": "Carbon `Accordion`: a vertical list of `<ui-accordion-item>`s with 1px dividers. Sets the size (heading height sm 32 / md 40 / lg 48), the chevron side (`align=\"start\"`) and `flush` on its items. Several items may be open at once, as in Carbon. 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": [
    "lit@^3.3.0"
  ],
  "registryDependencies": [
    "@kanok-ui/shared-element",
    "@kanok-ui/shared-events",
    "@kanok-ui/shared-field",
    "@kanok-ui/shared-skeleton",
    "@kanok-ui/tokens"
  ],
  "files": [
    {
      "path": "src/primitives/accordion/accordion-item.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/accordion/accordion-item.ts",
      "content": "import { LitElement, css, html } from 'lit';\nimport { customElement, property } from 'lit/decorators.js';\nimport { moveTitleToHeading, uid } from '../shared/field.ts';\nimport type { OpenDetail } from '../shared/events.ts';\nimport { UiElement } from '../shared/element.ts';\n\n/**\n * Carbon `AccordionItem`: a heading button that shows or hides its content. Place inside\n * `<ui-accordion>`, which provides the dividers, size and chevron side.\n *\n * @slot - Content\n * @slot title - Heading text with markup; the `heading` attribute is the plain-text fallback\n * @fires ui-toggle - detail: { open } after the user opened or closed it\n * @csspart heading - The heading button\n * @csspart arrow - The chevron\n * @csspart title - The heading text\n * @csspart content - The content wrapper\n * @cssprop --ui-accordion-focus-radius - Corners of the heading's focus ring (default 0; Kanok: 6px)\n */\n@customElement('ui-accordion-item')\nexport class UiAccordionItem extends UiElement {\n    /** `el.focus()` lands on the control inside. */\n    static override readonly shadowRootOptions: ShadowRootInit = { ...LitElement.shadowRootOptions, delegatesFocus: true };\n\n    static override readonly styles = css`\n        :host {\n            --_h: var(--ui-field-height-md, 40px);\n\n            display: block;\n            font-family: var(--ui-font-family);\n        }\n\n        /* the dividers are drawn by the item's part, not :host, so a page-wide CSS reset can't remove them */\n        .item {\n            border-block-start: 1px solid var(--ui-hairline);\n            transition: border-color var(--ui-duration-moderate) var(--ui-easing);\n        }\n\n        :host(:last-of-type) .item {\n            border-block-end: 1px solid var(--ui-hairline);\n        }\n\n        :host([data-size='sm']) {\n            --_h: var(--ui-field-height-sm, 32px);\n        }\n\n        :host([data-size='lg']) {\n            --_h: var(--ui-field-height-lg, 48px);\n        }\n\n        .heading {\n            position: relative;\n            display: flex;\n            flex-direction: row-reverse;\n            align-items: flex-start;\n            justify-content: flex-start;\n            box-sizing: border-box;\n            width: 100%;\n            min-height: var(--_h);\n            margin: 0;\n            padding: 0 var(--ui-space-md) 0 0;\n            border: 0;\n            background: none;\n            color: var(--ui-ink);\n            font: inherit;\n            text-align: start;\n            cursor: pointer;\n            transition: background-color var(--ui-duration-moderate) var(--ui-easing);\n        }\n\n        .heading:hover {\n            background-color: var(--ui-ghost-hover);\n        }\n\n        /* a row: the ring inside, in rounded corners (--ui-accordion-focus-radius; Carbon: square) */\n        .heading:focus-visible {\n            outline: var(--ui-focus-width, 2px) solid var(--ui-focus);\n            outline-offset: -2px;\n            border-radius: var(--ui-accordion-focus-radius, 0);\n        }\n\n        .heading:disabled {\n            color: var(--ui-ink-disabled);\n            cursor: not-allowed;\n        }\n\n        .heading:disabled:hover {\n            background: none;\n        }\n\n        .arrow {\n            flex: 0 0 16px;\n            width: 16px;\n            height: 16px;\n            margin: calc((var(--_h) - 16px) / 2) 0 0;\n            fill: currentColor;\n            transform: rotate(-270deg);\n            transition: transform var(--ui-duration-moderate) var(--ui-easing);\n        }\n\n        :host([open]) .arrow {\n            transform: rotate(-90deg);\n        }\n\n        .title {\n            flex: 1;\n            margin: 0 0 0 var(--ui-space-md);\n            padding: calc((var(--_h) - 20px) / 2) 0;\n            font: var(--ui-font-body-sm);\n            line-height: 20px; /* body-01 */\n            letter-spacing: var(--ui-tracking-body);\n            word-break: break-word;\n        }\n\n        /* chevron on the start side (Carbon align=\"start\") */\n        :host([data-align='start']) .heading {\n            flex-direction: row;\n        }\n\n        :host([data-align='start']) .arrow {\n            margin: calc((var(--_h) - 16px) / 2 + 2px) 0 0 var(--ui-space-md);\n        }\n\n        :host([data-align='start']) .title {\n            margin-inline-end: var(--ui-space-md);\n        }\n\n        /*\n         * Carbon .cds--accordion__wrapper: every property moves (display too, allow-discrete) for 110ms with the\n         * entrance easing; it opens from @starting-style (no padding, height or opacity) and fades out as it closes.\n         */\n        .wrapper {\n            display: none;\n            overflow: hidden;\n            padding: 0;\n            max-height: 0;\n            opacity: 0;\n            transition: all var(--ui-duration-moderate) var(--ui-easing-entrance) allow-discrete;\n        }\n\n        :host([open]) .wrapper {\n            display: block;\n            overflow: visible;\n            max-height: none;\n            opacity: 1;\n            padding-block: var(--ui-space-xs) var(--ui-space-lg);\n        }\n\n        @starting-style {\n            :host([open]) .wrapper {\n                padding: 0;\n                max-height: 0;\n                opacity: 0;\n            }\n        }\n\n        .content {\n            padding-inline: var(--ui-space-md);\n            font: var(--ui-font-body-sm);\n            line-height: 20px;\n            letter-spacing: var(--ui-tracking-body);\n        }\n\n        @media (min-width: 672px) {\n            .content {\n                padding-inline-end: var(--ui-space-xxl); /* Carbon spacing-09 */\n            }\n        }\n\n        @media (min-width: 1056px) {\n            .content {\n                padding-inline-end: 25%;\n            }\n        }\n\n        :host([data-align='start']) .content {\n            margin-inline-start: calc(var(--ui-space-md) + var(--ui-space-md));\n        }\n\n        /* flush: no outer dividers, a 16px-inset line instead (Carbon isFlush) */\n        :host([data-flush]) .item {\n            border-color: transparent;\n        }\n\n        :host([data-flush]) .item::before {\n            content: '';\n            display: block;\n            height: 1px;\n            margin-inline: var(--ui-space-md);\n            background-color: var(--ui-hairline);\n        }\n\n        @media (forced-colors: active) {\n            .heading:focus-visible {\n                outline-color: Highlight;\n            }\n        }\n    `;\n\n    /** Heading text; the `title` slot replaces it when markup is needed. (Before 0.5: the `title` attribute, still accepted.) */\n    @property() heading = '';\n\n    /** @deprecated Use `heading` (a `title` attribute also shows the browser's tooltip). */\n    get titleText() {\n        return this.heading;\n    }\n\n    set titleText(value: string) {\n        this.heading = value;\n    }\n\n    static override get observedAttributes() {\n        return [...super.observedAttributes, 'title'];\n    }\n\n    override attributeChangedCallback(name: string, old: string | null, value: string | null) {\n        if (!moveTitleToHeading(this, name, value)) super.attributeChangedCallback(name, old, value);\n    }\n    @property({ type: Boolean, reflect: true }) open = false;\n    @property({ type: Boolean, reflect: true }) disabled = false;\n\n    private readonly ids = uid('ui-accordion');\n\n    override connectedCallback() {\n        super.connectedCallback();\n        // the accordion exposes role=list; each item is one of its list items (Carbon renders <li>)\n        if (!this.hasAttribute('role')) this.setAttribute('role', 'listitem');\n    }\n\n    private toggle() {\n        if (this.disabled) return;\n        this.open = !this.open;\n        this.dispatchEvent(new CustomEvent('ui-toggle', { detail: { open: this.open }, bubbles: true, composed: true }));\n    }\n\n    override render() {\n        return html`<div class=\"item\">\n            <button class=\"heading\" part=\"heading\" id=\"${this.ids}-heading\" type=\"button\" aria-expanded=${this.open ? 'true' : 'false'} aria-controls=\"${this.ids}-content\" ?disabled=${this.disabled} @click=${this.toggle}>\n                <svg class=\"arrow\" part=\"arrow\" viewBox=\"0 0 16 16\" aria-hidden=\"true\"><path d=\"M11 8 6 13l-.7-.7L9.6 8 5.3 3.7 6 3z\" /></svg>\n                <span class=\"title\" part=\"title\"><slot name=\"title\">${this.heading}</slot></span>\n            </button>\n            <div class=\"wrapper\" id=\"${this.ids}-content\" role=\"region\" aria-labelledby=\"${this.ids}-heading\" ?hidden=${!this.open}>\n                <div class=\"content\" part=\"content\"><slot></slot></div>\n            </div>\n        </div>`;\n    }\n}\n\nexport interface UiAccordionItemEventMap extends HTMLElementEventMap {\n    'ui-toggle': CustomEvent<OpenDetail>;\n}\n\n/** Typed listeners for UiAccordionItem's events (declaration merging with the class). */\nexport interface UiAccordionItem {\n    addEventListener<K extends keyof UiAccordionItemEventMap>(type: K, listener: (this: UiAccordionItem, event: UiAccordionItemEventMap[K]) => unknown, options?: boolean | AddEventListenerOptions): void;\n    addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;\n    removeEventListener<K extends keyof UiAccordionItemEventMap>(type: K, listener: (this: UiAccordionItem, event: UiAccordionItemEventMap[K]) => unknown, options?: boolean | EventListenerOptions): void;\n    removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;\n}\n\ndeclare global {\n    interface HTMLElementTagNameMap {\n        'ui-accordion-item': UiAccordionItem;\n    }\n}\n"
    },
    {
      "path": "src/primitives/accordion/accordion-skeleton.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/accordion/accordion-skeleton.ts",
      "content": "import { html, css } from 'lit';\nimport { customElement, property } from 'lit/decorators.js';\nimport { skeletonStyles, UiSkeletonElement } from '../shared/skeleton.ts';\n\n/**\n * Carbon `AccordionSkeleton` (`cds-accordion-skeleton`): `count` headings (a title bar and the chevron), the first\n * open with three lines (90 / 80 / 95%) unless `open` is off; `alignment=\"start\"` puts the chevron first. Hidden from\n * assistive tech.\n *\n * @csspart title - Each title bar\n * @csspart line - Each line of the open item\n */\n@customElement('ui-accordion-skeleton')\nexport class UiAccordionSkeleton extends UiSkeletonElement {\n    static override readonly styles = [\n        skeletonStyles,\n        css`\n            :host {\n                display: block;\n            }\n\n            .item {\n                border-block-start: 1px solid var(--ui-hairline);\n            }\n\n            .item:last-child {\n                border-block-end: 1px solid var(--ui-hairline);\n            }\n\n            .heading {\n                display: flex;\n                align-items: center;\n                gap: var(--ui-space-md);\n                block-size: 40px;\n                padding: 0 var(--ui-space-md);\n            }\n\n            :host([alignment='start']) .heading {\n                flex-direction: row-reverse;\n            }\n\n            .title {\n                flex: 1;\n                block-size: 16px;\n            }\n\n            .chevron {\n                flex-shrink: 0;\n                inline-size: 16px;\n                block-size: 16px;\n                fill: var(--ui-icon-primary);\n                transform: rotate(90deg); /* as <ui-accordion-item>: pointing down, up when open */\n            }\n\n            .open {\n                transform: rotate(-90deg);\n            }\n\n            /* Carbon's content: 16px in, a quarter of the width free at the end */\n            .content {\n                display: flex;\n                flex-direction: column;\n                gap: var(--ui-space-xs);\n                padding: 0 25% var(--ui-space-xs) var(--ui-space-md);\n            }\n\n            .line {\n                block-size: 16px;\n            }\n\n            .line:nth-child(1) {\n                inline-size: 90%;\n            }\n\n            .line:nth-child(2) {\n                inline-size: 80%;\n            }\n\n            .line:nth-child(3) {\n                inline-size: 95%;\n            }\n        `,\n    ];\n\n    @property({ type: Number }) count = 4;\n\n    /** The first item shows its content. */\n    @property({ type: Boolean }) open = true;\n\n    @property({ reflect: true }) alignment: 'start' | 'end' = 'end';\n\n    override render() {\n        const heading = (open: boolean) => html`<div class=\"heading\">\n            <span class=\"bone title\" part=\"title\"></span>\n            <svg class=${open ? 'chevron open' : 'chevron'} viewBox=\"0 0 16 16\" aria-hidden=\"true\"><path d=\"M11 8 6 13l-.7-.7L9.6 8 5.3 3.7 6 3z\" /></svg>\n        </div>`;\n        return Array.from({ length: Math.max(1, this.count) }, (_, i) => {\n            const open = this.open && i === 0;\n            return html`<div class=\"item\">\n                ${heading(open)}\n                ${open ? html`<div class=\"content\"><span class=\"bone line\" part=\"line\"></span><span class=\"bone line\" part=\"line\"></span><span class=\"bone line\" part=\"line\"></span></div>` : ''}\n            </div>`;\n        });\n    }\n}\n\ndeclare global {\n    interface HTMLElementTagNameMap {\n        'ui-accordion-skeleton': UiAccordionSkeleton;\n    }\n}\n"
    },
    {
      "path": "src/primitives/accordion/accordion.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/accordion/accordion.ts",
      "content": "// Its child elements are one per file beside it; this module re-exports them (one entry point).\nimport { css, html } from 'lit';\nimport { customElement, property, queryAssignedElements } from 'lit/decorators.js';\nimport { UiElement } from '../shared/element.ts';\nimport type { UiAccordionItem } from './accordion-item.ts';\nexport * from './accordion-item.ts';\n\nexport type AccordionSize = 'sm' | 'md' | 'lg';\n\n/**\n * Carbon `Accordion`: a vertical list of `<ui-accordion-item>`s with 1px dividers. Sets the size\n * (heading height sm 32 / md 40 / lg 48), the chevron side (`align=\"start\"`) and `flush` on its items.\n * Several items may be open at once, as in Carbon.\n *\n * @slot - `<ui-accordion-item>` elements\n */\n@customElement('ui-accordion')\nexport class UiAccordion extends UiElement {\n    static override readonly styles = css`\n        :host {\n            display: block;\n            width: 100%;\n            list-style: none;\n            font-family: var(--ui-font-family);\n            /* the reflected \\`align\\` attribute is an HTML presentational hint for text-align: undo it */\n            text-align: start;\n        }\n    `;\n\n    /** Heading height: sm 32px, md 40px (default), lg 48px. */\n    @property({ reflect: true }) size: AccordionSize = 'md';\n    /** Chevron before the title instead of after it. */\n    @property({ reflect: true }) align: 'start' | 'end' = 'end';\n    /** No outer dividers; an inset line between items (Carbon `isFlush`, ignored with `align=\"start\"`). */\n    @property({ type: Boolean, reflect: true }) flush = false;\n    /** Disables every item; removing it again leaves disabled only the items that have their own `disabled`. */\n    @property({ type: Boolean, reflect: true }) disabled = false;\n\n    @queryAssignedElements({ selector: 'ui-accordion-item' }) private readonly items!: UiAccordionItem[];\n\n    protected override updated() {\n        this.sync();\n    }\n\n    private sync() {\n        for (const item of this.items) {\n            item.dataset.size = this.size;\n            item.dataset.align = this.align;\n            item.toggleAttribute('data-flush', this.flush && this.align !== 'start');\n            // mark the items this accordion disabled, so removing `disabled` restores only those (an item disabled on its own stays disabled)\n            if (this.disabled && !item.disabled) {\n                item.disabled = true;\n                item.dataset.uiAccordionDisabled = '';\n            } else if (!this.disabled && 'uiAccordionDisabled' in item.dataset) {\n                item.disabled = false;\n                delete item.dataset.uiAccordionDisabled;\n            }\n        }\n    }\n\n    /** Focus the first enabled item's heading. */\n    override focus(options?: FocusOptions) {\n        this.items.find((i) => !i.disabled)?.focus(options);\n    }\n\n    override render() {\n        return html`<div role=\"list\"><slot @slotchange=${() => this.sync()}></slot></div>`;\n    }\n}\n\ndeclare global {\n    interface HTMLElementTagNameMap {\n        'ui-accordion': UiAccordion;\n    }\n}\n"
    }
  ]
}
