@oscarpalmer/oui 0.37.0 → 0.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/dist/css/a11y.css +1 -0
- package/dist/css/badge.css +12 -8
- package/dist/css/button.css +111 -14
- package/dist/css/color-picker.css +859 -0
- package/dist/css/color.css +86 -87
- package/dist/css/combobox.css +105 -4
- package/dist/css/content.css +8 -6
- package/dist/css/floatable.css +3 -3
- package/dist/css/form.css +106 -6
- package/dist/css/icon.css +99 -0
- package/dist/css/listbox.css +5 -0
- package/dist/css/message.css +6 -3
- package/dist/css/mixins/badge.mixins.css +2 -0
- package/dist/css/mixins/button.mixins.css +3 -0
- package/dist/css/mixins/message.mixins.css +1 -0
- package/dist/css/mixins/misc.mixins.css +2 -0
- package/dist/css/mixins/shadow.mixins.css +1 -0
- package/dist/css/reset.css +3 -3
- package/dist/css/splitter.css +1 -1
- package/dist/css/tabs.css +115 -23
- package/dist/css/typography.css +90 -0
- package/dist/js/color-picker/constants.color-picker.d.mts +2 -0
- package/dist/js/color-picker/constants.color-picker.mjs +59 -0
- package/dist/js/color-picker/dom.color-picker.d.mts +8 -0
- package/dist/js/color-picker/dom.color-picker.mjs +191 -0
- package/dist/js/color-picker/event.color-picker.d.mts +9 -0
- package/dist/js/color-picker/event.color-picker.mjs +2 -0
- package/dist/js/color-picker/form.color-picker.d.mts +5 -0
- package/dist/js/color-picker/form.color-picker.mjs +24 -0
- package/dist/js/color-picker/index.d.mts +2 -0
- package/dist/js/color-picker/index.mjs +303 -0
- package/dist/js/color-picker/misc.color-picker.d.mts +2 -0
- package/dist/js/color-picker/misc.color-picker.mjs +2 -0
- package/dist/js/color-picker/models.color-picker.d.mts +2 -0
- package/dist/js/color-picker/models.color-picker.mjs +24 -0
- package/dist/js/color-picker/output.color-picker.d.mts +8 -0
- package/dist/js/color-picker/output.color-picker.mjs +233 -0
- package/dist/js/color-picker/state.color-picker.d.mts +8 -0
- package/dist/js/color-picker/state.color-picker.mjs +2 -0
- package/dist/js/combobox/constants.combobox.d.mts +1 -1
- package/dist/js/combobox/dom.combobox.d.mts +12 -13
- package/dist/js/combobox/dom.combobox.mjs +12 -5
- package/dist/js/combobox/event.combobox.d.mts +20 -21
- package/dist/js/combobox/event.combobox.mjs +1 -1
- package/dist/js/combobox/index.d.mts +1 -1
- package/dist/js/combobox/index.mjs +56 -2
- package/dist/js/combobox/misc.combobox.d.mts +1 -1
- package/dist/js/combobox/misc.combobox.mjs +1 -1
- package/dist/js/combobox/models.combobox.d.mts +12 -13
- package/dist/js/combobox/state.combobox.d.mts +8 -9
- package/dist/js/combobox/state.combobox.mjs +1 -1
- package/dist/js/constants.color-picker-B-gFjL8m.d.mts +364 -0
- package/dist/js/constants.combobox-8EMRmv09.d.mts +18 -0
- package/dist/js/constants.listbox-DGnX32kv.d.mts +8 -0
- package/dist/js/dialog.d.mts +2 -2
- package/dist/js/dialog.mjs +1 -1
- package/dist/js/{draggable-a6w0J1OD.d.mts → draggable-B5-70SZm.d.mts} +5 -4
- package/dist/js/event.color-picker-BEpq0Adu.mjs +485 -0
- package/dist/js/floatable/floatable.embedded.d.mts +1 -1
- package/dist/js/floatable/floatable.embedded.mjs +11 -8
- package/dist/js/floatable/floatable.standalone.d.mts +1 -1
- package/dist/js/{floatable.embedded-Bct4U5Dm.d.mts → floatable.embedded-DQYkXt8X.d.mts} +1 -1
- package/dist/js/focus-trap/focus-trap.embedded.d.mts +1 -1
- package/dist/js/focus-trap/focus-trap.standalone.d.mts +1 -1
- package/dist/js/{focus-trap.embedded-DR8NpZfr.d.mts → focus-trap.embedded-CjyFQYow.d.mts} +2 -2
- package/dist/js/{index-EfkUSals.d.mts → index-C5D3-oiI.d.mts} +41 -3
- package/dist/js/index.d.mts +8 -7
- package/dist/js/index.mjs +6 -3
- package/dist/js/internal/attributable.d.mts +2 -3
- package/dist/js/internal/draggable.d.mts +1 -1
- package/dist/js/internal/draggable.mjs +1 -1
- package/dist/js/internal/listbox/listbox.constants.d.mts +7 -10
- package/dist/js/internal/listbox/listbox.constants.mjs +15 -16
- package/dist/js/internal/listbox/listbox.data.d.mts +9 -10
- package/dist/js/internal/listbox/listbox.data.mjs +1 -1
- package/dist/js/internal/listbox/listbox.dom.d.mts +19 -20
- package/dist/js/internal/listbox/listbox.dom.mjs +1 -1
- package/dist/js/internal/listbox/listbox.event.d.mts +3 -4
- package/dist/js/internal/listbox/listbox.event.mjs +4 -4
- package/dist/js/internal/listbox/listbox.form.d.mts +4 -5
- package/dist/js/internal/listbox/listbox.form.mjs +16 -15
- package/dist/js/internal/listbox/listbox.misc.d.mts +10 -11
- package/dist/js/internal/listbox/listbox.misc.mjs +1 -1
- package/dist/js/internal/listbox/listbox.model.d.mts +1 -1
- package/dist/js/internal/listbox/listbox.state.d.mts +5 -6
- package/dist/js/internal/listbox/listbox.state.mjs +3 -3
- package/dist/js/internal/misc.d.mts +4 -4
- package/dist/js/internal/misc.mjs +9 -1
- package/dist/js/internal/navigable.d.mts +9 -10
- package/dist/js/internal/navigable.mjs +1 -0
- package/dist/js/listbox/constants.listbox.d.mts +1 -1
- package/dist/js/listbox/event.listbox.d.mts +6 -7
- package/dist/js/listbox/event.listbox.mjs +1 -1
- package/dist/js/listbox/index.d.mts +43 -5
- package/dist/js/listbox/index.mjs +56 -2
- package/dist/js/listbox/misc.listbox.d.mts +1 -1
- package/dist/js/listbox/misc.listbox.mjs +1 -1
- package/dist/js/listbox/state.listbox.d.mts +7 -8
- package/dist/js/listbox/state.listbox.mjs +1 -1
- package/dist/js/{listbox.data-BWd0PCy7.mjs → listbox.data-DQ7-x2uY.mjs} +8 -7
- package/dist/js/{listbox.model-CRReGOmu.d.mts → listbox.model-BHPA7GM4.d.mts} +3 -3
- package/dist/js/menu.mjs +1 -1
- package/dist/js/{misc.listbox-BI-XsTOf.mjs → misc.listbox-DKB-j0UK.mjs} +4 -5
- package/dist/js/{misc.listbox-gnoJhrTr.d.mts → misc.listbox-mZMuYOxg.d.mts} +1 -1
- package/dist/js/movable/movable.embedded.d.mts +1 -1
- package/dist/js/movable/movable.standalone.d.mts +1 -1
- package/dist/js/popover.d.mts +2 -2
- package/dist/js/popover.mjs +1 -1
- package/dist/js/resizable/resizable.embedded.d.mts +1 -1
- package/dist/js/resizable/resizable.embedded.mjs +1 -1
- package/dist/js/resizable/resizable.standalone.d.mts +1 -1
- package/dist/js/{resizable.embedded-3qoR0Bjm.d.mts → resizable.embedded-dvhdfQgt.d.mts} +1 -1
- package/dist/js/sortable/sortable.embedded.d.mts +1 -1
- package/dist/js/sortable/sortable.standalone.d.mts +1 -1
- package/dist/js/splitter.d.mts +2 -3
- package/dist/js/splitter.mjs +2 -2
- package/dist/js/{state.combobox-4xq0FPCF.mjs → state.combobox-BWDFHwoi.mjs} +9 -9
- package/dist/js/tabs.d.mts +4 -5
- package/dist/js/tabs.mjs +4 -7
- package/dist/js/tooltip.d.mts +1 -1
- package/package.json +24 -22
- package/dist/js/constants.combobox-DmRAMC64.d.mts +0 -26
- package/dist/js/constants.listbox-DRsXUxd3.d.mts +0 -14
- package/src/css/a11y.scss +0 -13
- package/src/css/badge.scss +0 -62
- package/src/css/button.scss +0 -50
- package/src/css/color.scss +0 -115
- package/src/css/combobox.scss +0 -252
- package/src/css/content.scss +0 -180
- package/src/css/flex.scss +0 -107
- package/src/css/floatable.scss +0 -152
- package/src/css/form.scss +0 -573
- package/src/css/listbox.scss +0 -120
- package/src/css/message.scss +0 -73
- package/src/css/mixins.scss +0 -419
- package/src/css/reset.scss +0 -392
- package/src/css/splitter.scss +0 -89
- package/src/css/table.scss +0 -107
- package/src/css/tabs.scss +0 -85
- package/src/js/combobox/constants.combobox.ts +0 -83
- package/src/js/combobox/dom.combobox.ts +0 -407
- package/src/js/combobox/event.combobox.ts +0 -365
- package/src/js/combobox/index.ts +0 -320
- package/src/js/combobox/misc.combobox.ts +0 -104
- package/src/js/combobox/models.combobox.ts +0 -54
- package/src/js/combobox/state.combobox.ts +0 -246
- package/src/js/dialog.ts +0 -255
- package/src/js/floatable/floatable.embedded.ts +0 -332
- package/src/js/floatable/floatable.standalone.ts +0 -6
- package/src/js/focus-trap/focus-trap.embedded.ts +0 -411
- package/src/js/focus-trap/focus-trap.standalone.ts +0 -1
- package/src/js/index.ts +0 -15
- package/src/js/internal/attributable.ts +0 -73
- package/src/js/internal/draggable.ts +0 -657
- package/src/js/internal/listbox/listbox.constants.ts +0 -25
- package/src/js/internal/listbox/listbox.data.ts +0 -287
- package/src/js/internal/listbox/listbox.dom.ts +0 -445
- package/src/js/internal/listbox/listbox.event.ts +0 -129
- package/src/js/internal/listbox/listbox.form.ts +0 -115
- package/src/js/internal/listbox/listbox.misc.ts +0 -135
- package/src/js/internal/listbox/listbox.model.ts +0 -169
- package/src/js/internal/listbox/listbox.state.ts +0 -82
- package/src/js/internal/misc.ts +0 -27
- package/src/js/internal/navigable.ts +0 -315
- package/src/js/l10n.ts +0 -192
- package/src/js/listbox/constants.listbox.ts +0 -61
- package/src/js/listbox/event.listbox.ts +0 -106
- package/src/js/listbox/index.ts +0 -302
- package/src/js/listbox/misc.listbox.ts +0 -70
- package/src/js/listbox/state.listbox.ts +0 -196
- package/src/js/menu.ts +0 -348
- package/src/js/movable/movable.embedded.ts +0 -318
- package/src/js/movable/movable.standalone.ts +0 -2
- package/src/js/popover.ts +0 -229
- package/src/js/resizable/resizable.embedded.ts +0 -413
- package/src/js/resizable/resizable.standalone.ts +0 -5
- package/src/js/sortable/sortable.embedded.ts +0 -527
- package/src/js/sortable/sortable.standalone.ts +0 -2
- package/src/js/splitter.ts +0 -583
- package/src/js/tabs.ts +0 -447
- package/src/js/toolbar.ts +0 -63
- package/src/js/tooltip.ts +0 -367
- /package/dist/css/{mixins.css → mixins/input.mixins.css} +0 -0
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
OuiListboxAttributes,
|
|
3
|
-
OuiListboxAutoCompleteType,
|
|
4
|
-
} from '../internal/listbox/listbox.model';
|
|
5
|
-
|
|
6
|
-
// #region Variables
|
|
7
|
-
|
|
8
|
-
export const COMBOBOX_TAGNAME = 'oui-combobox';
|
|
9
|
-
|
|
10
|
-
export const COMBOBOX_ATTRIBUTE_ANCHOR = `${COMBOBOX_TAGNAME}-anchor`;
|
|
11
|
-
|
|
12
|
-
const attributeContent = `${COMBOBOX_TAGNAME}-content`;
|
|
13
|
-
|
|
14
|
-
const attributeFilter = `${COMBOBOX_TAGNAME}-filter`;
|
|
15
|
-
|
|
16
|
-
const attributeFilterInput = `${attributeFilter}-input`;
|
|
17
|
-
|
|
18
|
-
const attributeGroup = `${COMBOBOX_TAGNAME}-group`;
|
|
19
|
-
|
|
20
|
-
const attributeHeader = `${COMBOBOX_TAGNAME}-header`;
|
|
21
|
-
|
|
22
|
-
const attributeHidden = `${COMBOBOX_TAGNAME}-hidden`;
|
|
23
|
-
|
|
24
|
-
const attributeList = `${COMBOBOX_TAGNAME}-list`;
|
|
25
|
-
|
|
26
|
-
const attributeListEmpty = `${attributeList}-empty`;
|
|
27
|
-
|
|
28
|
-
const attributeMessage = `${COMBOBOX_TAGNAME}-message`;
|
|
29
|
-
|
|
30
|
-
const attributeOption = `${COMBOBOX_TAGNAME}-option`;
|
|
31
|
-
|
|
32
|
-
const attributeOptionActive = `${COMBOBOX_TAGNAME}-option-active`;
|
|
33
|
-
|
|
34
|
-
export const COMBOBOX_ATTRIBUTE_SELECTION = `${COMBOBOX_TAGNAME}-selection`;
|
|
35
|
-
|
|
36
|
-
export const COMBOBOX_ATTRIBUTE_SELECTION_ITEM = `${COMBOBOX_TAGNAME}-selection-item`;
|
|
37
|
-
|
|
38
|
-
export const COMBOBOX_AUTOCOMPLETES = new Set<OuiListboxAutoCompleteType>([
|
|
39
|
-
'both',
|
|
40
|
-
'inline',
|
|
41
|
-
'list',
|
|
42
|
-
'none',
|
|
43
|
-
]);
|
|
44
|
-
|
|
45
|
-
export const messageLabel = `<${COMBOBOX_TAGNAME}> must contain a <label> element for the <select> element`;
|
|
46
|
-
|
|
47
|
-
export const messageSelect = `<${COMBOBOX_TAGNAME}> must contain a valid <select> element`;
|
|
48
|
-
|
|
49
|
-
export const selectorAnchor = `[${COMBOBOX_ATTRIBUTE_ANCHOR}]`;
|
|
50
|
-
|
|
51
|
-
export const selectorContent = `[${attributeContent}]`;
|
|
52
|
-
|
|
53
|
-
export const selectorOption = `[${attributeOption}]`;
|
|
54
|
-
|
|
55
|
-
export const selectorSelectionItem = `[${COMBOBOX_ATTRIBUTE_SELECTION_ITEM}]`;
|
|
56
|
-
|
|
57
|
-
export const COMBOBOX_ATTRIBUTES: OuiListboxAttributes = {
|
|
58
|
-
active: attributeOptionActive,
|
|
59
|
-
content: attributeContent,
|
|
60
|
-
empty: attributeListEmpty,
|
|
61
|
-
filter: attributeFilter,
|
|
62
|
-
group: attributeGroup,
|
|
63
|
-
header: attributeHeader,
|
|
64
|
-
hidden: attributeHidden,
|
|
65
|
-
input: attributeFilterInput,
|
|
66
|
-
list: attributeList,
|
|
67
|
-
message: attributeMessage,
|
|
68
|
-
option: attributeOption,
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
export const COMBOBOX_MESSAGES = {
|
|
72
|
-
label: messageLabel,
|
|
73
|
-
select: messageSelect,
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
export const COMBOBOX_SELECTORS = {
|
|
77
|
-
anchor: selectorAnchor,
|
|
78
|
-
content: selectorContent,
|
|
79
|
-
selectionItem: selectorSelectionItem,
|
|
80
|
-
option: selectorOption,
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
// #endregion
|
|
@@ -1,407 +0,0 @@
|
|
|
1
|
-
import {setAria} from '@oscarpalmer/toretto/aria';
|
|
2
|
-
import {setAttribute} from '@oscarpalmer/toretto/attribute';
|
|
3
|
-
import {createElement} from '@oscarpalmer/toretto/create';
|
|
4
|
-
import {getData} from '@oscarpalmer/toretto/data';
|
|
5
|
-
import {
|
|
6
|
-
createListboxFilter,
|
|
7
|
-
createListboxInput,
|
|
8
|
-
createListboxList,
|
|
9
|
-
createListboxMessage,
|
|
10
|
-
createListboxValueLabel,
|
|
11
|
-
type CreateListboxContent,
|
|
12
|
-
type CreateListboxContentParameters,
|
|
13
|
-
} from '../internal/listbox/listbox.dom';
|
|
14
|
-
import type {OuiListboxPreview} from '../internal/listbox/listbox.model';
|
|
15
|
-
import {getLocalization, localize} from '../l10n';
|
|
16
|
-
import {
|
|
17
|
-
COMBOBOX_ATTRIBUTE_ANCHOR,
|
|
18
|
-
COMBOBOX_ATTRIBUTE_SELECTION,
|
|
19
|
-
COMBOBOX_ATTRIBUTE_SELECTION_ITEM,
|
|
20
|
-
} from './constants.combobox';
|
|
21
|
-
import type {
|
|
22
|
-
OuiComboboxSelection,
|
|
23
|
-
OuiComboboxSelectionItem,
|
|
24
|
-
OuiComboboxState,
|
|
25
|
-
} from './models.combobox';
|
|
26
|
-
|
|
27
|
-
// #region Types
|
|
28
|
-
|
|
29
|
-
type CreateAnchor = {
|
|
30
|
-
container?: HTMLElement;
|
|
31
|
-
element: HTMLElement;
|
|
32
|
-
selection?: OuiComboboxSelection;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
type CreateSelectionItemsParameters = {
|
|
36
|
-
container: HTMLElement;
|
|
37
|
-
items: OuiComboboxSelectionItem[];
|
|
38
|
-
options: HTMLElement[];
|
|
39
|
-
state?: OuiComboboxState;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
// #endregion
|
|
43
|
-
|
|
44
|
-
// #region Functions
|
|
45
|
-
|
|
46
|
-
export function createComboboxAnchor(parameters: CreateListboxContentParameters): CreateAnchor {
|
|
47
|
-
const {select} = parameters;
|
|
48
|
-
|
|
49
|
-
let container: HTMLElement | undefined;
|
|
50
|
-
let element: HTMLElement;
|
|
51
|
-
let selection: OuiComboboxSelection | undefined;
|
|
52
|
-
|
|
53
|
-
if (parameters.type === 'autocomplete') {
|
|
54
|
-
element = createListboxInput(parameters, select.selectedOptions[0]?.textContent ?? '');
|
|
55
|
-
} else {
|
|
56
|
-
({container, element, selection} = createComboboxButton(parameters));
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
setAttribute(container ?? element, COMBOBOX_ATTRIBUTE_ANCHOR, '');
|
|
60
|
-
|
|
61
|
-
return {container, element, selection};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export function createComboboxButton(parameters: CreateListboxContentParameters): CreateAnchor {
|
|
65
|
-
const {id, label, multiple, select} = parameters;
|
|
66
|
-
|
|
67
|
-
const element = createElement('button', {
|
|
68
|
-
aria: {
|
|
69
|
-
controls: `${id}_content`,
|
|
70
|
-
expanded: false,
|
|
71
|
-
haspopup: 'listbox',
|
|
72
|
-
labelledby: `${label.id} ${id}_value`, // Non-input anchor, so no implicit value label, so we need to explicitly reference the value label
|
|
73
|
-
},
|
|
74
|
-
property: {
|
|
75
|
-
textContent: multiple ? '' : (select.selectedOptions[0]?.textContent ?? ''),
|
|
76
|
-
},
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
if (!multiple) {
|
|
80
|
-
return {element};
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const container = createElement('div');
|
|
84
|
-
const selection = createComboboxSelection(id, select);
|
|
85
|
-
|
|
86
|
-
container.append(selection.container, element);
|
|
87
|
-
|
|
88
|
-
return {container, element, selection};
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export function createComboboxContent(
|
|
92
|
-
parameters: CreateListboxContentParameters,
|
|
93
|
-
): CreateListboxContent {
|
|
94
|
-
const {id, label} = parameters;
|
|
95
|
-
|
|
96
|
-
const element = createElement('div', {
|
|
97
|
-
aria: {
|
|
98
|
-
labelledby: label.id,
|
|
99
|
-
},
|
|
100
|
-
attribute: {
|
|
101
|
-
[parameters.attributes.content]: '',
|
|
102
|
-
popover: '',
|
|
103
|
-
},
|
|
104
|
-
property: {
|
|
105
|
-
id: `${id}_content`,
|
|
106
|
-
tabIndex: -1,
|
|
107
|
-
},
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
const filter = createListboxFilter(parameters);
|
|
111
|
-
const list = createListboxList(parameters);
|
|
112
|
-
const message = createListboxMessage(parameters.attributes.message);
|
|
113
|
-
const value = createListboxValueLabel(parameters.id);
|
|
114
|
-
|
|
115
|
-
if (filter != null) {
|
|
116
|
-
element.append(filter.container);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
element.append(list.element, message, value);
|
|
120
|
-
|
|
121
|
-
return {element, filter, list, message, value};
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export function createComboboxSelection(
|
|
125
|
-
id: string,
|
|
126
|
-
select: HTMLSelectElement,
|
|
127
|
-
): OuiComboboxSelection {
|
|
128
|
-
const container = createElement('ul', {
|
|
129
|
-
attribute: {
|
|
130
|
-
[COMBOBOX_ATTRIBUTE_SELECTION]: '',
|
|
131
|
-
},
|
|
132
|
-
property: {
|
|
133
|
-
id: `${id}_selection`,
|
|
134
|
-
},
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
const options = [...select.selectedOptions];
|
|
138
|
-
|
|
139
|
-
const items: OuiComboboxSelectionItem[] = [];
|
|
140
|
-
|
|
141
|
-
createComboboxSelectionItems({container, items, options});
|
|
142
|
-
|
|
143
|
-
const {button} = items[0] ?? {};
|
|
144
|
-
|
|
145
|
-
if (button != null) {
|
|
146
|
-
button.tabIndex = 0;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
return {
|
|
150
|
-
items,
|
|
151
|
-
container: container,
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
export function createComboboxSelectionItem(
|
|
156
|
-
option: HTMLElement,
|
|
157
|
-
state?: OuiComboboxState,
|
|
158
|
-
): OuiComboboxSelectionItem {
|
|
159
|
-
const optionLabel = option.textContent;
|
|
160
|
-
const optionValue = getData(option, 'value', false) ?? '';
|
|
161
|
-
|
|
162
|
-
const element = createElement('li');
|
|
163
|
-
|
|
164
|
-
const localization =
|
|
165
|
-
state == null
|
|
166
|
-
? option.textContent
|
|
167
|
-
: getLocalization(
|
|
168
|
-
state.localizations.global,
|
|
169
|
-
state.host,
|
|
170
|
-
'remove',
|
|
171
|
-
state.localizations.component,
|
|
172
|
-
);
|
|
173
|
-
|
|
174
|
-
const button = createElement('button', {
|
|
175
|
-
aria: {
|
|
176
|
-
label: localize(
|
|
177
|
-
localization,
|
|
178
|
-
{
|
|
179
|
-
label: optionLabel,
|
|
180
|
-
value: optionValue,
|
|
181
|
-
},
|
|
182
|
-
[optionLabel, optionValue],
|
|
183
|
-
),
|
|
184
|
-
},
|
|
185
|
-
attribute: {
|
|
186
|
-
[COMBOBOX_ATTRIBUTE_SELECTION_ITEM]: '',
|
|
187
|
-
tabindex: -1,
|
|
188
|
-
},
|
|
189
|
-
data: {
|
|
190
|
-
option: option.id,
|
|
191
|
-
},
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
const icon = createElement('span', {
|
|
195
|
-
aria: {
|
|
196
|
-
hidden: true,
|
|
197
|
-
},
|
|
198
|
-
property: {
|
|
199
|
-
innerHTML: '×',
|
|
200
|
-
},
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
const label = createElement('span', {
|
|
204
|
-
property: {
|
|
205
|
-
textContent: option.textContent,
|
|
206
|
-
},
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
button.append(icon, label);
|
|
210
|
-
element.append(button);
|
|
211
|
-
|
|
212
|
-
return {
|
|
213
|
-
button,
|
|
214
|
-
element,
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
export function createComboboxSelectionItems(parameters: CreateSelectionItemsParameters): void {
|
|
219
|
-
const {container, items, options, state} = parameters;
|
|
220
|
-
|
|
221
|
-
const {length} = options;
|
|
222
|
-
|
|
223
|
-
for (let index = 0; index < length; index += 1) {
|
|
224
|
-
const option = options[index];
|
|
225
|
-
|
|
226
|
-
const item = createComboboxSelectionItem(option, state);
|
|
227
|
-
|
|
228
|
-
container.append(item.element);
|
|
229
|
-
items.push(item);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
export function updateComboboxTabindices(state: OuiComboboxState, active?: HTMLElement): void {
|
|
234
|
-
if (active == null || state.selection == null) {
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
const next = state.selection.items.find(
|
|
239
|
-
item => getData(item.button, 'option', false) === active.id,
|
|
240
|
-
);
|
|
241
|
-
|
|
242
|
-
if (next == null) {
|
|
243
|
-
return;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
const {length} = state.selection.items;
|
|
247
|
-
|
|
248
|
-
for (let index = 0; index < length; index += 1) {
|
|
249
|
-
const item = state.selection.items[index];
|
|
250
|
-
|
|
251
|
-
item.button.tabIndex = item === next ? 0 : -1;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
next.button.focus();
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
export function updateComboboxAutocomplete(
|
|
258
|
-
preview: OuiListboxPreview,
|
|
259
|
-
state: OuiComboboxState,
|
|
260
|
-
active?: HTMLElement,
|
|
261
|
-
): void {
|
|
262
|
-
if (state.multiple) {
|
|
263
|
-
return;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
const content = active?.textContent ?? state.filter.element.value;
|
|
267
|
-
|
|
268
|
-
if (
|
|
269
|
-
preview === 'typed' &&
|
|
270
|
-
!content.toLocaleLowerCase().startsWith(state.filter.element.value.toLocaleLowerCase())
|
|
271
|
-
) {
|
|
272
|
-
return;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
if (state.anchor.element instanceof HTMLInputElement) {
|
|
276
|
-
const contentLength = content.length;
|
|
277
|
-
const filterLength = state.filter.element.value.length;
|
|
278
|
-
|
|
279
|
-
if (preview === 'set' || preview === 'typed') {
|
|
280
|
-
state.anchor.element.value = content;
|
|
281
|
-
|
|
282
|
-
state.anchor.element.setSelectionRange(
|
|
283
|
-
preview === 'typed' ? filterLength : contentLength,
|
|
284
|
-
contentLength,
|
|
285
|
-
);
|
|
286
|
-
}
|
|
287
|
-
} else {
|
|
288
|
-
state.anchor.element.textContent = content;
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
export function updateComboboxSelection(
|
|
293
|
-
state: OuiComboboxState,
|
|
294
|
-
active: HTMLElement | undefined,
|
|
295
|
-
added: boolean,
|
|
296
|
-
selected?: HTMLElement[],
|
|
297
|
-
): void {
|
|
298
|
-
if (state.selection == null) {
|
|
299
|
-
return;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
let options = active == null ? [] : [active];
|
|
303
|
-
|
|
304
|
-
if (added && selected != null) {
|
|
305
|
-
options = selected;
|
|
306
|
-
|
|
307
|
-
const {length} = state.selection.items;
|
|
308
|
-
|
|
309
|
-
for (let index = 0; index < length; index += 1) {
|
|
310
|
-
state.selection.items[index].element.remove();
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
state.selection.items.splice(0);
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
if (added) {
|
|
317
|
-
createComboboxSelectionItems({
|
|
318
|
-
options,
|
|
319
|
-
state,
|
|
320
|
-
container: state.selection.container,
|
|
321
|
-
items: state.selection.items,
|
|
322
|
-
});
|
|
323
|
-
|
|
324
|
-
return;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
let current = state.selection.items.findIndex(
|
|
328
|
-
item => getData(item.button, 'option', false) === active?.id,
|
|
329
|
-
);
|
|
330
|
-
|
|
331
|
-
if (current === -1) {
|
|
332
|
-
return;
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
const item = state.selection.items[current];
|
|
336
|
-
|
|
337
|
-
item.element.remove();
|
|
338
|
-
|
|
339
|
-
state.selection.items.splice(current, 1);
|
|
340
|
-
|
|
341
|
-
if (state.selection.items.length === 0) {
|
|
342
|
-
state.anchor.element.focus();
|
|
343
|
-
|
|
344
|
-
return;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
const {length} = state.selection.items;
|
|
348
|
-
|
|
349
|
-
if (current < 0) {
|
|
350
|
-
current = 0;
|
|
351
|
-
} else if (current >= length) {
|
|
352
|
-
current = length - 1;
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
for (let index = 0; index < length; index += 1) {
|
|
356
|
-
const {button} = state.selection.items[index];
|
|
357
|
-
|
|
358
|
-
button.tabIndex = index === current ? 0 : -1;
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
state.selection.items[current].button.focus();
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
export function updateComboboxSelectionItems(state: OuiComboboxState): void {
|
|
365
|
-
if (state.selection == null) {
|
|
366
|
-
return;
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
const localization = getLocalization(
|
|
370
|
-
state.localizations.global,
|
|
371
|
-
state.host,
|
|
372
|
-
'remove',
|
|
373
|
-
state.localizations.component,
|
|
374
|
-
);
|
|
375
|
-
|
|
376
|
-
const {length} = state.selection.items;
|
|
377
|
-
|
|
378
|
-
for (let index = 0; index < length; index += 1) {
|
|
379
|
-
const item = state.selection.items[index];
|
|
380
|
-
|
|
381
|
-
const option = state.options.selected.find(
|
|
382
|
-
option => option.id === getData(item.button, 'option', false),
|
|
383
|
-
);
|
|
384
|
-
|
|
385
|
-
if (option == null) {
|
|
386
|
-
continue;
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
const optionLabel = option.textContent;
|
|
390
|
-
const optionValue = getData(option, 'value', false) ?? '';
|
|
391
|
-
|
|
392
|
-
setAria(
|
|
393
|
-
item.button,
|
|
394
|
-
'label',
|
|
395
|
-
localize(
|
|
396
|
-
localization,
|
|
397
|
-
{
|
|
398
|
-
label: optionLabel,
|
|
399
|
-
value: optionValue,
|
|
400
|
-
},
|
|
401
|
-
[optionLabel, optionValue],
|
|
402
|
-
),
|
|
403
|
-
);
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
// #endregion
|