{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "form-group",
  "type": "registry:ui",
  "title": "<ui-form-group>",
  "description": "Carbon `FormGroup`: a `<fieldset>` with a Carbon label as its legend, for grouping related fields (an address, a date range). `disabled` disables every form control inside through the native fieldset; `message` shows helper text under the group, red when `invalid`. 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-field",
    "@kanok-ui/shared-slots",
    "@kanok-ui/tokens"
  ],
  "files": [
    {
      "path": "src/primitives/form-group/form-group.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/form-group/form-group.ts",
      "content": "import { html, css, nothing } from 'lit';\nimport { customElement, property } from 'lit/decorators.js';\nimport { fieldTextStyles, inDisabledGroup, uid } from '../shared/field.ts';\nimport { SlotController } from '../shared/slots.ts';\nimport { UiElement } from '../shared/element.ts';\n\n/**\n * Carbon `FormGroup`: a `<fieldset>` with a Carbon label as its legend, for grouping related\n * fields (an address, a date range). `disabled` disables every form control inside through the\n * native fieldset; `message` shows helper text under the group, red when `invalid`.\n *\n * @slot - The fields\n * @slot legend - Rich legend (overrides `legend`)\n * @slot message - Rich message\n * @csspart base - The fieldset\n * @csspart legend - The legend\n * @csspart message - The message\n */\n@customElement('ui-form-group')\nexport class UiFormGroup extends UiElement {\n    static override readonly styles = [fieldTextStyles, css`\n        :host {\n            display: block;\n            font-family: var(--ui-font-family);\n        }\n\n        fieldset {\n            margin: 0;\n            padding: 0;\n            border: none;\n            min-inline-size: 0;\n        }\n\n        legend {\n            padding: 0;\n        }\n\n        .message {\n            margin: var(--ui-space-xs) 0 0;\n            font: var(--ui-font-caption);\n            letter-spacing: var(--ui-tracking-caption);\n            color: var(--ui-ink-muted);\n        }\n\n        :host([invalid]) .message {\n            color: var(--ui-error-text, var(--ui-error));\n        }\n\n        :host([disabled]) .label,\n        :host([disabled]) .message {\n            color: var(--ui-ink-disabled);\n        }\n    `];\n\n    @property() legend = '';\n\n    @property({ type: Boolean, reflect: true }) disabled = false;\n\n    @property({ type: Boolean, reflect: true }) invalid = false;\n\n    /** Helper / error text under the group. */\n    @property() message = '';\n\n    private readonly ids = uid('ui-form-group');\n    private readonly slots = new SlotController(this);\n\n    protected override updated(changed: Map<string, unknown>) {\n        if (changed.has('disabled')) this.relayDisabled();\n    }\n\n    /**\n     * The slotted fields are light-DOM children, not descendants of the shadow `<fieldset>`, so the\n     * browser does not disable them for us. ui-* fields check `inDisabledGroup()` themselves, so they\n     * only need a re-render and `data-group-disabled` for their label colour (never `formDisabledCallback`: that belongs to the browser, and calling it\n     * with `false` would undo a real disabled `<fieldset>` around the group). Native controls get\n     * `disabled` (restored later).\n     */\n    private relayDisabled() {\n        const controls = this.querySelectorAll<HTMLElement & { formDisabledCallback?: unknown; requestUpdate?: (name?: string, oldValue?: unknown) => void }>('*');\n        for (const el of controls) {\n            if (typeof el.formDisabledCallback === 'function' && el.matches(':defined')) {\n                // greys its label and helper (Carbon fieldset[disabled] .cds--label): :host(:disabled) can't see this group\n                el.toggleAttribute('data-group-disabled', inDisabledGroup(el));\n                // under the name the fields' form controller updates with, and its old value (an update is due)\n                el.requestUpdate?.('fieldsetDisabled', !inDisabledGroup(el));\n            } else if (el instanceof HTMLInputElement || el instanceof HTMLSelectElement || el instanceof HTMLTextAreaElement || el instanceof HTMLButtonElement) {\n                if (this.disabled && !el.disabled) {\n                    el.disabled = true;\n                    el.dataset.uiFieldsetDisabled = '';\n                } else if (!this.disabled && 'uiFieldsetDisabled' in el.dataset) {\n                    el.disabled = false;\n                    delete el.dataset.uiFieldsetDisabled;\n                }\n            }\n        }\n    }\n\n    override render() {\n        const hasMessage = this.message || this.slots.has('message');\n        const messageId = `${this.ids}-message`;\n        return html`<fieldset part=\"base\" ?disabled=${this.disabled} aria-invalid=${this.invalid ? 'true' : nothing} aria-describedby=${hasMessage ? messageId : nothing}>\n            <legend class=\"label\" part=\"legend\" id=${`${this.ids}-legend`}><slot name=\"legend\">${this.legend}</slot></legend>\n            <slot @slotchange=${() => this.relayDisabled()}></slot>\n            ${hasMessage ? html`<div class=\"message\" part=\"message\" id=${messageId}><slot name=\"message\">${this.message}</slot></div>` : nothing}\n        </fieldset>`;\n    }\n}\n\ndeclare global {\n    interface HTMLElementTagNameMap {\n        'ui-form-group': UiFormGroup;\n    }\n}\n"
    }
  ]
}
