@openelement/ui 1.0.0-alpha.1 → 1.0.0-alpha.10

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/src/open-tabs.js CHANGED
@@ -1,401 +1,331 @@
1
- // <auto-generated by open:compiled-element; v0.44.0-alpha.1 - do not edit>
2
- import { effect, OpenElement } from '@openelement/element';
3
- import { nextInstanceId, recipe } from './component-recipes.js';
4
- import { readInstanceState, writeInstanceState } from './instance-state.js';
1
+ import { readInstanceState, writeInstanceState } from "./instance-state.js";
2
+ import { nextInstanceId, recipe } from "./component-recipes.js";
3
+ import { OpenElement, effect } from "@openelement/element";
4
+ //#region src/open-tabs.tsx
5
5
  const __partProgram = {
6
- "version": 1,
7
- "tag": "open-tabs",
8
- "root": {
9
- "id": "root",
10
- "kind": "shadow-open",
11
- "nodes": [
12
- "e0"
13
- ]
14
- },
15
- "template": [
16
- {
17
- "k": "el",
18
- "id": "e0",
19
- "tag": "div",
20
- "attrs": [],
21
- "children": [
22
- {
23
- "k": "el",
24
- "id": "e1",
25
- "tag": "div",
26
- "attrs": [
27
- [
28
- "class",
29
- "tabs"
30
- ],
31
- [
32
- "role",
33
- "tablist"
34
- ]
35
- ],
36
- "children": [
37
- {
38
- "k": "el",
39
- "id": "e2",
40
- "tag": "slot",
41
- "attrs": [
42
- [
43
- "name",
44
- "tab"
45
- ]
46
- ],
47
- "children": []
48
- }
49
- ]
50
- },
51
- {
52
- "k": "el",
53
- "id": "e3",
54
- "tag": "slot",
55
- "attrs": [
56
- [
57
- "name",
58
- "panel"
59
- ]
60
- ],
61
- "children": []
62
- }
63
- ]
64
- }
65
- ],
66
- "parts": [
67
- {
68
- "k": "event",
69
- "event": "keydown",
70
- "handler": "onKeydown",
71
- "action": {
72
- "kind": "method",
73
- "name": "onKeydown"
74
- },
75
- "path": [
76
- 0,
77
- 0
78
- ],
79
- "index": 0,
80
- "location": {
81
- "id": "p0",
82
- "kind": "sink",
83
- "path": [
84
- 0,
85
- 0
86
- ],
87
- "node": "e1"
88
- }
89
- }
90
- ],
91
- "regions": [],
92
- "dependencies": [],
93
- "locations": [
94
- {
95
- "id": "e0",
96
- "kind": "element",
97
- "tag": "div",
98
- "path": [
99
- 0
100
- ]
101
- },
102
- {
103
- "id": "e1",
104
- "kind": "element",
105
- "tag": "div",
106
- "path": [
107
- 0,
108
- 0
109
- ]
110
- },
111
- {
112
- "id": "p0",
113
- "kind": "sink",
114
- "part": 0,
115
- "node": "e1",
116
- "path": [
117
- 0,
118
- 0
119
- ]
120
- },
121
- {
122
- "id": "e2",
123
- "kind": "element",
124
- "tag": "slot",
125
- "path": [
126
- 0,
127
- 0,
128
- 0
129
- ]
130
- },
131
- {
132
- "id": "e3",
133
- "kind": "element",
134
- "tag": "slot",
135
- "path": [
136
- 0,
137
- 1
138
- ]
139
- }
140
- ],
141
- "metadata": {
142
- "tag": "open-tabs",
143
- "className": "OpenTabs",
144
- "sourceFile": "open-tabs.tsx",
145
- "properties": [
146
- {
147
- "name": "active",
148
- "attribute": null,
149
- "type": "number",
150
- "converter": "number",
151
- "reflect": false,
152
- "default": 0
153
- },
154
- {
155
- "name": "tabsId",
156
- "attribute": null,
157
- "type": "string",
158
- "converter": "string",
159
- "reflect": false,
160
- "default": ""
161
- }
162
- ],
163
- "observedAttributes": [],
164
- "cem": {
165
- "tagName": "open-tabs",
166
- "className": "OpenTabs",
167
- "declaration": {
168
- "name": "OpenTabs",
169
- "module": "open-tabs.tsx"
170
- },
171
- "attributes": [],
172
- "members": [
173
- {
174
- "name": "active",
175
- "fieldName": "active",
176
- "type": "number",
177
- "attribute": null,
178
- "reflect": false
179
- },
180
- {
181
- "name": "tabsId",
182
- "fieldName": "tabsId",
183
- "type": "string",
184
- "attribute": null,
185
- "reflect": false
186
- }
187
- ]
188
- }
189
- }
6
+ "version": 1,
7
+ "tag": "open-tabs",
8
+ "root": {
9
+ "id": "root",
10
+ "kind": "shadow-open",
11
+ "nodes": ["e0"]
12
+ },
13
+ "template": [{
14
+ "k": "el",
15
+ "id": "e0",
16
+ "tag": "div",
17
+ "attrs": [],
18
+ "children": [{
19
+ "k": "el",
20
+ "id": "e1",
21
+ "tag": "div",
22
+ "attrs": [["class", "tabs"], ["role", "tablist"]],
23
+ "children": [{
24
+ "k": "el",
25
+ "id": "e2",
26
+ "tag": "slot",
27
+ "attrs": [["name", "tab"]],
28
+ "children": []
29
+ }]
30
+ }, {
31
+ "k": "el",
32
+ "id": "e3",
33
+ "tag": "slot",
34
+ "attrs": [["name", "panel"]],
35
+ "children": []
36
+ }]
37
+ }],
38
+ "parts": [{
39
+ "k": "event",
40
+ "event": "keydown",
41
+ "handler": "onKeydown",
42
+ "action": {
43
+ "kind": "method",
44
+ "name": "onKeydown"
45
+ },
46
+ "path": [0, 0],
47
+ "index": 0,
48
+ "location": {
49
+ "id": "p0",
50
+ "kind": "sink",
51
+ "path": [0, 0],
52
+ "node": "e1"
53
+ }
54
+ }],
55
+ "regions": [],
56
+ "dependencies": [],
57
+ "locations": [
58
+ {
59
+ "id": "e0",
60
+ "kind": "element",
61
+ "tag": "div",
62
+ "path": [0]
63
+ },
64
+ {
65
+ "id": "e1",
66
+ "kind": "element",
67
+ "tag": "div",
68
+ "path": [0, 0]
69
+ },
70
+ {
71
+ "id": "p0",
72
+ "kind": "sink",
73
+ "part": 0,
74
+ "node": "e1",
75
+ "path": [0, 0]
76
+ },
77
+ {
78
+ "id": "e2",
79
+ "kind": "element",
80
+ "tag": "slot",
81
+ "path": [
82
+ 0,
83
+ 0,
84
+ 0
85
+ ]
86
+ },
87
+ {
88
+ "id": "e3",
89
+ "kind": "element",
90
+ "tag": "slot",
91
+ "path": [0, 1]
92
+ }
93
+ ],
94
+ "metadata": {
95
+ "tag": "open-tabs",
96
+ "className": "OpenTabs",
97
+ "sourceFile": "open-tabs.tsx",
98
+ "properties": [{
99
+ "name": "active",
100
+ "attribute": null,
101
+ "type": "number",
102
+ "converter": "number",
103
+ "reflect": false,
104
+ "default": 0
105
+ }, {
106
+ "name": "tabsId",
107
+ "attribute": null,
108
+ "type": "string",
109
+ "converter": "string",
110
+ "reflect": false,
111
+ "default": ""
112
+ }],
113
+ "observedAttributes": [],
114
+ "cem": {
115
+ "tagName": "open-tabs",
116
+ "className": "OpenTabs",
117
+ "declaration": {
118
+ "name": "OpenTabs",
119
+ "module": "open-tabs.tsx"
120
+ },
121
+ "attributes": [],
122
+ "members": [{
123
+ "name": "active",
124
+ "fieldName": "active",
125
+ "type": "number",
126
+ "attribute": null,
127
+ "reflect": false
128
+ }, {
129
+ "name": "tabsId",
130
+ "fieldName": "tabsId",
131
+ "type": "string",
132
+ "attribute": null,
133
+ "reflect": false
134
+ }]
135
+ }
136
+ }
190
137
  };
191
- const __compiledProperties = [
192
- {
193
- "name": "active",
194
- "attribute": null,
195
- "type": "number",
196
- "converter": "number",
197
- "reflect": false,
198
- "default": 0
199
- },
200
- {
201
- "name": "tabsId",
202
- "attribute": null,
203
- "type": "string",
204
- "converter": "string",
205
- "reflect": false,
206
- "default": ""
207
- }
208
- ];
138
+ const __compiledProperties = [{
139
+ "name": "active",
140
+ "attribute": null,
141
+ "type": "number",
142
+ "converter": "number",
143
+ "reflect": false,
144
+ "default": 0
145
+ }, {
146
+ "name": "tabsId",
147
+ "attribute": null,
148
+ "type": "string",
149
+ "converter": "string",
150
+ "reflect": false,
151
+ "default": ""
152
+ }];
209
153
  const __elementMetadata = {
210
- "tag": "open-tabs",
211
- "className": "OpenTabs",
212
- "sourceFile": "open-tabs.tsx",
213
- "properties": [
214
- {
215
- "name": "active",
216
- "attribute": null,
217
- "type": "number",
218
- "converter": "number",
219
- "reflect": false,
220
- "default": 0
221
- },
222
- {
223
- "name": "tabsId",
224
- "attribute": null,
225
- "type": "string",
226
- "converter": "string",
227
- "reflect": false,
228
- "default": ""
229
- }
230
- ],
231
- "observedAttributes": [],
232
- "cem": {
233
- "tagName": "open-tabs",
234
- "className": "OpenTabs",
235
- "declaration": {
236
- "name": "OpenTabs",
237
- "module": "open-tabs.tsx"
238
- },
239
- "attributes": [],
240
- "members": [
241
- {
242
- "name": "active",
243
- "fieldName": "active",
244
- "type": "number",
245
- "attribute": null,
246
- "reflect": false
247
- },
248
- {
249
- "name": "tabsId",
250
- "fieldName": "tabsId",
251
- "type": "string",
252
- "attribute": null,
253
- "reflect": false
254
- }
255
- ]
256
- }
154
+ "tag": "open-tabs",
155
+ "className": "OpenTabs",
156
+ "sourceFile": "open-tabs.tsx",
157
+ "properties": [{
158
+ "name": "active",
159
+ "attribute": null,
160
+ "type": "number",
161
+ "converter": "number",
162
+ "reflect": false,
163
+ "default": 0
164
+ }, {
165
+ "name": "tabsId",
166
+ "attribute": null,
167
+ "type": "string",
168
+ "converter": "string",
169
+ "reflect": false,
170
+ "default": ""
171
+ }],
172
+ "observedAttributes": [],
173
+ "cem": {
174
+ "tagName": "open-tabs",
175
+ "className": "OpenTabs",
176
+ "declaration": {
177
+ "name": "OpenTabs",
178
+ "module": "open-tabs.tsx"
179
+ },
180
+ "attributes": [],
181
+ "members": [{
182
+ "name": "active",
183
+ "fieldName": "active",
184
+ "type": "number",
185
+ "attribute": null,
186
+ "reflect": false
187
+ }, {
188
+ "name": "tabsId",
189
+ "fieldName": "tabsId",
190
+ "type": "string",
191
+ "attribute": null,
192
+ "reflect": false
193
+ }]
194
+ }
257
195
  };
258
196
  const __observedAttributes = [];
259
197
  const __compiledProps = {
260
- active: {
261
- type: Number,
262
- default: 0,
263
- reflect: false,
264
- attribute: false
265
- },
266
- tabsId: {
267
- type: String,
268
- default: '',
269
- reflect: false,
270
- attribute: false
271
- }
198
+ active: {
199
+ type: Number,
200
+ default: 0,
201
+ reflect: false,
202
+ attribute: false
203
+ },
204
+ tabsId: {
205
+ type: String,
206
+ default: "",
207
+ reflect: false,
208
+ attribute: false
209
+ }
272
210
  };
273
- export class OpenTabs extends OpenElement {
274
- static __partProgram = __partProgram;
275
- static __compiledProperties = __compiledProperties;
276
- static __elementMetadata = __elementMetadata;
277
- static props = __compiledProps;
278
- static observedAttributes = __observedAttributes;
279
- static styles = [
280
- recipe(`
211
+ var OpenTabs = class extends OpenElement {
212
+ static __partProgram = __partProgram;
213
+ static __compiledProperties = __compiledProperties;
214
+ static __elementMetadata = __elementMetadata;
215
+ static props = __compiledProps;
216
+ static observedAttributes = __observedAttributes;
217
+ static styles = [recipe(`
281
218
  :host {
282
219
  display: block;
283
220
  }
284
221
 
285
222
  .tabs {
286
223
  display: flex;
287
- gap: var(--size-1);
288
- padding: var(--size-1);
289
- border-bottom: 1px solid var(--surface-border);
224
+ gap: calc(var(--spacing) * 1);
225
+ padding: calc(var(--spacing) * 1);
226
+ border-bottom: 1px solid color-mix(in srgb, var(--color-border) 78%, var(--color-primary));
290
227
  }
291
228
 
292
229
  ::slotted([slot='tab']) {
293
- padding: var(--size-2) var(--size-4);
230
+ padding: calc(var(--spacing) * 2) calc(var(--spacing) * 4);
294
231
  border-color: transparent;
295
232
  background: transparent;
296
- color: var(--text-secondary);
233
+ color: var(--color-muted-foreground);
297
234
  cursor: pointer;
298
235
  }
299
236
 
300
237
  ::slotted([slot='tab']:hover) {
301
- color: var(--text-primary);
238
+ color: var(--color-foreground);
302
239
  }
303
240
 
304
241
  ::slotted(.tab-active) {
305
- color: var(--text-primary);
306
- background: var(--brand-subtle);
307
- border-color: var(--surface-border-strong);
242
+ color: var(--color-foreground);
243
+ background: color-mix(in srgb, var(--color-primary) 14%, transparent);
244
+ border-color: color-mix(in srgb, color-mix(in srgb, var(--color-foreground) 25%, var(--color-border)) 62%, var(--color-primary));
308
245
  }
309
246
 
310
247
  ::slotted([slot='panel']) {
311
- padding-block: var(--size-4);
312
- color: var(--text-secondary);
248
+ padding-block: calc(var(--spacing) * 4);
249
+ color: var(--color-muted-foreground);
313
250
  }
314
- `)
315
- ];
316
- active = 0;
317
- tabsId = '';
318
- onDsdHydrated() {
319
- this.activate();
320
- }
321
- onCsrRendered() {
322
- this.activate();
323
- }
324
- disconnectedCallback() {
325
- readInstanceState(this, 'decorateEffect', ()=>undefined)?.();
326
- writeInstanceState(this, 'decorateEffect', undefined);
327
- super.disconnectedCallback();
328
- }
329
- activate() {
330
- if (this.tabsId === '') this.tabsId = `open-tabs-${nextInstanceId()}`;
331
- // The decorate effect re-runs when the compiled `active` signal changes;
332
- // its first synchronous run applies the initial wiring.
333
- const off = effect(()=>{
334
- void this.active;
335
- this.decorate();
336
- });
337
- writeInstanceState(this, 'decorateEffect', off);
338
- }
339
- tabs() {
340
- return [
341
- ...this.querySelectorAll('[slot="tab"]')
342
- ];
343
- }
344
- count() {
345
- return Math.min(this.tabs().length, this.querySelectorAll('[slot="panel"]').length);
346
- }
347
- select(idx) {
348
- this.active = idx;
349
- }
350
- onKeydown(e) {
351
- const count = this.count();
352
- if (count === 0) return;
353
- const key = e.key;
354
- const next = key === 'Home' ? 0 : key === 'End' ? count - 1 : key === 'ArrowLeft' ? (this.active - 1 + count) % count : key === 'ArrowRight' ? (this.active + 1) % count : undefined;
355
- if (next === undefined) return;
356
- e.preventDefault();
357
- this.select(next);
358
- // Selection follows focus: move DOM focus onto the newly active tab.
359
- const tab = this.tabs()[next];
360
- if (tab && typeof tab.focus === 'function') tab.focus();
361
- }
362
- decorate() {
363
- const tabs = this.tabs();
364
- const panels = [
365
- ...this.querySelectorAll('[slot="panel"]')
366
- ];
367
- const count = Math.min(tabs.length, panels.length);
368
- const active = this.active;
369
- const prefix = this.tabsId;
370
- const wired = readInstanceState(this, 'wiredTabs', ()=>new WeakSet());
371
- tabs.forEach((tab, i)=>{
372
- const enabled = i < count;
373
- tab.setAttribute('role', 'tab');
374
- tab.setAttribute('id', `${prefix}-tab-${i}`);
375
- tab.setAttribute('aria-selected', i === active && enabled ? 'true' : 'false');
376
- tab.setAttribute('aria-controls', `${prefix}-panel-${i}`);
377
- tab.setAttribute('tabindex', i === active ? '0' : '-1');
378
- tab.classList.toggle('tab-active', i === active);
379
- if (enabled) tab.removeAttribute('aria-disabled');
380
- else tab.setAttribute('aria-disabled', 'true');
381
- if (!wired.has(tab)) {
382
- wired.add(tab);
383
- tab.addEventListener('click', ()=>{
384
- const idx = this.tabs().indexOf(tab);
385
- if (idx >= 0 && idx < this.count()) this.select(idx);
386
- });
387
- }
388
- });
389
- panels.forEach((panel, i)=>{
390
- panel.setAttribute('role', 'tabpanel');
391
- panel.setAttribute('id', `${prefix}-panel-${i}`);
392
- panel.setAttribute('aria-labelledby', `${prefix}-tab-${i}`);
393
- if (i === active) panel.removeAttribute('hidden');
394
- else panel.setAttribute('hidden', '');
395
- });
396
- }
397
- render() {
398
- throw new Error('[open:compiled-element] open-tabs is compiled to a Part Program; the runtime JSX render path is not available in 0.44.');
399
- }
400
- }
401
- export { __partProgram, __elementMetadata };
251
+ `)];
252
+ active = 0;
253
+ tabsId = "";
254
+ onDsdHydrated() {
255
+ this.activate();
256
+ }
257
+ onCsrRendered() {
258
+ this.activate();
259
+ }
260
+ disconnectedCallback() {
261
+ readInstanceState(this, "decorateEffect", () => void 0)?.();
262
+ writeInstanceState(this, "decorateEffect", void 0);
263
+ super.disconnectedCallback();
264
+ }
265
+ activate() {
266
+ if (this.tabsId === "") this.tabsId = `open-tabs-${nextInstanceId()}`;
267
+ const off = effect(() => {
268
+ this.active;
269
+ this.decorate();
270
+ });
271
+ writeInstanceState(this, "decorateEffect", off);
272
+ }
273
+ tabs() {
274
+ return [...this.querySelectorAll("[slot=\"tab\"]")];
275
+ }
276
+ count() {
277
+ return Math.min(this.tabs().length, this.querySelectorAll("[slot=\"panel\"]").length);
278
+ }
279
+ select(idx) {
280
+ this.active = idx;
281
+ }
282
+ onKeydown(e) {
283
+ const count = this.count();
284
+ if (count === 0) return;
285
+ const key = e.key;
286
+ const next = key === "Home" ? 0 : key === "End" ? count - 1 : key === "ArrowLeft" ? (this.active - 1 + count) % count : key === "ArrowRight" ? (this.active + 1) % count : void 0;
287
+ if (next === void 0) return;
288
+ e.preventDefault();
289
+ this.select(next);
290
+ const tab = this.tabs()[next];
291
+ if (tab && typeof tab.focus === "function") tab.focus();
292
+ }
293
+ decorate() {
294
+ const tabs = this.tabs();
295
+ const panels = [...this.querySelectorAll("[slot=\"panel\"]")];
296
+ const count = Math.min(tabs.length, panels.length);
297
+ const active = this.active;
298
+ const prefix = this.tabsId;
299
+ const wired = readInstanceState(this, "wiredTabs", () => /* @__PURE__ */ new WeakSet());
300
+ tabs.forEach((tab, i) => {
301
+ const enabled = i < count;
302
+ tab.setAttribute("role", "tab");
303
+ tab.setAttribute("id", `${prefix}-tab-${i}`);
304
+ tab.setAttribute("aria-selected", i === active && enabled ? "true" : "false");
305
+ tab.setAttribute("aria-controls", `${prefix}-panel-${i}`);
306
+ tab.setAttribute("tabindex", i === active ? "0" : "-1");
307
+ tab.classList.toggle("tab-active", i === active);
308
+ if (enabled) tab.removeAttribute("aria-disabled");
309
+ else tab.setAttribute("aria-disabled", "true");
310
+ if (!wired.has(tab)) {
311
+ wired.add(tab);
312
+ tab.addEventListener("click", () => {
313
+ const idx = this.tabs().indexOf(tab);
314
+ if (idx >= 0 && idx < this.count()) this.select(idx);
315
+ });
316
+ }
317
+ });
318
+ panels.forEach((panel, i) => {
319
+ panel.setAttribute("role", "tabpanel");
320
+ panel.setAttribute("id", `${prefix}-panel-${i}`);
321
+ panel.setAttribute("aria-labelledby", `${prefix}-tab-${i}`);
322
+ if (i === active) panel.removeAttribute("hidden");
323
+ else panel.setAttribute("hidden", "");
324
+ });
325
+ }
326
+ render() {
327
+ throw new Error("[open:compiled-element] open-tabs is compiled to a Part Program; the runtime JSX render path is not available.");
328
+ }
329
+ };
330
+ //#endregion
331
+ export { OpenTabs, __elementMetadata, __partProgram };