@apliteni/apliteni-ui 0.142.1 → 0.142.4
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/README.md +24 -36
- package/guidelines/state-set.md +4 -4
- package/package.json +3 -3
- package/react/dist/index.css +7 -3
- package/react/dist/index.js +12 -5
- package/src/index.d.ts +13 -96
- package/src/index.js +17 -30
- package/src/styles/command-palette.css +9 -5
- package/src/styles/drawer.css +8 -0
- package/src/styles/dropdown.css +30 -8
- package/src/styles/feedback.css +1 -1
- package/src/styles/filter-bar.css +5 -2
- package/src/styles/input.css +14 -15
- package/src/styles/layout.css +5 -2
- package/src/styles/table.css +28 -2
- package/src/styles/tap-zone.css +9 -4
- package/src/styles/topbar.css +8 -6
- package/src/components/account-nav.js +0 -37
- package/src/components/avatar.js +0 -53
- package/src/components/back.js +0 -57
- package/src/components/button-busy.js +0 -69
- package/src/components/command-palette.js +0 -471
- package/src/components/confirm.js +0 -131
- package/src/components/drawer.js +0 -169
- package/src/components/dropdown.js +0 -1055
- package/src/components/feedback.js +0 -171
- package/src/components/filter-bar.js +0 -86
- package/src/components/footer.js +0 -102
- package/src/components/index.js +0 -352
- package/src/components/loading.js +0 -127
- package/src/components/nav.js +0 -220
- package/src/components/overlay.js +0 -263
- package/src/components/pagination.js +0 -323
- package/src/components/segmented.js +0 -33
- package/src/components/shell.js +0 -511
- package/src/components/stat.js +0 -82
- package/src/components/success.js +0 -131
- package/src/components/table-values.js +0 -32
- package/src/components/tabs.js +0 -82
- package/src/components/toasts.js +0 -118
- package/src/components/tooltip.js +0 -347
- package/src/components/topbar.js +0 -270
|
@@ -1,323 +0,0 @@
|
|
|
1
|
-
import { PAGE_SIZES, DEFAULT_PAGE_SIZE } from '../logic/pagination.js';
|
|
2
|
-
export { PAGE_SIZES, DEFAULT_PAGE_SIZE } from '../logic/pagination.js';
|
|
3
|
-
// Pagination — the strip under a table or a list, as an HTML string.
|
|
4
|
-
//
|
|
5
|
-
// It renders a page the CALLER computed. Rows never come in here: `page`,
|
|
6
|
-
// `pageSize` and `total` are numbers, so a page counted by a server and a page
|
|
7
|
-
// sliced out of an array in memory produce the same markup.
|
|
8
|
-
//
|
|
9
|
-
// `total: null` is the honest shape for an API that cannot count what it has not
|
|
10
|
-
// fetched. The component then knows no last page, so it draws Prev and Next and
|
|
11
|
-
// nothing else — see `ui-pager--open` below.
|
|
12
|
-
import { esc } from './index.js';
|
|
13
|
-
import { safeUrl } from '../html.js';
|
|
14
|
-
// The sizes a table offers, and the one it starts on. Named here so no call site
|
|
15
|
-
// writes either number: both moved once already and would have moved in thirteen
|
|
16
|
-
// files. MUI's DataGrid ships exactly this pair (default 100, options 25/50/100),
|
|
17
|
-
// AG Grid defaults to 100, and the finance portal's two data-heavy surfaces
|
|
18
|
-
// already page at 100. A 250 step was in the first draft of this component and
|
|
19
|
-
// no surveyed kit offers one, so it went rather than being invented.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
// The classes button({ variant: 'ghost', size: 'sm' }) emits, written out because
|
|
23
|
-
// button() takes no extra class and every control here needs one of its own for
|
|
24
|
-
// the React component to key on. src/components/pagination.test.js asserts the
|
|
25
|
-
// two agree, so a change to button()'s class list fails there instead of drifting.
|
|
26
|
-
const GHOST_SM = 'ui-btn ui-btn--ghost ui-btn--sm';
|
|
27
|
-
|
|
28
|
-
const VARIANTS = ['steps', 'numbered', 'jump'];
|
|
29
|
-
|
|
30
|
-
// The id seeds a <label for> and the control it names, so two pagers that share
|
|
31
|
-
// one are two labels pointing at one control: the second table's "Rows" label
|
|
32
|
-
// focuses the FIRST table's select, and the second select has no accessible name
|
|
33
|
-
// at all. `tabs()` states the same requirement in words and leaves it there; a
|
|
34
|
-
// pager is dropped under a table by a caller who is not thinking about ids, and
|
|
35
|
-
// two tables on a page is the ordinary case rather than the exotic one. So an
|
|
36
|
-
// omitted id is unique by construction instead. A caller who needs a stable id —
|
|
37
|
-
// a server rendering the same page twice, a test — passes one.
|
|
38
|
-
let seq = 0;
|
|
39
|
-
const cx = (...a) => a.filter(Boolean).join(' ');
|
|
40
|
-
|
|
41
|
-
// Every number here arrives from a URL in real use — `?page=-2`, `?page=abc`,
|
|
42
|
-
// `?page=` — so each is coerced before it is clamped, and nothing that is not a
|
|
43
|
-
// finite integer reaches the markup.
|
|
44
|
-
//
|
|
45
|
-
// `Number()` alone is not that check, and the first draft of this used it. It
|
|
46
|
-
// reads '', ' ', null, [] and false as 0, all of which are finite: `?total=` then
|
|
47
|
-
// meant "this result holds zero rows" and erased the whole component, and
|
|
48
|
-
// `?pageSize=` meant one row per page. Only a number, or a string with something
|
|
49
|
-
// in it, is a number here. A Symbol is refused rather than thrown on — a string
|
|
50
|
-
// factory that raises a TypeError is a worse answer than a pager.
|
|
51
|
-
//
|
|
52
|
-
// The cap is Number.MAX_SAFE_INTEGER because above it arithmetic stops moving:
|
|
53
|
-
// `at - 1 === at === at + 1`, so Prev and Next would carry the same target while
|
|
54
|
-
// both rendered live, and a page past 1e21 prints as `1e+21`, which parseInt reads
|
|
55
|
-
// back as 1.
|
|
56
|
-
const CAP = Number.MAX_SAFE_INTEGER;
|
|
57
|
-
const int = (v, fallback) => {
|
|
58
|
-
const raw = typeof v === 'number' ? v
|
|
59
|
-
: (typeof v === 'string' && v.trim() !== '') ? Number(v)
|
|
60
|
-
: NaN;
|
|
61
|
-
if (!Number.isFinite(raw)) return fallback;
|
|
62
|
-
return Math.min(Math.max(Math.trunc(raw), -CAP), CAP);
|
|
63
|
-
};
|
|
64
|
-
const fmt = (n) => n.toLocaleString('en-US');
|
|
65
|
-
|
|
66
|
-
// A control at an end is DISABLED, never removed. Polaris states the rule as
|
|
67
|
-
// "Hint when merchants are at the first or the last page by disabling the
|
|
68
|
-
// corresponding button": removing it slides the next control sideways under a
|
|
69
|
-
// pointer already travelling toward it, and takes away the only evidence a
|
|
70
|
-
// screen-reader user has that they are at the start.
|
|
71
|
-
//
|
|
72
|
-
// An <a> has no disabled state, so an end that is off renders as
|
|
73
|
-
// <button disabled> even when `href` was given — a link that goes nowhere reads
|
|
74
|
-
// as available right up until it is followed.
|
|
75
|
-
function control({ cls, page, label, href, disabled = false, current = false }) {
|
|
76
|
-
const attrs = `class="${cls}" data-page="${page}"${current ? ' aria-current="page"' : ''}`;
|
|
77
|
-
return href && !disabled
|
|
78
|
-
? `<a href="${esc(safeUrl(href(page)))}" ${attrs}>${esc(label)}</a>`
|
|
79
|
-
: `<button type="button" ${attrs}${disabled ? ' disabled aria-disabled="true"' : ''}>${esc(label)}</button>`;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* The page numbers a `numbered` pager shows, with `null` where a run was cut.
|
|
84
|
-
*
|
|
85
|
-
* Seven slots at most: page 1, the last page, the current page with one
|
|
86
|
-
* neighbour each side, and a gap for each run removed between them. Two rules
|
|
87
|
-
* keep the strip honest — no two gaps side by side, and no gap standing in for a
|
|
88
|
-
* single page, because an ellipsis hiding one number is wider than the number
|
|
89
|
-
* and costs a click to find out what it was.
|
|
90
|
-
*/
|
|
91
|
-
function slotsFor(page, pageCount) {
|
|
92
|
-
const wanted = [1, pageCount, page - 1, page, page + 1]
|
|
93
|
-
.filter((n) => n >= 1 && n <= pageCount);
|
|
94
|
-
const shown = [...new Set(wanted)].sort((a, b) => a - b);
|
|
95
|
-
const out = [];
|
|
96
|
-
for (const n of shown) {
|
|
97
|
-
const prev = out.length ? out[out.length - 1] : null;
|
|
98
|
-
if (prev != null) {
|
|
99
|
-
if (n - prev === 2) out.push(prev + 1); // one page hidden — draw it, not a gap
|
|
100
|
-
else if (n - prev > 2) out.push(null);
|
|
101
|
-
}
|
|
102
|
-
out.push(n);
|
|
103
|
-
}
|
|
104
|
-
return out;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* pagination({ … }) → the <nav> a caller drops under a table.
|
|
109
|
-
*
|
|
110
|
-
* A pager for a single page draws no steps: GOV.UK's guidance is "Do not show
|
|
111
|
-
* pagination if there's only one page of content", and the kit was rendering
|
|
112
|
-
* two permanently dead buttons under every short table. With no size control to
|
|
113
|
-
* offer, such a pager has no job at all and returns the empty string; with one,
|
|
114
|
-
* the <nav> stays for the size control alone — somebody looking at 25 of 25 rows
|
|
115
|
-
* may still want 100 per page — and carries `ui-pager--single`.
|
|
116
|
-
*/
|
|
117
|
-
export function pagination({
|
|
118
|
-
page = 1,
|
|
119
|
-
pageSize = DEFAULT_PAGE_SIZE,
|
|
120
|
-
total = null,
|
|
121
|
-
hasMore = false,
|
|
122
|
-
pageSizes = null,
|
|
123
|
-
variant = 'steps',
|
|
124
|
-
label = 'Pagination',
|
|
125
|
-
loading = false,
|
|
126
|
-
href = null,
|
|
127
|
-
id,
|
|
128
|
-
} = {}) {
|
|
129
|
-
const uid = esc(String(id ?? `pager-${++seq}`));
|
|
130
|
-
const kind = VARIANTS.includes(variant) ? variant : 'steps';
|
|
131
|
-
// A size of zero or less is not a size, so it is read as absent rather than
|
|
132
|
-
// clamped to 1 — clamping turns `?pageSize=0` into 4,812 pages of one row.
|
|
133
|
-
const asked = int(pageSize, DEFAULT_PAGE_SIZE);
|
|
134
|
-
const size = asked > 0 ? asked : DEFAULT_PAGE_SIZE;
|
|
135
|
-
// A total that is not a number is a total nobody knows — the open shape is the
|
|
136
|
-
// truthful answer to it, and it is the same answer `total: null` asks for.
|
|
137
|
-
const asRows = int(total, null);
|
|
138
|
-
const counted = total != null && asRows !== null;
|
|
139
|
-
const rows = counted ? Math.max(0, asRows) : null;
|
|
140
|
-
const last = counted ? Math.max(1, Math.ceil(rows / size)) : null;
|
|
141
|
-
// One below the cap when nothing is counted, because the open shape emits
|
|
142
|
-
// `at + 1` as Next's target and MAX_SAFE_INTEGER + 1 is not representable — it
|
|
143
|
-
// rounds back onto its neighbour, so Prev and Next would carry one page again.
|
|
144
|
-
const at = counted
|
|
145
|
-
? Math.min(Math.max(1, int(page, 1)), last)
|
|
146
|
-
: Math.min(Math.max(1, int(page, 1)), CAP - 1);
|
|
147
|
-
|
|
148
|
-
// The current size is offered even when the caller's list forgot it: a select
|
|
149
|
-
// whose value is not among its options renders as the first one, which reports
|
|
150
|
-
// a page size the table is not using.
|
|
151
|
-
// Capped: this is a string factory, and a caller who hands it a hundred thousand
|
|
152
|
-
// sizes gets a hundred thousand <option>s and megabytes of HTML rather than an
|
|
153
|
-
// error. Twelve is past any real size menu — MUI ships four.
|
|
154
|
-
const offered = (Array.isArray(pageSizes) ? pageSizes : [])
|
|
155
|
-
.slice(0, 12)
|
|
156
|
-
.map((s) => int(s, 0))
|
|
157
|
-
.filter((s) => s > 0);
|
|
158
|
-
const sizes = offered.length
|
|
159
|
-
? [...new Set([...offered, size])].sort((a, b) => a - b)
|
|
160
|
-
: [];
|
|
161
|
-
|
|
162
|
-
const single = counted && last === 1;
|
|
163
|
-
if (single && !sizes.length) return '';
|
|
164
|
-
|
|
165
|
-
const from = (at - 1) * size + 1;
|
|
166
|
-
const to = counted ? Math.min(at * size, rows) : null;
|
|
167
|
-
// Not "1–0 of 0" for an empty result, and not "7–7 of 7" for a single row:
|
|
168
|
-
// both are arithmetic a reader has to undo.
|
|
169
|
-
const status = !counted ? `Page ${fmt(at)}`
|
|
170
|
-
: rows === 0 ? '0 of 0'
|
|
171
|
-
: from === to ? `${fmt(from)} of ${fmt(rows)}`
|
|
172
|
-
: `${fmt(from)}–${fmt(to)} of ${fmt(rows)}`;
|
|
173
|
-
|
|
174
|
-
const sizeBlock = sizes.length
|
|
175
|
-
? `<div class="ui-pager__size">`
|
|
176
|
-
+ `<label class="ui-pager__size-label" for="${uid}-size">Rows</label>`
|
|
177
|
-
+ `<select class="ui-select ui-pager__size-select" id="${uid}-size"${loading ? ' disabled' : ''}>`
|
|
178
|
-
+ sizes.map((s) => `<option value="${s}"${s === size ? ' selected' : ''}>${fmt(s)}</option>`).join('')
|
|
179
|
-
+ `</select></div>`
|
|
180
|
-
: '';
|
|
181
|
-
|
|
182
|
-
const step = (spec) => control({ cls: `${GHOST_SM} ui-pager__step`, href, ...spec, disabled: loading || spec.disabled });
|
|
183
|
-
const atStart = at === 1;
|
|
184
|
-
const atEnd = counted && at === last;
|
|
185
|
-
|
|
186
|
-
let steps = '';
|
|
187
|
-
if (single) {
|
|
188
|
-
steps = ''; // GOV.UK: no pagination for one page of content.
|
|
189
|
-
} else if (!counted) {
|
|
190
|
-
// The open shape: no last page exists, so no control may claim to reach one.
|
|
191
|
-
// Next is off when the caller says there is nothing after this page.
|
|
192
|
-
steps = `<div class="ui-pager__steps">`
|
|
193
|
-
+ step({ page: Math.max(1, at - 1), label: 'Prev', disabled: atStart })
|
|
194
|
-
+ step({ page: at + 1, label: 'Next', disabled: !hasMore })
|
|
195
|
-
+ `</div>`;
|
|
196
|
-
} else {
|
|
197
|
-
let middle = '';
|
|
198
|
-
if (kind === 'numbered') {
|
|
199
|
-
middle = slotsFor(at, last).map((n) => (n == null
|
|
200
|
-
? '<span class="ui-pager__gap" aria-hidden="true">…</span>'
|
|
201
|
-
: control({
|
|
202
|
-
cls: cx(`${GHOST_SM} ui-pager__page`, n === at && 'is-current'),
|
|
203
|
-
href,
|
|
204
|
-
page: n,
|
|
205
|
-
label: fmt(n),
|
|
206
|
-
current: n === at,
|
|
207
|
-
disabled: loading,
|
|
208
|
-
}))).join('');
|
|
209
|
-
} else if (kind === 'jump') {
|
|
210
|
-
middle = `<span class="ui-pager__jump"><label for="${uid}-jump">Page</label>`
|
|
211
|
-
+ `<input class="ui-input ui-pager__jump-input" id="${uid}-jump" type="number"`
|
|
212
|
-
+ ` min="1" max="${last}" value="${at}"${loading ? ' disabled' : ''}>`
|
|
213
|
-
+ `<span class="ui-pager__jump-of">of ${fmt(last)}</span></span>`;
|
|
214
|
-
}
|
|
215
|
-
// First and Last are the numbered variant's own job — its first and last
|
|
216
|
-
// slots are always those two pages, so a second pair of controls for them
|
|
217
|
-
// would be the same jump written twice.
|
|
218
|
-
const ends = kind !== 'numbered';
|
|
219
|
-
steps = `<div class="ui-pager__steps">`
|
|
220
|
-
+ (ends ? step({ page: 1, label: 'First', disabled: atStart }) : '')
|
|
221
|
-
+ step({ page: Math.max(1, at - 1), label: 'Prev', disabled: atStart })
|
|
222
|
-
+ middle
|
|
223
|
-
+ step({ page: Math.min(last, at + 1), label: 'Next', disabled: atEnd })
|
|
224
|
-
+ (ends ? step({ page: last, label: 'Last', disabled: atEnd }) : '')
|
|
225
|
-
+ `</div>`;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
// The status line is the only live region in the component: a strip where the
|
|
229
|
-
// numbers, the size control and four buttons all announced would read the same
|
|
230
|
-
// change out four times.
|
|
231
|
-
return `<nav class="${cx('ui-pager', `ui-pager--${kind}`, !counted && 'ui-pager--open', single && 'ui-pager--single')}"`
|
|
232
|
-
+ ` aria-label="${esc(label)}"${loading ? ' aria-busy="true"' : ''}>`
|
|
233
|
-
+ `<p class="ui-pager__status" aria-live="polite" aria-atomic="true">${esc(status)}</p>`
|
|
234
|
-
+ sizeBlock
|
|
235
|
-
+ steps
|
|
236
|
-
+ `</nav>`;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* Make a rendered pager work: delegate the steps, the size control and the jump
|
|
241
|
-
* input from `root`, so a pager re-rendered underneath stays wired.
|
|
242
|
-
*
|
|
243
|
-
* @returns {() => void} a function that removes the listeners.
|
|
244
|
-
*
|
|
245
|
-
* Delegate pager events from the root so handlers survive rerenders.
|
|
246
|
-
*/
|
|
247
|
-
export function wirePagination(root = document, { onPage, onPageSize } = {}) {
|
|
248
|
-
const scope = typeof root === 'string' ? document.querySelector(root) : root;
|
|
249
|
-
if (!scope || typeof scope.addEventListener !== 'function') return () => {};
|
|
250
|
-
|
|
251
|
-
const pageOf = (el) => int(el.getAttribute('data-page'), null);
|
|
252
|
-
const inPager = (el) => el && el.closest && el.closest('.ui-pager');
|
|
253
|
-
|
|
254
|
-
const onClick = (e) => {
|
|
255
|
-
const step = e.target.closest?.('.ui-pager__step, .ui-pager__page');
|
|
256
|
-
if (!step || !inPager(step) || step.tagName === 'A' || step.disabled) return;
|
|
257
|
-
const page = pageOf(step);
|
|
258
|
-
if (page !== null) onPage?.(page);
|
|
259
|
-
};
|
|
260
|
-
|
|
261
|
-
const onChange = (e) => {
|
|
262
|
-
const select = e.target.closest?.('.ui-pager__size-select');
|
|
263
|
-
if (!select || !inPager(select)) return;
|
|
264
|
-
const size = int(select.value, null);
|
|
265
|
-
if (size !== null && size > 0) onPageSize?.(size);
|
|
266
|
-
};
|
|
267
|
-
|
|
268
|
-
// Enter commits; so does leaving the box. A value the input cannot parse — it
|
|
269
|
-
// is type="number", so a rejected keystroke leaves it empty — is not a page,
|
|
270
|
-
// and the box goes back to the one it was showing rather than to page 1.
|
|
271
|
-
const commit = (box) => {
|
|
272
|
-
const asked = int(box.value, null);
|
|
273
|
-
const max = int(box.getAttribute('max'), null);
|
|
274
|
-
if (asked === null || asked < 1) {
|
|
275
|
-
box.value = box.defaultValue;
|
|
276
|
-
return;
|
|
277
|
-
}
|
|
278
|
-
const page = max === null ? asked : Math.min(asked, max);
|
|
279
|
-
box.value = String(page);
|
|
280
|
-
if (String(page) !== box.defaultValue) onPage?.(page);
|
|
281
|
-
};
|
|
282
|
-
const onKeydown = (e) => {
|
|
283
|
-
const box = e.target.closest?.('.ui-pager__jump-input');
|
|
284
|
-
if (!box || !inPager(box) || e.key !== 'Enter') return;
|
|
285
|
-
// A lone number input inside a <form> submits it on Enter, which reloads the
|
|
286
|
-
// page the reader was trying to move within.
|
|
287
|
-
e.preventDefault();
|
|
288
|
-
commit(box);
|
|
289
|
-
};
|
|
290
|
-
const onBlur = (e) => {
|
|
291
|
-
const box = e.target.closest?.('.ui-pager__jump-input');
|
|
292
|
-
if (box && inPager(box)) commit(box);
|
|
293
|
-
};
|
|
294
|
-
|
|
295
|
-
scope.addEventListener('click', onClick);
|
|
296
|
-
scope.addEventListener('change', onChange);
|
|
297
|
-
scope.addEventListener('keydown', onKeydown);
|
|
298
|
-
scope.addEventListener('focusout', onBlur);
|
|
299
|
-
return () => {
|
|
300
|
-
scope.removeEventListener('click', onClick);
|
|
301
|
-
scope.removeEventListener('change', onChange);
|
|
302
|
-
scope.removeEventListener('keydown', onKeydown);
|
|
303
|
-
scope.removeEventListener('focusout', onBlur);
|
|
304
|
-
};
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
/**
|
|
308
|
-
* Rewrite a pager's row range in place, so the live region it already holds is
|
|
309
|
-
* the thing that announces — as `setBusy()` does.
|
|
310
|
-
*
|
|
311
|
-
* @returns {Element|null} the status element, or null when there is nothing to
|
|
312
|
-
* update — safe against a torn-down view.
|
|
313
|
-
*
|
|
314
|
-
* Update the existing live region so screen readers can announce it.
|
|
315
|
-
*/
|
|
316
|
-
export function setPagerStatus(root, text) {
|
|
317
|
-
const el = typeof root === 'string' ? document.querySelector(root) : root;
|
|
318
|
-
if (!el || typeof el.querySelector !== 'function') return null;
|
|
319
|
-
const status = el.matches?.('.ui-pager__status') ? el : el.querySelector('.ui-pager__status');
|
|
320
|
-
if (!status) return null;
|
|
321
|
-
if (status.textContent !== String(text)) status.textContent = String(text);
|
|
322
|
-
return status;
|
|
323
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { segmentedNextIndex } from '../logic/segmented.js';
|
|
2
|
-
export { segmentedNextIndex } from '../logic/segmented.js';
|
|
3
|
-
export function initSegmented(root = document) {
|
|
4
|
-
const cleanups = [];
|
|
5
|
-
root.querySelectorAll('[data-seg]').forEach(group => {
|
|
6
|
-
if (group.__segWired) return;
|
|
7
|
-
group.__segWired = true;
|
|
8
|
-
const buttons = () => [...group.querySelectorAll('button')].filter(b => !b.disabled);
|
|
9
|
-
const pick = button => {
|
|
10
|
-
group.querySelectorAll('button').forEach(b => {
|
|
11
|
-
const active = b === button;
|
|
12
|
-
b.setAttribute('aria-pressed', String(active));
|
|
13
|
-
b.classList.toggle('is-active', active);
|
|
14
|
-
b.tabIndex = active ? 0 : -1;
|
|
15
|
-
});
|
|
16
|
-
group.dispatchEvent(new group.ownerDocument.defaultView.CustomEvent('ui-segment-change', {
|
|
17
|
-
bubbles: true, detail: { value: button.dataset.value },
|
|
18
|
-
}));
|
|
19
|
-
};
|
|
20
|
-
const click = e => { const b = e.target.closest('button'); if (buttons().includes(b)) pick(b); };
|
|
21
|
-
const keydown = e => {
|
|
22
|
-
const list = buttons();
|
|
23
|
-
const index = list.indexOf(e.target);
|
|
24
|
-
if (index < 0) return;
|
|
25
|
-
const next = segmentedNextIndex(e.key, index, list.length);
|
|
26
|
-
if (next == null) return;
|
|
27
|
-
e.preventDefault(); list[next].focus(); pick(list[next]);
|
|
28
|
-
};
|
|
29
|
-
group.addEventListener('click', click); group.addEventListener('keydown', keydown);
|
|
30
|
-
cleanups.push(() => { group.removeEventListener('click', click); group.removeEventListener('keydown', keydown); delete group.__segWired; });
|
|
31
|
-
});
|
|
32
|
-
return () => cleanups.forEach(fn => fn());
|
|
33
|
-
}
|