@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/components/shell.js
DELETED
|
@@ -1,511 +0,0 @@
|
|
|
1
|
-
// The kit's one page shell: a full-height rail beside one <main>, in two layouts.
|
|
2
|
-
// `topbar` switches the product band on; it is off unless the caller hands one over.
|
|
3
|
-
// wireShell() once after mounting wires the fold, the nav's groups and the reader's menu.
|
|
4
|
-
// why: docs/components.md#the-page-shell
|
|
5
|
-
import { topbar as productTopbar } from './topbar.js';
|
|
6
|
-
import { esc, icon, button } from './index.js';
|
|
7
|
-
import { avatar } from './avatar.js';
|
|
8
|
-
import { sidebarNav, breadcrumbs, wireNav } from './nav.js';
|
|
9
|
-
import { dropdown, wireDropdown } from './dropdown.js';
|
|
10
|
-
import { drawer, wireDrawer, closeDrawer } from './drawer.js';
|
|
11
|
-
import { backLink } from './back.js';
|
|
12
|
-
import { prism } from '../assets/brand.js';
|
|
13
|
-
import { ACCOUNT_NAV, toMenuTuple, initials } from './account-nav.js';
|
|
14
|
-
import { paletteHotkey } from './command-palette.js';
|
|
15
|
-
import { safeUrl } from '../html.js';
|
|
16
|
-
// The one account navigation definition lives in account-nav.js because topbar.js needs
|
|
17
|
-
// it too; re-exported here so the name docs/components.md publishes keeps working.
|
|
18
|
-
export { ACCOUNT_NAV };
|
|
19
|
-
|
|
20
|
-
const str = (v) => (v == null ? '' : String(v));
|
|
21
|
-
const isRecord = (v) => typeof v === 'object' && v !== null;
|
|
22
|
-
|
|
23
|
-
// ---- the options bag, settled once --------------------------------------
|
|
24
|
-
//
|
|
25
|
-
// A default parameter covers `undefined` and nothing else, so `nav: null` from an
|
|
26
|
-
// /auth/me and a `crumbs` string from somebody reading the migration note both arrived
|
|
27
|
-
// as they were. A shell that throws mid-render takes the page with it, so each option is
|
|
28
|
-
// settled here, before the first sink sees it. Adding one to appShell() means adding it
|
|
29
|
-
// to SHAPES or deciding in the open that it needs nothing.
|
|
30
|
-
|
|
31
|
-
// The account menu's nav takes the old tuple — [id, icon, label, href?, target?] — and
|
|
32
|
-
// nav.js's object shape side by side. A nav that is not a list falls back to ACCOUNT_NAV;
|
|
33
|
-
// an entry that is neither shape is dropped. An empty list is an answer and stays.
|
|
34
|
-
const toItems = (nav) => (Array.isArray(nav) ? nav : ACCOUNT_NAV)
|
|
35
|
-
.filter(isRecord)
|
|
36
|
-
.map((n) => (Array.isArray(n)
|
|
37
|
-
? { id: n[0], icon: n[1], label: n[2], href: n[3], target: n[4] }
|
|
38
|
-
: n));
|
|
39
|
-
|
|
40
|
-
// The trail is the caller's, and `crumbs` changed shape this release: `crumb: 'Payouts'`
|
|
41
|
-
// became `crumbs: [{ label }]`, one letter apart. A non-list is NOT read as a one-crumb
|
|
42
|
-
// trail — that hides the migration mistake — so it is no trail at all, which shows. A
|
|
43
|
-
// crumb with no label would draw an empty cell, so it goes too.
|
|
44
|
-
const toCrumbs = (crumbs) => (Array.isArray(crumbs) ? crumbs : [])
|
|
45
|
-
.filter((c) => isRecord(c) && !Array.isArray(c) && str(c.label) !== '');
|
|
46
|
-
|
|
47
|
-
// A back link replaces the trail rather than joining it: the two would name the same parent
|
|
48
|
-
// twice. Anything but a record is no back link; its fields go through as given, so a back
|
|
49
|
-
// backLink() refuses leaves the trail standing. why: docs/components.md#the-back-link
|
|
50
|
-
const toBack = (b) => (isRecord(b) && !Array.isArray(b) ? { href: b.href, label: b.label } : null);
|
|
51
|
-
|
|
52
|
-
// The reader, as two strings. railUser() and initials() both read them, and an
|
|
53
|
-
// /auth/me answering `account: null` or a numeric display name reached both.
|
|
54
|
-
const toReader = (a) => (isRecord(a) ? { name: str(a.name), email: str(a.email) } : { name: '', email: '' });
|
|
55
|
-
|
|
56
|
-
// ---- the topbar, which interpolates where the rail escapes ----------------
|
|
57
|
-
//
|
|
58
|
-
// brand() writes `word` straight into its markup and accountMenu() does the same with
|
|
59
|
-
// the reader's name, address and menu entries, so the escaping is here on the one path
|
|
60
|
-
// into productTopbar() rather than in each caller. The caller passes text either way.
|
|
61
|
-
|
|
62
|
-
// The reader the menu draws. Both fields are always written, empty when the caller gave
|
|
63
|
-
// none: accountMenu()'s defaults are a demo identity, so a key dropped here is a key its
|
|
64
|
-
// fixture fills in. `initials` is derived from what the caller passed rather than from
|
|
65
|
-
// the entities made of it — `<Ada>` and `<Ada>` do not start with the same
|
|
66
|
-
// character. toMenuTuple() escapes the entries and reads item objects, so tuples go
|
|
67
|
-
// through toItems() first; a nav nobody passed stays unpassed.
|
|
68
|
-
const toMenuReader = (a) => {
|
|
69
|
-
const { name, email } = toReader(a);
|
|
70
|
-
const rest = isRecord(a) && !Array.isArray(a) ? a : {};
|
|
71
|
-
const out = { ...rest, name: esc(name), email: esc(email), initials: initials(name, email), key: email || name };
|
|
72
|
-
if (out.nav != null) out.nav = toItems(out.nav).map(toMenuTuple);
|
|
73
|
-
return out;
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
const toTopbar = (t) => {
|
|
77
|
-
if (!isRecord(t) || Array.isArray(t)) return null;
|
|
78
|
-
const out = { ...t };
|
|
79
|
-
if (out.word != null) out.word = esc(str(out.word));
|
|
80
|
-
if (out.account != null) out.account = toMenuReader(out.account);
|
|
81
|
-
return out;
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
// ---- the two layouts, and the two widths ---------------------------------
|
|
85
|
-
//
|
|
86
|
-
// Each is a name the kit knows or the default — read strictly, and not through
|
|
87
|
-
// String(), which turned `['topbar']` into a layout and drew half a page.
|
|
88
|
-
// why: docs/components.md#the-page-shell
|
|
89
|
-
const toLayout = (v) => (v === 'topbar' ? 'topbar' : 'rail');
|
|
90
|
-
|
|
91
|
-
// why: docs/foundations.md#widths
|
|
92
|
-
const toWidth = (v) => (v === 'wide' ? 'wide' : 'centered');
|
|
93
|
-
|
|
94
|
-
// `search: 'palette-id'`, or the same id in `{ palette }` with a placeholder beside
|
|
95
|
-
// it. No palette to open, no field — the argument `signOutHref` takes.
|
|
96
|
-
// `shortLabel` is the word the band draws below 560px, where the sentence used to
|
|
97
|
-
// truncate mid-word. why: docs/components.md#the-page-shell
|
|
98
|
-
const toSearch = (v) => {
|
|
99
|
-
const given = typeof v === 'string' ? { palette: v } : (isRecord(v) && !Array.isArray(v) ? v : null);
|
|
100
|
-
const palette = given && typeof given.palette === 'string' ? given.palette.trim() : '';
|
|
101
|
-
if (!palette) return null;
|
|
102
|
-
return {
|
|
103
|
-
palette,
|
|
104
|
-
placeholder: str(given.placeholder) || 'Search or run a command…',
|
|
105
|
-
shortLabel: str(given.shortLabel) || 'Search',
|
|
106
|
-
};
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
// `maxWidth` lands inside a style attribute, so a length is all this accepts — a number
|
|
110
|
-
// and a unit, or `none`. Anything else yields '' and the caller writes no style
|
|
111
|
-
// attribute, falling through to --measure. It must REMOVE the property rather than pass
|
|
112
|
-
// a bad value on: a custom property accepts any token stream, so garbage is a valid
|
|
113
|
-
// declaration that drops the column to `none`, the full track.
|
|
114
|
-
// why: docs/foundations.md#widths
|
|
115
|
-
const LENGTH = /^(?:\d+|\d*\.\d+)(?:px|rem|em|ch|%|vw)$/;
|
|
116
|
-
const mainMax = (v) => {
|
|
117
|
-
const s = str(v).trim();
|
|
118
|
-
return s === 'none' || LENGTH.test(s) ? s : '';
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
// ---- the fold, and where the reader's choice is kept ---------------------
|
|
122
|
-
//
|
|
123
|
-
// A cookie rather than localStorage, because a server can read one and paint the
|
|
124
|
-
// rail at the width the reader left it. why: docs/components.md#the-page-shell
|
|
125
|
-
export const RAIL_COOKIE = 'apliteni-ui-rail';
|
|
126
|
-
const RAIL_MAX_AGE = 60 * 60 * 24 * 365;
|
|
127
|
-
const RAIL_VALUE = new RegExp(`(?:^|;\\s*)${RAIL_COOKIE}=(collapsed|expanded)(?:;|$)`);
|
|
128
|
-
|
|
129
|
-
// A sandboxed frame throws on document.cookie; it has no stored choice.
|
|
130
|
-
const cookieOf = (doc) => {
|
|
131
|
-
try { return doc ? doc.cookie : ''; } catch (e) { return ''; }
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
/** The reader's stored choice — true, false, or null when there is none. With no
|
|
135
|
-
* argument it reads `document.cookie`; handed a Cookie header, only that. */
|
|
136
|
-
export function railCollapsed(cookies) {
|
|
137
|
-
const src = arguments.length ? cookies : cookieOf(typeof document === 'undefined' ? null : document);
|
|
138
|
-
const m = RAIL_VALUE.exec(String(src ?? ''));
|
|
139
|
-
return m ? m[1] === 'collapsed' : null;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// The name says what the press will do, and aria-expanded says what the rail is.
|
|
143
|
-
const railName = (collapsed) => (collapsed ? 'Expand sidebar' : 'Collapse sidebar');
|
|
144
|
-
|
|
145
|
-
// Lucide `panel-left-close`, unmodified: a frame, the seam at 9, and a chevron
|
|
146
|
-
// pointing the way the press moves the rail's edge. The folded rail mirrors the
|
|
147
|
-
// chevron about 15 in layout.css, which lands it exactly on Lucide
|
|
148
|
-
// `panel-left-open` — so both states are a shipped glyph and neither is drawn by
|
|
149
|
-
// hand. The seam does not move: it IS the rail, and the compartment it cuts off
|
|
150
|
-
// stays on the side the rail is on. Only the nodes are written here — a child a
|
|
151
|
-
// stylesheet can reach — and they are spliced into icon()'s own wrapper rather
|
|
152
|
-
// than a copy of it. why: docs/components.md#the-page-shell
|
|
153
|
-
const MARK = '<rect x="3" y="3" width="18" height="18" rx="2"/>'
|
|
154
|
-
+ '<path class="ui-app__fold-seam" d="M9 3v18"/>'
|
|
155
|
-
+ '<path class="ui-app__fold-arrow" d="m16 15-3-3 3-3"/>';
|
|
156
|
-
const railMark = () => icon('').replace('></svg>', `>${MARK}</svg>`);
|
|
157
|
-
|
|
158
|
-
// The rail's own skin, outside the <nav>: folding the rail is not a place to go.
|
|
159
|
-
// It stands at the far end of the head band's brand row, and its name is written
|
|
160
|
-
// out rather than put in a tooltip, because the name IS the chip layout.css lands
|
|
161
|
-
// beside the glyph — at both widths. why: docs/components.md#the-page-shell
|
|
162
|
-
const railToggle = (collapsed) =>
|
|
163
|
-
`<div class="ui-app__fold-row">`
|
|
164
|
-
+ `<button type="button" class="ui-nav__item ui-app__fold" data-rail-toggle`
|
|
165
|
-
+ ` aria-expanded="${collapsed ? 'false' : 'true'}" aria-label="${railName(collapsed)}">`
|
|
166
|
-
+ `<span class="ui-nav__ic">${railMark()}</span>`
|
|
167
|
-
+ `<span class="ui-nav__label">${railName(collapsed)}</span></button></div>`;
|
|
168
|
-
|
|
169
|
-
// The one pass. Each key names the function that settles it; nothing else in
|
|
170
|
-
// this file re-checks a value that has been through here.
|
|
171
|
-
const SHAPES = {
|
|
172
|
-
nav: toItems, crumbs: toCrumbs, back: toBack, account: toReader, maxWidth: mainMax, topbar: toTopbar,
|
|
173
|
-
layout: toLayout, width: toWidth, search: toSearch,
|
|
174
|
-
// Drawn by default; `collapsible: false` is the way out, for a page that will
|
|
175
|
-
// never call wireShell(). why: docs/components.md#the-page-shell
|
|
176
|
-
collapsible: (v) => v !== false,
|
|
177
|
-
// A boolean is the caller's answer. Anything else leaves it to the reader.
|
|
178
|
-
collapsed: (v) => (typeof v === 'boolean' ? v : null),
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
// The text options settle by the same argument. `body: null` from a record with no
|
|
182
|
-
// description drew the word "null" on the page and `word: null` left the brand link with
|
|
183
|
-
// no accessible name; dropping the key is what lets the declared default apply.
|
|
184
|
-
const TEXT = ['word', 'brandHref', 'navLabel', 'title', 'sub', 'body', 'signOutHref', 'active'];
|
|
185
|
-
|
|
186
|
-
function settle(options) {
|
|
187
|
-
const out = { ...options };
|
|
188
|
-
for (const key of Object.keys(SHAPES)) out[key] = SHAPES[key](out[key]);
|
|
189
|
-
for (const key of TEXT) if (out[key] == null) delete out[key];
|
|
190
|
-
return out;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
// The face of the reader block: the initials, and the two lines beside them that
|
|
194
|
-
// the fold takes away. `named` is the accessible name when nothing else carries
|
|
195
|
-
// one; under the menu trigger it is null, because the button is named by the words
|
|
196
|
-
// inside it. why: docs/components.md#the-page-shell
|
|
197
|
-
const readerFace = (name, email, named, markOnly = false) =>
|
|
198
|
-
`<span class="ui-app__av"${named ? ` role="img" aria-label="Signed in as ${esc(named)}"` : ' aria-hidden="true"'}>`
|
|
199
|
-
+ `${avatar({ key: email || name, initials: initials(name, email), size: 32 })}</span>`
|
|
200
|
-
+ (markOnly ? '' : `<span class="ui-app__who"${named ? ' aria-hidden="true"' : ''}>`
|
|
201
|
-
+ (name ? `<b>${esc(name)}</b>` : '')
|
|
202
|
-
+ (email ? `<span>${esc(email)}</span>` : '')
|
|
203
|
-
+ `</span>`);
|
|
204
|
-
|
|
205
|
-
// Who is signed in, and the one action on the session. A sibling of the <nav>, not
|
|
206
|
-
// its footer: a name and address are not navigation. Given a sign-out href the block
|
|
207
|
-
// is the trigger of the kit's own dropdown(), with Sign out inside it; without one
|
|
208
|
-
// there is no menu, and with nobody signed in there is no block.
|
|
209
|
-
//
|
|
210
|
-
// One block, two places: only the direction it opens is the layout's answer.
|
|
211
|
-
// `portal: true` either way — the rail and the band are both sticky.
|
|
212
|
-
function readerBlock({ name, email }, signOutHref, { band = false, portal = true } = {}) {
|
|
213
|
-
if (!name && !email) return '';
|
|
214
|
-
const cls = `ui-app__user${band ? ' ui-app__user--bar' : ''}`;
|
|
215
|
-
const who = [name, email].filter(Boolean).join(', ');
|
|
216
|
-
// The name is said once, by whichever part is on screen: the two lines in the rail,
|
|
217
|
-
// an aria-label on the band where the mark is the whole trigger.
|
|
218
|
-
const face = band ? readerFace(name, email, null, true) : readerFace(name, email, null);
|
|
219
|
-
if (!signOutHref) {
|
|
220
|
-
return `<div class="${cls}">${readerFace(name, email, who, band)}</div>`;
|
|
221
|
-
}
|
|
222
|
-
// The head says who the menu belongs to — and on a folded rail, or on a band, it is
|
|
223
|
-
// the only place a sighted reader can read the address.
|
|
224
|
-
const head = `<div class="ui-dropdown__head">`
|
|
225
|
-
+ (name ? `<b>${esc(name)}</b>` : '')
|
|
226
|
-
+ (email ? `<span>${esc(email)}</span>` : '')
|
|
227
|
-
+ `</div>`;
|
|
228
|
-
return `<div class="${cls}">${dropdown({
|
|
229
|
-
variant: 'menu',
|
|
230
|
-
portal,
|
|
231
|
-
direction: band ? 'down' : 'up',
|
|
232
|
-
align: band ? 'end' : 'start',
|
|
233
|
-
chevron: !band,
|
|
234
|
-
ariaLabel: band ? `Signed in as ${who}` : undefined,
|
|
235
|
-
triggerClass: 'ui-app__user-trigger',
|
|
236
|
-
triggerContent: face,
|
|
237
|
-
panelClass: 'ui-app__user-panel',
|
|
238
|
-
header: head,
|
|
239
|
-
items: [{ label: 'Sign out', icon: 'logout', href: signOutHref, danger: true }],
|
|
240
|
-
})}</div>`;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
// A field to look at, a button to press. `data-cmdk-open` and the cap's class are the
|
|
244
|
-
// palette's own, and the cap is NOT aria-hidden: it is half the button's name.
|
|
245
|
-
// why: docs/components.md#the-page-shell
|
|
246
|
-
// The short word repeats the sentence, so it is `aria-hidden`: the sentence and the
|
|
247
|
-
// cap are the name at every width, and layout.css clips rather than drops them.
|
|
248
|
-
const searchField = ({ palette, placeholder, shortLabel }) =>
|
|
249
|
-
`<button type="button" class="ui-app__search" data-cmdk-open="${esc(palette)}" aria-haspopup="dialog">`
|
|
250
|
-
+ `<span class="ui-app__search-ic" aria-hidden="true">${icon('search')}</span>`
|
|
251
|
-
+ `<span class="ui-app__search-txt">${esc(placeholder)}</span>`
|
|
252
|
-
+ `<span class="ui-app__search-short" aria-hidden="true">${esc(shortLabel)}</span>`
|
|
253
|
-
+ `<kbd class="ui-cmdk__key" data-palette-hotkey>${esc(paletteHotkey())}</kbd>`
|
|
254
|
-
+ `</button>`;
|
|
255
|
-
|
|
256
|
-
// The band: search at its start, the reader at its end, beside the rail rather than
|
|
257
|
-
// across the top of both. why: docs/components.md#the-page-shell
|
|
258
|
-
const shellBar = (search, account, signOutHref, lead = '') =>
|
|
259
|
-
`<header class="ui-app__bar">`
|
|
260
|
-
+ lead
|
|
261
|
-
+ (search ? searchField(search) : '')
|
|
262
|
-
+ `<span class="ui-app__bar-gap"></span>`
|
|
263
|
-
+ readerBlock(account, signOutHref, { band: true })
|
|
264
|
-
+ `</header>`;
|
|
265
|
-
|
|
266
|
-
// Below 720px the rail is not drawn. A band holds the menu control and the brand's mark,
|
|
267
|
-
// and the control opens the same rail in the kit's left drawer. Each part carries
|
|
268
|
-
// `ui-app__phone`, so layout.css draws it at that width only.
|
|
269
|
-
// why: docs/components.md#the-page-shell
|
|
270
|
-
const menuControl = (id) => button({ label: 'Menu', variant: 'ghost', icon: 'menu', iconOnly: true })
|
|
271
|
-
.replace('<button ', `<button data-drawer-open="${id}" aria-haspopup="dialog" `)
|
|
272
|
-
.replace('class="', 'class="ui-app__menu ');
|
|
273
|
-
|
|
274
|
-
const bandBrand = (word, href, uid) =>
|
|
275
|
-
`<a class="ui-app__brand ui-app__brand--band" href="${esc(safeUrl(href))}" aria-label="${esc(word)}">`
|
|
276
|
-
+ `${prism(`appb-${uid}`, 24)}</a>`;
|
|
277
|
-
|
|
278
|
-
// Unique-per-render suffix for the brand mark's clip id — the same reason
|
|
279
|
-
// nav.js keeps a module counter. Two shells on one page must not collide.
|
|
280
|
-
let _shellUid = 0;
|
|
281
|
-
|
|
282
|
-
export function appShell(options = {}) {
|
|
283
|
-
// Everything in SHAPES arrives settled; the rest is text, and a text default
|
|
284
|
-
// is what a default parameter is for.
|
|
285
|
-
const {
|
|
286
|
-
word = 'apliteni-ui',
|
|
287
|
-
brandHref = '#',
|
|
288
|
-
nav,
|
|
289
|
-
active,
|
|
290
|
-
navLabel = 'Account',
|
|
291
|
-
crumbs,
|
|
292
|
-
back,
|
|
293
|
-
title = '',
|
|
294
|
-
sub = '',
|
|
295
|
-
body = '',
|
|
296
|
-
account,
|
|
297
|
-
signOutHref = '',
|
|
298
|
-
topbar,
|
|
299
|
-
maxWidth,
|
|
300
|
-
collapsible,
|
|
301
|
-
collapsed,
|
|
302
|
-
layout,
|
|
303
|
-
width,
|
|
304
|
-
search,
|
|
305
|
-
} = settle(options);
|
|
306
|
-
// The layout's one branch, read once. Everything below asks this and not the string.
|
|
307
|
-
const banded = layout === 'topbar';
|
|
308
|
-
const up = back ? backLink(back) : '';
|
|
309
|
-
const menuId = `ui-app-menu-${++_shellUid}`;
|
|
310
|
-
// No footer slot: the nav is places to go, and the one thing that was in it —
|
|
311
|
-
// sign out — is in the reader's menu at the rail's foot.
|
|
312
|
-
const rail = sidebarNav({
|
|
313
|
-
sections: [{ label: navLabel, items: nav }],
|
|
314
|
-
active,
|
|
315
|
-
activeIs: up ? 'section' : 'page',
|
|
316
|
-
ariaLabel: navLabel,
|
|
317
|
-
});
|
|
318
|
-
// One band over a page, never two: the banded layout draws its own, so the
|
|
319
|
-
// compatibility bag is not drawn beside it. why: docs/components.md#the-page-shell
|
|
320
|
-
const compat = banded ? null : topbar;
|
|
321
|
-
// The topbar already says the product word, so the rail head steps aside when there is
|
|
322
|
-
// one. The word is the link's only text and the narrow rail folds it out of view, so
|
|
323
|
-
// the name is written out — the mark itself is aria-hidden. The banded layout's own
|
|
324
|
-
// bar says no word, so there the rail keeps the lockup: that layout's head band IS
|
|
325
|
-
// the product's mark. why: docs/components.md#the-page-shell
|
|
326
|
-
const brand = compat ? '' : `<a class="ui-app__brand" href="${esc(safeUrl(brandHref))}" aria-label="${esc(word)}">`
|
|
327
|
-
+ `${prism(`appb-${++_shellUid}`, 24)}<span>${esc(word)}</span></a>`;
|
|
328
|
-
// The named region covers the brand and fold as well as the navigation.
|
|
329
|
-
// The primary navigation keeps its own landmark inside the region.
|
|
330
|
-
// The rail holds primary navigation, so it is not a complementary landmark.
|
|
331
|
-
// A fold needs the toggle that undoes it. `data-rail="auto"` marks a shell whose
|
|
332
|
-
// caller left the choice to the reader; wireShell() applies the stored one there.
|
|
333
|
-
const folded = collapsible && collapsed === true;
|
|
334
|
-
const auto = collapsible && collapsed === null ? ' data-rail="auto"' : '';
|
|
335
|
-
// Where this stands is the one thing the two layouts disagree about on the rail.
|
|
336
|
-
const fold = collapsible ? railToggle(folded) : '';
|
|
337
|
-
// The head band: the product's mark, and the rail's own control at the far end of
|
|
338
|
-
// the same line, under one rule. Either may be absent — a shell with a topbar says
|
|
339
|
-
// the word up there, and `collapsible: false` draws no toggle — so the band itself
|
|
340
|
-
// goes when both are.
|
|
341
|
-
const inHead = banded ? '' : fold;
|
|
342
|
-
const head = brand || inHead
|
|
343
|
-
? `<div class="ui-app__head">${brand}${inHead}</div>`
|
|
344
|
-
: '';
|
|
345
|
-
// The rail's foot: the reader, or the control that took their place. One block
|
|
346
|
-
// either way. why: docs/components.md#the-page-shell
|
|
347
|
-
const foot = banded
|
|
348
|
-
? (fold ? `<div class="ui-app__foot">${fold}</div>` : '')
|
|
349
|
-
: readerBlock(account, signOutHref);
|
|
350
|
-
// The phone's way to the same rail: the menu control, and the drawer it opens. The
|
|
351
|
-
// drawer holds a second copy of the nav and the reader, because a drawer is a dialog
|
|
352
|
-
// and the rail is a landmark; layout.css draws one or the other. The banded layout
|
|
353
|
-
// keeps its reader on the band, so its drawer has no foot.
|
|
354
|
-
const menu = menuControl(menuId);
|
|
355
|
-
const mark = bandBrand(word, brandHref, ++_shellUid);
|
|
356
|
-
const phone = `<div class="ui-app__drawer">${drawer({
|
|
357
|
-
side: 'left',
|
|
358
|
-
size: 'sm',
|
|
359
|
-
title: word,
|
|
360
|
-
id: menuId,
|
|
361
|
-
body: sidebarNav({
|
|
362
|
-
sections: [{ label: navLabel, items: nav }],
|
|
363
|
-
active,
|
|
364
|
-
activeIs: up ? 'section' : 'page',
|
|
365
|
-
ariaLabel: navLabel,
|
|
366
|
-
}),
|
|
367
|
-
// Not portalled: a panel lifted to the page would sit outside the open drawer, inert
|
|
368
|
-
// and under it, so Sign out could not be reached.
|
|
369
|
-
footer: banded ? '' : readerBlock(account, signOutHref, { portal: false }),
|
|
370
|
-
})}</div>`;
|
|
371
|
-
const main = `<main class="ui-app__main${width === 'wide' ? ' ui-app__main--wide' : ''}"${maxWidth ? ` style="--ui-app-main: ${maxWidth}"` : ''}>
|
|
372
|
-
${up || (crumbs.length ? breadcrumbs({ items: crumbs }) : '')}
|
|
373
|
-
${title ? `<h1>${title}</h1>` : ''}
|
|
374
|
-
${sub ? `<p class="ui-app__sub">${sub}</p>` : ''}
|
|
375
|
-
<div class="ui-app__body">${body}</div>
|
|
376
|
-
</main>`;
|
|
377
|
-
// The second column is a box of its own: the band and the page are two rows of it.
|
|
378
|
-
const well = banded
|
|
379
|
-
? `<div class="ui-app__well">${shellBar(search, account, signOutHref, menu + mark)}${main}</div>`
|
|
380
|
-
: `${compat ? '' : `<header class="ui-app__bar ui-app__bar--phone">${menu}${mark}</header>`}${main}`;
|
|
381
|
-
const grid = `<div class="ui-app${banded ? ' ui-app--topbar' : ''}${folded ? ' is-collapsed' : ''}"${auto}>
|
|
382
|
-
<div class="ui-app__rail" role="region" aria-label="Sidebar">
|
|
383
|
-
${head}
|
|
384
|
-
${rail}
|
|
385
|
-
${foot}
|
|
386
|
-
</div>
|
|
387
|
-
${well}
|
|
388
|
-
${phone}
|
|
389
|
-
</div>`;
|
|
390
|
-
return compat
|
|
391
|
-
? `<div class="ui-app-page">${productTopbar(compat).replace('<div class="topbar__in">', `<div class="topbar__in">${menu}`)}${grid}</div>`
|
|
392
|
-
: grid;
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
// ---- Behaviour -----------------------------------------------------------
|
|
396
|
-
// One click listener per document, so a shell rendered after wiring folds too
|
|
397
|
-
// and a frame is wired in its own document. wireShell(root, { persist: false })
|
|
398
|
-
// keeps every shell under root out of the cookie, shells drawn there later
|
|
399
|
-
// included; only `persist: true` on that root turns it back on.
|
|
400
|
-
const _wiredDocs = new WeakSet();
|
|
401
|
-
// The roots wireShell() was handed, per document: a resize has to find a drawer open
|
|
402
|
-
// inside a shadow root, which the document's own querySelectorAll does not enter.
|
|
403
|
-
const _wiredRoots = new WeakMap();
|
|
404
|
-
const _unpersisted = new WeakSet();
|
|
405
|
-
|
|
406
|
-
// The toggle, addressed from the rail that owns it: a fold row of a shell's own rail
|
|
407
|
-
// and nowhere else, so a stray [data-rail-toggle] in the page body folds nothing. The
|
|
408
|
-
// path is written once — the listener, the reflector and wireShell() all have to mean
|
|
409
|
-
// the same control. A descendant and not a child, because the two layouts stand the
|
|
410
|
-
// row in two places: the head band, or the rail's foot.
|
|
411
|
-
// why: docs/components.md#the-page-shell
|
|
412
|
-
const FOLD_PATH = '.ui-app__fold-row > [data-rail-toggle]';
|
|
413
|
-
const RAIL_FOLD = `.ui-app__rail ${FOLD_PATH}`;
|
|
414
|
-
|
|
415
|
-
const DRAWER_LINK = '.ui-app__drawer a.ui-nav__item[href]';
|
|
416
|
-
|
|
417
|
-
// Under an opted-out root? Steps out of a shadow root through its host.
|
|
418
|
-
const optedOut = (node) => {
|
|
419
|
-
for (let n = node; n; n = n.parentNode || n.host) if (_unpersisted.has(n)) return true;
|
|
420
|
-
return false;
|
|
421
|
-
};
|
|
422
|
-
|
|
423
|
-
function setRail(app, collapsed) {
|
|
424
|
-
app.classList.toggle('is-collapsed', collapsed);
|
|
425
|
-
const rail = app.querySelector(':scope > .ui-app__rail');
|
|
426
|
-
if (!rail) return;
|
|
427
|
-
for (const btn of rail.querySelectorAll(`:scope ${FOLD_PATH}`)) {
|
|
428
|
-
btn.setAttribute('aria-expanded', collapsed ? 'false' : 'true');
|
|
429
|
-
btn.setAttribute('aria-label', railName(collapsed));
|
|
430
|
-
const label = btn.querySelector('.ui-nav__label');
|
|
431
|
-
if (label) label.textContent = railName(collapsed);
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
function listen(doc) {
|
|
436
|
-
if (_wiredDocs.has(doc)) return;
|
|
437
|
-
_wiredDocs.add(doc);
|
|
438
|
-
// A drawer left open while the window grows past the phone width would be hidden and
|
|
439
|
-
// still hold the page inert, so it closes there. Its wrapper is not drawn above that
|
|
440
|
-
// width, which is how the stylesheet's breakpoint is read without a second copy of it.
|
|
441
|
-
const view = doc.defaultView;
|
|
442
|
-
if (view) {
|
|
443
|
-
view.addEventListener('resize', () => {
|
|
444
|
-
for (const r of _wiredRoots.get(doc) || []) {
|
|
445
|
-
r.querySelectorAll('.ui-app__drawer .ui-drawer.is-open').forEach((d) => {
|
|
446
|
-
if (view.getComputedStyle(d.parentElement).display === 'none') closeDrawer(d);
|
|
447
|
-
});
|
|
448
|
-
}
|
|
449
|
-
});
|
|
450
|
-
}
|
|
451
|
-
doc.addEventListener('click', (e) => {
|
|
452
|
-
// A shell's own toggle only, in the head of its own rail: a stray
|
|
453
|
-
// [data-rail-toggle] in the page body folds nothing. composedPath() rather
|
|
454
|
-
// than target, so a shell inside an open shadow root is found. closest()
|
|
455
|
-
// rather than a chain of parents, which the head band made one link longer
|
|
456
|
-
// and which said nothing about what it was walking through.
|
|
457
|
-
const path = e.composedPath();
|
|
458
|
-
// A press on a place in the phone drawer closes it. A group's toggle is a button
|
|
459
|
-
// and goes nowhere, so only a link does. why: docs/components.md#the-page-shell
|
|
460
|
-
const row = path.find((n) => n.nodeType === 1 && n.matches(DRAWER_LINK));
|
|
461
|
-
if (row) closeDrawer(row.closest('.ui-drawer'));
|
|
462
|
-
const btn = path.find((n) => n.nodeType === 1 && n.matches(RAIL_FOLD));
|
|
463
|
-
const app = btn && btn.closest('.ui-app');
|
|
464
|
-
if (!app) return;
|
|
465
|
-
const next = !app.classList.contains('is-collapsed');
|
|
466
|
-
setRail(app, next);
|
|
467
|
-
if (!optedOut(app)) {
|
|
468
|
-
try {
|
|
469
|
-
doc.cookie = `${RAIL_COOKIE}=${next ? 'collapsed' : 'expanded'}; path=/; `
|
|
470
|
-
+ `max-age=${RAIL_MAX_AGE}; SameSite=Lax`;
|
|
471
|
-
} catch (err) { /* a sandboxed frame: the fold works, nothing is kept */ }
|
|
472
|
-
}
|
|
473
|
-
// A document with no window (DOMParser, createHTMLDocument) has no CustomEvent to send.
|
|
474
|
-
if (view) {
|
|
475
|
-
app.dispatchEvent(new view.CustomEvent('ui-rail', { bubbles: true, composed: true, detail: { collapsed: next } }));
|
|
476
|
-
}
|
|
477
|
-
});
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
export function wireShell(root = document, { persist } = {}) {
|
|
481
|
-
wireNav(root);
|
|
482
|
-
// The reader's menu is a dropdown() like any other, so it is wired like any
|
|
483
|
-
// other. Idempotent, and a shell with no account draws none to find.
|
|
484
|
-
wireDropdown(root);
|
|
485
|
-
wireDrawer(root);
|
|
486
|
-
// A server cannot know which key the reader holds, so the browser corrects it here —
|
|
487
|
-
// off the ROOT's window, not the global one. why: docs/components.md#the-page-shell
|
|
488
|
-
const here = root.nodeType === 9 ? root : root.ownerDocument;
|
|
489
|
-
const view = here && here.defaultView;
|
|
490
|
-
const key = paletteHotkey(view && view.navigator ? view.navigator.platform : '');
|
|
491
|
-
for (const kbd of root.querySelectorAll('[data-palette-hotkey]')) kbd.textContent = key;
|
|
492
|
-
const doc = root.nodeType === 9 ? root : root.ownerDocument;
|
|
493
|
-
listen(doc);
|
|
494
|
-
if (!_wiredRoots.has(doc)) _wiredRoots.set(doc, new Set());
|
|
495
|
-
const roots = _wiredRoots.get(doc);
|
|
496
|
-
for (const r of roots) if (r !== doc && !(r.host || r).isConnected) roots.delete(r);
|
|
497
|
-
roots.add(root);
|
|
498
|
-
if (persist === false) _unpersisted.add(root);
|
|
499
|
-
else if (persist === true) _unpersisted.delete(root);
|
|
500
|
-
const saved = railCollapsed(cookieOf(doc));
|
|
501
|
-
const apps = [...root.querySelectorAll('.ui-app')];
|
|
502
|
-
if (root.matches && root.matches('.ui-app')) apps.push(root);
|
|
503
|
-
for (const app of apps) {
|
|
504
|
-
if (!app.querySelector(`:scope > ${RAIL_FOLD}`)) continue;
|
|
505
|
-
// The stored choice goes to a shell whose caller left it to the reader — a
|
|
506
|
-
// paint late, where a server drew it without reading the cookie. Any other
|
|
507
|
-
// shell keeps what it was drawn with, and gets its rows' titles if folded.
|
|
508
|
-
const auto = saved != null && !optedOut(app) && app.getAttribute('data-rail') === 'auto';
|
|
509
|
-
setRail(app, auto ? saved : app.classList.contains('is-collapsed'));
|
|
510
|
-
}
|
|
511
|
-
}
|
package/src/components/stat.js
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
// Stat band — a row of key figures, as an HTML string.
|
|
2
|
-
// why: docs/components.md#stat-bands
|
|
3
|
-
//
|
|
4
|
-
// A band is a <dl>: each figure is a <div> holding its label as a <dt> and its
|
|
5
|
-
// value, change and trend as <dd>s, which is the grouping HTML allows inside a
|
|
6
|
-
// description list and the one a screen reader reads as "term, then its values".
|
|
7
|
-
import { esc } from './index.js';
|
|
8
|
-
import { icon } from '../assets/icons.js';
|
|
9
|
-
|
|
10
|
-
export const STAT_VARIANTS = ['band', 'tiles', 'open'];
|
|
11
|
-
export const STAT_TONES = ['good', 'bad', 'neutral'];
|
|
12
|
-
|
|
13
|
-
const cx = (...a) => a.filter(Boolean).join(' ');
|
|
14
|
-
let seq = 0;
|
|
15
|
-
|
|
16
|
-
// The arrow is read off the sign the caller printed, so the figure and the
|
|
17
|
-
// glyph beside it cannot disagree. U+2212, the en dash and an accounting
|
|
18
|
-
// bracket are negatives too: a formatter that typesets its figures uses them.
|
|
19
|
-
const directionOf = (text) => {
|
|
20
|
-
const t = text.trim();
|
|
21
|
-
return /^[-−–(]/.test(t) ? 'down' : /^\+/.test(t) ? 'up' : 'flat';
|
|
22
|
-
};
|
|
23
|
-
const GLYPH = { up: 'arrowUp', down: 'arrowDown', flat: 'minus' };
|
|
24
|
-
const hasChange = (delta) => delta && delta.value != null && delta.value !== '';
|
|
25
|
-
|
|
26
|
-
// One row and one line: the caption, the change, then what it is measured
|
|
27
|
-
// against. Nothing to compare draws no row. why: docs/components.md#stat-bands
|
|
28
|
-
const contextRow = (caption, delta, basisId) => {
|
|
29
|
-
if (!hasChange(delta)) return caption ? `<dd class="ui-stat__caption">${esc(caption)}</dd>` : '';
|
|
30
|
-
// The space is read where the CSS gap is only drawn: "of income+1.2 pts" else.
|
|
31
|
-
const lead = caption ? `<span class="ui-stat__caption">${esc(caption)}</span> ` : '';
|
|
32
|
-
const text = String(delta.value);
|
|
33
|
-
const dir = GLYPH[delta.direction] ? delta.direction : directionOf(text);
|
|
34
|
-
// Never dropped: a basis is passed when the band's caption does not cover this figure.
|
|
35
|
-
const own = delta.basis ? ` <span class="ui-stat__basis">${esc(delta.basis)}</span>` : '';
|
|
36
|
-
const describedby = !own && basisId ? ` aria-describedby="${basisId}"` : '';
|
|
37
|
-
return `<dd class="ui-stat__delta"${describedby}>${lead}${icon(GLYPH[dir])}`
|
|
38
|
-
+ `<span class="ui-stat__change">${esc(text)}</span>${own}</dd>`;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
// `tone` says whether the change is good news, and nothing else. It is never
|
|
42
|
-
// inferred from the direction: costs going up and unclassified rows going down
|
|
43
|
-
// are both real, and a band that paints every rise green is editorialising.
|
|
44
|
-
// A figure with no change has no news to colour.
|
|
45
|
-
const figure = ({ label = '', value = '', caption = '', delta, trend = '' }, tile, basisId) => {
|
|
46
|
-
const tone = hasChange(delta) && STAT_TONES.includes(delta.tone) && delta.tone !== 'neutral' ? delta.tone : '';
|
|
47
|
-
const cls = cx('ui-stat', tone && `ui-stat--${tone}`, tile && 'ui-card ui-card--pad-sm');
|
|
48
|
-
// `trend` is trusted markup — an <svg> the caller drew. The kit sizes and
|
|
49
|
-
// colours it and draws no chart of its own.
|
|
50
|
-
return `<div class="${cls}">`
|
|
51
|
-
+ `<dt class="ui-stat__label">${esc(label)}</dt>`
|
|
52
|
-
+ `<dd class="ui-stat__value">${esc(value)}</dd>`
|
|
53
|
-
+ contextRow(caption, delta, basisId)
|
|
54
|
-
+ (trend ? `<dd class="ui-stat__trend">${trend}</dd>` : '')
|
|
55
|
-
+ '</div>';
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
// `basis` is the band's caption: what every change is measured against, said
|
|
59
|
-
// once before the list the way a table's <caption> is, in every layout — under
|
|
60
|
-
// a row of tiles it would read as a note on the last card.
|
|
61
|
-
//
|
|
62
|
-
// `basisId` is the other way to answer the same question: the id of a statement
|
|
63
|
-
// the caller has already placed before the figures, which each change points at
|
|
64
|
-
// instead. It is for a band whose basis is stated by something beside it — a
|
|
65
|
-
// period control over a dashboard's figures selects the window every change is
|
|
66
|
-
// measured against, and a caption under it would say that again. React's
|
|
67
|
-
// StatBand has carried it since the period showcase; this is the factory's half.
|
|
68
|
-
// `basis` wins when both are passed, because a band that draws its own caption
|
|
69
|
-
// has said it.
|
|
70
|
-
// why: docs/components.md#stat-bands
|
|
71
|
-
export function statBand({ stats = [], variant = 'tiles', basis = '', basisId: shared = '', label, id } = {}) {
|
|
72
|
-
const v = STAT_VARIANTS.includes(variant) ? variant : 'tiles';
|
|
73
|
-
const base = id ? esc(id) : `ui-stats-${++seq}`;
|
|
74
|
-
const basisId = basis ? `${base}-basis` : (shared ? esc(shared) : '');
|
|
75
|
-
const cls = cx('ui-stats', `ui-stats--${v}`, v === 'band' && 'ui-card');
|
|
76
|
-
const named = label ? ` role="group" aria-label="${esc(label)}"` : '';
|
|
77
|
-
const items = stats.map((s) => figure(s, v === 'tiles', basisId)).join('');
|
|
78
|
-
return `<div class="${cls}"${named}>`
|
|
79
|
-
+ (basis ? `<p class="ui-stats__basis" id="${basisId}">${esc(basis)}</p>` : '')
|
|
80
|
-
+ `<dl class="ui-stats__list">${items}</dl>`
|
|
81
|
-
+ '</div>';
|
|
82
|
-
}
|