@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.
Files changed (42) hide show
  1. package/README.md +24 -36
  2. package/guidelines/state-set.md +4 -4
  3. package/package.json +3 -3
  4. package/react/dist/index.css +7 -3
  5. package/react/dist/index.js +12 -5
  6. package/src/index.d.ts +13 -96
  7. package/src/index.js +17 -30
  8. package/src/styles/command-palette.css +9 -5
  9. package/src/styles/drawer.css +8 -0
  10. package/src/styles/dropdown.css +30 -8
  11. package/src/styles/feedback.css +1 -1
  12. package/src/styles/filter-bar.css +5 -2
  13. package/src/styles/input.css +14 -15
  14. package/src/styles/layout.css +5 -2
  15. package/src/styles/table.css +28 -2
  16. package/src/styles/tap-zone.css +9 -4
  17. package/src/styles/topbar.css +8 -6
  18. package/src/components/account-nav.js +0 -37
  19. package/src/components/avatar.js +0 -53
  20. package/src/components/back.js +0 -57
  21. package/src/components/button-busy.js +0 -69
  22. package/src/components/command-palette.js +0 -471
  23. package/src/components/confirm.js +0 -131
  24. package/src/components/drawer.js +0 -169
  25. package/src/components/dropdown.js +0 -1055
  26. package/src/components/feedback.js +0 -171
  27. package/src/components/filter-bar.js +0 -86
  28. package/src/components/footer.js +0 -102
  29. package/src/components/index.js +0 -352
  30. package/src/components/loading.js +0 -127
  31. package/src/components/nav.js +0 -220
  32. package/src/components/overlay.js +0 -263
  33. package/src/components/pagination.js +0 -323
  34. package/src/components/segmented.js +0 -33
  35. package/src/components/shell.js +0 -511
  36. package/src/components/stat.js +0 -82
  37. package/src/components/success.js +0 -131
  38. package/src/components/table-values.js +0 -32
  39. package/src/components/tabs.js +0 -82
  40. package/src/components/toasts.js +0 -118
  41. package/src/components/tooltip.js +0 -347
  42. package/src/components/topbar.js +0 -270
@@ -1,169 +0,0 @@
1
- // Drawer — the kit's edge-anchored overlay panel: a panel that slides in from
2
- // any screen edge over a scrim. Header / scrollable body / footer actions, sizes
3
- // sm|md|lg along the slide axis.
4
- //
5
- // container.innerHTML = drawer({ side: 'right', title: 'Filters', body });
6
- // wireDrawer(container); // scrim/Esc/close-button + focus trap
7
- //
8
- // A page trigger opens it by id: <button data-drawer-open="ID">. Inertness,
9
- // Escape and the focus trap are shared with confirm(): both are
10
- // "content over a scrim, focus-trapped, Esc-dismissable", and they push onto one
11
- // stack in ./overlay.js, so the two can never disagree about which of them the
12
- // keyboard belongs to.
13
- import { esc, icon } from './index.js';
14
- import { OVERLAY_LAYER, adoptOverlay, focusablesIn, popOverlay, pushOverlay, returnFocus, syncOverlays } from './overlay.js';
15
-
16
- const cx = (...a) => a.filter(Boolean).join(' ');
17
-
18
- // Module counter (never Date/random) → stable, unique ids for aria-labelledby.
19
- let _uid = 0;
20
- const nextId = (p = 'drawer') => `${p}-${++_uid}`;
21
-
22
- /**
23
- * The public factory. Returns an HTML string; wire it with wireDrawer().
24
- *
25
- * `specimen` renders open as a *picture* of the panel — see confirm() for why a
26
- * documentation page wants that. Use `open` when the drawer is real.
27
- *
28
- * @param {object} [o]
29
- * @param {string} [o.side] 'right' (default) | 'left' | 'top' | 'bottom'
30
- * @param {string} [o.size] 'sm' | 'md' (default) | 'lg', along the slide axis
31
- * @param {string} [o.title] header heading, also the accessible name
32
- * @param {string} [o.body] scrollable body HTML (trusted markup)
33
- * @param {string} [o.footer] pinned footer actions HTML (trusted markup)
34
- * @param {boolean} [o.open] render already-open, as a real panel
35
- * @param {boolean} [o.specimen] render open as a picture of the panel
36
- * @param {string} [o.id] root id a [data-drawer-open] trigger targets
37
- * @param {string} [o.ariaLabel] accessible name when there is no visible title
38
- * @param {boolean} [o.dismissible] close button + scrim/Esc dismiss (default true)
39
- * @param {string} [o.closeLabel] accessible name for the close button
40
- * @returns {string} html
41
- */
42
- export function drawer({
43
- side = 'right', size = 'md', title, body = '', footer = '',
44
- open = false, specimen = false, id, ariaLabel, dismissible = true, closeLabel = 'Close',
45
- } = {}) {
46
- const titleId = title ? nextId('drawer-title') : null;
47
- const nameAttr = titleId
48
- ? `aria-labelledby="${titleId}"`
49
- : `aria-label="${esc(ariaLabel || 'Dialog')}"`;
50
-
51
- const closeBtn = dismissible
52
- ? `<button type="button" class="ui-drawer__close" data-drawer-close aria-label="${esc(closeLabel)}">${icon('x')}</button>`
53
- : '';
54
- const header = (title || dismissible)
55
- ? `<header class="ui-drawer__header">`
56
- + (title ? `<h2 class="ui-drawer__title" id="${titleId}">${esc(title)}</h2>` : '<span></span>')
57
- + `${closeBtn}</header>`
58
- : '';
59
- const bodyEl = `<div class="ui-drawer__body">${body}</div>`;
60
- const footEl = footer ? `<footer class="ui-drawer__footer">${footer}</footer>` : '';
61
-
62
- const rootCls = cx('ui-drawer', `ui-drawer--${side}`, `ui-drawer--${size}`, (open || specimen) && 'is-open');
63
- return `<div class="${esc(rootCls)}"${specimen ? '' : ' data-drawer'} data-drawer-side="${esc(side)}"`
64
- + `${dismissible ? '' : ' data-drawer-static'}${id ? ` id="${esc(id)}"` : ''}>`
65
- + `<div class="ui-drawer__scrim" data-drawer-scrim></div>`
66
- + `<aside class="ui-drawer__panel" role="dialog"${specimen ? '' : ' aria-modal="true"'} ${nameAttr} tabindex="-1" data-drawer-panel>`
67
- + `${header}${bodyEl}${footEl}`
68
- + `</aside></div>`;
69
- }
70
-
71
- /**
72
- * One group inside a drawer's body: an optional heading over label/value rows,
73
- * then any trailing markup (an action that belongs to the group). Rows render as
74
- * a <dl>, so a screen reader hears each label with its value.
75
- *
76
- * drawer({ title, body: drawerSection({ title: 'Source', rows: [['Statement', '#4102']] }) })
77
- *
78
- * why: docs/components.md#the-drawer
79
- *
80
- * @param {object} [o]
81
- * @param {string} [o.title] group heading (escaped)
82
- * @param {Array<[string, string | { html: string }]>} [o.rows] [label, value] pairs. Both are
83
- * escaped, since a value is usually data (a bank feed's description); pass the value as
84
- * `{ html: '…' }` to write trusted markup as it is
85
- * @param {string} [o.body] trailing markup after the rows (trusted)
86
- * @returns {string} html
87
- */
88
- export function drawerSection({ title, rows = [], body = '' } = {}) {
89
- const head = title ? `<h3 class="ui-drawer__section-title">${esc(title)}</h3>` : '';
90
- const value = (v) => (v !== null && typeof v === 'object' && 'html' in v ? String(v.html) : esc(v));
91
- const list = rows.length
92
- ? `<dl class="ui-drawer__rows">${rows.map(([term, detail]) =>
93
- `<div class="ui-drawer__row"><dt>${esc(term)}</dt><dd>${value(detail)}</dd></div>`).join('')}</dl>`
94
- : '';
95
- return `<section class="ui-drawer__section">${head}${list}${body}</section>`;
96
- }
97
-
98
- // ---- Shared behaviour ----------------------------------------------------
99
- // One open/close/scrim/close-button implementation for every drawer in the kit;
100
- // inertness, Escape and Tab belong to the overlay stack. Per-instance handlers
101
- // are attached once (guarded by a flag on the node); the [data-drawer-open]
102
- // delegation is attached once per document (guarded by a flag on the document
103
- // node, so multiple documents each get their own). Safe to call repeatedly
104
- // (Storybook re-renders).
105
-
106
- export function openDrawer(root, returnFocusTo) {
107
- if (!root || root.classList.contains('is-open')) return;
108
- root.__drawerReturn = returnFocusTo
109
- || (document.activeElement instanceof HTMLElement ? document.activeElement : null);
110
- root.classList.add('is-open');
111
- const panel = root.querySelector('[data-drawer-panel]');
112
- const dismissible = !root.hasAttribute('data-drawer-static');
113
- pushOverlay(root, panel, dismissible ? () => closeDrawer(root) : null, OVERLAY_LAYER.drawer);
114
- // Focus the first focusable control, else the panel itself.
115
- const first = panel && focusablesIn(panel)[0];
116
- (first || panel)?.focus();
117
- }
118
-
119
- export function closeDrawer(root) {
120
- if (!root || !root.classList.contains('is-open')) return;
121
- root.classList.remove('is-open');
122
- const back = root.__drawerReturn;
123
- root.__drawerReturn = null;
124
- // The trigger can be gone by now — focus() on a detached node does nothing at
125
- // all, which leaves the reader with no place on the page. popOverlay is told
126
- // where focus is headed so it can catch the other way that happens: a trigger
127
- // still on the page, inside what an overlay left open underneath has re-hidden.
128
- popOverlay(root, back);
129
- returnFocus(back, root.ownerDocument);
130
- }
131
-
132
- export function wireDrawer(root = document) {
133
- const scope = root === document ? document : root;
134
- scope.querySelectorAll('[data-drawer]').forEach((dr) => {
135
- if (dr.__drawerWired) return;
136
- dr.__drawerWired = true;
137
- const dismissible = !dr.hasAttribute('data-drawer-static');
138
-
139
- dr.querySelector('[data-drawer-scrim]')?.addEventListener('click', () => {
140
- if (dismissible) closeDrawer(dr);
141
- });
142
- dr.querySelectorAll('[data-drawer-close]').forEach((btn) =>
143
- btn.addEventListener('click', () => closeDrawer(dr)));
144
-
145
- // Rendered with `open: true`, so nothing called openDrawer() and nothing put
146
- // it on the stack. Adopting it here is what makes its aria-modal true.
147
- adoptOverlay(dr, dr.querySelector('[data-drawer-panel]'), dismissible ? () => closeDrawer(dr) : null,
148
- OVERLAY_LAYER.drawer);
149
- });
150
-
151
- const doc = root === document ? document : (root.ownerDocument || document);
152
- if (!doc.__drawerGlobalWired) {
153
- doc.__drawerGlobalWired = true;
154
- // Any [data-drawer-open="ID"] trigger opens the matching drawer.
155
- doc.addEventListener('click', (e) => {
156
- // composedPath() and not target: a trigger inside an open shadow root is retargeted
157
- // to its host here, and its drawer is found in the tree the trigger is in.
158
- const opener = e.composedPath().find((n) => n.nodeType === 1 && n.hasAttribute('data-drawer-open'));
159
- if (!opener) return;
160
- e.preventDefault();
161
- const id = opener.getAttribute('data-drawer-open');
162
- const target = (opener.getRootNode().getElementById?.(id)) || doc.getElementById(id);
163
- if (target) openDrawer(target, opener);
164
- });
165
- }
166
- // This runs on every re-render, which is the moment to notice that an overlay
167
- // was destroyed while it was open and hand the page back.
168
- syncOverlays(doc);
169
- }