@monster-orange/den-ui 0.7.5 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +240 -0
- package/package.json +15 -1
- package/src/bulk-bar.css +96 -0
- package/src/bulk-bar.d.ts +45 -0
- package/src/bulk-bar.js +147 -0
- package/src/button.css +59 -0
- package/src/button.d.ts +27 -0
- package/src/button.js +81 -0
- package/src/filter-bar.css +184 -0
- package/src/filter-bar.d.ts +67 -0
- package/src/filter-bar.js +307 -0
- package/src/icons.js +10 -4
- package/src/kit.d.ts +49 -0
- package/src/kit.js +70 -0
- package/src/panel-fold.css +150 -0
- package/src/panel-fold.d.ts +67 -0
- package/src/panel-fold.js +152 -0
- package/src/savestate.css +75 -0
- package/src/savestate.d.ts +73 -0
- package/src/savestate.js +294 -0
- package/src/setting-row.css +56 -0
- package/src/setting-row.d.ts +75 -0
- package/src/setting-row.js +260 -0
- package/src/shell-client.d.ts +13 -0
- package/src/shell-client.js +49 -2
- package/src/shell-html.d.ts +52 -0
- package/src/shell-html.js +104 -5
- package/src/shell.css +37 -0
- package/src/strings.js +89 -0
- package/src/switch.css +88 -0
- package/src/switch.d.ts +32 -0
- package/src/switch.js +85 -0
package/README.md
CHANGED
|
@@ -142,6 +142,7 @@ syncPinToggles }`.
|
|
|
142
142
|
DenUI.update.set({ version }); // the update pill; .hide()
|
|
143
143
|
DenUI.report.open({ prefill }); // ⌘⇧F and any [data-den-report] too
|
|
144
144
|
DenUI.busy.run(action, run, opts) // the working pop-up (busy.js)
|
|
145
|
+
DenUI.saveState(el, { save, copyText, watch }) // save-state line
|
|
145
146
|
|
|
146
147
|
### The adapter
|
|
147
148
|
|
|
@@ -441,6 +442,245 @@ never converted to HTML and back).
|
|
|
441
442
|
- The content element has `data-md-dirty` while it holds unsaved text
|
|
442
443
|
(for an update pill's `askFirst`).
|
|
443
444
|
|
|
445
|
+
## The save-state line (`den-savestate`)
|
|
446
|
+
|
|
447
|
+
- `src/savestate.js`, `src/savestate.css` (exports `./savestate`,
|
|
448
|
+
`./savestate.css`): what an autosaving editor says about its text. It
|
|
449
|
+
works with any input, textarea or editor; the host gives the save.
|
|
450
|
+
|
|
451
|
+
const line = createSaveState(document.querySelector("#save-line"), {
|
|
452
|
+
save: () => api.saveDraft(field.value), // rejects on failure
|
|
453
|
+
copyText: () => `${title.value}\n\n${field.value}`,
|
|
454
|
+
watch: field, // input → changed(), focusout → flush()
|
|
455
|
+
});
|
|
456
|
+
// line.changed(), line.flush(), line.retry(), line.state(), line.destroy()
|
|
457
|
+
|
|
458
|
+
- The element becomes `<p class="den-savestate">` with `role="status"`,
|
|
459
|
+
`aria-live="off"` and `data-state` (`idle`, `saving`, `saved`,
|
|
460
|
+
`error`): a 6 px dot, then the words, 13 px on a 20 px line (idle is
|
|
461
|
+
empty and keeps its height).
|
|
462
|
+
- It saves 800 ms after the last change, and at once on blur and when the
|
|
463
|
+
page goes hidden. "Saving…" shows only when a save takes more than
|
|
464
|
+
400 ms; "Saved" (title "Saved at {time}", from `time.js`) stays until the
|
|
465
|
+
next save. A failure shows "Not saved. Retrying…" with Copy text (what
|
|
466
|
+
`copyText()` returns), retries at 2 s, 4 s and 8 s, then every 30 s, and
|
|
467
|
+
at once when the browser is back online.
|
|
468
|
+
- A visually hidden polite region beside the line says only the error and
|
|
469
|
+
its recovery; `aria-live="off"` keeps the routine "Saved" quiet.
|
|
470
|
+
- Only the dot's colour moves, over `--dur-fast`; none under reduced
|
|
471
|
+
motion. Its words are `kit.savestate.*` in `strings.js` (en, es, ja).
|
|
472
|
+
- `saveScheduler({ save, onChange })` is the same timing with no DOM.
|
|
473
|
+
- Link `savestate.css` in the page's `<head>`. Without that, savestate.js
|
|
474
|
+
links it from `opts.css`, else from beside another kit stylesheet on the
|
|
475
|
+
page.
|
|
476
|
+
|
|
477
|
+
## The panel fold toggle, its edge strip and the switch
|
|
478
|
+
|
|
479
|
+
- `src/panel-fold.js`, `src/panel-fold.css` (exports `./panel-fold`,
|
|
480
|
+
`./panel-fold.css`): a side panel that folds away so the main column
|
|
481
|
+
reads clean (issues 548 and 549). The host keeps the state (shown or
|
|
482
|
+
folded, remembered or not) and lays its page out; the kit draws the two
|
|
483
|
+
controls and owns their words, keys and focus.
|
|
484
|
+
|
|
485
|
+
import { foldToggleHtml, edgeStripHtml, hydrateFoldToggle,
|
|
486
|
+
hydrateEdgeStrip } from "@monster-orange/den-ui/panel-fold";
|
|
487
|
+
// link panel-fold.css after tokens.css
|
|
488
|
+
bar.innerHTML = foldToggleHtml({ pressed: true, controls: "side", lang });
|
|
489
|
+
slot.innerHTML = edgeStripHtml({ count: 2, controls: "side", lang });
|
|
490
|
+
const fold = hydrateFoldToggle(bar.querySelector(".den-fold"), {
|
|
491
|
+
onToggle: (next) => layout(next ? "panel" : "folded"),
|
|
492
|
+
});
|
|
493
|
+
const strip = hydrateEdgeStrip(slot.querySelector(".den-strip"), {
|
|
494
|
+
onShow: () => { layout("panel"); fold.set(true); },
|
|
495
|
+
});
|
|
496
|
+
fold.set(kept === "panel"); // the host's own change: no call
|
|
497
|
+
strip.setCount(3);
|
|
498
|
+
|
|
499
|
+
- **The toggle** is a `<button class="den-fold">` with an icon and the
|
|
500
|
+
kit's word ("Panel"), `aria-pressed` (pressed: the panel shows) and
|
|
501
|
+
`aria-controls` when given. A press (click, Enter, Space) moves
|
|
502
|
+
`aria-pressed` and calls `onToggle(next)`; focus stays on it. 32px tall;
|
|
503
|
+
44px on a phone or a touch screen.
|
|
504
|
+
- **The strip** goes where the folded panel was: 40px wide, a
|
|
505
|
+
`role="complementary"` region named "Panel, hidden", a "Show panel" icon
|
|
506
|
+
button (32px, a 44×44px tap on a phone or a touch screen) and the count
|
|
507
|
+
under it (none at 0, 99+ past 99). The count is seen as a number and
|
|
508
|
+
heard as the kit's badge words: `what` is `"open"` (default),
|
|
509
|
+
`"waiting"`, `"down"` or `"running"`. Show panel calls `onShow()`; when
|
|
510
|
+
the host then hides the strip and leaves focus there, focus goes to the
|
|
511
|
+
fold toggle for the same panel (else to the panel, when it takes
|
|
512
|
+
focus). A focus the host moved itself is kept.
|
|
513
|
+
- Hosts pass data, never words: a `label`, `title` or `aria-label` given to
|
|
514
|
+
either builder is not used. Words: `kit.fold.panel`, `kit.fold.show`,
|
|
515
|
+
`kit.fold.hidden` and `kit.badge.*`, in en, es and ja. Show or hide each
|
|
516
|
+
with the `hidden` attribute.
|
|
517
|
+
- `src/switch.js`, `src/switch.css` (exports `./switch`, `./switch.css`):
|
|
518
|
+
a labelled on/off control (issue 551).
|
|
519
|
+
|
|
520
|
+
import { switchHtml, hydrateSwitch } from "@monster-orange/den-ui/switch";
|
|
521
|
+
row.innerHTML = switchHtml({ label: "Show notes in the text",
|
|
522
|
+
help: "Kept on this device.", on: true, disabled: false, id: "notes" });
|
|
523
|
+
const sw = hydrateSwitch(row.querySelector(".den-switch"), {
|
|
524
|
+
onChange: (on) => save(on),
|
|
525
|
+
});
|
|
526
|
+
sw.set(false); sw.setDisabled(true); sw.on(); sw.destroy();
|
|
527
|
+
|
|
528
|
+
- `<label class="den-switch">` holds the label, the help under it, then an
|
|
529
|
+
`<input type="checkbox" role="switch">` named by the label alone
|
|
530
|
+
(`aria-labelledby`) and described by the help (`aria-describedby`). The
|
|
531
|
+
label and help are the host's own words, the name of its own setting,
|
|
532
|
+
as a page's name in the rail is; the switch adds no words of its own (a
|
|
533
|
+
screen reader says on and off). No label: nothing is drawn. No `id`: one
|
|
534
|
+
of the kit's (`den-sw-N`). A click on the row, Space or Enter calls
|
|
535
|
+
`onChange(on)`; disabled is out of the tab order and calls nothing.
|
|
536
|
+
- The row is 44px tall. The track is `--accent-fill` on and
|
|
537
|
+
`--border-strong` off (`--border` when disabled); the knob is
|
|
538
|
+
`--surface` and slides over `--dur-fast`, not at all under reduced
|
|
539
|
+
motion. A transparent border shows the track in forced colours.
|
|
540
|
+
- Under `style-src 'self'`: no inline styles, nothing injected.
|
|
541
|
+
|
|
542
|
+
## A list's filter bar and bulk bar
|
|
543
|
+
|
|
544
|
+
Two parts for a list of things (issues 552 and 553). Both are data-only:
|
|
545
|
+
the host passes its facets, counts, choices, actions and callbacks; the
|
|
546
|
+
kit draws the markup and owns every word, in en, es and ja. A facet's,
|
|
547
|
+
an option's and an action's label are the host's own words, given as data
|
|
548
|
+
(as a rail page's label is); the kit never takes a host's words for its
|
|
549
|
+
own parts or names.
|
|
550
|
+
|
|
551
|
+
- `src/filter-bar.js`, `src/filter-bar.css` (exports `./filter-bar`,
|
|
552
|
+
`./filter-bar.css`): one "Filters (n)" button that opens a panel of
|
|
553
|
+
facets, and what is chosen as chips under the row, each with ×, then
|
|
554
|
+
Clear all.
|
|
555
|
+
|
|
556
|
+
import { mountFilterBar } from "@monster-orange/den-ui/filter-bar";
|
|
557
|
+
// link filter-bar.css after tokens.css
|
|
558
|
+
const bar = mountFilterBar(el, {
|
|
559
|
+
id: "docs-filter",
|
|
560
|
+
facets: [{ id: "status", label: "Status",
|
|
561
|
+
options: [{ value: "draft", label: "Draft", count: 2 }] }],
|
|
562
|
+
selected: { status: ["draft"] },
|
|
563
|
+
onChange: (selected, change) => applyFilter(selected),
|
|
564
|
+
start: findBox, // the host's nodes before Filters
|
|
565
|
+
end: [sortButton, addButton],// and after it, in the same row
|
|
566
|
+
});
|
|
567
|
+
bar.update({ facets }); // new counts; focus stays put
|
|
568
|
+
|
|
569
|
+
`change` is `{ facet, value, on }` (an option or a chip),
|
|
570
|
+
`{ clear: facetId }` (a facet's Clear) or `{ clear: null }` (Clear
|
|
571
|
+
all). Each option shows its count; one with 0 can't be chosen unless it is chosen.
|
|
572
|
+
Filters is a disclosure (`aria-expanded`, `aria-controls`); the panel
|
|
573
|
+
is a group named "Filters", a group per facet, its options toggle
|
|
574
|
+
buttons (`aria-pressed`). Esc in the panel closes it, focus on Filters.
|
|
575
|
+
Removing a chip focuses the next chip, else the one before, else
|
|
576
|
+
Filters; Clear all focuses Filters; a facet's Clear its first option.
|
|
577
|
+
Under 720px the start node takes its own line and the chips scroll in
|
|
578
|
+
their own row; there, and on `(pointer: coarse)`, every control is
|
|
579
|
+
`--tap` (44px) tall. `filterBarHtml(data)` draws it in Node.
|
|
580
|
+
|
|
581
|
+
- `src/bulk-bar.js`, `src/bulk-bar.css` (exports `./bulk-bar`,
|
|
582
|
+
`./bulk-bar.css`): "{n} selected", Clear, and the host's actions with
|
|
583
|
+
their counts ("Pause 3"), sticky at the bottom of the list.
|
|
584
|
+
|
|
585
|
+
import { mountBulkBar } from "@monster-orange/den-ui/bulk-bar";
|
|
586
|
+
const bulk = mountBulkBar(el, {
|
|
587
|
+
count: 3,
|
|
588
|
+
actions: [{ id: "pause", label: "Pause", count: 3 },
|
|
589
|
+
{ id: "move", label: "Move", count: 3, disabled: true }],
|
|
590
|
+
onAction: (id, button) => // a host's own dialog: the button
|
|
591
|
+
askConfirm({ title, message, opener: button }), // gets focus back
|
|
592
|
+
onClear: () => unselectAll(),
|
|
593
|
+
returnFocus: () => selectAllBox,
|
|
594
|
+
});
|
|
595
|
+
bulk.update({ count: 0 }); // hidden at 0
|
|
596
|
+
|
|
597
|
+
`el` becomes the bar,
|
|
598
|
+
`<div class="den-bulk" role="region" aria-label="3 selected">`; a
|
|
599
|
+
visually hidden polite region beside it says the count when it
|
|
600
|
+
changes and "Selection cleared" after Clear. A disabled action never
|
|
601
|
+
reaches the host. Clear hides the bar at once and focus goes to
|
|
602
|
+
`returnFocus`. It sticks 12px over the bottom of the scrolling list
|
|
603
|
+
(and over the safe area). Under 720px each action takes the bar's
|
|
604
|
+
width; there, and on a touch screen, every button is 44px tall.
|
|
605
|
+
`bulkBarHtml(data)` draws it in Node.
|
|
606
|
+
|
|
607
|
+
- `DenUI.filterBar(el, opts)` and `DenUI.bulkBar(el, opts)` mount them
|
|
608
|
+
in the kit's language. Den serves the four files at `/kit/`.
|
|
609
|
+
- The words are `kit.filter.*` and `kit.bulk.*` in `strings.js`. Both
|
|
610
|
+
work under `script-src 'self'; style-src 'self'`.
|
|
611
|
+
|
|
612
|
+
## The general button, the page action menu and the settings row
|
|
613
|
+
|
|
614
|
+
Three pieces, data in, the kit's words out (en, es, ja).
|
|
615
|
+
|
|
616
|
+
- **The general button** (issue 556): `src/button.css` and `src/button.js`
|
|
617
|
+
(exports `./button.css`, `./button`). `.den-btn` for any page, inside the
|
|
618
|
+
frame or not: secondary is the base, `.primary` the accent fill, `.sm`
|
|
619
|
+
the small size; a link drawn as a button is `a.den-btn`. A visible focus
|
|
620
|
+
ring, and a 44px tap on a touch screen (its box unchanged). These are
|
|
621
|
+
the values Den's frame drew; Den now links `button.css` and keeps no
|
|
622
|
+
copy.
|
|
623
|
+
|
|
624
|
+
buttonHtml({ label, variant: "primary", size: "sm", href?, type?,
|
|
625
|
+
disabled?, id?, attrs: { "data-…": …, "aria-…": … } })
|
|
626
|
+
|
|
627
|
+
A disabled link has no href and `aria-disabled`. Any other variant,
|
|
628
|
+
size or attribute is dropped.
|
|
629
|
+
|
|
630
|
+
- **The page action menu** (issue 555), in `shell-html.js` and
|
|
631
|
+
`shell-client.js` (its look in `shell.css`, More in `button.css`):
|
|
632
|
+
|
|
633
|
+
btnBox.innerHTML = pageMenuButtonHtml({ id: "doc-more", lang });
|
|
634
|
+
hydratePageMenu(document.getElementById("doc-more"), {
|
|
635
|
+
items: [ // or () => items, each opening
|
|
636
|
+
{ id: "edit", label: "Edit", href: "/doc/edit" },
|
|
637
|
+
{ id: "copy", label: { key: "app.copy" }, onSelect: copyLink },
|
|
638
|
+
{ hr: true },
|
|
639
|
+
{ id: "dl", label: "Download", disabled: true,
|
|
640
|
+
note: "Downloads are off.", noteHref: "/settings#downloads" },
|
|
641
|
+
],
|
|
642
|
+
onSelect: (id, item) => {}, // an item with no onSelect
|
|
643
|
+
lang,
|
|
644
|
+
});
|
|
645
|
+
|
|
646
|
+
"More ▾" is the kit's word. A label or note is the host's words, or
|
|
647
|
+
`{ key, vars }` in the kit's tables (add yours with `addStrings`). A
|
|
648
|
+
disabled item has `aria-disabled`, is faint, does nothing (the menu
|
|
649
|
+
stays open), and is described by its note, right under it: a row to
|
|
650
|
+
follow when it has `noteHref`, else a line. Keys, focus back and a press
|
|
651
|
+
outside are ◐ ▾'s. Below 720px (or on touch) More and each row are 44px.
|
|
652
|
+
`menuRowHtml(row)` is now exported: the row builder the kit's own menus
|
|
653
|
+
use (◐ ▾ and the account menu draw exactly what they drew before); it
|
|
654
|
+
takes `disabled`, `describedBy`, `id` and `cls` too.
|
|
655
|
+
|
|
656
|
+
- **The settings on/off row** (issue 554): `src/setting-row.js` and
|
|
657
|
+
`src/setting-row.css` (exports `./setting-row`, `./setting-row.css`).
|
|
658
|
+
Link them with `button.css` and `savestate.css`.
|
|
659
|
+
|
|
660
|
+
const row = mountSettingRow(el, {
|
|
661
|
+
id: "downloads", label: "Owners can download", help: "…",
|
|
662
|
+
checked: true, who: ["Admins", "Owners"], // [] is nobody
|
|
663
|
+
last: { by: "@sam", at: "2026-11-18T10:40:00Z" }, // null: none yet
|
|
664
|
+
readOnly: false, lang,
|
|
665
|
+
onSave: (checked) => api.save(checked), // rejects on failure
|
|
666
|
+
});
|
|
667
|
+
row.set("saved"); row.checked(); row.destroy();
|
|
668
|
+
|
|
669
|
+
A checkbox and its label, the help line, Save, the save state and the
|
|
670
|
+
line "Admins and Owners can change this · Last changed 2 minutes ago by
|
|
671
|
+
@sam". Save calls `onSave` with the box's state: "Saving…" past 400 ms,
|
|
672
|
+
then "Saved", or "Not saved. Try again."; Save is busy
|
|
673
|
+
(`aria-disabled`) meanwhile and keeps focus; a change to the box clears
|
|
674
|
+
"Saved". The state line wears `savestate.css`'s look and is a polite
|
|
675
|
+
status. `settingRowHtml(o)` draws it in Node, and
|
|
676
|
+
`hydrateSettingRow(el, { onSave })` wires it. With `form` (`action`, and
|
|
677
|
+
`csrf`, `field`, `method` if needed) it is a form that posts with no
|
|
678
|
+
script. `readOnly` disables the box
|
|
679
|
+
and Save. The words are `kit.setrow.*` and `kit.savestate.*`.
|
|
680
|
+
|
|
681
|
+
- `DenUI.buttonHtml`, `DenUI.pageMenu(btn, opts)` and
|
|
682
|
+
`DenUI.settingRow(el, opts)` are the same, in the kit's language.
|
|
683
|
+
|
|
444
684
|
## 0.7.1
|
|
445
685
|
|
|
446
686
|
The top bar's search sits in the same place in every product (issue 303).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@monster-orange/den-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Den's UI kit: tokens, fonts and shared components, framework-free",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"./busy": "./src/busy.js",
|
|
21
21
|
"./busy-words": "./src/busy-words.js",
|
|
22
22
|
"./dialog": "./src/dialog.js",
|
|
23
|
+
"./savestate": "./src/savestate.js",
|
|
23
24
|
"./strings": "./src/strings.js",
|
|
24
25
|
"./icons": "./src/icons.js",
|
|
25
26
|
"./shell-html": "./src/shell-html.js",
|
|
@@ -36,6 +37,19 @@
|
|
|
36
37
|
"./dialog.css": "./src/dialog.css",
|
|
37
38
|
"./markdown-editor": "./src/markdown-editor.js",
|
|
38
39
|
"./markdown-editor.css": "./src/markdown-editor.css",
|
|
40
|
+
"./savestate.css": "./src/savestate.css",
|
|
41
|
+
"./panel-fold": "./src/panel-fold.js",
|
|
42
|
+
"./panel-fold.css": "./src/panel-fold.css",
|
|
43
|
+
"./switch": "./src/switch.js",
|
|
44
|
+
"./switch.css": "./src/switch.css",
|
|
45
|
+
"./filter-bar": "./src/filter-bar.js",
|
|
46
|
+
"./filter-bar.css": "./src/filter-bar.css",
|
|
47
|
+
"./bulk-bar": "./src/bulk-bar.js",
|
|
48
|
+
"./bulk-bar.css": "./src/bulk-bar.css",
|
|
49
|
+
"./button": "./src/button.js",
|
|
50
|
+
"./button.css": "./src/button.css",
|
|
51
|
+
"./setting-row": "./src/setting-row.js",
|
|
52
|
+
"./setting-row.css": "./src/setting-row.css",
|
|
39
53
|
"./inventory": {
|
|
40
54
|
"types": "./inventory/nav-inventory.d.ts",
|
|
41
55
|
"default": "./inventory/nav-inventory.js"
|
package/src/bulk-bar.css
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/* den-ui: the bulk bar's look (bulk-bar.js, issue 553). Tokens only: no
|
|
2
|
+
colour of its own. Linked, never injected: clean under style-src
|
|
3
|
+
'self'. Sticky at the bottom of the scrolling list, over its rows. */
|
|
4
|
+
.den-bulk {
|
|
5
|
+
position: sticky;
|
|
6
|
+
bottom: max(var(--space-3), env(safe-area-inset-bottom, 0px));
|
|
7
|
+
z-index: 2;
|
|
8
|
+
display: flex;
|
|
9
|
+
flex-wrap: wrap;
|
|
10
|
+
align-items: center;
|
|
11
|
+
gap: var(--space-2) var(--space-3);
|
|
12
|
+
box-sizing: border-box;
|
|
13
|
+
margin-top: var(--space-3);
|
|
14
|
+
padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4);
|
|
15
|
+
font-family: var(--sans);
|
|
16
|
+
font-size: var(--fs-s);
|
|
17
|
+
color: var(--text);
|
|
18
|
+
background: var(--surface);
|
|
19
|
+
border: 1px solid var(--border-strong);
|
|
20
|
+
border-radius: var(--radius);
|
|
21
|
+
box-shadow: var(--shadow-menu);
|
|
22
|
+
}
|
|
23
|
+
.den-bulk[hidden] {
|
|
24
|
+
display: none;
|
|
25
|
+
}
|
|
26
|
+
.den-bulk-count {
|
|
27
|
+
font-weight: 500;
|
|
28
|
+
font-variant-numeric: tabular-nums;
|
|
29
|
+
}
|
|
30
|
+
.den-bulk-actions {
|
|
31
|
+
display: inline-flex;
|
|
32
|
+
flex-wrap: wrap;
|
|
33
|
+
gap: var(--space-2);
|
|
34
|
+
margin-inline-start: auto;
|
|
35
|
+
}
|
|
36
|
+
.den-bulk-clear,
|
|
37
|
+
.den-bulk-act {
|
|
38
|
+
display: inline-flex;
|
|
39
|
+
align-items: center;
|
|
40
|
+
justify-content: center;
|
|
41
|
+
box-sizing: border-box;
|
|
42
|
+
min-height: var(--tap-min);
|
|
43
|
+
margin: 0;
|
|
44
|
+
padding: 0 var(--space-3);
|
|
45
|
+
font: inherit;
|
|
46
|
+
white-space: nowrap;
|
|
47
|
+
color: var(--text);
|
|
48
|
+
background: var(--surface);
|
|
49
|
+
border: 1px solid var(--border-strong);
|
|
50
|
+
border-radius: var(--radius-button);
|
|
51
|
+
cursor: pointer;
|
|
52
|
+
}
|
|
53
|
+
.den-bulk-clear {
|
|
54
|
+
border-color: transparent;
|
|
55
|
+
background: transparent;
|
|
56
|
+
color: var(--accent-text);
|
|
57
|
+
}
|
|
58
|
+
.den-bulk-act:hover:not([disabled]) {
|
|
59
|
+
border-color: var(--accent);
|
|
60
|
+
}
|
|
61
|
+
.den-bulk-act[disabled] {
|
|
62
|
+
cursor: not-allowed;
|
|
63
|
+
border-style: dashed;
|
|
64
|
+
color: var(--muted);
|
|
65
|
+
}
|
|
66
|
+
.den-bulk-clear:focus-visible,
|
|
67
|
+
.den-bulk-act:focus-visible {
|
|
68
|
+
outline: 2px solid var(--accent);
|
|
69
|
+
outline-offset: 2px;
|
|
70
|
+
}
|
|
71
|
+
/* The live region beside the bar: heard, never seen. */
|
|
72
|
+
.den-bulk-live {
|
|
73
|
+
position: absolute;
|
|
74
|
+
width: 1px;
|
|
75
|
+
height: 1px;
|
|
76
|
+
padding: 0;
|
|
77
|
+
margin: -1px;
|
|
78
|
+
overflow: hidden;
|
|
79
|
+
clip: rect(0 0 0 0);
|
|
80
|
+
white-space: nowrap;
|
|
81
|
+
border: 0;
|
|
82
|
+
}
|
|
83
|
+
/* A phone or a narrow pane: each action the bar's width. */
|
|
84
|
+
@media (max-width: 720px) {
|
|
85
|
+
.den-bulk-actions {
|
|
86
|
+
flex: 1 1 100%;
|
|
87
|
+
flex-direction: column;
|
|
88
|
+
margin-inline-start: 0;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
@media (max-width: 720px), (pointer: coarse) {
|
|
92
|
+
.den-bulk-clear,
|
|
93
|
+
.den-bulk-act {
|
|
94
|
+
min-height: var(--tap);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/** One of the host's actions on the selected rows. */
|
|
2
|
+
export interface BulkAction {
|
|
3
|
+
id: string;
|
|
4
|
+
/** The host's own word for it; the kit adds the count. */
|
|
5
|
+
label: string;
|
|
6
|
+
/** How many rows it acts on ("Pause 3"); none: the label alone. */
|
|
7
|
+
count?: number;
|
|
8
|
+
/** Drawn, but can't be pressed. */
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface BulkBarData {
|
|
13
|
+
/** How many rows are selected; 0 hides the bar. */
|
|
14
|
+
count?: number;
|
|
15
|
+
actions?: BulkAction[];
|
|
16
|
+
lang?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface BulkBarOptions extends Omit<BulkBarData, "lang"> {
|
|
20
|
+
/**
|
|
21
|
+
* An action pressed. A host that opens a dialog passes `button` as its
|
|
22
|
+
* opener, so focus comes back to it.
|
|
23
|
+
*/
|
|
24
|
+
onAction?: (id: string, button: HTMLButtonElement) => void;
|
|
25
|
+
/** Clear pressed: the host unselects its rows; the bar hides at once. */
|
|
26
|
+
onClear?: () => void;
|
|
27
|
+
/** Where focus goes when the bar hides with focus in it. */
|
|
28
|
+
returnFocus?: HTMLElement | null | (() => HTMLElement | null);
|
|
29
|
+
/** The words' language (default: <html lang>). */
|
|
30
|
+
lang?: string | (() => string);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface BulkBar {
|
|
34
|
+
update(data: { count?: number; actions?: BulkAction[] }): void;
|
|
35
|
+
destroy(): void;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** The bar as markup, in the kit's words; hidden at 0. Pure: runs in Node. */
|
|
39
|
+
export declare function bulkBarHtml(data?: BulkBarData): string;
|
|
40
|
+
|
|
41
|
+
/** The bulk bar in `el` (el becomes the bar), with its live region beside it. */
|
|
42
|
+
export declare function mountBulkBar(
|
|
43
|
+
el: HTMLElement,
|
|
44
|
+
opts: BulkBarOptions,
|
|
45
|
+
): BulkBar;
|
package/src/bulk-bar.js
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The bulk bar (issue 553): what a list says while rows are selected.
|
|
3
|
+
* "{n} selected", Clear, then the host's actions with their counts
|
|
4
|
+
* ("Pause 3"), sticky at the bottom of the list. Framework-free and
|
|
5
|
+
* data-only: the host passes the count, its actions and callbacks; the
|
|
6
|
+
* kit draws the markup and owns its words (kit.bulk.* in strings.js).
|
|
7
|
+
*
|
|
8
|
+
* bulkBarHtml({ count, actions, lang }) → string (pure; hidden at 0)
|
|
9
|
+
* const bar = mountBulkBar(el, {
|
|
10
|
+
* count: 3,
|
|
11
|
+
* actions: [{ id, label, count?, disabled? }],
|
|
12
|
+
* onAction: (id, button) => …, an action pressed; a host that opens a
|
|
13
|
+
* dialog passes `button` as its opener
|
|
14
|
+
* (askConfirm({ …, opener: button })),
|
|
15
|
+
* so focus comes back to it
|
|
16
|
+
* onClear: () => …, Clear pressed: the host unselects its
|
|
17
|
+
* rows; the bar hides at once
|
|
18
|
+
* returnFocus: el | () => el, where focus goes when the bar hides
|
|
19
|
+
* with focus in it (a Select all, say)
|
|
20
|
+
* lang: "en" | () => "en", default: <html lang>
|
|
21
|
+
* })
|
|
22
|
+
* bar.update({ count?, actions? }) bar.destroy()
|
|
23
|
+
*
|
|
24
|
+
* An action's label is the host's own word (its data); the kit adds the
|
|
25
|
+
* count in the language's form ("Pause 3", ja "一時停止(3)"). A disabled
|
|
26
|
+
* action is a disabled button and never reaches the host.
|
|
27
|
+
*
|
|
28
|
+
* `el` becomes the bar: <div class="den-bulk" role="region"
|
|
29
|
+
* aria-label="3 selected">, hidden at 0. A visually hidden polite live
|
|
30
|
+
* region beside it says the count when it changes, and "Selection
|
|
31
|
+
* cleared" after Clear.
|
|
32
|
+
*
|
|
33
|
+
* Its look is bulk-bar.css (link it after tokens.css): sticky, 12px over
|
|
34
|
+
* the bottom of the scrolling list (and over the safe area). Under 720px
|
|
35
|
+
* each action takes the bar's width; there, and on a touch screen, every
|
|
36
|
+
* button is 44px tall.
|
|
37
|
+
*/
|
|
38
|
+
import { esc, kitT } from "./strings.js";
|
|
39
|
+
|
|
40
|
+
const selectedWords = (count, lang) =>
|
|
41
|
+
kitT(lang, "kit.bulk.selected", { n: count });
|
|
42
|
+
|
|
43
|
+
function actionsHtml(actions, lang) {
|
|
44
|
+
return (actions || [])
|
|
45
|
+
.map((a) => {
|
|
46
|
+
const words =
|
|
47
|
+
typeof a.count === "number"
|
|
48
|
+
? kitT(lang, "kit.bulk.action", { label: a.label, n: a.count })
|
|
49
|
+
: a.label;
|
|
50
|
+
return (
|
|
51
|
+
`<button type="button" class="den-bulk-act" data-action="${esc(a.id)}"` +
|
|
52
|
+
`${a.disabled ? " disabled" : ""}>${esc(words)}</button>`
|
|
53
|
+
);
|
|
54
|
+
})
|
|
55
|
+
.join("");
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function innerHtml(count, actions, lang) {
|
|
59
|
+
return (
|
|
60
|
+
`<span class="den-bulk-count">${esc(selectedWords(count, lang))}</span>` +
|
|
61
|
+
`<button type="button" class="den-bulk-clear">${esc(kitT(lang, "kit.bulk.clear"))}</button>` +
|
|
62
|
+
`<span class="den-bulk-actions">${actionsHtml(actions, lang)}</span>`
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** The bar as markup (see the top of this file). Pure: runs in Node. */
|
|
67
|
+
export function bulkBarHtml({ count = 0, actions = [], lang = "en" } = {}) {
|
|
68
|
+
const n = Math.max(0, Number(count) || 0);
|
|
69
|
+
return (
|
|
70
|
+
`<div class="den-bulk" role="region" aria-label="${esc(selectedWords(n, lang))}"${n ? "" : " hidden"}>` +
|
|
71
|
+
innerHtml(n, actions, lang) +
|
|
72
|
+
`</div>`
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** The bulk bar in `el` (see the top of this file). */
|
|
77
|
+
export function mountBulkBar(el, opts = {}) {
|
|
78
|
+
let count = Math.max(0, Number(opts.count) || 0);
|
|
79
|
+
let actions = opts.actions || [];
|
|
80
|
+
const lang = () => {
|
|
81
|
+
const l = typeof opts.lang === "function" ? opts.lang() : opts.lang;
|
|
82
|
+
return l || document.documentElement.lang?.slice(0, 2) || "en";
|
|
83
|
+
};
|
|
84
|
+
el.classList.add("den-bulk");
|
|
85
|
+
el.setAttribute("role", "region");
|
|
86
|
+
const live = document.createElement("span");
|
|
87
|
+
live.className = "den-bulk-live";
|
|
88
|
+
live.setAttribute("aria-live", "polite");
|
|
89
|
+
el.after(live);
|
|
90
|
+
|
|
91
|
+
function paint(say) {
|
|
92
|
+
const l = lang();
|
|
93
|
+
const had = el.contains(document.activeElement);
|
|
94
|
+
const focusAct = had ? document.activeElement.dataset?.action : null;
|
|
95
|
+
const focusClear = had
|
|
96
|
+
? document.activeElement.classList.contains("den-bulk-clear")
|
|
97
|
+
: false;
|
|
98
|
+
el.setAttribute("aria-label", selectedWords(count, l));
|
|
99
|
+
el.innerHTML = innerHtml(count, actions, l);
|
|
100
|
+
el.hidden = count === 0;
|
|
101
|
+
if (say) live.textContent = say;
|
|
102
|
+
if (!had) return;
|
|
103
|
+
if (count === 0) {
|
|
104
|
+
const to =
|
|
105
|
+
typeof opts.returnFocus === "function"
|
|
106
|
+
? opts.returnFocus()
|
|
107
|
+
: opts.returnFocus;
|
|
108
|
+
to?.focus?.({ preventScroll: true });
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
// A redraw keeps focus on the same control.
|
|
112
|
+
const again = focusAct
|
|
113
|
+
? el.querySelector(`.den-bulk-act[data-action="${CSS.escape(focusAct)}"]`)
|
|
114
|
+
: focusClear
|
|
115
|
+
? el.querySelector(".den-bulk-clear")
|
|
116
|
+
: null;
|
|
117
|
+
if (again && !again.disabled) again.focus({ preventScroll: true });
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const onClick = (e) => {
|
|
121
|
+
const b = e.target.closest?.("button");
|
|
122
|
+
if (!b || !el.contains(b) || b.disabled) return;
|
|
123
|
+
if (b.classList.contains("den-bulk-clear")) {
|
|
124
|
+
count = 0;
|
|
125
|
+
paint(kitT(lang(), "kit.bulk.cleared"));
|
|
126
|
+
opts.onClear?.();
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
if (b.classList.contains("den-bulk-act"))
|
|
130
|
+
opts.onAction?.(b.dataset.action, b);
|
|
131
|
+
};
|
|
132
|
+
el.addEventListener("click", onClick);
|
|
133
|
+
paint(count ? selectedWords(count, lang()) : "");
|
|
134
|
+
|
|
135
|
+
return {
|
|
136
|
+
update(data = {}) {
|
|
137
|
+
const was = count;
|
|
138
|
+
if (data.count != null) count = Math.max(0, Number(data.count) || 0);
|
|
139
|
+
if (data.actions) actions = data.actions;
|
|
140
|
+
paint(count !== was && count > 0 ? selectedWords(count, lang()) : "");
|
|
141
|
+
},
|
|
142
|
+
destroy() {
|
|
143
|
+
el.removeEventListener("click", onClick);
|
|
144
|
+
live.remove();
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
}
|
package/src/button.css
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/* den-ui: the general button (issue 556), for any page, inside the frame or
|
|
2
|
+
not. Tokens only. Secondary is the base; `.primary` is the accent fill;
|
|
3
|
+
`.sm` is the small size. A link drawn as a button is `a.den-btn`.
|
|
4
|
+
The values are the ones Den's frame drew, value for value. */
|
|
5
|
+
.den-btn {
|
|
6
|
+
border: 1px solid var(--border);
|
|
7
|
+
background: var(--surface);
|
|
8
|
+
border-radius: var(--radius-button);
|
|
9
|
+
padding: 6px 12px;
|
|
10
|
+
cursor: pointer;
|
|
11
|
+
font: inherit;
|
|
12
|
+
font-weight: 500;
|
|
13
|
+
white-space: nowrap;
|
|
14
|
+
color: var(--text);
|
|
15
|
+
}
|
|
16
|
+
.den-btn:hover {
|
|
17
|
+
border-color: var(--border-strong);
|
|
18
|
+
}
|
|
19
|
+
.den-btn.primary {
|
|
20
|
+
background: var(--accent-fill);
|
|
21
|
+
border-color: var(--accent-fill);
|
|
22
|
+
color: var(--on-accent);
|
|
23
|
+
}
|
|
24
|
+
.den-btn.sm {
|
|
25
|
+
padding: 2px 9px;
|
|
26
|
+
font-size: 12.5px;
|
|
27
|
+
}
|
|
28
|
+
.den-btn:disabled, a.den-btn[aria-disabled="true"] {
|
|
29
|
+
opacity: 0.6;
|
|
30
|
+
cursor: default;
|
|
31
|
+
}
|
|
32
|
+
a.den-btn {
|
|
33
|
+
text-decoration: none;
|
|
34
|
+
display: inline-flex;
|
|
35
|
+
align-items: center;
|
|
36
|
+
justify-content: center;
|
|
37
|
+
}
|
|
38
|
+
.den-btn:focus-visible {
|
|
39
|
+
outline: 2px solid var(--accent);
|
|
40
|
+
outline-offset: 2px;
|
|
41
|
+
}
|
|
42
|
+
/* A touch screen: a 44px tap, centred on the button; its look and box
|
|
43
|
+
never change (as .den-hit). */
|
|
44
|
+
@media (pointer: coarse) {
|
|
45
|
+
.den-btn {
|
|
46
|
+
position: relative;
|
|
47
|
+
}
|
|
48
|
+
.den-btn::after {
|
|
49
|
+
content: "";
|
|
50
|
+
position: absolute;
|
|
51
|
+
left: 50%;
|
|
52
|
+
top: 50%;
|
|
53
|
+
width: 100%;
|
|
54
|
+
height: 100%;
|
|
55
|
+
min-width: var(--tap);
|
|
56
|
+
min-height: var(--tap);
|
|
57
|
+
transform: translate(-50%, -50%);
|
|
58
|
+
}
|
|
59
|
+
}
|
package/src/button.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** The general button's look: secondary (the base) or the accent fill. */
|
|
2
|
+
export type ButtonVariant = "secondary" | "primary";
|
|
3
|
+
/** The general button's size: md (the base) or small. */
|
|
4
|
+
export type ButtonSize = "md" | "sm";
|
|
5
|
+
|
|
6
|
+
export interface ButtonOptions {
|
|
7
|
+
/** The host's words (escaped). */
|
|
8
|
+
label: string;
|
|
9
|
+
variant?: ButtonVariant;
|
|
10
|
+
size?: ButtonSize;
|
|
11
|
+
/** A link drawn as a button. */
|
|
12
|
+
href?: string;
|
|
13
|
+
type?: "button" | "submit" | "reset";
|
|
14
|
+
/** A disabled button; a link with no href and aria-disabled. */
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
id?: string;
|
|
17
|
+
/** data- and aria- attributes only; any other is dropped. */
|
|
18
|
+
attrs?: Record<string, string | number | boolean | null | undefined>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** The class list for a variant and size: "den-btn primary sm". */
|
|
22
|
+
export declare function buttonClass(
|
|
23
|
+
variant?: ButtonVariant,
|
|
24
|
+
size?: ButtonSize,
|
|
25
|
+
): string;
|
|
26
|
+
/** A `.den-btn` (button.css): a button, or a link drawn as one. */
|
|
27
|
+
export declare function buttonHtml(o: ButtonOptions): string;
|