luxen-ui 0.16.2 → 0.17.1

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.
Files changed (47) hide show
  1. package/README.md +50 -49
  2. package/cdn/custom-elements.json +237 -1
  3. package/cdn/elements/avatar/avatar.d.ts.map +1 -1
  4. package/cdn/elements/avatar/avatar.js +1 -1
  5. package/cdn/elements/avatar/avatar.js.map +1 -1
  6. package/cdn/elements/dropdown-item/dropdown-item.d.ts +4 -0
  7. package/cdn/elements/dropdown-item/dropdown-item.d.ts.map +1 -1
  8. package/cdn/elements/dropdown-item/dropdown-item.js +2 -2
  9. package/cdn/elements/dropdown-item/dropdown-item.js.map +1 -1
  10. package/cdn/elements/segmented-control/index.d.ts +2 -0
  11. package/cdn/elements/segmented-control/index.d.ts.map +1 -0
  12. package/cdn/elements/segmented-control/index.js +2 -0
  13. package/cdn/elements/segmented-control/index.js.map +1 -0
  14. package/cdn/elements/segmented-control/segmented-control.d.ts +80 -0
  15. package/cdn/elements/segmented-control/segmented-control.d.ts.map +1 -0
  16. package/cdn/elements/segmented-control/segmented-control.js +2 -0
  17. package/cdn/elements/segmented-control/segmented-control.js.map +1 -0
  18. package/cdn/registry.d.ts +1 -1
  19. package/cdn/registry.d.ts.map +1 -1
  20. package/cdn/registry.js.map +1 -1
  21. package/cdn/standalone.css +167 -0
  22. package/cdn/standalone.js +25 -22
  23. package/cdn/standalone.js.map +1 -1
  24. package/cdn/styles/elements/segmented-control.css +165 -0
  25. package/dist/css/elements/segmented-control.css +165 -0
  26. package/dist/custom-elements.json +237 -1
  27. package/dist/elements/avatar/avatar.d.ts.map +1 -1
  28. package/dist/elements/avatar/avatar.js +27 -7
  29. package/dist/elements/dropdown-item/dropdown-item.css +18 -0
  30. package/dist/elements/dropdown-item/dropdown-item.d.ts +4 -0
  31. package/dist/elements/dropdown-item/dropdown-item.d.ts.map +1 -1
  32. package/dist/elements/dropdown-item/dropdown-item.js +11 -2
  33. package/dist/elements/segmented-control/index.d.ts +2 -0
  34. package/dist/elements/segmented-control/index.d.ts.map +1 -0
  35. package/dist/elements/segmented-control/index.js +4 -0
  36. package/dist/elements/segmented-control/segmented-control.d.ts +80 -0
  37. package/dist/elements/segmented-control/segmented-control.d.ts.map +1 -0
  38. package/dist/elements/segmented-control/segmented-control.js +307 -0
  39. package/dist/metadata/dropdown-item.json +16 -1
  40. package/dist/metadata/index.json +122 -2
  41. package/dist/metadata/segmented-control.json +105 -0
  42. package/dist/registry.d.ts +1 -1
  43. package/dist/registry.d.ts.map +1 -1
  44. package/dist/templates/elements/dropdown.md +52 -0
  45. package/dist/templates/elements/segmented-control.md +252 -0
  46. package/elements.json +8 -0
  47. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"dropdown-item.d.ts","sourceRoot":"","sources":["../../../src/html/elements/dropdown-item/dropdown-item.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,KAAK,cAAc,EAAE,MAAM,KAAK,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAU7D;;;;;;;;;;;;;GAaG;AACH,qBAAa,YAAa,SAAQ,YAAY;IAC5C,OAAgB,MAAM,4BAAwB;IAE9C,OAAO,CAAC,gBAAgB,CAIrB;IAEH,2CAA2C;IAE3C,QAAQ,CAAC,KAAK,SAAM;IAEpB,yBAAyB;IAEzB,QAAQ,CAAC,QAAQ,UAAS;IAE1B,gDAAgD;IAEhD,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,UAAU,CAAY;IAEhD,4CAA4C;IAE5C,QAAQ,CAAC,OAAO,UAAS;IAEzB,+EAA+E;IAE/E,QAAQ,CAAC,WAAW,UAAS;IAG7B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IAErC,2DAA2D;IAC3D,IAAI,UAAU,IAAI,OAAO,CAExB;IAEQ,iBAAiB;IAU1B,OAAO,KAAK,UAAU,GAErB;IAED,2EAA2E;IAC3E,YAAY,IAAI,MAAM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c,CAAC,IAAI,CAAC;IAM9C,OAAO,CAAC,YAAY;YAKN,wBAAwB;IA2BtC,OAAO,CAAC,oBAAoB,CAK1B;IAEO,MAAM;CAiEhB"}
@@ -15,7 +15,7 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
15
15
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
16
16
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
17
17
  };
18
- var _DropdownItem_value_accessor_storage, _DropdownItem_disabled_accessor_storage, _DropdownItem_type_accessor_storage, _DropdownItem_checked_accessor_storage, _DropdownItem_submenuOpen_accessor_storage, _DropdownItem__hasSubmenu_accessor_storage;
18
+ var _DropdownItem_value_accessor_storage, _DropdownItem_disabled_accessor_storage, _DropdownItem_type_accessor_storage, _DropdownItem_variant_accessor_storage, _DropdownItem_checked_accessor_storage, _DropdownItem_submenuOpen_accessor_storage, _DropdownItem__hasSubmenu_accessor_storage;
19
19
  import { html, nothing, unsafeCSS } from 'lit';
20
20
  import { LuxenElement } from '../../shared/luxen-element.js';
21
21
  import { property, state } from 'lit/decorators.js';
@@ -36,6 +36,8 @@ const styles = unsafeCSS(rawStyles);
36
36
  *
37
37
  * @cssproperty --color - Text color.
38
38
  *
39
+ * @attribute variant - destructive — Renders the item as a destructive action (red), for delete-style entries.
40
+ *
39
41
  * @customElement l-dropdown-item
40
42
  */
41
43
  export class DropdownItem extends LuxenElement {
@@ -49,6 +51,7 @@ export class DropdownItem extends LuxenElement {
49
51
  _DropdownItem_value_accessor_storage.set(this, '');
50
52
  _DropdownItem_disabled_accessor_storage.set(this, false);
51
53
  _DropdownItem_type_accessor_storage.set(this, 'normal');
54
+ _DropdownItem_variant_accessor_storage.set(this, undefined);
52
55
  _DropdownItem_checked_accessor_storage.set(this, false);
53
56
  _DropdownItem_submenuOpen_accessor_storage.set(this, false);
54
57
  _DropdownItem__hasSubmenu_accessor_storage.set(this, false);
@@ -68,6 +71,9 @@ export class DropdownItem extends LuxenElement {
68
71
  /** The type of item: `normal` or `checkbox`. */
69
72
  get type() { return __classPrivateFieldGet(this, _DropdownItem_type_accessor_storage, "f"); }
70
73
  set type(value) { __classPrivateFieldSet(this, _DropdownItem_type_accessor_storage, value, "f"); }
74
+ /** Visual variant. `destructive` marks a delete-style action in red. */
75
+ get variant() { return __classPrivateFieldGet(this, _DropdownItem_variant_accessor_storage, "f"); }
76
+ set variant(value) { __classPrivateFieldSet(this, _DropdownItem_variant_accessor_storage, value, "f"); }
71
77
  /** Whether the checkbox item is checked. */
72
78
  get checked() { return __classPrivateFieldGet(this, _DropdownItem_checked_accessor_storage, "f"); }
73
79
  set checked(value) { __classPrivateFieldSet(this, _DropdownItem_checked_accessor_storage, value, "f"); }
@@ -228,7 +234,7 @@ export class DropdownItem extends LuxenElement {
228
234
  `;
229
235
  }
230
236
  }
231
- _DropdownItem_value_accessor_storage = new WeakMap(), _DropdownItem_disabled_accessor_storage = new WeakMap(), _DropdownItem_type_accessor_storage = new WeakMap(), _DropdownItem_checked_accessor_storage = new WeakMap(), _DropdownItem_submenuOpen_accessor_storage = new WeakMap(), _DropdownItem__hasSubmenu_accessor_storage = new WeakMap();
237
+ _DropdownItem_value_accessor_storage = new WeakMap(), _DropdownItem_disabled_accessor_storage = new WeakMap(), _DropdownItem_type_accessor_storage = new WeakMap(), _DropdownItem_variant_accessor_storage = new WeakMap(), _DropdownItem_checked_accessor_storage = new WeakMap(), _DropdownItem_submenuOpen_accessor_storage = new WeakMap(), _DropdownItem__hasSubmenu_accessor_storage = new WeakMap();
232
238
  DropdownItem.styles = [hostStyles, styles];
233
239
  __decorate([
234
240
  property()
@@ -239,6 +245,9 @@ __decorate([
239
245
  __decorate([
240
246
  property()
241
247
  ], DropdownItem.prototype, "type", null);
248
+ __decorate([
249
+ property({ reflect: true })
250
+ ], DropdownItem.prototype, "variant", null);
242
251
  __decorate([
243
252
  property({ type: Boolean, reflect: true })
244
253
  ], DropdownItem.prototype, "checked", null);
@@ -0,0 +1,2 @@
1
+ export * from './segmented-control.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/html/elements/segmented-control/index.ts"],"names":[],"mappings":"AAEA,cAAc,wBAAwB,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { define } from '../../define.js';
2
+ import { SegmentedControl } from './segmented-control.js';
3
+ export * from './segmented-control.js';
4
+ define('segmented-control', SegmentedControl);
@@ -0,0 +1,80 @@
1
+ import { LuxenFormAssociatedElement } from '../../shared/luxen-form-associated-element.js';
2
+ export type SegmentedControlSize = 'sm' | 'md' | 'lg' | 'xl';
3
+ /** Fired when the selected segment changes. Bubbles; not composed. */
4
+ export declare class SegmentChangeEvent extends Event {
5
+ readonly value: string;
6
+ readonly index: number;
7
+ constructor(value: string, index: number);
8
+ }
9
+ interface SegmentedControlEventMap {
10
+ change: SegmentChangeEvent;
11
+ }
12
+ /**
13
+ * @summary A single-select segmented control: a compact, mutually-exclusive
14
+ * switch between a few options (radio-group semantics with a sliding pill).
15
+ * Progressively enhances light-DOM `<button>`s so it works before JS runs.
16
+ * Form-associated: give it a `name` and its selected `value` is submitted with
17
+ * the form (and restored on reset), like a native radio group.
18
+ *
19
+ * @example
20
+ * Mark the initially-selected segment with `aria-checked="true"` (or set
21
+ * `value` to its `value` attribute) so it is styled before the script upgrades
22
+ * the element.
23
+ * ```html
24
+ * <l-segmented-control label="Metric" value="cost">
25
+ * <button value="volume">Volume</button>
26
+ * <button value="cost" aria-checked="true">Cost</button>
27
+ * </l-segmented-control>
28
+ * ```
29
+ *
30
+ * @event change - Fired when the selected segment changes. Not cancelable. Bubbles. Properties: `value: string`, `index: number`.
31
+ *
32
+ * @cssproperty [--indicator-color=var(--l-color-surface)] - Background of the sliding pill behind the selected segment.
33
+ * @cssproperty [--border-radius=var(--l-radius-lg)] - Corner radius of the track.
34
+ *
35
+ * @customElement l-segmented-control
36
+ */
37
+ export declare class SegmentedControl extends LuxenFormAssociatedElement {
38
+ createRenderRoot(): this;
39
+ private _initialized;
40
+ private _setupTimer;
41
+ private _buttons;
42
+ private _resizeObserver;
43
+ /** Value of the selected segment (its `value` attribute, else its index). */
44
+ value: string;
45
+ /** Control height, aligned with buttons and form controls at the same size. */
46
+ size: SegmentedControlSize;
47
+ /** Accessible label announced for the group. Not displayed on screen. */
48
+ label?: string;
49
+ /** Stretch segments to fill the container width. */
50
+ fullWidth: boolean;
51
+ connectedCallback(): void;
52
+ disconnectedCallback(): void;
53
+ /** @returns true when setup ran or was already done; false to schedule a retry. */
54
+ private _trySetup;
55
+ updated(changed: Map<string, unknown>): void;
56
+ formResetCallback(): void;
57
+ formStateRestoreCallback(state: string, mode: 'restore' | 'autocomplete'): void;
58
+ private _setup;
59
+ private _teardown;
60
+ /** Resolve the selected index from `value`, else an authored `aria-checked`, else 0. */
61
+ private _resolveActiveIndex;
62
+ private _syncValueFromIndex;
63
+ private _select;
64
+ /** Index of the next non-disabled segment from `from`, moving by `dir`, wrapping. */
65
+ private _nextEnabled;
66
+ private _isDisabled;
67
+ /** Reflect the host `disabled` state onto the segments (aria + tab order). */
68
+ private _applyDisabledState;
69
+ private _updateIndicator;
70
+ private _onClick;
71
+ private _onKeyDown;
72
+ }
73
+ export interface SegmentedControl {
74
+ addEventListener<K extends keyof SegmentedControlEventMap>(type: K, listener: (this: SegmentedControl, ev: SegmentedControlEventMap[K]) => void, options?: boolean | AddEventListenerOptions): void;
75
+ addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
76
+ removeEventListener<K extends keyof SegmentedControlEventMap>(type: K, listener: (this: SegmentedControl, ev: SegmentedControlEventMap[K]) => void, options?: boolean | EventListenerOptions): void;
77
+ removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
78
+ }
79
+ export {};
80
+ //# sourceMappingURL=segmented-control.d.ts.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;IAI3B,OAAO,CAAC,OAAO;IAuBf,qFAAqF;IACrF,OAAO,CAAC,YAAY;IASpB,OAAO,CAAC,WAAW;IAInB,8EAA8E;IAC9E,OAAO,CAAC,mBAAmB;IAe3B,OAAO,CAAC,gBAAgB;IASxB,OAAO,CAAC,QAAQ,CAQd;IAKF,OAAO,CAAC,UAAU,CAkChB;CACH;AAQD,MAAM,WAAW,gBAAgB;IAC/B,gBAAgB,CAAC,CAAC,SAAS,MAAM,wBAAwB,EACvD,IAAI,EAAE,CAAC,EACP,QAAQ,EAAE,CAAC,IAAI,EAAE,gBAAgB,EAAE,EAAE,EAAE,wBAAwB,CAAC,CAAC,CAAC,KAAK,IAAI,EAC3E,OAAO,CAAC,EAAE,OAAO,GAAG,uBAAuB,GAC1C,IAAI,CAAC;IACR,gBAAgB,CACd,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,kCAAkC,EAC5C,OAAO,CAAC,EAAE,OAAO,GAAG,uBAAuB,GAC1C,IAAI,CAAC;IACR,mBAAmB,CAAC,CAAC,SAAS,MAAM,wBAAwB,EAC1D,IAAI,EAAE,CAAC,EACP,QAAQ,EAAE,CAAC,IAAI,EAAE,gBAAgB,EAAE,EAAE,EAAE,wBAAwB,CAAC,CAAC,CAAC,KAAK,IAAI,EAC3E,OAAO,CAAC,EAAE,OAAO,GAAG,oBAAoB,GACvC,IAAI,CAAC;IACR,mBAAmB,CACjB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,kCAAkC,EAC5C,OAAO,CAAC,EAAE,OAAO,GAAG,oBAAoB,GACvC,IAAI,CAAC;CACT"}
@@ -0,0 +1,307 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { property } from 'lit/decorators.js';
8
+ import { LuxenFormAssociatedElement } from '../../shared/luxen-form-associated-element.js';
9
+ /** Fired when the selected segment changes. Bubbles; not composed. */
10
+ export class SegmentChangeEvent extends Event {
11
+ constructor(value, index) {
12
+ super('change', { bubbles: true, composed: false, cancelable: false });
13
+ this.value = value;
14
+ this.index = index;
15
+ }
16
+ }
17
+ /**
18
+ * @summary A single-select segmented control: a compact, mutually-exclusive
19
+ * switch between a few options (radio-group semantics with a sliding pill).
20
+ * Progressively enhances light-DOM `<button>`s so it works before JS runs.
21
+ * Form-associated: give it a `name` and its selected `value` is submitted with
22
+ * the form (and restored on reset), like a native radio group.
23
+ *
24
+ * @example
25
+ * Mark the initially-selected segment with `aria-checked="true"` (or set
26
+ * `value` to its `value` attribute) so it is styled before the script upgrades
27
+ * the element.
28
+ * ```html
29
+ * <l-segmented-control label="Metric" value="cost">
30
+ * <button value="volume">Volume</button>
31
+ * <button value="cost" aria-checked="true">Cost</button>
32
+ * </l-segmented-control>
33
+ * ```
34
+ *
35
+ * @event change - Fired when the selected segment changes. Not cancelable. Bubbles. Properties: `value: string`, `index: number`.
36
+ *
37
+ * @cssproperty [--indicator-color=var(--l-color-surface)] - Background of the sliding pill behind the selected segment.
38
+ * @cssproperty [--border-radius=var(--l-radius-lg)] - Corner radius of the track.
39
+ *
40
+ * @customElement l-segmented-control
41
+ */
42
+ // oxlint-disable-next-line typescript/no-unsafe-declaration-merging -- typed addEventListener overloads merged below; no uninitialized properties.
43
+ export class SegmentedControl extends LuxenFormAssociatedElement {
44
+ constructor() {
45
+ super(...arguments);
46
+ this._initialized = false;
47
+ this._setupTimer = 0;
48
+ this._buttons = [];
49
+ this._resizeObserver = null;
50
+ /** Value of the selected segment (its `value` attribute, else its index). */
51
+ this.value = '';
52
+ /** Control height, aligned with buttons and form controls at the same size. */
53
+ this.size = 'md';
54
+ /** Stretch segments to fill the container width. */
55
+ this.fullWidth = false;
56
+ // --- Event handlers ---
57
+ this._onClick = (e) => {
58
+ if (this.disabled)
59
+ return;
60
+ const btn = e.target.closest('button');
61
+ if (!btn)
62
+ return;
63
+ const index = this._buttons.indexOf(btn);
64
+ if (index < 0 || this._isDisabled(btn))
65
+ return;
66
+ this._select(index);
67
+ btn.focus();
68
+ };
69
+ // Typed `Event` (not `KeyboardEvent`): the listener is attached to `this`,
70
+ // whose merged addEventListener overloads (see the interface below) fall back
71
+ // to the platform `EventListener` signature for non-map events like `keydown`.
72
+ this._onKeyDown = (e) => {
73
+ if (this.disabled)
74
+ return;
75
+ const ke = e;
76
+ const target = e.target;
77
+ if (target.getAttribute('role') !== 'radio')
78
+ return;
79
+ const current = this._buttons.indexOf(target);
80
+ if (current < 0)
81
+ return;
82
+ let next = current;
83
+ switch (ke.key) {
84
+ case 'ArrowRight':
85
+ case 'ArrowDown':
86
+ next = this._nextEnabled(current, 1);
87
+ break;
88
+ case 'ArrowLeft':
89
+ case 'ArrowUp':
90
+ next = this._nextEnabled(current, -1);
91
+ break;
92
+ case 'Home':
93
+ next = this._nextEnabled(-1, 1);
94
+ break;
95
+ case 'End':
96
+ next = this._nextEnabled(this._buttons.length, -1);
97
+ break;
98
+ case ' ':
99
+ // Space (re)selects the focused segment (APG radio group).
100
+ break;
101
+ default:
102
+ return;
103
+ }
104
+ e.preventDefault();
105
+ this._select(next);
106
+ this._buttons[next].focus();
107
+ };
108
+ }
109
+ createRenderRoot() {
110
+ return this;
111
+ }
112
+ // --- Lifecycle ---
113
+ connectedCallback() {
114
+ super.connectedCallback();
115
+ // Children may not be parsed yet when the element upgrades mid-parse: try
116
+ // synchronously, then retry once on a macrotask. setTimeout, not rAF — rAF
117
+ // is suspended in hidden documents, so the element would stay inert there.
118
+ if (!this._trySetup()) {
119
+ this._setupTimer = window.setTimeout(() => this._trySetup(), 0);
120
+ }
121
+ }
122
+ disconnectedCallback() {
123
+ super.disconnectedCallback();
124
+ clearTimeout(this._setupTimer);
125
+ this._teardown();
126
+ }
127
+ /** @returns true when setup ran or was already done; false to schedule a retry. */
128
+ _trySetup() {
129
+ if (this._initialized || !this.isConnected)
130
+ return true;
131
+ if (this.querySelectorAll('button').length < 2)
132
+ return false;
133
+ this._setup();
134
+ return true;
135
+ }
136
+ updated(changed) {
137
+ if (!this._initialized)
138
+ return;
139
+ if (changed.has('value')) {
140
+ this._select(this._resolveActiveIndex(), false);
141
+ }
142
+ if (changed.has('size')) {
143
+ this._updateIndicator();
144
+ }
145
+ if (changed.has('label')) {
146
+ if (this.label) {
147
+ this.setAttribute('aria-label', this.label);
148
+ }
149
+ else {
150
+ this.removeAttribute('aria-label');
151
+ }
152
+ }
153
+ if (changed.has('disabled')) {
154
+ this._applyDisabledState();
155
+ }
156
+ }
157
+ // --- Form lifecycle ---
158
+ formResetCallback() {
159
+ // Restoring `value` re-selects the default segment via `updated()`.
160
+ this.value = this._defaultFormValue;
161
+ super.formResetCallback();
162
+ }
163
+ formStateRestoreCallback(state, mode) {
164
+ this.value = state;
165
+ super.formStateRestoreCallback(state, mode);
166
+ }
167
+ // --- Setup / Teardown ---
168
+ _setup() {
169
+ this._buttons = Array.from(this.querySelectorAll('button'));
170
+ if (this._buttons.length < 2)
171
+ return;
172
+ this._initialized = true;
173
+ this.setAttribute('role', 'radiogroup');
174
+ if (this.label)
175
+ this.setAttribute('aria-label', this.label);
176
+ const activeIndex = this._resolveActiveIndex();
177
+ for (let i = 0; i < this._buttons.length; i++) {
178
+ const btn = this._buttons[i];
179
+ // Force type=button so a segment never submits the enclosing form.
180
+ btn.type = 'button';
181
+ btn.setAttribute('role', 'radio');
182
+ btn.setAttribute('aria-checked', String(i === activeIndex));
183
+ btn.setAttribute('tabindex', i === activeIndex ? '0' : '-1');
184
+ // A segment with no visible text is icon-only: square it and require an
185
+ // accessible name (the icon itself is decorative to assistive tech).
186
+ if ((btn.textContent ?? '').trim() === '') {
187
+ btn.setAttribute('data-icon-only', '');
188
+ if (!btn.hasAttribute('aria-label') && !btn.hasAttribute('aria-labelledby')) {
189
+ // eslint-disable-next-line no-console
190
+ console.warn(`<${this.localName}>: icon-only segment #${i} has no accessible name; add aria-label.`);
191
+ }
192
+ }
193
+ }
194
+ this.addEventListener('click', this._onClick);
195
+ this.addEventListener('keydown', this._onKeyDown);
196
+ // Reflect a whole-control `disabled` onto the segments (aria + tab order).
197
+ this._applyDisabledState();
198
+ // Canonicalize `value` to the active segment now that roles are set, and
199
+ // seed the form value (the value a form reset restores to).
200
+ this._syncValueFromIndex(activeIndex);
201
+ this._defaultFormValue = this.value;
202
+ this._syncFormValue(this.value);
203
+ // Initial pill position. Synchronous first (offset reads force layout),
204
+ // then a ResizeObserver keeps it correct across hidden→visible transitions
205
+ // and size changes — rAF is suspended in hidden documents, so it must not
206
+ // be the only scheduling mechanism.
207
+ this._updateIndicator();
208
+ this._resizeObserver = new ResizeObserver(() => this._updateIndicator());
209
+ this._resizeObserver.observe(this);
210
+ }
211
+ _teardown() {
212
+ this.removeEventListener('click', this._onClick);
213
+ this.removeEventListener('keydown', this._onKeyDown);
214
+ this._resizeObserver?.disconnect();
215
+ this._resizeObserver = null;
216
+ this._initialized = false;
217
+ }
218
+ // --- Selection ---
219
+ /** Resolve the selected index from `value`, else an authored `aria-checked`, else 0. */
220
+ _resolveActiveIndex() {
221
+ const { _buttons } = this;
222
+ if (this.value !== '') {
223
+ const byValue = _buttons.findIndex((b) => (b.getAttribute('value') ?? '') === this.value);
224
+ if (byValue >= 0)
225
+ return byValue;
226
+ const asIndex = Number(this.value);
227
+ if (Number.isInteger(asIndex) && asIndex >= 0 && asIndex < _buttons.length)
228
+ return asIndex;
229
+ }
230
+ const checked = _buttons.findIndex((b) => b.getAttribute('aria-checked') === 'true');
231
+ if (checked >= 0)
232
+ return checked;
233
+ // No explicit selection: default to the first enabled segment (else 0).
234
+ const firstEnabled = _buttons.findIndex((b) => !this._isDisabled(b));
235
+ return firstEnabled >= 0 ? firstEnabled : 0;
236
+ }
237
+ _syncValueFromIndex(index) {
238
+ this.value = this._buttons[index]?.getAttribute('value') ?? String(index);
239
+ }
240
+ _select(index, emitEvent = true) {
241
+ if (index < 0 || index >= this._buttons.length)
242
+ return;
243
+ // Whether this is an actual change — re-selecting the current segment must
244
+ // not re-fire `change` (matches native radio / `<select>`).
245
+ const changed = this._buttons[index].getAttribute('aria-checked') !== 'true';
246
+ for (let i = 0; i < this._buttons.length; i++) {
247
+ const isActive = i === index;
248
+ this._buttons[i].setAttribute('aria-checked', String(isActive));
249
+ // Disabled control keeps every segment out of the tab order.
250
+ this._buttons[i].setAttribute('tabindex', isActive && !this.disabled ? '0' : '-1');
251
+ }
252
+ this._syncValueFromIndex(index);
253
+ this._syncFormValue(this.value);
254
+ this._updateIndicator();
255
+ if (emitEvent && changed) {
256
+ this.hasInteracted = true;
257
+ this.dispatchEvent(new SegmentChangeEvent(this.value, index));
258
+ }
259
+ }
260
+ /** Index of the next non-disabled segment from `from`, moving by `dir`, wrapping. */
261
+ _nextEnabled(from, dir) {
262
+ const len = this._buttons.length;
263
+ for (let step = 1; step <= len; step++) {
264
+ const i = (from + dir * step + len * step) % len;
265
+ if (!this._isDisabled(this._buttons[i]))
266
+ return i;
267
+ }
268
+ return from;
269
+ }
270
+ _isDisabled(btn) {
271
+ return btn.disabled || btn.getAttribute('aria-disabled') === 'true';
272
+ }
273
+ /** Reflect the host `disabled` state onto the segments (aria + tab order). */
274
+ _applyDisabledState() {
275
+ for (const btn of this._buttons) {
276
+ if (this.disabled) {
277
+ btn.setAttribute('aria-disabled', 'true');
278
+ btn.setAttribute('tabindex', '-1');
279
+ }
280
+ else {
281
+ btn.removeAttribute('aria-disabled');
282
+ // Restore the roving tabindex (only the selected segment is tabbable).
283
+ btn.setAttribute('tabindex', btn.getAttribute('aria-checked') === 'true' ? '0' : '-1');
284
+ }
285
+ }
286
+ }
287
+ // --- Indicator ---
288
+ _updateIndicator() {
289
+ const active = this._buttons.find((b) => b.getAttribute('aria-checked') === 'true');
290
+ if (!active)
291
+ return;
292
+ this.style.setProperty('--_indicator-left', `${active.offsetLeft}px`);
293
+ this.style.setProperty('--_indicator-width', `${active.offsetWidth}px`);
294
+ }
295
+ }
296
+ __decorate([
297
+ property({ reflect: true })
298
+ ], SegmentedControl.prototype, "value", void 0);
299
+ __decorate([
300
+ property({ reflect: true })
301
+ ], SegmentedControl.prototype, "size", void 0);
302
+ __decorate([
303
+ property({ reflect: true })
304
+ ], SegmentedControl.prototype, "label", void 0);
305
+ __decorate([
306
+ property({ type: Boolean, reflect: true, attribute: 'full-width' })
307
+ ], SegmentedControl.prototype, "fullWidth", void 0);
@@ -39,6 +39,14 @@
39
39
  "reflects": false,
40
40
  "description": "The type of item: `normal` or `checkbox`."
41
41
  },
42
+ {
43
+ "name": "variant",
44
+ "attribute": "variant",
45
+ "type": "'destructive' | undefined",
46
+ "default": "undefined",
47
+ "reflects": true,
48
+ "description": "Visual variant. `destructive` marks a delete-style action in red."
49
+ },
42
50
  {
43
51
  "name": "checked",
44
52
  "attribute": "checked",
@@ -64,7 +72,14 @@
64
72
  "description": "Whether this item has nested `slot=\"submenu\"` items."
65
73
  }
66
74
  ],
67
- "attributes": [],
75
+ "attributes": [
76
+ {
77
+ "name": "variant",
78
+ "data": false,
79
+ "values": [],
80
+ "description": "destructive — Renders the item as a destructive action (red), for delete-style entries."
81
+ }
82
+ ],
68
83
  "events": [],
69
84
  "methods": [
70
85
  {
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.16.2",
2
+ "version": "0.17.1",
3
3
  "elements": [
4
4
  {
5
5
  "name": "alert",
@@ -2289,6 +2289,14 @@
2289
2289
  "reflects": false,
2290
2290
  "description": "The type of item: `normal` or `checkbox`."
2291
2291
  },
2292
+ {
2293
+ "name": "variant",
2294
+ "attribute": "variant",
2295
+ "type": "'destructive' | undefined",
2296
+ "default": "undefined",
2297
+ "reflects": true,
2298
+ "description": "Visual variant. `destructive` marks a delete-style action in red."
2299
+ },
2292
2300
  {
2293
2301
  "name": "checked",
2294
2302
  "attribute": "checked",
@@ -2314,7 +2322,14 @@
2314
2322
  "description": "Whether this item has nested `slot=\"submenu\"` items."
2315
2323
  }
2316
2324
  ],
2317
- "attributes": [],
2325
+ "attributes": [
2326
+ {
2327
+ "name": "variant",
2328
+ "data": false,
2329
+ "values": [],
2330
+ "description": "destructive — Renders the item as a destructive action (red), for delete-style entries."
2331
+ }
2332
+ ],
2318
2333
  "events": [],
2319
2334
  "methods": [
2320
2335
  {
@@ -3837,6 +3852,111 @@
3837
3852
  "commands": [],
3838
3853
  "examples": []
3839
3854
  },
3855
+ {
3856
+ "name": "segmented-control",
3857
+ "displayName": "Segmented control",
3858
+ "type": "progressive",
3859
+ "isCustomElement": true,
3860
+ "tag": "l-segmented-control",
3861
+ "nativeTag": null,
3862
+ "selector": "l-segmented-control",
3863
+ "subItemOf": null,
3864
+ "summary": "A single-select segmented control: a compact, mutually-exclusive\nswitch between a few options (radio-group semantics with a sliding pill).\nProgressively enhances light-DOM `<button>`s so it works before JS runs.\nForm-associated: give it a `name` and its selected `value` is submitted with\nthe form (and restored on reset), like a native radio group.",
3865
+ "status": "stable",
3866
+ "appearances": [],
3867
+ "import": {
3868
+ "css": "luxen-ui/css/segmented-control",
3869
+ "js": "luxen-ui/segmented-control"
3870
+ },
3871
+ "properties": [
3872
+ {
3873
+ "name": "value",
3874
+ "attribute": "value",
3875
+ "type": "string",
3876
+ "default": "''",
3877
+ "reflects": true,
3878
+ "description": "Value of the selected segment (its `value` attribute, else its index)."
3879
+ },
3880
+ {
3881
+ "name": "size",
3882
+ "attribute": "size",
3883
+ "type": "SegmentedControlSize",
3884
+ "default": "'md'",
3885
+ "reflects": true,
3886
+ "description": "Control height, aligned with buttons and form controls at the same size."
3887
+ },
3888
+ {
3889
+ "name": "label",
3890
+ "attribute": "label",
3891
+ "type": "string | undefined",
3892
+ "default": null,
3893
+ "reflects": true,
3894
+ "description": "Accessible label announced for the group. Not displayed on screen."
3895
+ },
3896
+ {
3897
+ "name": "fullWidth",
3898
+ "attribute": "full-width",
3899
+ "type": "boolean",
3900
+ "default": "false",
3901
+ "reflects": true,
3902
+ "description": "Stretch segments to fill the container width."
3903
+ }
3904
+ ],
3905
+ "attributes": [],
3906
+ "events": [
3907
+ {
3908
+ "name": "change",
3909
+ "description": "Fired when the selected segment changes. Not cancelable. Bubbles. Properties: `value: string`, `index: number`.",
3910
+ "cancelable": false
3911
+ }
3912
+ ],
3913
+ "methods": [
3914
+ {
3915
+ "name": "formResetCallback",
3916
+ "params": [],
3917
+ "returns": null,
3918
+ "description": ""
3919
+ },
3920
+ {
3921
+ "name": "formStateRestoreCallback",
3922
+ "params": [
3923
+ {
3924
+ "name": "state",
3925
+ "type": "string"
3926
+ },
3927
+ {
3928
+ "name": "mode",
3929
+ "type": "'restore' | 'autocomplete'"
3930
+ }
3931
+ ],
3932
+ "returns": null,
3933
+ "description": ""
3934
+ }
3935
+ ],
3936
+ "slots": [],
3937
+ "cssClasses": [],
3938
+ "cssParts": [],
3939
+ "cssProperties": [
3940
+ {
3941
+ "name": "--indicator-color",
3942
+ "default": "var(--l-color-surface)",
3943
+ "description": "Background of the sliding pill behind the selected segment."
3944
+ },
3945
+ {
3946
+ "name": "--border-radius",
3947
+ "default": "var(--l-radius-lg)",
3948
+ "description": "Corner radius of the track."
3949
+ }
3950
+ ],
3951
+ "commands": [],
3952
+ "examples": [
3953
+ {
3954
+ "title": "Mark the initially-selected segment with `aria-checked=\"true\"` (or set",
3955
+ "language": "html",
3956
+ "code": "`value` to its `value` attribute) so it is styled before the script upgrades\nthe element.\n```html\n<l-segmented-control label=\"Metric\" value=\"cost\">\n <button value=\"volume\">Volume</button>\n <button value=\"cost\" aria-checked=\"true\">Cost</button>\n</l-segmented-control>\n```"
3957
+ }
3958
+ ]
3959
+ },
3840
3960
  {
3841
3961
  "name": "select",
3842
3962
  "displayName": "Select",