@oscarpalmer/oui 0.35.0 → 0.37.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/dist/css/badge.css +18 -15
- package/dist/css/button.css +35 -31
- package/dist/css/color.css +20 -20
- package/dist/css/combobox.css +134 -35
- package/dist/css/content.css +29 -10
- package/dist/css/floatable.css +10 -10
- package/dist/css/form.css +393 -129
- package/dist/css/listbox.css +176 -0
- package/dist/css/message.css +13 -10
- package/dist/css/reset.css +29 -88
- package/dist/css/splitter.css +2 -2
- package/dist/css/tabs.css +103 -0
- package/dist/js/combobox/constants.combobox.d.mts +2 -2
- package/dist/js/combobox/constants.combobox.mjs +40 -33
- package/dist/js/combobox/dom.combobox.d.mts +8 -91
- package/dist/js/combobox/dom.combobox.mjs +204 -2
- package/dist/js/combobox/event.combobox.d.mts +14 -8
- package/dist/js/combobox/event.combobox.mjs +2 -2
- package/dist/js/combobox/index.d.mts +1 -1
- package/dist/js/combobox/index.mjs +20 -18
- package/dist/js/combobox/misc.combobox.d.mts +2 -2
- package/dist/js/combobox/misc.combobox.mjs +2 -2
- package/dist/js/combobox/models.combobox.d.mts +44 -2
- package/dist/js/combobox/state.combobox.d.mts +9 -10
- package/dist/js/combobox/state.combobox.mjs +2 -2
- package/dist/js/constants.combobox-DmRAMC64.d.mts +26 -0
- package/dist/js/constants.listbox-DRsXUxd3.d.mts +14 -0
- package/dist/js/focus-trap/focus-trap.embedded.mjs +6 -10
- package/dist/js/index-EfkUSals.d.mts +139 -0
- package/dist/js/index.d.mts +5 -2
- package/dist/js/index.mjs +5 -2
- package/dist/js/internal/attributable.mjs +4 -3
- package/dist/js/internal/draggable.mjs +16 -22
- package/dist/js/internal/listbox/listbox.constants.d.mts +11 -0
- package/dist/js/internal/listbox/listbox.constants.mjs +23 -0
- package/dist/js/internal/listbox/listbox.data.d.mts +20 -0
- package/dist/js/internal/listbox/listbox.data.mjs +2 -0
- package/dist/js/internal/listbox/listbox.dom.d.mts +66 -0
- package/dist/js/internal/listbox/listbox.dom.mjs +2 -0
- package/dist/js/internal/listbox/listbox.event.d.mts +5 -0
- package/dist/js/internal/listbox/listbox.event.mjs +63 -0
- package/dist/js/internal/listbox/listbox.form.d.mts +6 -0
- package/dist/js/internal/listbox/listbox.form.mjs +52 -0
- package/dist/js/internal/listbox/listbox.misc.d.mts +12 -0
- package/dist/js/internal/listbox/listbox.misc.mjs +2 -0
- package/dist/js/internal/listbox/listbox.model.d.mts +2 -0
- package/dist/js/internal/listbox/listbox.model.mjs +1 -0
- package/dist/js/internal/listbox/listbox.state.d.mts +7 -0
- package/dist/js/internal/listbox/listbox.state.mjs +40 -0
- package/dist/js/internal/misc.d.mts +6 -0
- package/dist/js/internal/misc.mjs +13 -0
- package/dist/js/internal/navigable.d.mts +11 -5
- package/dist/js/internal/navigable.mjs +44 -18
- package/dist/js/l10n-Bn-7RcwR.d.mts +20 -0
- package/dist/js/l10n.d.mts +2 -20
- package/dist/js/listbox/constants.listbox.d.mts +2 -0
- package/dist/js/listbox/constants.listbox.mjs +40 -0
- package/dist/js/listbox/event.listbox.d.mts +8 -0
- package/dist/js/listbox/event.listbox.mjs +2 -0
- package/dist/js/listbox/index.d.mts +116 -0
- package/dist/js/listbox/index.mjs +189 -0
- package/dist/js/listbox/misc.listbox.d.mts +2 -0
- package/dist/js/listbox/misc.listbox.mjs +2 -0
- package/dist/js/listbox/state.listbox.d.mts +11 -0
- package/dist/js/listbox/state.listbox.mjs +2 -0
- package/dist/js/listbox.data-BWd0PCy7.mjs +424 -0
- package/dist/js/listbox.model-CRReGOmu.d.mts +125 -0
- package/dist/js/misc.listbox-BI-XsTOf.mjs +197 -0
- package/dist/js/misc.listbox-gnoJhrTr.d.mts +20 -0
- package/dist/js/movable/movable.embedded.mjs +3 -6
- package/dist/js/resizable/resizable.embedded.mjs +16 -26
- package/dist/js/sortable/sortable.embedded.mjs +4 -2
- package/dist/js/splitter.mjs +15 -12
- package/dist/js/state.combobox-4xq0FPCF.mjs +365 -0
- package/dist/js/tabs.d.mts +25 -0
- package/dist/js/tabs.mjs +240 -0
- package/dist/js/tooltip.mjs +13 -12
- package/package.json +7 -3
- package/src/css/badge.scss +6 -18
- package/src/css/button.scss +6 -45
- package/src/css/color.scss +20 -20
- package/src/css/combobox.scss +21 -52
- package/src/css/content.scss +30 -3
- package/src/css/floatable.scss +17 -17
- package/src/css/form.scss +84 -72
- package/src/css/listbox.scss +120 -0
- package/src/css/message.scss +13 -28
- package/src/css/mixins.scss +253 -28
- package/src/css/reset.scss +37 -86
- package/src/css/splitter.scss +2 -2
- package/src/css/tabs.scss +85 -0
- package/src/js/combobox/constants.combobox.ts +46 -25
- package/src/js/combobox/dom.combobox.ts +36 -454
- package/src/js/combobox/event.combobox.ts +129 -218
- package/src/js/combobox/index.ts +37 -30
- package/src/js/combobox/misc.combobox.ts +30 -114
- package/src/js/combobox/models.combobox.ts +7 -47
- package/src/js/combobox/state.combobox.ts +126 -127
- package/src/js/focus-trap/focus-trap.embedded.ts +11 -19
- package/src/js/index.ts +2 -0
- package/src/js/internal/draggable.ts +29 -33
- package/src/js/internal/listbox/listbox.constants.ts +25 -0
- package/src/js/{combobox/data.combobox.ts → internal/listbox/listbox.data.ts} +94 -43
- package/src/js/internal/listbox/listbox.dom.ts +445 -0
- package/src/js/internal/listbox/listbox.event.ts +129 -0
- package/src/js/{combobox/form.combobox.ts → internal/listbox/listbox.form.ts} +13 -14
- package/src/js/internal/listbox/listbox.misc.ts +135 -0
- package/src/js/internal/listbox/listbox.model.ts +169 -0
- package/src/js/internal/listbox/listbox.state.ts +82 -0
- package/src/js/internal/misc.ts +27 -0
- package/src/js/internal/navigable.ts +80 -23
- package/src/js/l10n.ts +8 -8
- package/src/js/listbox/constants.listbox.ts +61 -0
- package/src/js/listbox/event.listbox.ts +106 -0
- package/src/js/listbox/index.ts +302 -0
- package/src/js/listbox/misc.listbox.ts +70 -0
- package/src/js/listbox/state.listbox.ts +196 -0
- package/src/js/movable/movable.embedded.ts +11 -13
- package/src/js/resizable/resizable.embedded.ts +25 -39
- package/src/js/splitter.ts +21 -18
- package/src/js/tabs.ts +447 -0
- package/src/js/tooltip.ts +20 -17
- package/dist/js/combobox/data.combobox.d.mts +0 -18
- package/dist/js/combobox/data.combobox.mjs +0 -2
- package/dist/js/combobox/form.combobox.d.mts +0 -6
- package/dist/js/combobox/form.combobox.mjs +0 -2
- package/dist/js/constants.combobox-h_kyDegw.d.mts +0 -248
- package/dist/js/data.combobox-B8HMkDOh.mjs +0 -1030
package/src/js/tabs.ts
ADDED
|
@@ -0,0 +1,447 @@
|
|
|
1
|
+
import {getAria, setAria} from '@oscarpalmer/toretto/aria';
|
|
2
|
+
import {getAttribute, setAttribute} from '@oscarpalmer/toretto/attribute';
|
|
3
|
+
import {createElement} from '@oscarpalmer/toretto/create';
|
|
4
|
+
import {
|
|
5
|
+
getNavigableOrientation,
|
|
6
|
+
OuiNavigable,
|
|
7
|
+
type OuiNavigableOrientation,
|
|
8
|
+
} from './internal/navigable';
|
|
9
|
+
|
|
10
|
+
// #region Types
|
|
11
|
+
|
|
12
|
+
declare global {
|
|
13
|
+
interface HTMLElementTagNameMap {
|
|
14
|
+
[TAGNAME]: OuiTabsElement;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export class OuiTabsEvent extends Event {
|
|
19
|
+
constructor(
|
|
20
|
+
name: 'oui:beforechange' | 'oui:change',
|
|
21
|
+
public oldIndex: number,
|
|
22
|
+
public newIndex: number,
|
|
23
|
+
cancelable: boolean,
|
|
24
|
+
) {
|
|
25
|
+
super(name, {
|
|
26
|
+
cancelable,
|
|
27
|
+
bubbles: true,
|
|
28
|
+
composed: true,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
type OuiTabsContent = {
|
|
34
|
+
element: HTMLDivElement;
|
|
35
|
+
panels: OuiTabsPanels;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export class OuiTabsElement extends HTMLElement {
|
|
39
|
+
static observedAttributes = ['active'];
|
|
40
|
+
|
|
41
|
+
#state?: OuiTabsState;
|
|
42
|
+
|
|
43
|
+
get active(): number {
|
|
44
|
+
return this.#state?.active ?? 0;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
set active(value: number) {
|
|
48
|
+
setActive(this.#state, value);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
get panel(): HTMLElement {
|
|
52
|
+
return this.#state?.panels.elements[this.active] as HTMLElement;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
get tab(): HTMLButtonElement {
|
|
56
|
+
return this.#state?.tabList.tabs[this.active] as HTMLButtonElement;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
attributeChangedCallback(name: string, _: string | null, value: string | null): void {
|
|
60
|
+
switch (name) {
|
|
61
|
+
case 'active':
|
|
62
|
+
setActive(this.#state, value);
|
|
63
|
+
break;
|
|
64
|
+
|
|
65
|
+
default:
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
connectedCallback(): void {
|
|
71
|
+
if (this.#state == null) {
|
|
72
|
+
this.#state = initializeTabs(this);
|
|
73
|
+
} else {
|
|
74
|
+
attachTabs(this.#state);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
disconnectedCallback(): void {
|
|
79
|
+
if (this.#state != null) {
|
|
80
|
+
detachTabs(this.#state);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
type OuiTabsPanels = {
|
|
86
|
+
elements: HTMLElement[];
|
|
87
|
+
hidden: Array<boolean | 'until-found'>;
|
|
88
|
+
roles: Array<string | null>;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
type OuiTabsState = {
|
|
92
|
+
active: number;
|
|
93
|
+
content: HTMLDivElement;
|
|
94
|
+
host: OuiTabsElement;
|
|
95
|
+
id: string;
|
|
96
|
+
navigable?: OuiNavigable;
|
|
97
|
+
orientation: OuiNavigableOrientation;
|
|
98
|
+
panels: OuiTabsPanels;
|
|
99
|
+
tabList: OuiTabsTabList;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
type OuiTabsTabList = {
|
|
103
|
+
element: HTMLDivElement;
|
|
104
|
+
tabs: HTMLButtonElement[];
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
// #endregion
|
|
108
|
+
|
|
109
|
+
// #region Functions
|
|
110
|
+
|
|
111
|
+
function attachTabs(state: OuiTabsState): void {
|
|
112
|
+
const navigable = new OuiNavigable(state.tabList.element, {
|
|
113
|
+
orientation: state.orientation,
|
|
114
|
+
selector: SELECTOR_TAB,
|
|
115
|
+
vertical: false,
|
|
116
|
+
onActivate: navigable => {
|
|
117
|
+
const index = state.tabList.tabs.indexOf(navigable.active.element as HTMLButtonElement);
|
|
118
|
+
|
|
119
|
+
if (index > -1 && index !== state.active) {
|
|
120
|
+
onActivate(state, index);
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
state.navigable = navigable;
|
|
126
|
+
|
|
127
|
+
const {length} = state.panels.elements;
|
|
128
|
+
|
|
129
|
+
for (let index = 0; index < length; index += 1) {
|
|
130
|
+
const panel = state.panels.elements[index];
|
|
131
|
+
|
|
132
|
+
panel.hidden = index !== state.active;
|
|
133
|
+
panel.role = 'tabpanel';
|
|
134
|
+
|
|
135
|
+
if (index === 0) {
|
|
136
|
+
panel.insertAdjacentElement('beforebegin', state.tabList.element);
|
|
137
|
+
panel.insertAdjacentElement('beforebegin', state.content);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
state.content.append(panel);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function createContent(prefix: string, panels: HTMLElement[], active: number): OuiTabsContent {
|
|
145
|
+
const content = createElement('div', {
|
|
146
|
+
attribute: {
|
|
147
|
+
[ATTRIBUTE_CONTENT]: '',
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
const {length} = panels;
|
|
152
|
+
|
|
153
|
+
const hidden: Array<boolean | 'until-found'> = [];
|
|
154
|
+
const roles: Array<string | null> = [];
|
|
155
|
+
|
|
156
|
+
for (let index = 0; index < length; index += 1) {
|
|
157
|
+
const panel = panels[index];
|
|
158
|
+
|
|
159
|
+
hidden.push(panel.hidden);
|
|
160
|
+
roles.push(panel.role);
|
|
161
|
+
|
|
162
|
+
panel.hidden = index !== active;
|
|
163
|
+
|
|
164
|
+
if (panel.id === '') {
|
|
165
|
+
panel.id = `${prefix}_panel_${index}`;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return {
|
|
170
|
+
element: content,
|
|
171
|
+
panels: {
|
|
172
|
+
hidden,
|
|
173
|
+
roles,
|
|
174
|
+
elements: panels,
|
|
175
|
+
},
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function createTab(
|
|
180
|
+
prefix: string,
|
|
181
|
+
index: number,
|
|
182
|
+
panel: HTMLElement,
|
|
183
|
+
label: string,
|
|
184
|
+
selected: boolean,
|
|
185
|
+
): HTMLButtonElement {
|
|
186
|
+
return createElement('button', {
|
|
187
|
+
aria: {
|
|
188
|
+
selected,
|
|
189
|
+
controls: panel.id,
|
|
190
|
+
},
|
|
191
|
+
attribute: {
|
|
192
|
+
[ATTRIBUTE_TAB]: '',
|
|
193
|
+
},
|
|
194
|
+
property: {
|
|
195
|
+
id: `${prefix}_tab_${index}`,
|
|
196
|
+
role: 'tab',
|
|
197
|
+
tabIndex: selected ? 0 : -1,
|
|
198
|
+
textContent: label,
|
|
199
|
+
type: 'button',
|
|
200
|
+
},
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function createTabList(
|
|
205
|
+
prefix: string,
|
|
206
|
+
panels: HTMLElement[],
|
|
207
|
+
labels: string[],
|
|
208
|
+
active: number,
|
|
209
|
+
): OuiTabsTabList {
|
|
210
|
+
const element = createElement('div', {
|
|
211
|
+
attribute: {
|
|
212
|
+
[ATTRIBUTE_TABLIST]: '',
|
|
213
|
+
},
|
|
214
|
+
property: {
|
|
215
|
+
role: 'tablist',
|
|
216
|
+
},
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
const {length} = panels;
|
|
220
|
+
|
|
221
|
+
const tabs: HTMLButtonElement[] = [];
|
|
222
|
+
|
|
223
|
+
for (let index = 0; index < length; index += 1) {
|
|
224
|
+
const tab = createTab(prefix, index, panels[index], labels[index], index === active);
|
|
225
|
+
|
|
226
|
+
element.append(tab);
|
|
227
|
+
tabs.push(tab);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return {
|
|
231
|
+
element,
|
|
232
|
+
tabs,
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function detachTabs(state: OuiTabsState): void {
|
|
237
|
+
state.navigable?.destroy();
|
|
238
|
+
|
|
239
|
+
const {length} = state.panels.elements;
|
|
240
|
+
|
|
241
|
+
for (let index = 0; index < length; index += 1) {
|
|
242
|
+
const panel = state.panels.elements[index];
|
|
243
|
+
|
|
244
|
+
panel.hidden = state.panels.hidden[index];
|
|
245
|
+
panel.role = state.panels.roles[index];
|
|
246
|
+
|
|
247
|
+
state.content.before(panel);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
state.tabList.element.remove();
|
|
251
|
+
state.content.remove();
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function getActive(element: OuiTabsElement, max: number): number {
|
|
255
|
+
const attribute = getAttribute(element, 'active');
|
|
256
|
+
|
|
257
|
+
let index = 0;
|
|
258
|
+
|
|
259
|
+
if (attribute != null) {
|
|
260
|
+
const value = Number.parseInt(attribute, 10);
|
|
261
|
+
|
|
262
|
+
if (!Number.isNaN(value) && value >= 0) {
|
|
263
|
+
index = value > max ? max : value;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
return index;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function getId(): string {
|
|
271
|
+
index += 1;
|
|
272
|
+
|
|
273
|
+
return `oui_tabs_${index}`;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function getLabels(panels: HTMLElement[]): string[] | undefined {
|
|
277
|
+
const labels: string[] = [];
|
|
278
|
+
|
|
279
|
+
const {length} = panels;
|
|
280
|
+
|
|
281
|
+
for (let index = 0; index < length; index += 1) {
|
|
282
|
+
const panel = panels[index];
|
|
283
|
+
|
|
284
|
+
const labelledBy = getAria(panel, 'labelledby');
|
|
285
|
+
|
|
286
|
+
if (typeof labelledBy === 'string' && labelledBy.trim().length > 0) {
|
|
287
|
+
const label: string[] = [];
|
|
288
|
+
const selectors = labelledBy.split(/\s+/);
|
|
289
|
+
|
|
290
|
+
for (const selector of selectors) {
|
|
291
|
+
const element = document.getElementById(selector);
|
|
292
|
+
|
|
293
|
+
if (element == null) {
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
label.push(element.textContent);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
labels.push(label.join(' '));
|
|
301
|
+
|
|
302
|
+
continue;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
const label = getAria(panel, 'label');
|
|
306
|
+
|
|
307
|
+
if (typeof label === 'string' && label.trim().length > 0) {
|
|
308
|
+
labels.push(label);
|
|
309
|
+
|
|
310
|
+
continue;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
return labels;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
function initializeTabs(element: OuiTabsElement): OuiTabsState {
|
|
320
|
+
const panels = [...element.querySelectorAll(SELECTOR_PANEL)] as HTMLElement[];
|
|
321
|
+
|
|
322
|
+
if (panels.length === 0) {
|
|
323
|
+
throw new Error(MESSAGE_EMPTY);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
const labels = getLabels(panels);
|
|
327
|
+
|
|
328
|
+
if (labels == null) {
|
|
329
|
+
throw new Error(MESSAGE_INVALID);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
let id: string;
|
|
333
|
+
|
|
334
|
+
if (element.id === '') {
|
|
335
|
+
id = getId();
|
|
336
|
+
} else {
|
|
337
|
+
id = element.id;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
const active = getActive(element, panels.length - 1);
|
|
341
|
+
const orientation = getNavigableOrientation(element, false, false);
|
|
342
|
+
|
|
343
|
+
const content = createContent(id, panels, active);
|
|
344
|
+
const tabList = createTabList(id, panels, labels, active);
|
|
345
|
+
|
|
346
|
+
const state: OuiTabsState = {
|
|
347
|
+
active,
|
|
348
|
+
id,
|
|
349
|
+
orientation,
|
|
350
|
+
tabList,
|
|
351
|
+
content: content.element,
|
|
352
|
+
host: element,
|
|
353
|
+
panels: content.panels,
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
attachTabs(state);
|
|
357
|
+
|
|
358
|
+
return state;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
function onActivate(state: OuiTabsState, next: number): void {
|
|
362
|
+
const current = state.active;
|
|
363
|
+
|
|
364
|
+
const event = new OuiTabsEvent('oui:beforechange', current, next, true);
|
|
365
|
+
|
|
366
|
+
state.host.dispatchEvent(event);
|
|
367
|
+
|
|
368
|
+
if (event.defaultPrevented) {
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
state.active = next;
|
|
373
|
+
|
|
374
|
+
const {length} = state.panels.elements;
|
|
375
|
+
|
|
376
|
+
for (let index = 0; index < length; index += 1) {
|
|
377
|
+
const panel = state.panels.elements[index];
|
|
378
|
+
|
|
379
|
+
panel.hidden = index !== next;
|
|
380
|
+
|
|
381
|
+
setAria(state.tabList.tabs[index], 'selected', index === next);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
setAttribute(state.host, 'active', next);
|
|
385
|
+
|
|
386
|
+
state.host.dispatchEvent(new OuiTabsEvent('oui:change', current, next, false));
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
function setActive(state: OuiTabsState | undefined, value: unknown): void {
|
|
390
|
+
if (state == null) {
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
const max = state.panels.elements.length - 1;
|
|
395
|
+
|
|
396
|
+
let index: number | undefined;
|
|
397
|
+
|
|
398
|
+
if (typeof value === 'number' && !Number.isNaN(value) && value >= 0) {
|
|
399
|
+
index = value > max ? max : value;
|
|
400
|
+
} else if (typeof value === 'string') {
|
|
401
|
+
const parsed = Number.parseInt(value, 10);
|
|
402
|
+
|
|
403
|
+
if (!Number.isNaN(parsed) && parsed >= 0) {
|
|
404
|
+
index = parsed > max ? max : parsed;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
if (index == null) {
|
|
409
|
+
setAttribute(state.host, 'active', state.active);
|
|
410
|
+
} else if (index !== state.active) {
|
|
411
|
+
state.navigable?.navigate(index, false);
|
|
412
|
+
|
|
413
|
+
onActivate(state, index);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
// #endregion
|
|
418
|
+
|
|
419
|
+
// #region Variables
|
|
420
|
+
|
|
421
|
+
const TAGNAME = 'oui-tabs';
|
|
422
|
+
|
|
423
|
+
const ATTRIBUTE_CONTENT = `${TAGNAME}-content`;
|
|
424
|
+
|
|
425
|
+
const ATTRIBUTE_PANEL = `${TAGNAME}-panel`;
|
|
426
|
+
|
|
427
|
+
const ATTRIBUTE_TAB = `${TAGNAME}-tab`;
|
|
428
|
+
|
|
429
|
+
const ATTRIBUTE_TABLIST = `${TAGNAME}-tablist`;
|
|
430
|
+
|
|
431
|
+
const MESSAGE_EMPTY = `<${TAGNAME}> must contain at least one [${ATTRIBUTE_PANEL}] child element`;
|
|
432
|
+
|
|
433
|
+
const MESSAGE_INVALID = `A [${ATTRIBUTE_PANEL}] child element of <${TAGNAME}> must have a valid 'aria-label' or 'aria-labelledby' attribute`;
|
|
434
|
+
|
|
435
|
+
const SELECTOR_PANEL = `:scope > [${ATTRIBUTE_PANEL}]`;
|
|
436
|
+
|
|
437
|
+
const SELECTOR_TAB = `[${ATTRIBUTE_TAB}]`;
|
|
438
|
+
|
|
439
|
+
let index = 0;
|
|
440
|
+
|
|
441
|
+
// #endregion
|
|
442
|
+
|
|
443
|
+
// #region Initialization
|
|
444
|
+
|
|
445
|
+
customElements.define(TAGNAME, OuiTabsElement);
|
|
446
|
+
|
|
447
|
+
// #endregion
|
package/src/js/tooltip.ts
CHANGED
|
@@ -182,15 +182,16 @@ function findElements(attribute?: string): HTMLElement[] | undefined {
|
|
|
182
182
|
}
|
|
183
183
|
|
|
184
184
|
function getContent(): HTMLElement {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
185
|
+
return createElement('div', {
|
|
186
|
+
attribute: {
|
|
187
|
+
[ATTRIBUTE_CONTENT]: '',
|
|
188
|
+
popover: 'hint',
|
|
189
|
+
},
|
|
190
|
+
property: {
|
|
191
|
+
role: 'tooltip',
|
|
192
|
+
tabIndex: -1,
|
|
193
|
+
},
|
|
189
194
|
});
|
|
190
|
-
|
|
191
|
-
setAttribute(content, ATTRIBUTE_CONTENT, '');
|
|
192
|
-
|
|
193
|
-
return content;
|
|
194
195
|
}
|
|
195
196
|
|
|
196
197
|
function getElements(anchor: HTMLElement): HTMLElement[] | undefined {
|
|
@@ -204,21 +205,23 @@ function getElements(anchor: HTMLElement): HTMLElement[] | undefined {
|
|
|
204
205
|
return elements as HTMLElement[];
|
|
205
206
|
}
|
|
206
207
|
|
|
207
|
-
let
|
|
208
|
+
let textContent = getAria(anchor, 'label');
|
|
208
209
|
|
|
209
|
-
if (isNullableOrWhitespace(
|
|
210
|
-
|
|
210
|
+
if (isNullableOrWhitespace(textContent)) {
|
|
211
|
+
textContent = getAria(anchor, 'description');
|
|
211
212
|
}
|
|
212
213
|
|
|
213
|
-
if (isNullableOrWhitespace(
|
|
214
|
+
if (isNullableOrWhitespace(textContent)) {
|
|
214
215
|
return;
|
|
215
216
|
}
|
|
216
217
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
218
|
+
return [
|
|
219
|
+
createElement('p', {
|
|
220
|
+
property: {
|
|
221
|
+
textContent,
|
|
222
|
+
},
|
|
223
|
+
}),
|
|
224
|
+
];
|
|
222
225
|
}
|
|
223
226
|
|
|
224
227
|
function getState(anchor: HTMLElement, elements: HTMLElement[]): OuiTooltipState {
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { I as OuiComboboxState } from "../constants.combobox-h_kyDegw.mjs";
|
|
2
|
-
//#region src/js/combobox/data.combobox.d.ts
|
|
3
|
-
type ApplySelectionParameters = {
|
|
4
|
-
added: boolean;
|
|
5
|
-
emit?: boolean;
|
|
6
|
-
option?: HTMLElement;
|
|
7
|
-
selected?: HTMLElement[];
|
|
8
|
-
state: OuiComboboxState;
|
|
9
|
-
values?: string[];
|
|
10
|
-
};
|
|
11
|
-
declare function applyComboboxSelection(parameters: ApplySelectionParameters): void;
|
|
12
|
-
declare function filterComboboxOption(state: OuiComboboxState, value: unknown, textContent?: boolean): HTMLElement | undefined;
|
|
13
|
-
declare function filterComboboxOptions(state: OuiComboboxState): HTMLElement | undefined;
|
|
14
|
-
declare function setComboboxValue(state: OuiComboboxState, value: unknown, emit?: boolean): void;
|
|
15
|
-
declare function setComboboxValues(state: OuiComboboxState, value: unknown, emit?: boolean): void;
|
|
16
|
-
declare function toggleComboboxOption(state: OuiComboboxState, option?: HTMLElement): void;
|
|
17
|
-
//#endregion
|
|
18
|
-
export { applyComboboxSelection, filterComboboxOption, filterComboboxOptions, setComboboxValue, setComboboxValues, toggleComboboxOption };
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { a as setComboboxValues, i as setComboboxValue, n as filterComboboxOption, o as toggleComboboxOption, r as filterComboboxOptions, t as applyComboboxSelection } from "../data.combobox-B8HMkDOh.mjs";
|
|
2
|
-
export { applyComboboxSelection, filterComboboxOption, filterComboboxOptions, setComboboxValue, setComboboxValues, toggleComboboxOption };
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { I as OuiComboboxState } from "../constants.combobox-h_kyDegw.mjs";
|
|
2
|
-
//#region src/js/combobox/form.combobox.d.ts
|
|
3
|
-
declare function updateComboboxForm(state: OuiComboboxState, values: string[], emit?: boolean): void;
|
|
4
|
-
declare function updateComboboxValidity(state: OuiComboboxState): void;
|
|
5
|
-
//#endregion
|
|
6
|
-
export { updateComboboxForm, updateComboboxValidity };
|