{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "icon-button",
  "type": "registry:ui",
  "title": "<ui-icon-button>",
  "description": "Carbon `IconButton`: a square `<ui-button icon-only>` named by an icon tooltip (`label`), so the name is visible on hover / focus and read by screen readers. Kinds primary / secondary / tertiary / ghost (default ghost), sizes sm 32 / md 40 / lg 48. `pressed` makes it a toggle. `tooltip-placement` takes every Carbon `align` value: top, bottom, left, right, each with `-start` / `-end` (Carbon's deprecated `top-left` … names are not taken); `align` works too, Carbon's name for it. 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/badge-indicator",
    "@kanok-ui/button",
    "@kanok-ui/core-badge-indicator",
    "@kanok-ui/shared-element",
    "@kanok-ui/tooltip",
    "@kanok-ui/tokens"
  ],
  "files": [
    {
      "path": "src/primitives/icon-button/icon-button.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/icon-button/icon-button.ts",
      "content": "import { LitElement, html, css, isServer, nothing } from 'lit';\nimport { customElement, property, query } from 'lit/decorators.js';\nimport type { UiButton } from '../button/button.ts';\nimport type { TooltipPlacement } from '../tooltip/tooltip.ts';\nimport '../button/button.ts';\nimport '../tooltip/tooltip.ts';\nimport { badgeText } from '../../core/badge-indicator.ts';\nimport '../badge-indicator/badge-indicator.ts';\nimport { UiElement } from '../shared/element.ts';\n\nexport type IconButtonKind = 'primary' | 'secondary' | 'tertiary' | 'ghost';\n/** Carbon IconButton sizes (no xl / 2xl, unlike Button): sm 32 · md 40 · lg 48px. */\nexport type IconButtonSize = 'sm' | 'md' | 'lg';\n\n/**\n * Carbon `IconButton`: a square `<ui-button icon-only>` named by an icon tooltip (`label`),\n * so the name is visible on hover / focus and read by screen readers. Kinds primary / secondary /\n * tertiary / ghost (default ghost), sizes sm 32 / md 40 / lg 48. `pressed` makes it a toggle.\n * `tooltip-placement` takes every Carbon `align` value: top, bottom, left, right, each with `-start` / `-end`\n * (Carbon's deprecated `top-left` … names are not taken); `align` works too, Carbon's name for it.\n *\n * `badge-count` (Carbon `badgeCount`, for a ghost lg button) puts a `<ui-badge-indicator>` in its corner: 0 a dot, a\n * number a count read as the button's description; or put your own `<ui-badge-indicator>` inside. Hidden while disabled.\n *\n * @slot - The 16px icon\n * @slot badge-indicator - A `<ui-badge-indicator>` (it takes this slot itself)\n * @fires click - Native\n * @csspart button - The inner `<ui-button>`\n * @csspart tooltip - The `<ui-tooltip>`\n * @fires ui-navigate - detail: { href } (cancelable) on a plain click of the link; cancel it to route client-side (README: SPA router)\n * @attr align - Carbon IconButton's name for `tooltip-placement` (same values)\n */\n@customElement('ui-icon-button')\nexport class UiIconButton extends UiElement {\n    static override readonly shadowRootOptions: ShadowRootInit = { ...LitElement.shadowRootOptions, delegatesFocus: true };\n\n    static override readonly styles = css`\n        :host {\n            display: inline-block;\n            vertical-align: middle;\n        }\n\n        :host([size='sm']) {\n            --_ui-badge-dot-offset: 4px;\n        }\n\n        :host([disabled]) ::slotted(ui-badge-indicator) {\n            display: none;\n        }\n\n        ::slotted(svg) {\n            width: 16px;\n            height: 16px;\n            fill: currentColor;\n        }\n    `;\n\n    /** Required: the accessible name and tooltip text. */\n    @property() label = '';\n\n    @property({ reflect: true }) kind: IconButtonKind = 'ghost';\n\n    @property({ reflect: true }) size: IconButtonSize = 'lg';\n\n    /** Where the tooltip goes: top, bottom, left, right, each with `-start` / `-end` (Carbon `align`). */\n    @property({ attribute: 'tooltip-placement' }) tooltipPlacement: TooltipPlacement = 'bottom';\n\n    /** Carbon IconButton's name for `tooltipPlacement` (same values); an `align` attribute works too. */\n    get align(): TooltipPlacement {\n        return this.tooltipPlacement;\n    }\n\n    set align(value: TooltipPlacement) {\n        this.tooltipPlacement = value;\n    }\n\n    static override get observedAttributes() {\n        return [...super.observedAttributes, 'align'];\n    }\n\n    override attributeChangedCallback(name: string, old: string | null, value: string | null) {\n        if (name !== 'align') super.attributeChangedCallback(name, old, value);\n        else if (value !== null) this.align = value as TooltipPlacement;\n    }\n\n    @property({ type: Boolean, reflect: true }) disabled = false;\n\n    /** Disabled but focusable, so its tooltip can still be read (and say why, e.g. \"Delete — needs approver rights\"). */\n    @property({ type: Boolean, reflect: true, attribute: 'disabled-focusable' }) disabledFocusable = false;\n\n    /** Busy: the icon gives way to a centred spinner, as `<ui-button loading>` (MUI IconButton `loading`). */\n    @property({ type: Boolean, reflect: true }) loading = false;\n\n    /** What `loading` announces (default: the translation's \"Loading\"). */\n    @property({ attribute: 'loading-label' }) loadingLabel = '';\n\n    /** Toggle state (`aria-pressed`); leave unset for a plain button. */\n    @property({ type: Boolean, reflect: true }) pressed?: boolean;\n\n    @property() href = '';\n\n    /** The button opens a popup (`aria-haspopup`); pair with `expanded`. */\n    @property() haspopup = '';\n\n    @property({ type: Boolean }) expanded = false;\n\n    /** A badge in the corner: 0 a dot, a number a count (Carbon `badgeCount`). */\n    @property({\n        attribute: 'badge-count',\n        // a removed attribute is no badge (Lit's Number converter would give null, which shows a dot)\n        converter: { fromAttribute: (value: string | null) => (value === null ? undefined : Number(value)) },\n    })\n    badgeCount?: number;\n\n    @query('ui-button') private readonly button!: UiButton;\n\n    override focus(options?: FocusOptions) {\n        this.button?.focus(options);\n    }\n\n    /** The count of the badge (own or slotted) for screen readers, as Carbon's `aria-describedby` on it. */\n    private get badgeDescription() {\n        if (this.disabled) return '';\n        if (this.badgeCount !== undefined) return badgeText(this.badgeCount);\n        if (isServer) return ''; // the server can't see the light DOM: the client renders it after upgrade\n        return badgeText(this.querySelector('ui-badge-indicator')?.count);\n    }\n\n    override render() {\n        return html`<ui-tooltip as-label part=\"tooltip\" text=${this.label} placement=${this.tooltipPlacement}>\n            <ui-button\n                part=\"button\"\n                icon-only\n                kind=${this.kind}\n                size=${this.size}\n                href=${this.href}\n                ?disabled=${this.disabled}\n                ?disabled-focusable=${this.disabledFocusable}\n                ?loading=${this.loading}\n                loading-label=${this.loadingLabel}\n                .pressed=${this.pressed}\n                haspopup=${this.haspopup}\n                ?expanded=${this.expanded}\n                description=${this.badgeDescription}\n            >\n                <slot slot=\"prefix\"></slot>\n                <slot name=\"badge-indicator\" slot=\"badge-indicator\" @slotchange=${() => this.requestUpdate()}></slot>\n                ${this.badgeCount === undefined || this.disabled ? nothing : html`<ui-badge-indicator .count=${this.badgeCount}></ui-badge-indicator>`}\n            </ui-button>\n        </ui-tooltip>`;\n    }\n}\n\ndeclare global {\n    interface HTMLElementTagNameMap {\n        'ui-icon-button': UiIconButton;\n    }\n}\n"
    }
  ]
}
