@birdycom/omniaui 0.16.2 → 0.17.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/bin/lib/copy-js.mjs +8 -0
- package/bin/lib/webicons-builtin.json +1 -1
- package/dist/back-link.d.ts +6 -0
- package/dist/back-link.js +54 -0
- package/dist/barcode.d.ts +5 -1
- package/dist/barcode.js +29 -8
- package/dist/calendar.d.ts +17 -0
- package/dist/calendar.js +190 -0
- package/dist/code-block.css +3 -0
- package/dist/combobox.d.ts +27 -4
- package/dist/combobox.js +231 -33
- package/dist/components-extra.css +33 -2
- package/dist/components.css +2096 -163
- package/dist/components.min.css +1 -1
- package/dist/countdown.d.ts +11 -0
- package/dist/countdown.js +76 -0
- package/dist/data-table.d.ts +28 -0
- package/dist/data-table.js +186 -18
- package/dist/docs-ui.css +11 -1
- package/dist/glass-lens.d.ts +41 -0
- package/dist/glass-lens.js +307 -0
- package/dist/input-mask.d.ts +31 -0
- package/dist/input-mask.js +228 -0
- package/dist/nav-overflow.d.ts +11 -0
- package/dist/nav-overflow.js +151 -0
- package/dist/oc-theme.css +1 -1
- package/dist/parts/app-0160-apps.css +6 -0
- package/dist/parts/app-compound-overlays.css +68 -0
- package/dist/parts/app-countdown.css +66 -0
- package/dist/parts/app-data-table-footer.css +6 -3
- package/dist/parts/app-data-table-server.css +47 -0
- package/dist/parts/app-data-table.css +27 -1
- package/dist/parts/app-header-settings.css +9 -0
- package/dist/parts/app-mode-badge.css +12 -0
- package/dist/parts/app-module-color.css +152 -0
- package/dist/parts/app-name-card.css +5 -0
- package/dist/parts/app-page-header.css +1 -1
- package/dist/parts/app-recovery-codes-extras.css +13 -0
- package/dist/parts/app-sidebar-meta.css +14 -3
- package/dist/parts/app-sidebar-provider.css +98 -0
- package/dist/parts/app-table-actions.css +16 -0
- package/dist/parts/app-tree.css +6 -0
- package/dist/parts/app-type-picker.css +272 -0
- package/dist/parts/data-dl-numbered.css +17 -0
- package/dist/parts/data-graph.css +12 -4
- package/dist/parts/forms-combobox-catalog.css +142 -0
- package/dist/parts/forms-combobox-icons.css +40 -2
- package/dist/parts/forms-copy-field-extras.css +47 -0
- package/dist/parts/forms-field-extras.css +55 -0
- package/dist/parts/forms-form-section.css +39 -1
- package/dist/parts/forms-ledger.css +98 -0
- package/dist/parts/media-aspect-flush.css +6 -0
- package/dist/parts/media-barcode.css +25 -4
- package/dist/parts/media-doc-viewer.css +2 -0
- package/dist/parts/media-entity-card.css +5 -0
- package/dist/parts/media-glass-liquid.css +10 -5
- package/dist/parts/media-glass-options.css +37 -5
- package/dist/parts/media-glass.css +85 -35
- package/dist/parts/media-scrim.css +51 -0
- package/dist/parts/nav-topbar-variants.css +12 -4
- package/dist/parts/site-header-variants.css +40 -4
- package/dist/parts/site-hero-media.css +88 -0
- package/dist/parts/site-price-card.css +3 -1
- package/dist/parts/site-split-reverse.css +11 -0
- package/dist/parts/site-tint-card.css +5 -4
- package/dist/parts/utility-hover.css +6 -3
- package/dist/showcase.css +73 -31
- package/dist/sidebar.d.ts +22 -0
- package/dist/sidebar.js +161 -0
- package/dist/tabs.d.ts +9 -0
- package/dist/tabs.js +104 -0
- package/dist/theme.js +20 -4
- package/manifest.json +24 -0
- package/package.json +10 -2
- package/snippets/accordion-accent.html +1 -1
- package/snippets/copy-field.html +44 -6
- package/snippets/countdown.html +12 -0
- package/snippets/dropdown-menu.html +2 -0
- package/snippets/glass.html +3 -3
- package/snippets/hero-media.html +20 -0
- package/snippets/page-header.html +1 -1
- package/snippets/recovery-codes.html +55 -6
- package/snippets/scrim.html +19 -0
package/dist/combobox.js
CHANGED
|
@@ -1,18 +1,29 @@
|
|
|
1
1
|
// File: packages/ui/src/combobox.js
|
|
2
|
-
// Map: label/value of an option -> filter -> active option (arrows, Home/End)
|
|
3
|
-
// ->
|
|
2
|
+
// Map: label/value of an option -> filter -> option markup from data (setOptions) -> active option (arrows, Home/End)
|
|
3
|
+
// -> choose (Enter, click; clear and custom rows) -> server search (event or URL, debounced) -> portal (list in body)
|
|
4
|
+
// -> open/close -> bind one .oc-combobox -> init every [data-oc-combobox] -> boot
|
|
4
5
|
// Behaviour for the CSS combobox (.oc-combobox) in plain HTML and Blade: typing filters the list, the arrow keys move
|
|
5
6
|
// the active option (aria-activedescendant), Enter or a click chooses, Escape closes. The chosen option gets
|
|
6
|
-
// aria-selected, its label goes into the field and its icon (.oc-combobox-option-icon) into the
|
|
7
|
-
// A hidden input in the wrapper (input[type=hidden]) gets the option's data-value, for forms.
|
|
8
|
-
//
|
|
7
|
+
// aria-selected, its label goes into the field and its icon (.oc-combobox-option-icon, or its image / emoji) into the
|
|
8
|
+
// field's .oc-combobox-icon. A hidden input in the wrapper (input[type=hidden]) gets the option's data-value, for forms.
|
|
9
|
+
// Catalog mode (0.17.0), all optional, on the wrapper:
|
|
10
|
+
// data-oc-search="event" no local filter; event oc-combobox-search { query } (debounced, loading row on); answer with root.ocSetOptions(items, query)
|
|
11
|
+
// data-oc-search-url="/x?q=" no local filter; fetches url + query, JSON [{ value, label, description, icon, image, emoji, disabled }]
|
|
12
|
+
// data-oc-search-delay="250" debounce in ms
|
|
13
|
+
// data-oc-portal the list moves to document.body while open (position: fixed under the field)
|
|
14
|
+
// li.oc-combobox-clear a row with data-value="" that clears the choice
|
|
15
|
+
// li.oc-combobox-custom a row that takes what was typed (data-oc-custom-label='Use "{query}"'), shown when nothing matches exactly
|
|
16
|
+
// .oc-combobox-footer > a a manage link under the list (event oc-combobox-manage)
|
|
17
|
+
// Events on the wrapper: oc-combobox-change { value, label, custom }, oc-combobox-search { query }, oc-combobox-manage.
|
|
9
18
|
|
|
10
19
|
const OPTION = ".oc-combobox-option";
|
|
20
|
+
const VISUAL = ".oc-combobox-option-icon, .oc-combobox-option-image, .oc-combobox-option-emoji";
|
|
11
21
|
|
|
12
|
-
/** Text label of an option (without the icon). */
|
|
22
|
+
/** Text label of an option (without the icon, image, emoji or description). */
|
|
13
23
|
export function optionLabel(option) {
|
|
14
|
-
const
|
|
15
|
-
|
|
24
|
+
const own = option.querySelector(".oc-combobox-option-label");
|
|
25
|
+
if (own) return own.textContent.trim();
|
|
26
|
+
return [...option.childNodes].filter((n) => !(n.nodeType === 1 && n.matches(VISUAL))).map((n) => n.textContent).join("").trim();
|
|
16
27
|
}
|
|
17
28
|
|
|
18
29
|
/** Value of an option: data-value, else its label. */
|
|
@@ -22,30 +33,124 @@ export function optionValue(option) {
|
|
|
22
33
|
|
|
23
34
|
/** True when the label contains the query (case and accents ignored). */
|
|
24
35
|
export function matches(label, query) {
|
|
25
|
-
const fold = (s) => String(s).normalize("NFD").replace(/[̀-ͯ]/g, "").toLowerCase();
|
|
26
36
|
return fold(label).includes(fold(query).trim());
|
|
27
37
|
}
|
|
38
|
+
const fold = (s) => String(s).normalize("NFD").replace(/[̀-ͯ]/g, "").toLowerCase();
|
|
39
|
+
|
|
40
|
+
/** One <li class="oc-combobox-option"> from data: { value, label, description, icon, image, emoji, disabled }. */
|
|
41
|
+
export function optionElement(item, doc = document) {
|
|
42
|
+
const li = doc.createElement("li");
|
|
43
|
+
li.className = "oc-combobox-option";
|
|
44
|
+
li.setAttribute("role", "option");
|
|
45
|
+
li.tabIndex = -1;
|
|
46
|
+
li.dataset.value = String(item.value ?? item.label ?? "");
|
|
47
|
+
li.setAttribute("aria-selected", "false");
|
|
48
|
+
if (item.disabled) li.setAttribute("aria-disabled", "true");
|
|
49
|
+
if (item.icon) {
|
|
50
|
+
const span = doc.createElement("span");
|
|
51
|
+
span.className = "oc-combobox-option-icon";
|
|
52
|
+
span.setAttribute("aria-hidden", "true");
|
|
53
|
+
const icon = doc.createElement("iconify-icon");
|
|
54
|
+
icon.setAttribute("icon", String(item.icon));
|
|
55
|
+
icon.setAttribute("aria-hidden", "true");
|
|
56
|
+
span.append(icon);
|
|
57
|
+
li.append(span);
|
|
58
|
+
} else if (item.image) {
|
|
59
|
+
const img = doc.createElement("img");
|
|
60
|
+
img.className = "oc-combobox-option-image";
|
|
61
|
+
img.src = String(item.image);
|
|
62
|
+
img.alt = "";
|
|
63
|
+
li.append(img);
|
|
64
|
+
} else if (item.emoji) {
|
|
65
|
+
const span = doc.createElement("span");
|
|
66
|
+
span.className = "oc-combobox-option-emoji";
|
|
67
|
+
span.setAttribute("aria-hidden", "true");
|
|
68
|
+
span.textContent = String(item.emoji);
|
|
69
|
+
li.append(span);
|
|
70
|
+
}
|
|
71
|
+
if (item.description) {
|
|
72
|
+
const text = doc.createElement("span");
|
|
73
|
+
text.className = "oc-combobox-option-text";
|
|
74
|
+
const label = doc.createElement("span");
|
|
75
|
+
label.className = "oc-combobox-option-label";
|
|
76
|
+
label.textContent = String(item.label ?? "");
|
|
77
|
+
const desc = doc.createElement("span");
|
|
78
|
+
desc.className = "oc-combobox-option-description";
|
|
79
|
+
desc.textContent = String(item.description);
|
|
80
|
+
text.append(label, desc);
|
|
81
|
+
li.append(text);
|
|
82
|
+
} else li.append(doc.createTextNode(String(item.label ?? "")));
|
|
83
|
+
return li;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Markup for the field icon of an option: its icon, image or emoji (empty when it has none). */
|
|
87
|
+
function visualHtml(option) {
|
|
88
|
+
const icon = option.querySelector(":scope > .oc-combobox-option-icon");
|
|
89
|
+
if (icon) return icon.innerHTML;
|
|
90
|
+
const other = option.querySelector(":scope > .oc-combobox-option-image, :scope > .oc-combobox-option-emoji");
|
|
91
|
+
return other ? other.outerHTML : null;
|
|
92
|
+
}
|
|
28
93
|
|
|
29
94
|
let uid = 0;
|
|
30
95
|
|
|
31
96
|
/** Starts one .oc-combobox. Returns a function that stops it. */
|
|
32
97
|
export function bindCombobox(root) {
|
|
33
98
|
const input = root.querySelector(".oc-combobox-input");
|
|
34
|
-
const
|
|
35
|
-
if (!input || !
|
|
99
|
+
const popup = root.querySelector(":scope > .oc-combobox-list") ?? root.querySelector(".oc-combobox-list");
|
|
100
|
+
if (!input || !popup || root.dataset.ocBound != null) return () => {};
|
|
101
|
+
const list = popup.matches('[role="listbox"]') ? popup : popup.querySelector('[role="listbox"]') ?? popup;
|
|
36
102
|
root.dataset.ocBound = "";
|
|
103
|
+
const doc = root.ownerDocument;
|
|
104
|
+
const win = doc.defaultView ?? globalThis;
|
|
37
105
|
const slot = root.querySelector(":scope > .oc-combobox-icon");
|
|
38
106
|
const placeholderIcon = slot ? slot.innerHTML : "";
|
|
39
107
|
const hidden = root.querySelector(':scope > input[type="hidden"]');
|
|
40
108
|
const empty = list.querySelector(".oc-combobox-empty");
|
|
109
|
+
const custom = list.querySelector(".oc-combobox-custom");
|
|
110
|
+
const customTemplate = custom?.dataset.ocCustomLabel || 'Use "{query}"';
|
|
111
|
+
const searchUrl = root.dataset.ocSearchUrl;
|
|
112
|
+
const remote = root.dataset.ocSearch != null || searchUrl != null;
|
|
113
|
+
const delay = Number(root.dataset.ocSearchDelay ?? 250);
|
|
114
|
+
const portal = root.dataset.ocPortal != null;
|
|
41
115
|
const options = () => [...list.querySelectorAll(OPTION)];
|
|
116
|
+
const plain = () => options().filter((o) => !o.matches(".oc-combobox-clear, .oc-combobox-custom"));
|
|
42
117
|
const enabled = () => options().filter((o) => !o.hidden && o.getAttribute("aria-disabled") !== "true");
|
|
43
|
-
options().forEach((o) => { if (!o.id) o.id = `oc-combobox-option-${++uid}`; });
|
|
118
|
+
const ids = () => options().forEach((o) => { if (!o.id) o.id = `oc-combobox-option-${++uid}`; });
|
|
119
|
+
ids();
|
|
44
120
|
|
|
121
|
+
// Portal: the popup leaves the wrapper while open and comes back when it closes (a marker keeps its place).
|
|
122
|
+
const marker = portal ? doc.createComment("oc-combobox-list") : null;
|
|
123
|
+
const place = () => {
|
|
124
|
+
const r = root.getBoundingClientRect();
|
|
125
|
+
Object.assign(popup.style, { position: "fixed", top: `${r.bottom + 4}px`, left: `${r.left}px`, width: `${r.width}px` });
|
|
126
|
+
};
|
|
127
|
+
const showPortal = (open) => {
|
|
128
|
+
if (!portal) return;
|
|
129
|
+
if (open) {
|
|
130
|
+
if (popup.parentNode !== doc.body) {
|
|
131
|
+
popup.before(marker);
|
|
132
|
+
popup.classList.add("oc-combobox-list--portal");
|
|
133
|
+
if (root.dataset.module) popup.dataset.module = root.dataset.module;
|
|
134
|
+
doc.body.append(popup);
|
|
135
|
+
win.addEventListener("scroll", place, true);
|
|
136
|
+
win.addEventListener("resize", place);
|
|
137
|
+
}
|
|
138
|
+
place();
|
|
139
|
+
popup.dataset.open = "";
|
|
140
|
+
} else if (popup.parentNode === doc.body) {
|
|
141
|
+
popup.dataset.open = "false";
|
|
142
|
+
marker.replaceWith(popup);
|
|
143
|
+
win.removeEventListener("scroll", place, true);
|
|
144
|
+
win.removeEventListener("resize", place);
|
|
145
|
+
} else popup.dataset.open = "false";
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const focused = () => root.contains(doc.activeElement);
|
|
45
149
|
const setOpen = (open) => {
|
|
46
150
|
if (open) root.removeAttribute("data-open");
|
|
47
151
|
else root.dataset.open = "false";
|
|
48
|
-
input.setAttribute("aria-expanded", String(open &&
|
|
152
|
+
input.setAttribute("aria-expanded", String(open && focused()));
|
|
153
|
+
showPortal(open && focused());
|
|
49
154
|
};
|
|
50
155
|
const setActive = (option) => {
|
|
51
156
|
options().forEach((o) => o.toggleAttribute("data-active", o === option));
|
|
@@ -54,29 +159,106 @@ export function bindCombobox(root) {
|
|
|
54
159
|
option.scrollIntoView?.({ block: "nearest" });
|
|
55
160
|
} else input.removeAttribute("aria-activedescendant");
|
|
56
161
|
};
|
|
162
|
+
const setLoading = (on) => {
|
|
163
|
+
list.toggleAttribute("aria-busy", on);
|
|
164
|
+
if (on) list.setAttribute("aria-busy", "true");
|
|
165
|
+
let row = list.querySelector(".oc-combobox-loading");
|
|
166
|
+
if (on && !row) {
|
|
167
|
+
row = doc.createElement("li");
|
|
168
|
+
row.className = "oc-combobox-loading";
|
|
169
|
+
row.setAttribute("role", "presentation");
|
|
170
|
+
row.textContent = root.dataset.ocLoadingText || "Loading...";
|
|
171
|
+
list.append(row);
|
|
172
|
+
}
|
|
173
|
+
if (row) row.hidden = !on;
|
|
174
|
+
if (on && empty) empty.hidden = true;
|
|
175
|
+
};
|
|
176
|
+
const updateCustom = (q) => {
|
|
177
|
+
if (!custom) return false;
|
|
178
|
+
const query = q.trim();
|
|
179
|
+
const show = query !== "" && !plain().some((o) => fold(optionLabel(o)) === fold(query));
|
|
180
|
+
custom.hidden = !show;
|
|
181
|
+
custom.dataset.value = query;
|
|
182
|
+
custom.textContent = customTemplate.replace("{query}", query);
|
|
183
|
+
return show;
|
|
184
|
+
};
|
|
57
185
|
const filter = () => {
|
|
58
186
|
const q = input.value;
|
|
59
187
|
let shown = 0;
|
|
60
|
-
|
|
61
|
-
|
|
188
|
+
plain().forEach((o) => { o.hidden = remote ? false : !matches(optionLabel(o), q); if (!o.hidden) shown++; });
|
|
189
|
+
const withCustom = updateCustom(q);
|
|
190
|
+
if (empty) empty.hidden = shown > 0 || withCustom || list.getAttribute("aria-busy") === "true";
|
|
62
191
|
if (slot && !q) slot.innerHTML = placeholderIcon;
|
|
63
|
-
setActive(enabled()
|
|
192
|
+
setActive(enabled().find((o) => !o.matches(".oc-combobox-clear")) ?? null);
|
|
64
193
|
};
|
|
65
194
|
const choose = (option) => {
|
|
66
195
|
if (!option || option.getAttribute("aria-disabled") === "true") return;
|
|
67
|
-
|
|
68
|
-
const
|
|
69
|
-
|
|
196
|
+
const isClear = option.matches(".oc-combobox-clear");
|
|
197
|
+
const isCustom = option.matches(".oc-combobox-custom");
|
|
198
|
+
options().forEach((o) => o.setAttribute("aria-selected", String(o === option && !isClear)));
|
|
199
|
+
const value = isClear ? "" : isCustom ? option.dataset.value ?? "" : optionValue(option);
|
|
200
|
+
const label = isClear ? "" : isCustom ? value : optionLabel(option);
|
|
70
201
|
input.value = label;
|
|
71
202
|
if (hidden) hidden.value = value;
|
|
72
|
-
if (slot) slot.innerHTML =
|
|
73
|
-
|
|
203
|
+
if (slot) slot.innerHTML = (!isClear && !isCustom && visualHtml(option)) || placeholderIcon;
|
|
204
|
+
plain().forEach((o) => { o.hidden = false; });
|
|
205
|
+
if (custom) custom.hidden = true;
|
|
74
206
|
if (empty) empty.hidden = true;
|
|
75
207
|
setOpen(false);
|
|
76
|
-
root.dispatchEvent(new CustomEvent("oc-combobox-change", { bubbles: true, detail: { value, label } }));
|
|
208
|
+
root.dispatchEvent(new win.CustomEvent("oc-combobox-change", { bubbles: true, detail: { value, label, custom: isCustom } }));
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
/** Replaces the plain options with new ones from data (server search results). With `query`, an answer for an older
|
|
212
|
+
* question than what is in the field now is dropped. */
|
|
213
|
+
const setOptions = (items, query) => {
|
|
214
|
+
if (query != null && query !== input.value) return;
|
|
215
|
+
plain().forEach((o) => o.remove());
|
|
216
|
+
const before = custom ?? empty ?? list.querySelector(".oc-combobox-loading");
|
|
217
|
+
const current = hidden?.value;
|
|
218
|
+
for (const item of items ?? []) {
|
|
219
|
+
const li = optionElement(item, doc);
|
|
220
|
+
if (current != null && current !== "" && li.dataset.value === current) li.setAttribute("aria-selected", "true");
|
|
221
|
+
if (before && before.parentNode === list) list.insertBefore(li, before);
|
|
222
|
+
else list.append(li);
|
|
223
|
+
}
|
|
224
|
+
ids();
|
|
225
|
+
setLoading(false);
|
|
226
|
+
filter();
|
|
227
|
+
};
|
|
228
|
+
root.ocSetOptions = setOptions;
|
|
229
|
+
|
|
230
|
+
// Server search, debounced; an older answer that arrives after a newer question is dropped.
|
|
231
|
+
let timer;
|
|
232
|
+
let asked = 0;
|
|
233
|
+
const search = () => {
|
|
234
|
+
clearTimeout(timer);
|
|
235
|
+
const query = input.value;
|
|
236
|
+
timer = setTimeout(async () => {
|
|
237
|
+
const ticket = ++asked;
|
|
238
|
+
if (!searchUrl) {
|
|
239
|
+
// The listener answers with root.ocSetOptions(items, query); that also ends the loading row.
|
|
240
|
+
setLoading(true);
|
|
241
|
+
root.dispatchEvent(new win.CustomEvent("oc-combobox-search", { bubbles: true, detail: { query } }));
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
setLoading(true);
|
|
245
|
+
try {
|
|
246
|
+
const url = searchUrl + encodeURIComponent(query);
|
|
247
|
+
const init = { headers: { Accept: "application/json" } };
|
|
248
|
+
const res = await (win.fetch ? win.fetch(url, init) : fetch(url, init));
|
|
249
|
+
const items = await res.json();
|
|
250
|
+
if (ticket === asked) setOptions(Array.isArray(items) ? items : items?.data ?? []);
|
|
251
|
+
} catch {
|
|
252
|
+
if (ticket === asked) setLoading(false);
|
|
253
|
+
}
|
|
254
|
+
}, delay);
|
|
77
255
|
};
|
|
78
256
|
|
|
79
|
-
const onInput = () => {
|
|
257
|
+
const onInput = () => {
|
|
258
|
+
setOpen(true);
|
|
259
|
+
if (remote) { search(); updateCustom(input.value); }
|
|
260
|
+
filter();
|
|
261
|
+
};
|
|
80
262
|
const onKey = (e) => {
|
|
81
263
|
const items = enabled();
|
|
82
264
|
const at = items.findIndex((o) => o.hasAttribute("data-active"));
|
|
@@ -89,34 +271,50 @@ export function bindCombobox(root) {
|
|
|
89
271
|
else if (e.key === "Escape" && root.dataset.open !== "false") { e.preventDefault(); setOpen(false); }
|
|
90
272
|
};
|
|
91
273
|
const onClickInput = () => { if (root.dataset.open === "false") setOpen(true); };
|
|
92
|
-
// A
|
|
93
|
-
const onDown = (e) =>
|
|
94
|
-
const onClick = (e) =>
|
|
95
|
-
|
|
274
|
+
// A press in the list (an option, the scrollbar, the footer) keeps the focus in the field; a link still follows its click.
|
|
275
|
+
const onDown = (e) => e.preventDefault();
|
|
276
|
+
const onClick = (e) => {
|
|
277
|
+
const link = e.target.closest(".oc-combobox-footer a");
|
|
278
|
+
if (link) {
|
|
279
|
+
root.dispatchEvent(new win.CustomEvent("oc-combobox-manage", { bubbles: true, detail: { href: link.getAttribute("href") } }));
|
|
280
|
+
setOpen(false);
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
choose(e.target.closest(OPTION));
|
|
284
|
+
};
|
|
285
|
+
const onFocus = () => {
|
|
286
|
+
input.setAttribute("aria-expanded", String(root.dataset.open !== "false"));
|
|
287
|
+
if (root.dataset.open !== "false") showPortal(true);
|
|
288
|
+
};
|
|
96
289
|
const onBlur = (e) => {
|
|
97
|
-
if (root.contains(e.relatedTarget)) return;
|
|
290
|
+
if (root.contains(e.relatedTarget) || popup.contains(e.relatedTarget)) return;
|
|
98
291
|
input.setAttribute("aria-expanded", "false");
|
|
99
292
|
root.removeAttribute("data-open");
|
|
293
|
+
showPortal(false);
|
|
100
294
|
setActive(null);
|
|
101
295
|
};
|
|
102
296
|
|
|
103
297
|
input.addEventListener("input", onInput);
|
|
104
298
|
input.addEventListener("keydown", onKey);
|
|
105
299
|
input.addEventListener("click", onClickInput);
|
|
106
|
-
|
|
107
|
-
|
|
300
|
+
popup.addEventListener("mousedown", onDown);
|
|
301
|
+
popup.addEventListener("click", onClick);
|
|
108
302
|
root.addEventListener("focusin", onFocus);
|
|
109
303
|
root.addEventListener("focusout", onBlur);
|
|
110
304
|
const chosen = options().find((o) => o.getAttribute("aria-selected") === "true");
|
|
111
|
-
if (chosen && slot) slot.innerHTML = chosen
|
|
305
|
+
if (chosen && slot) slot.innerHTML = visualHtml(chosen) ?? placeholderIcon;
|
|
306
|
+
if (custom) custom.hidden = true;
|
|
112
307
|
return () => {
|
|
308
|
+
clearTimeout(timer);
|
|
309
|
+
showPortal(false);
|
|
113
310
|
input.removeEventListener("input", onInput);
|
|
114
311
|
input.removeEventListener("keydown", onKey);
|
|
115
312
|
input.removeEventListener("click", onClickInput);
|
|
116
|
-
|
|
117
|
-
|
|
313
|
+
popup.removeEventListener("mousedown", onDown);
|
|
314
|
+
popup.removeEventListener("click", onClick);
|
|
118
315
|
root.removeEventListener("focusin", onFocus);
|
|
119
316
|
root.removeEventListener("focusout", onBlur);
|
|
317
|
+
delete root.ocSetOptions;
|
|
120
318
|
delete root.dataset.ocBound;
|
|
121
319
|
};
|
|
122
320
|
}
|
|
@@ -223,6 +223,8 @@ a.oc-item:focus-visible { outline: 2px solid var(--oc-ring); outline-offset: 1px
|
|
|
223
223
|
.oc-item-title { margin: 0; font-weight: 500; line-height: 1.35; color: var(--oc-foreground); }
|
|
224
224
|
.oc-item-description { margin: 0; font-size: 0.8125rem; line-height: 1.45; color: var(--oc-muted-foreground); text-wrap: balance; }
|
|
225
225
|
.oc-item-actions { display: flex; flex: none; align-items: center; gap: 0.5rem; }
|
|
226
|
+
/* Small rows (links with a chevron) keep media, text and the trailing icon on one line in a narrow column. */
|
|
227
|
+
.oc-item--sm > .oc-item-content { flex-basis: 8rem; }
|
|
226
228
|
.oc-item-header,
|
|
227
229
|
.oc-item-footer { flex-basis: 100%; display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
|
|
228
230
|
.oc-item-group { display: flex; flex-direction: column; }
|
|
@@ -831,7 +833,8 @@ dialog.oc-drawer[open] .oc-drawer-content {
|
|
|
831
833
|
.oc-calendar-day:hover { background: var(--oc-accent); }
|
|
832
834
|
.oc-calendar-day:focus-visible { outline: 2px solid var(--oc-ring); outline-offset: -2px; }
|
|
833
835
|
.oc-calendar-day--today { background: var(--oc-muted); font-weight: 600; }
|
|
834
|
-
|
|
836
|
+
/* Days of the previous/next month: muted text only (no opacity), so the numbers still reach AA contrast. */
|
|
837
|
+
.oc-calendar-day--outside { color: var(--oc-muted-foreground); }
|
|
835
838
|
.oc-calendar-day:disabled { opacity: 0.35; pointer-events: none; }
|
|
836
839
|
.oc-calendar-day[aria-selected="true"],
|
|
837
840
|
.oc-calendar-day--range-start,
|
|
@@ -942,6 +945,33 @@ input.oc-input[type="month"] { inline-size: auto; min-inline-size: 11rem; }
|
|
|
942
945
|
.oc-radio-item--card { padding: 0.75rem 1rem; border: 1px solid var(--oc-border); border-radius: var(--oc-radius); }
|
|
943
946
|
.oc-radio-item--card:has(:checked) { border-color: var(--oc-primary); background: color-mix(in oklab, var(--oc-primary) 8%, transparent); }
|
|
944
947
|
.oc-radio-item--card:has(:focus-visible) { outline: 2px solid var(--oc-ring); outline-offset: 1px; }
|
|
948
|
+
/* Answered (0.17.0): data-result="correct" | "wrong" on a card once the answer is checked: a green or red edge and a
|
|
949
|
+
mark at the end; the cards nobody chose fade. Put the word in the card too for a screen reader
|
|
950
|
+
(<span class="oc-visually-hidden">Correct</span>); the mark is only a picture. */
|
|
951
|
+
.oc-radio-item--card[data-result] { position: relative; padding-inline-end: 2.75rem; }
|
|
952
|
+
.oc-radio-item--card[data-result="correct"] { --oc-answer-tone: var(--oc-success); }
|
|
953
|
+
.oc-radio-item--card[data-result="wrong"] { --oc-answer-tone: var(--oc-destructive); }
|
|
954
|
+
.oc-radio-item--card[data-result],
|
|
955
|
+
.oc-radio-item--card[data-result]:has(:checked) {
|
|
956
|
+
border-color: var(--oc-answer-tone);
|
|
957
|
+
background: color-mix(in oklab, var(--oc-answer-tone) 10%, transparent);
|
|
958
|
+
}
|
|
959
|
+
.oc-radio-item--card[data-result]::after {
|
|
960
|
+
content: "";
|
|
961
|
+
position: absolute;
|
|
962
|
+
inset-block-start: 50%;
|
|
963
|
+
inset-inline-end: 0.85rem;
|
|
964
|
+
inline-size: 1.25rem;
|
|
965
|
+
block-size: 1.25rem;
|
|
966
|
+
translate: 0 -50%;
|
|
967
|
+
background: var(--oc-answer-tone);
|
|
968
|
+
}
|
|
969
|
+
.oc-radio-item--card[data-result="correct"]::after { -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2C6.5 2 2 6.5 2 12s4.5 10 10 10s10-4.5 10-10S17.5 2 12 2m-2 15l-5-5l1.41-1.41L10 14.17l7.59-7.59L19 8z'/%3E%3C/svg%3E") center / contain no-repeat; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2C6.5 2 2 6.5 2 12s4.5 10 10 10s10-4.5 10-10S17.5 2 12 2m-2 15l-5-5l1.41-1.41L10 14.17l7.59-7.59L19 8z'/%3E%3C/svg%3E") center / contain no-repeat; }
|
|
970
|
+
.oc-radio-item--card[data-result="wrong"]::after { -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2C6.47 2 2 6.47 2 12s4.47 10 10 10s10-4.47 10-10S17.53 2 12 2m5 13.59L15.59 17L12 13.41L8.41 17L7 15.59L10.59 12L7 8.41L8.41 7L12 10.59L15.59 7L17 8.41L13.41 12z'/%3E%3C/svg%3E") center / contain no-repeat; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2C6.47 2 2 6.47 2 12s4.47 10 10 10s10-4.47 10-10S17.53 2 12 2m5 13.59L15.59 17L12 13.41L8.41 17L7 15.59L10.59 12L7 8.41L8.41 7L12 10.59L15.59 7L17 8.41L13.41 12z'/%3E%3C/svg%3E") center / contain no-repeat; }
|
|
971
|
+
:is(fieldset, .oc-radio-group):has(> .oc-radio-item--card[data-result]) > .oc-radio-item--card:not([data-result]) { opacity: 0.55; }
|
|
972
|
+
/* The radios lock once there is a result; the marked cards stay fully readable. */
|
|
973
|
+
.oc-radio-item--card[data-result]:has(:disabled) { opacity: 1; cursor: default; }
|
|
974
|
+
.oc-radio-item--card[data-result] input.oc-radio:disabled { opacity: 1; }
|
|
945
975
|
|
|
946
976
|
.oc-scroll-area {
|
|
947
977
|
max-block-size: 14rem;
|
|
@@ -952,7 +982,8 @@ input.oc-input[type="month"] { inline-size: auto; min-inline-size: 11rem; }
|
|
|
952
982
|
border: 1px solid var(--oc-border);
|
|
953
983
|
border-radius: var(--oc-radius);
|
|
954
984
|
scrollbar-width: thin;
|
|
955
|
-
scrollbar
|
|
985
|
+
/* The .oc-scrollbar tokens (0.17.0) restyle it too; the defaults are its own look. */
|
|
986
|
+
scrollbar-color: var(--oc-scrollbar-thumb, var(--oc-border-strong)) var(--oc-scrollbar-track, transparent);
|
|
956
987
|
}
|
|
957
988
|
.oc-scroll-area:focus-visible { outline: 2px solid var(--oc-ring); outline-offset: 2px; }
|
|
958
989
|
.oc-scroll-area--x { max-block-size: none; overflow-y: hidden; white-space: nowrap; }
|