{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tag",
  "type": "registry:ui",
  "title": "<ui-tag>",
  "description": "Carbon tag in its four forms: read-only `Tag` (default), `DismissibleTag` (`dismissible`), `SelectableTag` (`selectable`, a toggle with `aria-pressed`) and `OperationalTag` (`operational`, a bordered button that opens something). Twelve colour `type`s, sizes sm 18 / md 24 / lg 32. 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-localize",
    "@kanok-ui/shared-skeleton",
    "@kanok-ui/tokens"
  ],
  "files": [
    {
      "path": "src/primitives/tag/tag-skeleton.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/tag/tag-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 `TagSkeleton` (`cds-tag-skeleton`): a 60px pill at the tag's height (sm 18 / md 24 / lg 32px). Hidden from\n * assistive tech.\n *\n * @csspart bone - The pill\n */\n@customElement('ui-tag-skeleton')\nexport class UiTagSkeleton extends UiSkeletonElement {\n    static override readonly styles = [\n        skeletonStyles,\n        css`\n            :host {\n                display: inline-block;\n                vertical-align: middle;\n            }\n\n            .bone {\n                inline-size: 60px;\n                block-size: 24px;\n                border-radius: var(--ui-tag-radius, 16px); /* the tag's corners */\n            }\n\n            :host([size='sm']) .bone {\n                block-size: 18px;\n            }\n\n            :host([size='lg']) .bone {\n                block-size: 32px;\n            }\n        `,\n    ];\n\n    @property({ reflect: true }) size: 'sm' | 'md' | 'lg' = 'md';\n\n    override render() {\n        return html`<div class=\"bone\" part=\"bone\"></div>`;\n    }\n}\n\ndeclare global {\n    interface HTMLElementTagNameMap {\n        'ui-tag-skeleton': UiTagSkeleton;\n    }\n}\n"
    },
    {
      "path": "src/primitives/tag/tag.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/tag/tag.ts",
      "content": "import { LitElement, html, css, nothing } from 'lit';\nimport { customElement, property } from 'lit/decorators.js';\nimport { LocalizeController } from '../shared/localize.ts';\nimport { UiElement } from '../shared/element.ts';\n\nexport type TagType = 'red' | 'magenta' | 'purple' | 'blue' | 'cyan' | 'teal' | 'green' | 'gray' | 'cool-gray' | 'warm-gray' | 'high-contrast' | 'outline';\nexport type TagSize = 'sm' | 'md' | 'lg';\n\nconst closeIcon = html`<svg viewBox=\"0 0 16 16\" aria-hidden=\"true\"><path d=\"m12 4.7-.7-.7L8 7.3 4.7 4l-.7.7L7.3 8 4 11.3l.7.7L8 8.7l3.3 3.3.7-.7L8.7 8z\" /></svg>`;\n\n/**\n * Carbon tag in its four forms: read-only `Tag` (default), `DismissibleTag` (`dismissible`),\n * `SelectableTag` (`selectable`, a toggle with `aria-pressed`) and `OperationalTag` (`operational`,\n * a bordered button that opens something). Twelve colour `type`s, sizes sm 18 / md 24 / lg 32.\n *\n * Geometry and colours follow Carbon `_tag.scss`: label-01 type, 16px radius, 32–208px wide,\n * 8px inline padding (12px for lg), a round close button as tall as the tag; colours come from\n * `--ui-tag-{background,color,hover,border}-<type>` generated from `@carbon/themes`.\n *\n * @slot - The tag text\n * @slot icon - A 16px icon before the text (Carbon `renderIcon`)\n * @fires ui-dismiss - The dismiss button was pressed (the tag stays until you remove it)\n * @fires change - A selectable tag was toggled (`selected` already updated)\n * @csspart base - The tag box\n * @csspart label - The text\n * @csspart dismiss-button - The close button of a dismissible tag\n * @cssprop --ui-tag-radius - Corner radius (default 16px: a pill)\n * @cssprop --ui-tag-selectable-border - Outline of a selectable tag (default `--ui-border-inverse`; Kanok: `--ui-hairline-strong`)\n * @cssprop --ui-tag-selected - Fill and outline of a chosen selectable tag (default `--ui-layer-selected-inverse`; Kanok: `--ui-primary`); its text `--ui-tag-selected-ink` (`--ui-inverse-ink`)\n * @cssprop --ui-tag-font - Font of the label (default `--ui-font-caption`; Kanok: medium weight)\n * @cssprop --ui-tag-high-contrast / --ui-tag-high-contrast-ink / --ui-tag-high-contrast-hover / --ui-tag-high-contrast-border / --ui-tag-high-contrast-edge / --ui-tag-high-contrast-focus - The high-contrast type (default Carbon's inverse block; Kanok: an outlined ink tag)\n * @cssprop --ui-focus-offset - `outline-offset` of its focus ring (default -2px: inside; Kanok: 2px outside)\n */\n@customElement('ui-tag')\nexport class UiTag 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: 24px;\n            --_bg: var(--ui-tag-background-gray);\n            --_fg: var(--ui-tag-color-gray);\n            --_hover: var(--ui-tag-hover-gray);\n            --_border: var(--ui-tag-border-gray);\n\n            display: inline-flex;\n            vertical-align: middle;\n            font-family: var(--ui-font-family);\n        }\n\n        :host([size='sm']) {\n            --_h: 18px;\n        }\n\n        :host([size='lg']) {\n            --_h: 32px;\n        }\n\n        :host([type='red']) { --_bg: var(--ui-tag-background-red); --_fg: var(--ui-tag-color-red); --_hover: var(--ui-tag-hover-red); --_border: var(--ui-tag-border-red); }\n        :host([type='magenta']) { --_bg: var(--ui-tag-background-magenta); --_fg: var(--ui-tag-color-magenta); --_hover: var(--ui-tag-hover-magenta); --_border: var(--ui-tag-border-magenta); }\n        :host([type='purple']) { --_bg: var(--ui-tag-background-purple); --_fg: var(--ui-tag-color-purple); --_hover: var(--ui-tag-hover-purple); --_border: var(--ui-tag-border-purple); }\n        :host([type='blue']) { --_bg: var(--ui-tag-background-blue); --_fg: var(--ui-tag-color-blue); --_hover: var(--ui-tag-hover-blue); --_border: var(--ui-tag-border-blue); }\n        :host([type='cyan']) { --_bg: var(--ui-tag-background-cyan); --_fg: var(--ui-tag-color-cyan); --_hover: var(--ui-tag-hover-cyan); --_border: var(--ui-tag-border-cyan); }\n        :host([type='teal']) { --_bg: var(--ui-tag-background-teal); --_fg: var(--ui-tag-color-teal); --_hover: var(--ui-tag-hover-teal); --_border: var(--ui-tag-border-teal); }\n        :host([type='green']) { --_bg: var(--ui-tag-background-green); --_fg: var(--ui-tag-color-green); --_hover: var(--ui-tag-hover-green); --_border: var(--ui-tag-border-green); }\n        :host([type='cool-gray']) { --_bg: var(--ui-tag-background-cool-gray); --_fg: var(--ui-tag-color-cool-gray); --_hover: var(--ui-tag-hover-cool-gray); --_border: var(--ui-tag-border-cool-gray); }\n        :host([type='warm-gray']) { --_bg: var(--ui-tag-background-warm-gray); --_fg: var(--ui-tag-color-warm-gray); --_hover: var(--ui-tag-hover-warm-gray); --_border: var(--ui-tag-border-warm-gray); }\n        /* --ui-tag-high-contrast-*: Carbon's inverse block; a design can make it an outlined ink tag */\n        :host([type='high-contrast']) { --_bg: var(--ui-tag-high-contrast, var(--ui-inverse-canvas)); --_fg: var(--ui-tag-high-contrast-ink, var(--ui-inverse-ink)); --_hover: var(--ui-tag-high-contrast-hover, var(--ui-inverse-hover)); --_border: var(--ui-tag-high-contrast-border, var(--ui-inverse-canvas)); }\n        :host([type='outline']) { --_bg: var(--ui-canvas); --_fg: var(--ui-ink); --_hover: var(--ui-ghost-hover); --_border: var(--ui-inverse-canvas); }\n\n        .tag {\n            box-sizing: border-box;\n            display: inline-flex;\n            align-items: center;\n            justify-content: center;\n            min-width: 32px;\n            max-width: 208px;\n            min-height: var(--_h);\n            margin: 0;\n            padding: 0 var(--ui-space-xs);\n            border: 0;\n            border-radius: var(--ui-tag-radius, 16px); /* a pill at every size */\n            background-color: var(--_bg);\n            color: var(--_fg);\n            font: var(--ui-tag-font, var(--ui-font-caption));\n            line-height: 16px; /* label-01 */\n            letter-spacing: var(--ui-tracking-caption);\n            cursor: default;\n            overflow-wrap: anywhere;\n        }\n\n        :host([size='lg']) .tag {\n            padding: 0 var(--ui-space-sm);\n        }\n\n        :host([type='outline']) .tag {\n            box-shadow: inset 0 0 0 1px var(--_border);\n        }\n\n        :host([type='high-contrast']) .tag {\n            box-shadow: var(--ui-tag-high-contrast-edge, none);\n        }\n\n        .label {\n            display: block;\n            overflow: hidden;\n            text-overflow: ellipsis;\n            white-space: nowrap;\n        }\n\n        ::slotted([slot='icon']) {\n            flex-shrink: 0;\n            width: 16px;\n            height: 16px;\n            margin-inline-end: var(--ui-space-xxs);\n            fill: currentColor;\n        }\n\n        :host(.has-icon) .tag {\n            padding-inline-start: var(--ui-space-xxs);\n        }\n\n        /* dismissible: the round close button is as tall as the tag and replaces the end padding */\n        :host([dismissible]) .tag {\n            padding-inline-end: 0;\n        }\n\n        .close {\n            display: flex;\n            flex-shrink: 0;\n            align-items: center;\n            justify-content: center;\n            width: var(--_h);\n            height: var(--_h);\n            margin: 0 0 0 2px;\n            padding: 0;\n            border: 0;\n            border-radius: 50%;\n            background-color: transparent;\n            color: currentColor;\n            cursor: pointer;\n            transition: background-color var(--ui-duration-fast) var(--ui-easing);\n        }\n\n        .close svg {\n            width: 16px;\n            height: 16px;\n            fill: currentColor;\n        }\n\n        .close:hover {\n            background-color: var(--_hover);\n        }\n\n        .close:focus-visible {\n            outline: var(--ui-focus-width, 2px) solid var(--ui-focus);\n            outline-offset: var(--ui-focus-offset, -2px);\n        }\n\n        :host([type='high-contrast']) .close:focus-visible {\n            outline-color: var(--ui-tag-high-contrast-focus, var(--ui-focus-inverse));\n        }\n\n        /* interactive forms: buttons with Carbon's focus ring */\n        /* no transition: Carbon's selectable and operational tags change colour at once */\n        button.tag {\n            cursor: pointer;\n            font-family: inherit;\n        }\n\n        button.tag:focus-visible {\n            outline: var(--ui-focus-width, 2px) solid var(--ui-focus);\n            outline-offset: 1px;\n        }\n\n        /* --ui-tag-selectable-border / --ui-tag-selected / -ink: Carbon's inverse outline and fill; a design can use its brand */\n        .selectable {\n            border: 1px solid var(--ui-tag-selectable-border, var(--ui-border-inverse));\n            background-color: var(--ui-surface-1);\n            color: var(--ui-ink);\n        }\n\n        .selectable:hover {\n            background-color: var(--ui-ghost-hover);\n        }\n\n        .selectable[aria-pressed='true'],\n        .selectable[aria-pressed='true']:hover {\n            border-color: var(--ui-tag-selected, var(--ui-border-inverse));\n            background-color: var(--ui-tag-selected, var(--ui-layer-selected-inverse));\n            color: var(--ui-tag-selected-ink, var(--ui-inverse-ink));\n        }\n\n        .operational {\n            border: 1px solid var(--_border);\n        }\n\n        .operational:hover {\n            background-color: var(--_hover);\n        }\n\n        /* disabled */\n        :host([disabled]) .tag,\n        :host([disabled]) .tag:hover {\n            background-color: var(--ui-surface-1);\n            color: var(--ui-ink-disabled);\n            box-shadow: none;\n            cursor: not-allowed;\n        }\n\n        :host([disabled]) .selectable,\n        :host([disabled]) .operational {\n            border-color: var(--ui-ink-disabled);\n        }\n\n        :host([disabled]) .close {\n            cursor: not-allowed;\n        }\n\n        :host([disabled]) .close:hover {\n            background-color: transparent;\n        }\n\n        @media (forced-colors: active) {\n            .tag {\n                border: 1px solid CanvasText;\n            }\n\n            /* the chosen tag is a fill, which forced colours drop: the system highlight shows it instead */\n            .selectable[aria-pressed='true'] {\n                forced-color-adjust: none;\n                border-color: Highlight;\n                background-color: Highlight;\n                color: HighlightText;\n            }\n        }\n    `;\n\n    /** Colour (Carbon `type`). */\n    @property({ reflect: true }) type: TagType = 'gray';\n\n    private readonly localize = new LocalizeController(this);\n    /** sm 18px · md 24px (default) · lg 32px */\n    @property({ reflect: true }) size: TagSize = 'md';\n    /** Shows a close button that fires `ui-dismiss`. */\n    @property({ type: Boolean, reflect: true }) dismissible = false;\n    /** A toggle button (`aria-pressed`); use `selected` for its state. */\n    @property({ type: Boolean, reflect: true }) selectable = false;\n    @property({ type: Boolean, reflect: true }) selected = false;\n    /** A bordered button for tags that open or trigger something. */\n    @property({ type: Boolean, reflect: true }) operational = false;\n    @property({ type: Boolean, reflect: true }) disabled = false;\n    /** A dismissible tag's full text for the browser tooltip (defaults to the text); other tags have none (Carbon WC). */\n    @property({ attribute: 'tag-title' }) tagTitle = '';\n    /** Accessible name of the close button; `{text}` is replaced with the tag text. */\n    @property({ attribute: 'dismiss-label' }) dismissLabel = '';\n\n    /** An operational tag's accessible name, when its text alone doesn't say it (e.g. \"+3\": \"3 more tags\"). */\n    @property() label = '';\n\n    /** An operational tag that opens a popup: whether it is open (`aria-expanded`, with `aria-haspopup`). */\n    @property({ type: Boolean }) expanded?: boolean;\n\n    private get text() {\n        return this.textContent?.trim() ?? '';\n    }\n\n    private onIconSlot(event: Event) {\n        const has = (event.target as HTMLSlotElement).assignedElements().length > 0;\n        this.classList.toggle('has-icon', has);\n    }\n\n    private dismiss(event: Event) {\n        event.stopPropagation();\n        if (this.disabled) return;\n        this.dispatchEvent(new CustomEvent('ui-dismiss', { bubbles: true, composed: true }));\n    }\n\n    private toggleSelected() {\n        if (this.disabled) return;\n        this.selected = !this.selected;\n        this.dispatchEvent(new Event('change', { bubbles: true }));\n    }\n\n    private renderContent() {\n        return html`<slot name=\"icon\" @slotchange=${this.onIconSlot}></slot><span class=\"label\" part=\"label\" title=${(this.dismissible && (this.tagTitle || this.text)) || nothing}><slot></slot></span>`;\n    }\n\n    override render() {\n        if (this.selectable) {\n            return html`<button class=\"tag selectable\" part=\"base\" type=\"button\" aria-pressed=${this.selected ? 'true' : 'false'} ?disabled=${this.disabled} @click=${this.toggleSelected}>\n                ${this.renderContent()}\n            </button>`;\n        }\n        if (this.operational) {\n            const popup = this.expanded !== undefined;\n            return html`<button\n                class=\"tag operational\"\n                part=\"base\"\n                type=\"button\"\n                aria-label=${this.label || nothing}\n                aria-haspopup=${popup ? 'true' : nothing}\n                aria-expanded=${popup ? String(this.expanded) : nothing}\n                ?disabled=${this.disabled}\n            >\n                ${this.renderContent()}\n            </button>`;\n        }\n        return html`<span class=\"tag\" part=\"base\">\n            ${this.renderContent()}\n            ${this.dismissible\n                ? html`<button class=\"close\" part=\"dismiss-button\" type=\"button\" aria-label=${(this.dismissLabel || this.localize.t.common.dismiss).replace('{text}', this.text)} ?disabled=${this.disabled} @click=${this.dismiss}>\n                      ${closeIcon}\n                  </button>`\n                : nothing}\n        </span>`;\n    }\n}\n\nexport interface UiTagEventMap extends HTMLElementEventMap {\n    'ui-dismiss': CustomEvent<null>;\n}\n\n/** Typed listeners for UiTag's events (declaration merging with the class). */\nexport interface UiTag {\n    addEventListener<K extends keyof UiTagEventMap>(type: K, listener: (this: UiTag, event: UiTagEventMap[K]) => unknown, options?: boolean | AddEventListenerOptions): void;\n    addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;\n    removeEventListener<K extends keyof UiTagEventMap>(type: K, listener: (this: UiTag, event: UiTagEventMap[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-tag': UiTag;\n    }\n}\n"
    }
  ]
}
