@apliteni/apliteni-ui 0.142.1 → 0.142.3
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 +2 -2
- 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/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
package/src/styles/input.css
CHANGED
|
@@ -38,18 +38,6 @@
|
|
|
38
38
|
.ui-textarea:hover,
|
|
39
39
|
.ui-select:hover { border-color: var(--field-edge-hover); }
|
|
40
40
|
|
|
41
|
-
/* The band and nothing beside it. Recolouring the field's own 1px edge to the
|
|
42
|
-
accent drew a SECOND accent band one pixel inside the first, and the unpainted
|
|
43
|
-
pixel between them read as a halo on the light ground — which is the glow Artur
|
|
44
|
-
rejected on #578 round r34. The edge keeps its resting ink.
|
|
45
|
-
why: docs/foundations.md#the-focus-ring */
|
|
46
|
-
.ui-input:focus-visible,
|
|
47
|
-
.ui-textarea:focus-visible,
|
|
48
|
-
.ui-select:focus-visible {
|
|
49
|
-
outline: var(--ring);
|
|
50
|
-
outline-offset: var(--ring-offset);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
41
|
.ui-input::placeholder,
|
|
54
42
|
.ui-textarea::placeholder { /* muted-ink: placeholder — empty form field */ color: var(--muted); opacity: 0.9; }
|
|
55
43
|
|
|
@@ -75,7 +63,15 @@
|
|
|
75
63
|
|
|
76
64
|
.ui-input.is-invalid, .ui-select.is-invalid,
|
|
77
65
|
.ui-textarea.is-invalid { border-color: var(--pink); }
|
|
78
|
-
/*
|
|
66
|
+
/* Keep the border's width, but make its ink transparent while the ring shows.
|
|
67
|
+
This also outranks the invalid and hover edges, so focus has one line. */
|
|
68
|
+
.ui-input:focus-visible,
|
|
69
|
+
.ui-textarea:focus-visible,
|
|
70
|
+
.ui-select:focus-visible {
|
|
71
|
+
border-color: transparent;
|
|
72
|
+
outline: var(--ring);
|
|
73
|
+
outline-offset: var(--ring-offset);
|
|
74
|
+
}
|
|
79
75
|
|
|
80
76
|
/* A search field with a value gets the browser's own clear button, and the
|
|
81
77
|
browser paints it — near-black on the light field, white on the dark one,
|
|
@@ -110,17 +106,20 @@
|
|
|
110
106
|
which is the colour every other quiet glyph on a field takes. It was one frozen
|
|
111
107
|
hex until #295, dark --muted's old value, which the ladder's re-pick left behind
|
|
112
108
|
at 2.49:1 on the light field. Held by stories/colour-tokens.test.js.
|
|
109
|
+
The mark is .ui-dropdown__chevron drawn as a path: its 8px border caret turned 45
|
|
110
|
+
degrees, at its 1.6px stroke and lifted by --caret-off, so both controls show one
|
|
111
|
+
chevron. It is a plain stroke with butt ends and a mitred point, 11.3px wide.
|
|
113
112
|
why: docs/foundations.md#colour-and-contrast */
|
|
114
113
|
.ui-select {
|
|
115
114
|
appearance: none;
|
|
116
|
-
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='
|
|
115
|
+
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='-6 -6 12 12' fill='none' stroke='%23a29db6' stroke-width='1.6'%3E%3Cpath d='M-5.09 -2.83L0 2.26l5.09-5.09'/%3E%3C/svg%3E");
|
|
117
116
|
background-repeat: no-repeat;
|
|
118
117
|
background-position: right 15px center;
|
|
119
118
|
padding-right: 40px;
|
|
120
119
|
cursor: pointer;
|
|
121
120
|
}
|
|
122
121
|
:root[data-theme="light"] .ui-select {
|
|
123
|
-
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='
|
|
122
|
+
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='-6 -6 12 12' fill='none' stroke='%235c6270' stroke-width='1.6'%3E%3Cpath d='M-5.09 -2.83L0 2.26l5.09-5.09'/%3E%3C/svg%3E");
|
|
124
123
|
}
|
|
125
124
|
|
|
126
125
|
/* Checkbox / radio — custom, token-driven. DataTable's selection boxes are bare
|
package/src/styles/layout.css
CHANGED
|
@@ -118,8 +118,7 @@
|
|
|
118
118
|
was the same sentence in a second file. What is left here is the rail's own
|
|
119
119
|
resting step. */
|
|
120
120
|
/* Re-tuned at #295, which took the light rail down a step with the page. Below 720px
|
|
121
|
-
the glyph is the whole row, so it is held at text grade rather than at 1.4.11's bar
|
|
122
|
-
stories/apps/shell-states.test.js:1535 `a resting glyph is dimmer but still legible`. */
|
|
121
|
+
the glyph is the whole row, so it is held at text grade rather than at 1.4.11's bar. */
|
|
123
122
|
.ui-app__rail .ui-nav__ic svg { opacity: 0.66; }
|
|
124
123
|
|
|
125
124
|
/* A destructive row of the rail is a navigation row and rests like one; the danger
|
|
@@ -280,6 +279,10 @@
|
|
|
280
279
|
:where(.ui-app.is-collapsed) .ui-app__rail .ui-nav__item.is-active { isolation: isolate; background: none; }
|
|
281
280
|
:where(.ui-app.is-collapsed) .ui-app__rail .ui-nav__item.is-active::before { content: ""; position: absolute; left: 0; top: 50%; width: var(--ui-nav-strip); height: 100%; border-radius: 10px; transform: translateY(-50%); /* motion: still — a mark on the current row, whose own highlight already transitions; this centres it, it does not travel */ background: var(--surface-3); /* code-bg: inherit — The plate contains no focus target. */ z-index: -1; }
|
|
282
281
|
:where(.ui-app.is-collapsed) .ui-app__rail .ui-nav__item:not(.is-danger):not(.is-active):hover { background: none; }
|
|
282
|
+
/* A row closes to the glyph column, so the rail's clip does not cut the right side of its
|
|
283
|
+
focus ring. why: docs/components.md#the-page-shell */
|
|
284
|
+
:where(.ui-app.is-collapsed) .ui-app__rail .ui-nav__item,
|
|
285
|
+
:where(.ui-app.is-collapsed) .ui-app__rail .ui-app__user-trigger { width: var(--ui-nav-strip); }
|
|
283
286
|
/* The label IS the chip. `fixed` is the fallback placement, out of the rail's own
|
|
284
287
|
clip; the @supports branch below pins it to the row and is the only one that
|
|
285
288
|
survives a scroll. The toggle's selector is unscoped, because it is wordless at
|
package/src/styles/table.css
CHANGED
|
@@ -50,6 +50,10 @@
|
|
|
50
50
|
.ui-table tfoot th { text-align: right; }
|
|
51
51
|
.ui-table td.ui-table__title { color: var(--strong); font-weight: var(--weight-medium); width: 99%; white-space: normal; }
|
|
52
52
|
.ui-table th:last-child { padding-right: 0; }
|
|
53
|
+
/* The last body cell ends where its header and the table end. A right-aligned amount in the
|
|
54
|
+
last column stood 16px in from both, because only the header and the action cell dropped
|
|
55
|
+
the cell gap. The variants below state their own end padding. why: docs/foundations.md#spacing-and-rhythm */
|
|
56
|
+
.ui-table td:last-child { padding-right: 0; }
|
|
53
57
|
.ui-table td.ui-table__act { padding-right: 0; text-align: right; }
|
|
54
58
|
.ui-table tr.is-dead td { /* muted-ink: state — revoked row */ color: var(--muted); }
|
|
55
59
|
.ui-table tbody tr { transition: background var(--dur-fast) var(--ease); }
|
|
@@ -68,6 +72,12 @@
|
|
|
68
72
|
border-top-left-radius: var(--radius-sm); border-bottom-left-radius: var(--radius-sm); }
|
|
69
73
|
.ui-table--hover:not(.ui-table--zebra) tbody tr:hover td:last-child {
|
|
70
74
|
border-top-right-radius: var(--radius-sm); border-bottom-right-radius: var(--radius-sm); }
|
|
75
|
+
/* The hover band is the last cell, which ends where the figures end, so a hovered row's fill
|
|
76
|
+
stopped at the last glyph. The last column of a hover table keeps one cell gap of room
|
|
77
|
+
inside the band, header and body alike, so the figures and their header still share one
|
|
78
|
+
right edge. The dense and compact variants state their own end padding below, and an
|
|
79
|
+
action cell keeps none. */
|
|
80
|
+
:where(.ui-table--hover:not(.ui-table--zebra)) :is(th, td):not(.ui-table__act):last-child { padding-right: var(--space-4); }
|
|
71
81
|
|
|
72
82
|
/* Data-table modifiers, composable: .ui-table--dense --zebra --hover.
|
|
73
83
|
* --dense --space-3 across, --space-2 down — one step in from the base table
|
|
@@ -178,6 +188,9 @@
|
|
|
178
188
|
padding: var(--space-4) var(--space-4) var(--space-4) 0;
|
|
179
189
|
border-radius: var(--radius-xs);
|
|
180
190
|
}
|
|
191
|
+
/* The last cell gave up its end gap above, so the link it holds gives up the same. */
|
|
192
|
+
.ui-table td.ui-table__linked:where(:last-child) > :is(a:not([class]), a.ui-identity):only-child { padding-right: 0; }
|
|
193
|
+
:where(.ui-table--hover:not(.ui-table--zebra)) td.ui-table__linked:last-child > :is(a:not([class]), a.ui-identity):only-child { padding-right: var(--space-4); }
|
|
181
194
|
.ui-table--dense td.ui-table__linked > :is(a:not([class]), a.ui-identity):only-child { padding: var(--space-2) var(--space-3); }
|
|
182
195
|
.ui-table--compact td.ui-table__linked > :is(a:not([class]), a.ui-identity):only-child { padding: var(--space-1) var(--space-3); }
|
|
183
196
|
/* Zebra insets the row's END cells only, so the fill does too: a marked identity behind a
|
|
@@ -298,7 +311,11 @@
|
|
|
298
311
|
half, so at 24px it hides a 12px shade outright — which is why the two sizes are
|
|
299
312
|
not one. why: guidelines/dense-tables.md */
|
|
300
313
|
.ui-table-scroll {
|
|
301
|
-
overflow: auto; max-height: var(--ui-table-height, 70vh);
|
|
314
|
+
overflow: auto; max-height: var(--ui-table-height, 70vh);
|
|
315
|
+
/* A transparent border, not padding: positioned cells cover an outline on the scrollport's
|
|
316
|
+
padding. The side and bottom bands draw in the border at the visible edge at every scroll
|
|
317
|
+
position. why: docs/foundations.md#the-focus-ring */
|
|
318
|
+
border: 0 solid transparent; border-inline-width: var(--space-1); border-bottom-width: var(--space-1); background-origin: border-box;
|
|
302
319
|
background-color: var(--table-bg);
|
|
303
320
|
background-image:
|
|
304
321
|
linear-gradient(to right, var(--table-bg) 50%, transparent),
|
|
@@ -326,13 +343,22 @@
|
|
|
326
343
|
}
|
|
327
344
|
/* The kit's first ringed scroller, and a scroll region inside a card like the rest, so
|
|
328
345
|
it draws the band inward too rather than spending a halo across the card around it.
|
|
329
|
-
It had no room of its own to draw in — the
|
|
346
|
+
It had no room of its own to draw in — the border above is horizontal — which is the
|
|
330
347
|
second reason the band is an outline: it is painted over the rows, in the cell padding
|
|
331
348
|
of the first and last, rather than under them. #531
|
|
332
349
|
why: docs/foundations.md#the-focus-ring */
|
|
333
350
|
.ui-table-scroll:focus-visible { outline: var(--ring-scroll); outline-offset: var(--ring-scroll-offset); }
|
|
351
|
+
@media (forced-colors: active) {
|
|
352
|
+
.ui-table-scroll { border-color: Canvas; }
|
|
353
|
+
}
|
|
334
354
|
.ui-table--sticky { border-collapse: separate; border-spacing: 0; }
|
|
335
355
|
.ui-table--sticky thead th { position: sticky; top: 0; z-index: var(--z-sticky); background: var(--table-bg); padding-top: var(--space-2); }
|
|
356
|
+
/* The header sticks at the region's top edge, which is where the inward band draws, and a
|
|
357
|
+
positioned cell paints over an outline. While the region holds the ring, the header
|
|
358
|
+
gives up the band's own 3px, so the ring is whole on the top side. The side bands lie in
|
|
359
|
+
the region's border, which no cell reaches.
|
|
360
|
+
why: docs/foundations.md#the-focus-ring */
|
|
361
|
+
.ui-table-scroll:focus-visible .ui-table--sticky thead th { clip-path: inset(calc(var(--ring-gap-width) + var(--ring-width)) 0 0 0); }
|
|
336
362
|
.ui-table--pinned .ui-table__identity, .ui-table--pinned .ui-table__selection { position: sticky; left: 0; z-index: var(--z-base); background: var(--table-bg); border-right: 1px solid var(--border); }
|
|
337
363
|
.ui-table--pinned thead .ui-table__identity, .ui-table--pinned thead .ui-table__selection { z-index: calc(var(--z-sticky) + 1); }
|
|
338
364
|
/* The divider is the pin's edge: it says the column stayed while the rest moved under it.
|
package/src/styles/topbar.css
CHANGED
|
@@ -210,12 +210,14 @@
|
|
|
210
210
|
font: inherit;
|
|
211
211
|
transition: background var(--dur-fast) var(--ease);
|
|
212
212
|
}
|
|
213
|
-
/*
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
213
|
+
/* Hover fills the row. Only keyboard focus draws its outline. */
|
|
214
|
+
.vopt:hover { background: var(--surface); /* code-bg: inherit — control paint; the containing surface is the ground, for a chip and for a band alike. */ }
|
|
215
|
+
:where(:root[data-theme="light"]) .vopt:hover { background: var(--surface-3); /* code-bg: inherit — control paint; the containing surface is the ground, for a chip and for a band alike. */ }
|
|
216
|
+
@media (forced-colors: active) {
|
|
217
|
+
.vopt:hover { border: 1px solid Highlight; padding: 9px 12px; }
|
|
218
|
+
}
|
|
219
|
+
/* The row is a keyboard stop: react/src/Dropdown.tsx:758
|
|
220
|
+
`els[next < 0 ? 0 : next]?.focus()` moves focus onto a `[data-dd-item]` with
|
|
219
221
|
the arrow keys, and this is one. It takes the ring on its own 10px radius, the
|
|
220
222
|
same way `.amenu a` above does. #482 */
|
|
221
223
|
.vopt:focus-visible { outline: var(--ring); outline-offset: var(--ring-offset); }
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
// The one account navigation definition, and the one way to hand it to a sink
|
|
2
|
-
// that interpolates raw. It lives here rather than in shell.js because both
|
|
3
|
-
// shell.js and topbar.js need it and shell.js already imports topbar.js — the
|
|
4
|
-
// other direction would be a cycle. shell.js re-exports ACCOUNT_NAV, which is
|
|
5
|
-
// the published name docs/components.md documents.
|
|
6
|
-
// why: docs/components.md#the-page-shell
|
|
7
|
-
import { esc } from './index.js';
|
|
8
|
-
import { avatarInitials } from '../logic/avatar.js';
|
|
9
|
-
import { ACCOUNT_NAV } from '../logic/account-nav.js';
|
|
10
|
-
|
|
11
|
-
export { ACCOUNT_NAV };
|
|
12
|
-
|
|
13
|
-
// topbar()'s account menu speaks [id, icon, label, href?, target?] tuples, and
|
|
14
|
-
// it interpolates every field raw — the label, the href and the target alike.
|
|
15
|
-
// Escape all three on the way in rather than sending the menu a string the rail
|
|
16
|
-
// would have escaped a second time.
|
|
17
|
-
export const toMenuTuple = (it) => [
|
|
18
|
-
esc(it.id ?? ''), it.icon, esc(it.label || ''),
|
|
19
|
-
it.href ? esc(it.href) : it.href,
|
|
20
|
-
it.target ? esc(it.target) : it.target,
|
|
21
|
-
];
|
|
22
|
-
|
|
23
|
-
// What accountMenu() falls back to. Derived on call, not frozen at import, so
|
|
24
|
-
// the menu and the rail cannot answer differently about the same definition.
|
|
25
|
-
export const accountMenuNav = () => ACCOUNT_NAV.map(toMenuTuple);
|
|
26
|
-
|
|
27
|
-
// One reader, one pair of initials. The rail (shell.js) and the topbar's
|
|
28
|
-
// account menu (topbar.js) both draw an avatar for the same person, and each
|
|
29
|
-
// computed it for itself: the rail preferred the display name, the menu only
|
|
30
|
-
// ever read the email's local part. So the /account preset — the one screen
|
|
31
|
-
// with both on it — said "AL" in the rail and "A" in the topbar. This lives
|
|
32
|
-
// beside ACCOUNT_NAV for the same reason ACCOUNT_NAV lives here: both files
|
|
33
|
-
// need it and shell.js already imports topbar.js.
|
|
34
|
-
//
|
|
35
|
-
// The displayed name alone supplies the letters. The part draws its user glyph
|
|
36
|
-
// when no name is shown.
|
|
37
|
-
export const initials = (name) => avatarInitials(name);
|
package/src/components/avatar.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { esc, icon } from './index.js';
|
|
2
|
-
import { safeUrl } from '../html.js';
|
|
3
|
-
import { avatarHue, avatarInitials } from '../logic/avatar.js';
|
|
4
|
-
export { avatarHue, avatarInitials, AVATAR_HUES } from '../logic/avatar.js';
|
|
5
|
-
|
|
6
|
-
// Avatar — a person's round mark. The letters come from `name`, the hue from a hash of
|
|
7
|
-
// `key`, and a photo covers the letter. A photo that fails to load removes itself, so the
|
|
8
|
-
// letter shows and not the browser's broken-image glyph.
|
|
9
|
-
// With no name the mark is the `user` glyph; `empty` is a dashed ring for "no one yet".
|
|
10
|
-
// It is decoration beside the name it stands for, so it is hidden from assistive
|
|
11
|
-
// technology, and it has no cursor, hover or focus of its own.
|
|
12
|
-
// why: docs/components.md#avatar
|
|
13
|
-
const cx = (...a) => a.filter(Boolean).join(' ');
|
|
14
|
-
const wiredDocs = new WeakSet();
|
|
15
|
-
|
|
16
|
-
function wireAvatarPhotos(doc) {
|
|
17
|
-
if (!doc || wiredDocs.has(doc)) return;
|
|
18
|
-
wiredDocs.add(doc);
|
|
19
|
-
doc.querySelectorAll('.ui-avatar > img[data-avatar-photo]').forEach((img) => {
|
|
20
|
-
if (!img.complete) return;
|
|
21
|
-
if (img.naturalWidth > 0) img.classList.add('is-loaded');
|
|
22
|
-
else img.remove();
|
|
23
|
-
});
|
|
24
|
-
doc.addEventListener('load', (event) => {
|
|
25
|
-
if (event.target?.matches?.('.ui-avatar > img[data-avatar-photo]')) event.target.classList.add('is-loaded');
|
|
26
|
-
}, true);
|
|
27
|
-
doc.addEventListener('error', (event) => {
|
|
28
|
-
if (event.target?.matches?.('.ui-avatar > img[data-avatar-photo]')) event.target.remove();
|
|
29
|
-
}, true);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (typeof document !== 'undefined') wireAvatarPhotos(document);
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* @param {object} [o]
|
|
36
|
-
* @param {string|number} [o.key] the app's stable id for the person; picks the hue
|
|
37
|
-
* @param {string} [o.name] the person's name; empty draws the `user` glyph
|
|
38
|
-
* @param {string} [o.initials] the letters to draw, when the caller has already chosen them
|
|
39
|
-
* @param {string} [o.src] a photo URL; the letters show if it fails to load
|
|
40
|
-
* @param {24|32} [o.size] the mark's size in px
|
|
41
|
-
* @param {boolean} [o.empty] a dashed ring in place of a person
|
|
42
|
-
* @returns {string} html
|
|
43
|
-
*/
|
|
44
|
-
export function avatar({ key, name, initials, src, size = 24, empty = false } = {}) {
|
|
45
|
-
if (typeof document !== 'undefined') wireAvatarPhotos(document);
|
|
46
|
-
const base = ['ui-avatar', size === 32 && 'ui-avatar--32'];
|
|
47
|
-
if (empty) return `<span class="${esc(cx(...base, 'ui-avatar--empty'))}" aria-hidden="true"></span>`;
|
|
48
|
-
const letters = initials || avatarInitials(name);
|
|
49
|
-
if (!letters) return `<span class="${esc(cx(...base, 'ui-avatar--anon'))}" aria-hidden="true">${icon('user')}</span>`;
|
|
50
|
-
const hue = avatarHue(key ?? name ?? letters);
|
|
51
|
-
const img = src ? `<img data-avatar-photo src="${esc(safeUrl(src))}" alt="" loading="lazy">` : '';
|
|
52
|
-
return `<span class="${esc(cx(...base, `ui-avatar--h${hue}`))}" data-initials="${letters.length}" aria-hidden="true">${esc(letters)}${img}</span>`;
|
|
53
|
-
}
|
package/src/components/back.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
// Back link — the control that takes a reader from a page up to the page it sits
|
|
2
|
-
// under, as an HTML string.
|
|
3
|
-
//
|
|
4
|
-
// It is a link to an address the caller names, never a script that walks the
|
|
5
|
-
// browser's history. A page opened in a new tab, from a bookmark or from a shared
|
|
6
|
-
// address has no history to walk, and the browser's own Back button already does
|
|
7
|
-
// that job; an <a href> is also the one shape a reader can open in a new tab.
|
|
8
|
-
//
|
|
9
|
-
// It has one treatment and takes no variant: a chevron and the destination's
|
|
10
|
-
// name in dim ink, with no box. Four were rendered side by side on
|
|
11
|
-
// docs/reviews/270-back-control.html and the owner chose this one, so the other
|
|
12
|
-
// three — a bordered button above the title, an icon-only arrow beside it, and
|
|
13
|
-
// the breadcrumb trail alone — are not built here.
|
|
14
|
-
// why: docs/components.md#the-back-link
|
|
15
|
-
import { esc, icon } from './index.js';
|
|
16
|
-
|
|
17
|
-
// "Back" names a direction rather than a place. It is what a caller who names no
|
|
18
|
-
// destination gets, and the one label that is not spelled out as "Back to …".
|
|
19
|
-
const BARE = 'Back';
|
|
20
|
-
|
|
21
|
-
// A `javascript:` address is the history walk this component replaces, arriving
|
|
22
|
-
// through the one parameter it has. Before a browser reads the scheme it strips
|
|
23
|
-
// C0 controls and spaces from the front and removes every tab, LF and CR wherever
|
|
24
|
-
// they sit, so "java\tscript:" is still javascript:. The check reads the address the
|
|
25
|
-
// same way (WHATWG URL Standard, basic URL parser).
|
|
26
|
-
const SCRIPTED = /^(?:javascript|data|vbscript):/i;
|
|
27
|
-
const LEADING = /^[\u0000-\u0020]+/;
|
|
28
|
-
const TAB_OR_NEWLINE = /[\t\n\r]/g;
|
|
29
|
-
|
|
30
|
-
// A label that already says "Back to Invoices" names the place after those words, or the
|
|
31
|
-
// link would be read as "Back to Back to Invoices". The whole phrase, since "Backups" and
|
|
32
|
-
// "Back office" are places too. why: docs/components.md#the-back-link
|
|
33
|
-
const SAID = /^back\s+to(?:\s+|$)/i;
|
|
34
|
-
|
|
35
|
-
const text = (v) => (typeof v === 'string' || typeof v === 'number' ? String(v).trim() : '');
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* backLink({ href, label }) → the link a page under another page puts above its
|
|
39
|
-
* title.
|
|
40
|
-
*
|
|
41
|
-
* `label` is the destination's name, spelled the way the sidebar or the trail
|
|
42
|
-
* spells it. The arrow says "back" on screen and is aria-hidden, so the link's
|
|
43
|
-
* accessible name says it in words: "Back to Invoices". That name still contains
|
|
44
|
-
* the visible text, which is what WCAG 2.5.3 asks of a named control.
|
|
45
|
-
*
|
|
46
|
-
* No address, no link: a back control with nowhere to go renders nothing.
|
|
47
|
-
*/
|
|
48
|
-
export function backLink({ href, label } = {}) {
|
|
49
|
-
const to = text(href);
|
|
50
|
-
if (!to || SCRIPTED.test(to.replace(LEADING, '').replace(TAB_OR_NEWLINE, ''))) return '';
|
|
51
|
-
const name = text(label).replace(SAID, '');
|
|
52
|
-
const bare = !name || name.toLowerCase() === BARE.toLowerCase();
|
|
53
|
-
const shown = bare ? BARE : name;
|
|
54
|
-
const named = bare ? '' : ` aria-label="${esc(`${BARE} to ${name}`)}"`;
|
|
55
|
-
return `<a class="ui-back" href="${esc(to)}"${named}>${icon('chevronLeft')}`
|
|
56
|
-
+ `<span class="ui-back__label">${esc(shown)}</span></a>`;
|
|
57
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
const disabledBeforeBusy = new WeakMap();
|
|
2
|
-
const wired = new WeakSet();
|
|
3
|
-
|
|
4
|
-
function wireActivationGuard(element) {
|
|
5
|
-
if (wired.has(element)) return;
|
|
6
|
-
const block = event => {
|
|
7
|
-
if (element.getAttribute('aria-busy') !== 'true') return;
|
|
8
|
-
if (event.type !== 'click' && event.key !== 'Enter' && event.key !== ' ') return;
|
|
9
|
-
event.preventDefault();
|
|
10
|
-
event.stopImmediatePropagation();
|
|
11
|
-
};
|
|
12
|
-
for (const type of ['click', 'keydown', 'keyup']) element.addEventListener(type, block, true);
|
|
13
|
-
element.setAttribute('data-btn-wired', '');
|
|
14
|
-
wired.add(element);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/** Update a factory button in place, preserving its icons and prior disabled state. */
|
|
18
|
-
export function setButtonBusy(element, { busy } = {}) {
|
|
19
|
-
wireActivationGuard(element);
|
|
20
|
-
const wasBusy = element.getAttribute('aria-busy') === 'true';
|
|
21
|
-
if ((busy || wasBusy) && !disabledBeforeBusy.has(element)) disabledBeforeBusy.set(element, {
|
|
22
|
-
disabled: wasBusy ? element.hasAttribute('data-btn-disabled') : element.hasAttribute('disabled'),
|
|
23
|
-
ariaDisabled: wasBusy && !element.hasAttribute('data-btn-disabled') ? null : element.getAttribute('aria-disabled'),
|
|
24
|
-
});
|
|
25
|
-
if (busy) {
|
|
26
|
-
element.removeAttribute('data-btn-ready');
|
|
27
|
-
element.setAttribute('aria-busy', 'true');
|
|
28
|
-
element.toggleAttribute('disabled', disabledBeforeBusy.get(element).disabled);
|
|
29
|
-
element.setAttribute('aria-disabled', 'true');
|
|
30
|
-
if (!element.querySelector('.ui-btn__dots')) {
|
|
31
|
-
const dots = element.ownerDocument.createElement('span');
|
|
32
|
-
dots.className = 'ui-btn__dots';
|
|
33
|
-
dots.setAttribute('aria-hidden', 'true');
|
|
34
|
-
dots.innerHTML = '<i></i><i></i><i></i>';
|
|
35
|
-
element.append(dots);
|
|
36
|
-
}
|
|
37
|
-
} else if (wasBusy) {
|
|
38
|
-
element.setAttribute('data-btn-ready', '');
|
|
39
|
-
element.removeAttribute('aria-busy');
|
|
40
|
-
element.querySelector('.ui-btn__dots')?.remove();
|
|
41
|
-
const prior = disabledBeforeBusy.get(element);
|
|
42
|
-
element.toggleAttribute('disabled', prior?.disabled ?? false);
|
|
43
|
-
if (prior?.ariaDisabled != null) element.setAttribute('aria-disabled', prior.ariaDisabled);
|
|
44
|
-
else element.removeAttribute('aria-disabled');
|
|
45
|
-
disabledBeforeBusy.delete(element);
|
|
46
|
-
}
|
|
47
|
-
if (busy || wasBusy) {
|
|
48
|
-
let status = element.nextElementSibling;
|
|
49
|
-
if (!status?.classList.contains('ui-btn__status')) {
|
|
50
|
-
status = element.ownerDocument.createElement('span');
|
|
51
|
-
status.className = 'ui-sr ui-btn__status';
|
|
52
|
-
status.setAttribute('role', 'status');
|
|
53
|
-
status.setAttribute('aria-live', 'polite');
|
|
54
|
-
element.after(status);
|
|
55
|
-
// Register the empty live region before its first text update.
|
|
56
|
-
setTimeout(() => {
|
|
57
|
-
status.textContent = messageFor(element);
|
|
58
|
-
}, 0);
|
|
59
|
-
} else {
|
|
60
|
-
const message = messageFor(element);
|
|
61
|
-
if (status.textContent !== message) status.textContent = message;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function messageFor(element) {
|
|
67
|
-
const name = element.querySelector('.ui-btn__label')?.textContent ?? element.getAttribute('aria-label') ?? 'Button';
|
|
68
|
-
return `${name}: ${element.getAttribute('aria-busy') === 'true' ? 'in progress' : 'complete'}`;
|
|
69
|
-
}
|