@f-ewald/components 1.38.0 → 1.39.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/custom-elements.json +9 -3
- package/dist/ui-checkbox.d.ts +10 -1
- package/dist/ui-checkbox.d.ts.map +1 -1
- package/dist/ui-checkbox.js +11 -2
- package/dist/ui-checkbox.js.map +1 -1
- package/docs/ui-checkbox.md +13 -2
- package/llms.txt +9 -0
- package/package.json +1 -1
package/custom-elements.json
CHANGED
|
@@ -20130,8 +20130,14 @@
|
|
|
20130
20130
|
"declarations": [
|
|
20131
20131
|
{
|
|
20132
20132
|
"kind": "class",
|
|
20133
|
-
"description": "A form-associated boolean checkbox, usable standalone or inside a native\n`<form>`. Submits `name=on` when checked (matching native\n`<input type=\"checkbox\">` semantics) and participates fully in form\n`reset()`, ancestor `<fieldset disabled>`, and `required` validity.\n\nRenders a native `<input type=\"checkbox\">` wrapped in a `<label>`, styled\nvia `:has()` on the wrapping label (matching `radio-pills`/`radio-cards`)\nrather than styling the native input directly; the checkbox itself renders\nat `1rem`, matching the existing radio-input convention. An optional\npre-rendered `icon` (matching `form-select`'s per-option icon convention)\nrenders between the box and the label, inside the same clickable `<label>`\n— for a row that pairs a checkbox with an icon/swatch and needs the whole\nrow, icon included, to stay one click target.",
|
|
20133
|
+
"description": "A form-associated boolean checkbox, usable standalone or inside a native\n`<form>`. Submits `name=on` when checked (matching native\n`<input type=\"checkbox\">` semantics) and participates fully in form\n`reset()`, ancestor `<fieldset disabled>`, and `required` validity.\n\nRenders a native `<input type=\"checkbox\">` wrapped in a `<label>`, styled\nvia `:has()` on the wrapping label (matching `radio-pills`/`radio-cards`)\nrather than styling the native input directly; the checkbox itself renders\nat `1rem`, matching the existing radio-input convention. An optional\npre-rendered `icon` (matching `form-select`'s per-option icon convention)\nrenders between the box and the label, inside the same clickable `<label>`\n— for a row that pairs a checkbox with an icon/swatch and needs the whole\nrow, icon included, to stay one click target.\n\nThe label is the default slot, with the `label` property as its fallback.\nSlot it instead of setting the property when it needs its own markup or\nstyling — a link, an emphasized word — since a property renders inside this\ncomponent's shadow DOM and cannot be reached from outside. Either way the\nlabel sits inside the native `<label>`, so it stays clickable and still\nnames the checkbox for assistive technology.",
|
|
20134
20134
|
"name": "UiCheckbox",
|
|
20135
|
+
"slots": [
|
|
20136
|
+
{
|
|
20137
|
+
"description": "The label, overriding the `label` property; for a label that needs its own markup or styling.",
|
|
20138
|
+
"name": ""
|
|
20139
|
+
}
|
|
20140
|
+
],
|
|
20135
20141
|
"members": [
|
|
20136
20142
|
{
|
|
20137
20143
|
"kind": "field",
|
|
@@ -20199,7 +20205,7 @@
|
|
|
20199
20205
|
"text": "string"
|
|
20200
20206
|
},
|
|
20201
20207
|
"default": "\"\"",
|
|
20202
|
-
"description": "Visible label text rendered next to the box.",
|
|
20208
|
+
"description": "Visible label text rendered next to the box; overridden by the default slot.",
|
|
20203
20209
|
"attribute": "label"
|
|
20204
20210
|
},
|
|
20205
20211
|
{
|
|
@@ -20414,7 +20420,7 @@
|
|
|
20414
20420
|
"text": "string"
|
|
20415
20421
|
},
|
|
20416
20422
|
"default": "\"\"",
|
|
20417
|
-
"description": "Visible label text rendered next to the box.",
|
|
20423
|
+
"description": "Visible label text rendered next to the box; overridden by the default slot.",
|
|
20418
20424
|
"fieldName": "label"
|
|
20419
20425
|
},
|
|
20420
20426
|
{
|
package/dist/ui-checkbox.d.ts
CHANGED
|
@@ -14,9 +14,18 @@ import { LitElement, type PropertyValues, type TemplateResult } from "lit";
|
|
|
14
14
|
* — for a row that pairs a checkbox with an icon/swatch and needs the whole
|
|
15
15
|
* row, icon included, to stay one click target.
|
|
16
16
|
*
|
|
17
|
+
* The label is the default slot, with the `label` property as its fallback.
|
|
18
|
+
* Slot it instead of setting the property when it needs its own markup or
|
|
19
|
+
* styling — a link, an emphasized word — since a property renders inside this
|
|
20
|
+
* component's shadow DOM and cannot be reached from outside. Either way the
|
|
21
|
+
* label sits inside the native `<label>`, so it stays clickable and still
|
|
22
|
+
* names the checkbox for assistive technology.
|
|
23
|
+
*
|
|
17
24
|
* @element ui-checkbox
|
|
18
25
|
* @fires change - The checkbox was toggled by the user, in either direction;
|
|
19
26
|
* detail: `{ checked }`. Programmatic `checked` assignments do not fire it.
|
|
27
|
+
* @slot - The label, overriding the `label` property; for a label that needs
|
|
28
|
+
* its own markup or styling.
|
|
20
29
|
*/
|
|
21
30
|
export declare class UiCheckbox extends LitElement {
|
|
22
31
|
#private;
|
|
@@ -32,7 +41,7 @@ export declare class UiCheckbox extends LitElement {
|
|
|
32
41
|
required: boolean;
|
|
33
42
|
/** Form field name; submitted as `name=on` only while checked. */
|
|
34
43
|
name: string;
|
|
35
|
-
/** Visible label text rendered next to the box. */
|
|
44
|
+
/** Visible label text rendered next to the box; overridden by the default slot. */
|
|
36
45
|
label: string;
|
|
37
46
|
/** Pre-rendered icon template displayed between the box and the label, e.g. `iconPencil(14)` from this package's icon set. */
|
|
38
47
|
icon: TemplateResult | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ui-checkbox.d.ts","sourceRoot":"","sources":["../src/ui-checkbox.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAsB,KAAK,cAAc,EAAE,KAAK,cAAc,EAAE,MAAM,KAAK,CAAC;AAK/F
|
|
1
|
+
{"version":3,"file":"ui-checkbox.d.ts","sourceRoot":"","sources":["../src/ui-checkbox.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAsB,KAAK,cAAc,EAAE,KAAK,cAAc,EAAE,MAAM,KAAK,CAAC;AAK/F;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,qBACa,UAAW,SAAQ,UAAU;;IACxC,MAAM,CAAC,cAAc,UAAQ;IAE7B,OAAgB,MAAM,4BA4EpB;IAEF,kCAAkC;IACL,OAAO,UAAS;IAC7C,8EAA8E;IACjD,aAAa,UAAS;IACnD,2EAA2E;IAC9C,QAAQ,UAAS;IAC9C,wEAAwE;IAC3C,QAAQ,UAAS;IAC9C,kEAAkE;IACtD,IAAI,SAAM;IACtB,mFAAmF;IACvE,KAAK,SAAM;IACvB,8HAA8H;IAC9F,IAAI,EAAE,cAAc,GAAG,IAAI,CAAQ;IACnE,qEAAqE;IACzC,QAAQ,SAAM;IAEjC,OAAO,CAAC,aAAa,CAAS;IAWvC,UAAmB,UAAU,CAAC,QAAQ,EAAE,cAAc,GAAG,IAAI,CAE5D;IAED,UAAmB,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI,CAQxD;IAED,kFAAkF;IAClF,iBAAiB,IAAI,IAAI,CAGxB;IAED,qDAAqD;IACrD,oBAAoB,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI,CAE5C;IAED,2EAA2E;IAC3E,wBAAwB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,QAAQ,GAAG,IAAI,GAAG,IAAI,CAGrE;IAwCQ,MAAM,sBAyBd;CACF;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,aAAa,EAAE,UAAU,CAAC;KAC3B;CACF"}
|
package/dist/ui-checkbox.js
CHANGED
|
@@ -23,9 +23,18 @@ import { tokens } from "./tokens.js";
|
|
|
23
23
|
* — for a row that pairs a checkbox with an icon/swatch and needs the whole
|
|
24
24
|
* row, icon included, to stay one click target.
|
|
25
25
|
*
|
|
26
|
+
* The label is the default slot, with the `label` property as its fallback.
|
|
27
|
+
* Slot it instead of setting the property when it needs its own markup or
|
|
28
|
+
* styling — a link, an emphasized word — since a property renders inside this
|
|
29
|
+
* component's shadow DOM and cannot be reached from outside. Either way the
|
|
30
|
+
* label sits inside the native `<label>`, so it stays clickable and still
|
|
31
|
+
* names the checkbox for assistive technology.
|
|
32
|
+
*
|
|
26
33
|
* @element ui-checkbox
|
|
27
34
|
* @fires change - The checkbox was toggled by the user, in either direction;
|
|
28
35
|
* detail: `{ checked }`. Programmatic `checked` assignments do not fire it.
|
|
36
|
+
* @slot - The label, overriding the `label` property; for a label that needs
|
|
37
|
+
* its own markup or styling.
|
|
29
38
|
*/
|
|
30
39
|
let UiCheckbox = class UiCheckbox extends LitElement {
|
|
31
40
|
constructor() {
|
|
@@ -40,7 +49,7 @@ let UiCheckbox = class UiCheckbox extends LitElement {
|
|
|
40
49
|
this.required = false;
|
|
41
50
|
/** Form field name; submitted as `name=on` only while checked. */
|
|
42
51
|
this.name = "";
|
|
43
|
-
/** Visible label text rendered next to the box. */
|
|
52
|
+
/** Visible label text rendered next to the box; overridden by the default slot. */
|
|
44
53
|
this.label = "";
|
|
45
54
|
/** Pre-rendered icon template displayed between the box and the label, e.g. `iconPencil(14)` from this package's icon set. */
|
|
46
55
|
this.icon = null;
|
|
@@ -213,7 +222,7 @@ let UiCheckbox = class UiCheckbox extends LitElement {
|
|
|
213
222
|
>`
|
|
214
223
|
: nothing}
|
|
215
224
|
<span
|
|
216
|
-
>${this.label}
|
|
225
|
+
><slot>${this.label}</slot>${this.required
|
|
217
226
|
? html `<span class="required-mark" aria-hidden="true"> *</span><span class="sr-only">
|
|
218
227
|
(required)</span
|
|
219
228
|
>`
|
package/dist/ui-checkbox.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ui-checkbox.js","sourceRoot":"","sources":["../src/ui-checkbox.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAA4C,MAAM,KAAK,CAAC;AAC/F,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC;;;;;;;;;;;;;;;;;;GAkBG;AAEI,IAAM,UAAU,GAAhB,MAAM,UAAW,SAAQ,UAAU;IAAnC;;QAiFL,kCAAkC;QACL,YAAO,G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C,QAAQ;YAC3B,CAAC,CAAC,IAAI,CAAA;;kBAEA;YACN,CAAC,CAAC,EAAE;;;KAGX,CAAC;IACJ,CAAC;CACF,CAAA;AA1H8B;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;2CAAiB;AAEhB;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;iDAAuB;AAEtB;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;4CAAkB;AAEjB;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;4CAAkB;AAElC;IAAX,QAAQ,EAAE;wCAAW;AAEV;IAAX,QAAQ,EAAE;yCAAY;AAES;IAA/B,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;wCAAoC;AAEvC;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;4CAAe;AAEzB;IAAhB,KAAK,EAAE;iDAA+B;AAlG5B,UAAU;IADtB,aAAa,CAAC,aAAa,CAAC;GAChB,UAAU,CA4MtB","sourcesContent":["import { LitElement, css, html, nothing, type PropertyValues, type TemplateResult } from \"lit\";\nimport { customElement, property, state } from \"lit/decorators.js\";\nimport { ref } from \"lit/directives/ref.js\";\nimport { tokens } from \"./tokens.js\";\n\n/**\n * A form-associated boolean checkbox, usable standalone or inside a native\n * `<form>`. Submits `name=on` when checked (matching native\n * `<input type=\"checkbox\">` semantics) and participates fully in form\n * `reset()`, ancestor `<fieldset disabled>`, and `required` validity.\n *\n * Renders a native `<input type=\"checkbox\">` wrapped in a `<label>`, styled\n * via `:has()` on the wrapping label (matching `radio-pills`/`radio-cards`)\n * rather than styling the native input directly; the checkbox itself renders\n * at `1rem`, matching the existing radio-input convention. An optional\n * pre-rendered `icon` (matching `form-select`'s per-option icon convention)\n * renders between the box and the label, inside the same clickable `<label>`\n * — for a row that pairs a checkbox with an icon/swatch and needs the whole\n * row, icon included, to stay one click target.\n *\n * @element ui-checkbox\n * @fires change - The checkbox was toggled by the user, in either direction;\n * detail: `{ checked }`. Programmatic `checked` assignments do not fire it.\n */\n@customElement(\"ui-checkbox\")\nexport class UiCheckbox extends LitElement {\n static formAssociated = true;\n\n static override styles = [\n tokens,\n css`\n :host {\n display: inline-block;\n }\n .checkbox {\n display: inline-flex;\n align-items: center;\n gap: 0.5rem;\n min-height: 2rem;\n cursor: pointer;\n font-family: var(--ui-font, ui-sans-serif, system-ui, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\", \"Noto Color Emoji\");\n font-size: var(--ui-font-size-sm, 0.75rem);\n line-height: var(--ui-line-height-tight, 1.25);\n color: var(--ui-text, #0f172a);\n }\n .checkbox input {\n width: 1rem;\n height: 1rem;\n margin: 0;\n accent-color: var(--ui-primary, #4f46e5);\n cursor: pointer;\n }\n .checkbox:has(input:focus-visible) {\n outline: none;\n }\n .checkbox:has(input:focus-visible) input {\n outline: none;\n box-shadow: var(--ui-focus-ring, 0 0 0 3px rgb(79 70 229 / 0.35));\n border-radius: var(--ui-radius-sm, 0.25rem);\n }\n .checkbox:has(input:disabled) {\n cursor: not-allowed;\n opacity: 0.6;\n }\n .checkbox:has(input:disabled) input {\n cursor: not-allowed;\n }\n .required-mark {\n color: var(--ui-danger, #dc2626);\n }\n .checkbox-icon {\n display: inline-flex;\n width: var(--checkbox-icon-size);\n height: var(--checkbox-icon-size);\n flex: 0 0 var(--checkbox-icon-size);\n }\n .checkbox-icon > svg {\n width: 100%;\n height: 100%;\n }\n .sr-only {\n position: absolute;\n width: 1px;\n height: 1px;\n margin: -1px;\n padding: 0;\n overflow: hidden;\n clip: rect(0 0 0 0);\n clip-path: inset(50%);\n white-space: nowrap;\n border: 0;\n }\n @media (forced-colors: active) {\n .checkbox:has(input:focus-visible) input {\n outline: 2px solid CanvasText;\n outline-offset: 2px;\n box-shadow: none;\n }\n .checkbox:has(input:disabled) {\n color: GrayText;\n opacity: 1;\n }\n }\n `,\n ];\n\n /** Whether the box is checked. */\n @property({ type: Boolean }) checked = false;\n /** Visual \"partial selection\" state; cleared on the next user interaction. */\n @property({ type: Boolean }) indeterminate = false;\n /** Disables interaction; merged with an ancestor `<fieldset disabled>`. */\n @property({ type: Boolean }) disabled = false;\n /** Marks the control invalid via `ElementInternals` while unchecked. */\n @property({ type: Boolean }) required = false;\n /** Form field name; submitted as `name=on` only while checked. */\n @property() name = \"\";\n /** Visible label text rendered next to the box. */\n @property() label = \"\";\n /** Pre-rendered icon template displayed between the box and the label, e.g. `iconPencil(14)` from this package's icon set. */\n @property({ attribute: false }) icon: TemplateResult | null = null;\n /** Square icon size in pixels — 14 (inline icon size) by default. */\n @property({ type: Number }) iconSize = 14;\n\n @state() private _formDisabled = false;\n\n #internals = this.attachInternals();\n #defaultChecked = false;\n #inputEl: HTMLInputElement | null = null;\n\n /** Whether the host or an ancestor fieldset currently disables the control. */\n get #isDisabled(): boolean {\n return this.disabled || this._formDisabled;\n }\n\n protected override willUpdate(_changed: PropertyValues): void {\n if (!this.hasUpdated) this.#defaultChecked = this.checked;\n }\n\n protected override updated(changed: PropertyValues): void {\n if (changed.has(\"checked\") || changed.has(\"name\")) this.#syncFormValue();\n if (changed.has(\"checked\") || changed.has(\"required\") || changed.has(\"disabled\") || changed.has(\"_formDisabled\")) {\n this.#syncValidity();\n }\n if (changed.has(\"indeterminate\") && this.#inputEl) {\n this.#inputEl.indeterminate = this.indeterminate;\n }\n }\n\n /** Restores the checked state captured at first render, per the form contract. */\n formResetCallback(): void {\n this.checked = this.#defaultChecked;\n this.indeterminate = false;\n }\n\n /** Mirrors an ancestor fieldset's disabled state. */\n formDisabledCallback(disabled: boolean): void {\n this._formDisabled = disabled;\n }\n\n /** Restores the checked state from saved form state (bfcache/autofill). */\n formStateRestoreCallback(state: string | File | FormData | null): void {\n if (typeof state !== \"string\") return;\n this.checked = state === \"on\";\n }\n\n #syncFormValue(): void {\n if (!this.name || !this.checked) {\n this.#internals.setFormValue(null);\n return;\n }\n this.#internals.setFormValue(\"on\");\n }\n\n #syncValidity(): void {\n if (this.#isDisabled) {\n this.#internals.setValidity({});\n return;\n }\n if (this.required && !this.checked) {\n this.#internals.setValidity(\n { valueMissing: true },\n \"Please check this box to continue.\",\n this.#inputEl ?? undefined,\n );\n } else {\n this.#internals.setValidity({});\n }\n }\n\n #onChange(e: Event): void {\n const input = e.target as HTMLInputElement;\n this.checked = input.checked;\n this.indeterminate = false;\n this.dispatchEvent(\n new CustomEvent(\"change\", { detail: { checked: this.checked }, bubbles: true, composed: true }),\n );\n }\n\n #onInputRef = (el: Element | undefined): void => {\n this.#inputEl = (el as HTMLInputElement | undefined) ?? null;\n if (this.#inputEl) this.#inputEl.indeterminate = this.indeterminate;\n };\n\n override render() {\n return html`\n <label class=\"checkbox\">\n <input\n ${ref(this.#onInputRef)}\n type=\"checkbox\"\n .checked=${this.checked}\n ?disabled=${this.#isDisabled}\n ?required=${this.required}\n @change=${(e: Event) => this.#onChange(e)}\n />\n ${this.icon\n ? html`<span class=\"checkbox-icon\" style=${`--checkbox-icon-size: ${this.iconSize}px`} aria-hidden=\"true\"\n >${this.icon}</span\n >`\n : nothing}\n <span\n >${this.label}${this.required\n ? html`<span class=\"required-mark\" aria-hidden=\"true\"> *</span><span class=\"sr-only\">\n (required)</span\n >`\n : \"\"}</span\n >\n </label>\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n \"ui-checkbox\": UiCheckbox;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ui-checkbox.js","sourceRoot":"","sources":["../src/ui-checkbox.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAA4C,MAAM,KAAK,CAAC;AAC/F,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAE,GAAG,EAAE,MAAM,uB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AEzC,IAAI,CAAC,IAAI;YACT,CAAC,CAAC,IAAI,CAAA,qCAAqC,yBAAyB,IAAI,CAAC,QAAQ,IAAI;iBAC9E,IAAI,CAAC,IAAI;cACZ;YACJ,CAAC,CAAC,OAAO;;mBAEA,IAAI,CAAC,KAAK,UAAU,IAAI,CAAC,QAAQ;YACxC,CAAC,CAAC,IAAI,CAAA;;kBAEA;YACN,CAAC,CAAC,EAAE;;;KAGX,CAAC;IACJ,CAAC;CACF,CAAA;AA1H8B;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;2CAAiB;AAEhB;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;iDAAuB;AAEtB;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;4CAAkB;AAEjB;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;4CAAkB;AAElC;IAAX,QAAQ,EAAE;wCAAW;AAEV;IAAX,QAAQ,EAAE;yCAAY;AAES;IAA/B,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;wCAAoC;AAEvC;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;4CAAe;AAEzB;IAAhB,KAAK,EAAE;iDAA+B;AAlG5B,UAAU;IADtB,aAAa,CAAC,aAAa,CAAC;GAChB,UAAU,CA4MtB","sourcesContent":["import { LitElement, css, html, nothing, type PropertyValues, type TemplateResult } from \"lit\";\nimport { customElement, property, state } from \"lit/decorators.js\";\nimport { ref } from \"lit/directives/ref.js\";\nimport { tokens } from \"./tokens.js\";\n\n/**\n * A form-associated boolean checkbox, usable standalone or inside a native\n * `<form>`. Submits `name=on` when checked (matching native\n * `<input type=\"checkbox\">` semantics) and participates fully in form\n * `reset()`, ancestor `<fieldset disabled>`, and `required` validity.\n *\n * Renders a native `<input type=\"checkbox\">` wrapped in a `<label>`, styled\n * via `:has()` on the wrapping label (matching `radio-pills`/`radio-cards`)\n * rather than styling the native input directly; the checkbox itself renders\n * at `1rem`, matching the existing radio-input convention. An optional\n * pre-rendered `icon` (matching `form-select`'s per-option icon convention)\n * renders between the box and the label, inside the same clickable `<label>`\n * — for a row that pairs a checkbox with an icon/swatch and needs the whole\n * row, icon included, to stay one click target.\n *\n * The label is the default slot, with the `label` property as its fallback.\n * Slot it instead of setting the property when it needs its own markup or\n * styling — a link, an emphasized word — since a property renders inside this\n * component's shadow DOM and cannot be reached from outside. Either way the\n * label sits inside the native `<label>`, so it stays clickable and still\n * names the checkbox for assistive technology.\n *\n * @element ui-checkbox\n * @fires change - The checkbox was toggled by the user, in either direction;\n * detail: `{ checked }`. Programmatic `checked` assignments do not fire it.\n * @slot - The label, overriding the `label` property; for a label that needs\n * its own markup or styling.\n */\n@customElement(\"ui-checkbox\")\nexport class UiCheckbox extends LitElement {\n static formAssociated = true;\n\n static override styles = [\n tokens,\n css`\n :host {\n display: inline-block;\n }\n .checkbox {\n display: inline-flex;\n align-items: center;\n gap: 0.5rem;\n min-height: 2rem;\n cursor: pointer;\n font-family: var(--ui-font, ui-sans-serif, system-ui, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\", \"Noto Color Emoji\");\n font-size: var(--ui-font-size-sm, 0.75rem);\n line-height: var(--ui-line-height-tight, 1.25);\n color: var(--ui-text, #0f172a);\n }\n .checkbox input {\n width: 1rem;\n height: 1rem;\n margin: 0;\n accent-color: var(--ui-primary, #4f46e5);\n cursor: pointer;\n }\n .checkbox:has(input:focus-visible) {\n outline: none;\n }\n .checkbox:has(input:focus-visible) input {\n outline: none;\n box-shadow: var(--ui-focus-ring, 0 0 0 3px rgb(79 70 229 / 0.35));\n border-radius: var(--ui-radius-sm, 0.25rem);\n }\n .checkbox:has(input:disabled) {\n cursor: not-allowed;\n opacity: 0.6;\n }\n .checkbox:has(input:disabled) input {\n cursor: not-allowed;\n }\n .required-mark {\n color: var(--ui-danger, #dc2626);\n }\n .checkbox-icon {\n display: inline-flex;\n width: var(--checkbox-icon-size);\n height: var(--checkbox-icon-size);\n flex: 0 0 var(--checkbox-icon-size);\n }\n .checkbox-icon > svg {\n width: 100%;\n height: 100%;\n }\n .sr-only {\n position: absolute;\n width: 1px;\n height: 1px;\n margin: -1px;\n padding: 0;\n overflow: hidden;\n clip: rect(0 0 0 0);\n clip-path: inset(50%);\n white-space: nowrap;\n border: 0;\n }\n @media (forced-colors: active) {\n .checkbox:has(input:focus-visible) input {\n outline: 2px solid CanvasText;\n outline-offset: 2px;\n box-shadow: none;\n }\n .checkbox:has(input:disabled) {\n color: GrayText;\n opacity: 1;\n }\n }\n `,\n ];\n\n /** Whether the box is checked. */\n @property({ type: Boolean }) checked = false;\n /** Visual \"partial selection\" state; cleared on the next user interaction. */\n @property({ type: Boolean }) indeterminate = false;\n /** Disables interaction; merged with an ancestor `<fieldset disabled>`. */\n @property({ type: Boolean }) disabled = false;\n /** Marks the control invalid via `ElementInternals` while unchecked. */\n @property({ type: Boolean }) required = false;\n /** Form field name; submitted as `name=on` only while checked. */\n @property() name = \"\";\n /** Visible label text rendered next to the box; overridden by the default slot. */\n @property() label = \"\";\n /** Pre-rendered icon template displayed between the box and the label, e.g. `iconPencil(14)` from this package's icon set. */\n @property({ attribute: false }) icon: TemplateResult | null = null;\n /** Square icon size in pixels — 14 (inline icon size) by default. */\n @property({ type: Number }) iconSize = 14;\n\n @state() private _formDisabled = false;\n\n #internals = this.attachInternals();\n #defaultChecked = false;\n #inputEl: HTMLInputElement | null = null;\n\n /** Whether the host or an ancestor fieldset currently disables the control. */\n get #isDisabled(): boolean {\n return this.disabled || this._formDisabled;\n }\n\n protected override willUpdate(_changed: PropertyValues): void {\n if (!this.hasUpdated) this.#defaultChecked = this.checked;\n }\n\n protected override updated(changed: PropertyValues): void {\n if (changed.has(\"checked\") || changed.has(\"name\")) this.#syncFormValue();\n if (changed.has(\"checked\") || changed.has(\"required\") || changed.has(\"disabled\") || changed.has(\"_formDisabled\")) {\n this.#syncValidity();\n }\n if (changed.has(\"indeterminate\") && this.#inputEl) {\n this.#inputEl.indeterminate = this.indeterminate;\n }\n }\n\n /** Restores the checked state captured at first render, per the form contract. */\n formResetCallback(): void {\n this.checked = this.#defaultChecked;\n this.indeterminate = false;\n }\n\n /** Mirrors an ancestor fieldset's disabled state. */\n formDisabledCallback(disabled: boolean): void {\n this._formDisabled = disabled;\n }\n\n /** Restores the checked state from saved form state (bfcache/autofill). */\n formStateRestoreCallback(state: string | File | FormData | null): void {\n if (typeof state !== \"string\") return;\n this.checked = state === \"on\";\n }\n\n #syncFormValue(): void {\n if (!this.name || !this.checked) {\n this.#internals.setFormValue(null);\n return;\n }\n this.#internals.setFormValue(\"on\");\n }\n\n #syncValidity(): void {\n if (this.#isDisabled) {\n this.#internals.setValidity({});\n return;\n }\n if (this.required && !this.checked) {\n this.#internals.setValidity(\n { valueMissing: true },\n \"Please check this box to continue.\",\n this.#inputEl ?? undefined,\n );\n } else {\n this.#internals.setValidity({});\n }\n }\n\n #onChange(e: Event): void {\n const input = e.target as HTMLInputElement;\n this.checked = input.checked;\n this.indeterminate = false;\n this.dispatchEvent(\n new CustomEvent(\"change\", { detail: { checked: this.checked }, bubbles: true, composed: true }),\n );\n }\n\n #onInputRef = (el: Element | undefined): void => {\n this.#inputEl = (el as HTMLInputElement | undefined) ?? null;\n if (this.#inputEl) this.#inputEl.indeterminate = this.indeterminate;\n };\n\n override render() {\n return html`\n <label class=\"checkbox\">\n <input\n ${ref(this.#onInputRef)}\n type=\"checkbox\"\n .checked=${this.checked}\n ?disabled=${this.#isDisabled}\n ?required=${this.required}\n @change=${(e: Event) => this.#onChange(e)}\n />\n ${this.icon\n ? html`<span class=\"checkbox-icon\" style=${`--checkbox-icon-size: ${this.iconSize}px`} aria-hidden=\"true\"\n >${this.icon}</span\n >`\n : nothing}\n <span\n ><slot>${this.label}</slot>${this.required\n ? html`<span class=\"required-mark\" aria-hidden=\"true\"> *</span><span class=\"sr-only\">\n (required)</span\n >`\n : \"\"}</span\n >\n </label>\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n \"ui-checkbox\": UiCheckbox;\n }\n}\n"]}
|
package/docs/ui-checkbox.md
CHANGED
|
@@ -14,6 +14,13 @@ renders between the box and the label, inside the same clickable `<label>`
|
|
|
14
14
|
— for a row that pairs a checkbox with an icon/swatch and needs the whole
|
|
15
15
|
row, icon included, to stay one click target.
|
|
16
16
|
|
|
17
|
+
The label is the default slot, with the `label` property as its fallback.
|
|
18
|
+
Slot it instead of setting the property when it needs its own markup or
|
|
19
|
+
styling — a link, an emphasized word — since a property renders inside this
|
|
20
|
+
component's shadow DOM and cannot be reached from outside. Either way the
|
|
21
|
+
label sits inside the native `<label>`, so it stays clickable and still
|
|
22
|
+
names the checkbox for assistive technology.
|
|
23
|
+
|
|
17
24
|
## Install
|
|
18
25
|
|
|
19
26
|
```js
|
|
@@ -25,6 +32,8 @@ import "@f-ewald/components/ui-checkbox.js";
|
|
|
25
32
|
```html
|
|
26
33
|
<ui-checkbox label="Subscribe to updates"></ui-checkbox>
|
|
27
34
|
<ui-checkbox name="terms" label="I agree to the terms" required></ui-checkbox>
|
|
35
|
+
<!-- Slot the label when it needs its own markup; it overrides the property -->
|
|
36
|
+
<ui-checkbox name="beta">Enable <strong>beta</strong> features</ui-checkbox>
|
|
28
37
|
<!-- .icon is set programmatically (a pre-rendered TemplateResult), not an attribute -->
|
|
29
38
|
<ui-checkbox label="Show list view"></ui-checkbox>
|
|
30
39
|
```
|
|
@@ -38,7 +47,7 @@ import "@f-ewald/components/ui-checkbox.js";
|
|
|
38
47
|
| `disabled` | `disabled` | `boolean` | `false` | Disables interaction; merged with an ancestor `<fieldset disabled>`. |
|
|
39
48
|
| `required` | `required` | `boolean` | `false` | Marks the control invalid via `ElementInternals` while unchecked. |
|
|
40
49
|
| `name` | `name` | `string` | `""` | Form field name; submitted as `name=on` only while checked. |
|
|
41
|
-
| `label` | `label` | `string` | `""` | Visible label text rendered next to the box. |
|
|
50
|
+
| `label` | `label` | `string` | `""` | Visible label text rendered next to the box; overridden by the default slot. |
|
|
42
51
|
| `icon` | _(JS property only)_ | `TemplateResult | null` | `null` | Pre-rendered icon template displayed between the box and the label, e.g. `iconPencil(14)` from this package's icon set. |
|
|
43
52
|
| `iconSize` | `iconSize` | `number` | `14` | Square icon size in pixels — 14 (inline icon size) by default. |
|
|
44
53
|
|
|
@@ -50,7 +59,9 @@ import "@f-ewald/components/ui-checkbox.js";
|
|
|
50
59
|
|
|
51
60
|
## Slots
|
|
52
61
|
|
|
53
|
-
|
|
62
|
+
| Slot | Description |
|
|
63
|
+
| --- | --- |
|
|
64
|
+
| `(default)` | The label, overriding the `label` property; for a label that needs its own markup or styling. |
|
|
54
65
|
|
|
55
66
|
## CSS custom properties
|
|
56
67
|
|
package/llms.txt
CHANGED
|
@@ -2697,6 +2697,13 @@ renders between the box and the label, inside the same clickable `<label>`
|
|
|
2697
2697
|
— for a row that pairs a checkbox with an icon/swatch and needs the whole
|
|
2698
2698
|
row, icon included, to stay one click target.
|
|
2699
2699
|
|
|
2700
|
+
The label is the default slot, with the `label` property as its fallback.
|
|
2701
|
+
Slot it instead of setting the property when it needs its own markup or
|
|
2702
|
+
styling — a link, an emphasized word — since a property renders inside this
|
|
2703
|
+
component's shadow DOM and cannot be reached from outside. Either way the
|
|
2704
|
+
label sits inside the native `<label>`, so it stays clickable and still
|
|
2705
|
+
names the checkbox for assistive technology.
|
|
2706
|
+
|
|
2700
2707
|
Import: `import "@f-ewald/components/ui-checkbox.js";`
|
|
2701
2708
|
|
|
2702
2709
|
Properties: `checked` (attribute `checked`) : boolean, default false; `indeterminate` (attribute `indeterminate`) : boolean, default false; `disabled` (attribute `disabled`) : boolean, default false; `required` (attribute `required`) : boolean, default false; `name` (attribute `name`) : string, default ""; `label` (attribute `label`) : string, default ""; `icon` (JS property only) : TemplateResult | null, default null; `iconSize` (attribute `iconSize`) : number, default 14
|
|
@@ -2707,6 +2714,8 @@ Example:
|
|
|
2707
2714
|
```html
|
|
2708
2715
|
<ui-checkbox label="Subscribe to updates"></ui-checkbox>
|
|
2709
2716
|
<ui-checkbox name="terms" label="I agree to the terms" required></ui-checkbox>
|
|
2717
|
+
<!-- Slot the label when it needs its own markup; it overrides the property -->
|
|
2718
|
+
<ui-checkbox name="beta">Enable <strong>beta</strong> features</ui-checkbox>
|
|
2710
2719
|
<!-- .icon is set programmatically (a pre-rendered TemplateResult), not an attribute -->
|
|
2711
2720
|
<ui-checkbox label="Show list view"></ui-checkbox>
|
|
2712
2721
|
```
|