@monster-orange/den-ui 0.7.6 → 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 +207 -0
- package/package.json +13 -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 +42 -0
- package/src/kit.js +60 -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/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 +73 -0
- package/src/switch.css +88 -0
- package/src/switch.d.ts +32 -0
- package/src/switch.js +85 -0
package/src/strings.js
CHANGED
|
@@ -205,6 +205,34 @@ export const en = {
|
|
|
205
205
|
"kit.savestate.error": "Not saved. Retrying…",
|
|
206
206
|
"kit.savestate.copy": "Copy text",
|
|
207
207
|
"kit.savestate.savedAt": "Saved at {time}",
|
|
208
|
+
// The panel fold toggle and its edge strip (panel-fold.js). The strip's
|
|
209
|
+
// count is worded by kit.badge.*.
|
|
210
|
+
"kit.fold.panel": "Panel",
|
|
211
|
+
"kit.fold.show": "Show panel",
|
|
212
|
+
"kit.fold.hidden": "Panel, hidden",
|
|
213
|
+
// The filter bar (filter-bar.js). A facet's and an option's labels are
|
|
214
|
+
// the host's; {facet} and {value} are those.
|
|
215
|
+
"kit.filter.button": "Filters",
|
|
216
|
+
"kit.filter.buttonN": "Filters ({n})",
|
|
217
|
+
"kit.filter.chosen": "Chosen filters",
|
|
218
|
+
"kit.filter.chip": "{facet}:",
|
|
219
|
+
"kit.filter.remove": "Remove {facet}: {value}",
|
|
220
|
+
"kit.filter.clear": "Clear",
|
|
221
|
+
"kit.filter.clearFacet": "Clear {facet}",
|
|
222
|
+
"kit.filter.clearAll": "Clear all",
|
|
223
|
+
// The bulk bar (bulk-bar.js). {label} is the host's action.
|
|
224
|
+
"kit.bulk.selected": "{n} selected",
|
|
225
|
+
"kit.bulk.clear": "Clear",
|
|
226
|
+
"kit.bulk.cleared": "Selection cleared",
|
|
227
|
+
"kit.bulk.action": "{label} {n}",
|
|
228
|
+
// The page action menu (issue 555) and the settings row (issue 554).
|
|
229
|
+
"kit.pmenu.more": "More",
|
|
230
|
+
"kit.setrow.save": "Save",
|
|
231
|
+
"kit.setrow.who": "{who} can change this",
|
|
232
|
+
"kit.setrow.nobody": "Nobody can change this",
|
|
233
|
+
"kit.setrow.last": "Last changed {time} by {who}",
|
|
234
|
+
"kit.setrow.never": "No changes yet",
|
|
235
|
+
"kit.setrow.error": "Not saved. Try again.",
|
|
208
236
|
};
|
|
209
237
|
|
|
210
238
|
export const es = {
|
|
@@ -406,6 +434,29 @@ export const es = {
|
|
|
406
434
|
"kit.savestate.error": "No se guardó. Reintentando…",
|
|
407
435
|
"kit.savestate.copy": "Copiar texto",
|
|
408
436
|
"kit.savestate.savedAt": "Guardado a las {time}",
|
|
437
|
+
"kit.fold.panel": "Panel",
|
|
438
|
+
"kit.fold.show": "Mostrar panel",
|
|
439
|
+
"kit.fold.hidden": "Panel, oculto",
|
|
440
|
+
"kit.filter.button": "Filtros",
|
|
441
|
+
"kit.filter.buttonN": "Filtros ({n})",
|
|
442
|
+
"kit.filter.chosen": "Filtros elegidos",
|
|
443
|
+
"kit.filter.chip": "{facet}:",
|
|
444
|
+
"kit.filter.remove": "Quitar {facet}: {value}",
|
|
445
|
+
"kit.filter.clear": "Quitar",
|
|
446
|
+
"kit.filter.clearFacet": "Quitar {facet}",
|
|
447
|
+
"kit.filter.clearAll": "Quitar todos",
|
|
448
|
+
"kit.bulk.selected": "{n} seleccionados",
|
|
449
|
+
"kit.bulk.selected.one": "{n} seleccionado",
|
|
450
|
+
"kit.bulk.clear": "Quitar selección",
|
|
451
|
+
"kit.bulk.cleared": "Selección quitada",
|
|
452
|
+
"kit.bulk.action": "{label} {n}",
|
|
453
|
+
"kit.pmenu.more": "Más",
|
|
454
|
+
"kit.setrow.save": "Guardar",
|
|
455
|
+
"kit.setrow.who": "{who} pueden cambiar esto",
|
|
456
|
+
"kit.setrow.nobody": "Nadie puede cambiar esto",
|
|
457
|
+
"kit.setrow.last": "Último cambio: {time}, por {who}",
|
|
458
|
+
"kit.setrow.never": "Sin cambios todavía",
|
|
459
|
+
"kit.setrow.error": "No se guardó. Inténtalo de nuevo.",
|
|
409
460
|
};
|
|
410
461
|
|
|
411
462
|
export const ja = {
|
|
@@ -602,6 +653,28 @@ export const ja = {
|
|
|
602
653
|
"kit.savestate.error": "保存できていません。再試行しています…",
|
|
603
654
|
"kit.savestate.copy": "テキストをコピー",
|
|
604
655
|
"kit.savestate.savedAt": "{time} に保存しました",
|
|
656
|
+
"kit.fold.panel": "パネル",
|
|
657
|
+
"kit.fold.show": "パネルを表示",
|
|
658
|
+
"kit.fold.hidden": "パネル(非表示)",
|
|
659
|
+
"kit.filter.button": "絞り込み",
|
|
660
|
+
"kit.filter.buttonN": "絞り込み({n})",
|
|
661
|
+
"kit.filter.chosen": "選んだ条件",
|
|
662
|
+
"kit.filter.chip": "{facet}:",
|
|
663
|
+
"kit.filter.remove": "{facet}:{value} を外す",
|
|
664
|
+
"kit.filter.clear": "解除",
|
|
665
|
+
"kit.filter.clearFacet": "{facet} を解除",
|
|
666
|
+
"kit.filter.clearAll": "すべて解除",
|
|
667
|
+
"kit.bulk.selected": "{n} 件を選択中",
|
|
668
|
+
"kit.bulk.clear": "選択を解除",
|
|
669
|
+
"kit.bulk.cleared": "選択を解除しました",
|
|
670
|
+
"kit.bulk.action": "{label}({n})",
|
|
671
|
+
"kit.pmenu.more": "その他",
|
|
672
|
+
"kit.setrow.save": "保存",
|
|
673
|
+
"kit.setrow.who": "{who}が変更できます",
|
|
674
|
+
"kit.setrow.nobody": "誰も変更できません",
|
|
675
|
+
"kit.setrow.last": "最終変更: {time}({who})",
|
|
676
|
+
"kit.setrow.never": "まだ変更はありません",
|
|
677
|
+
"kit.setrow.error": "保存できませんでした。もう一度お試しください。",
|
|
605
678
|
};
|
|
606
679
|
|
|
607
680
|
/** The kit's tables, by language (en is the fallback for any key). */
|
package/src/switch.css
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/* den-ui: the switch (issue 551), switch.js. Tokens only: no colour of
|
|
2
|
+
its own. Linked, never injected: clean under style-src 'self'. The row
|
|
3
|
+
is 44px tall and all of it is the tap; the track is the accent's fill
|
|
4
|
+
when on, the strong border when off; the knob slides over --dur-fast. */
|
|
5
|
+
.den-switch {
|
|
6
|
+
display: flex;
|
|
7
|
+
align-items: center;
|
|
8
|
+
justify-content: space-between;
|
|
9
|
+
gap: var(--space-3);
|
|
10
|
+
min-height: var(--tap);
|
|
11
|
+
font-family: var(--sans);
|
|
12
|
+
font-size: var(--fs-m);
|
|
13
|
+
line-height: var(--lh);
|
|
14
|
+
color: var(--text);
|
|
15
|
+
cursor: pointer;
|
|
16
|
+
}
|
|
17
|
+
.den-switch[hidden] {
|
|
18
|
+
display: none;
|
|
19
|
+
}
|
|
20
|
+
.den-switch-text {
|
|
21
|
+
display: flex;
|
|
22
|
+
flex-direction: column;
|
|
23
|
+
min-width: 0;
|
|
24
|
+
}
|
|
25
|
+
.den-switch-help {
|
|
26
|
+
font-size: var(--fs-s);
|
|
27
|
+
color: var(--muted);
|
|
28
|
+
}
|
|
29
|
+
.den-switch-input {
|
|
30
|
+
appearance: none;
|
|
31
|
+
-webkit-appearance: none;
|
|
32
|
+
position: relative;
|
|
33
|
+
flex: none;
|
|
34
|
+
box-sizing: border-box;
|
|
35
|
+
width: 44px;
|
|
36
|
+
height: 26px;
|
|
37
|
+
margin: 0;
|
|
38
|
+
/* Transparent: seen only in forced colours, where the fills are not. */
|
|
39
|
+
border: 1px solid transparent;
|
|
40
|
+
border-radius: 13px;
|
|
41
|
+
background-color: var(--border-strong);
|
|
42
|
+
cursor: pointer;
|
|
43
|
+
transition: background-color var(--dur-fast) ease;
|
|
44
|
+
}
|
|
45
|
+
.den-switch-input::after {
|
|
46
|
+
content: "";
|
|
47
|
+
position: absolute;
|
|
48
|
+
top: 2px;
|
|
49
|
+
left: 2px;
|
|
50
|
+
box-sizing: border-box;
|
|
51
|
+
width: 20px;
|
|
52
|
+
height: 20px;
|
|
53
|
+
border: 1px solid transparent;
|
|
54
|
+
border-radius: 50%;
|
|
55
|
+
background-color: var(--surface);
|
|
56
|
+
transition: transform var(--dur-fast) var(--ease);
|
|
57
|
+
}
|
|
58
|
+
.den-switch-input:checked {
|
|
59
|
+
background-color: var(--accent-fill);
|
|
60
|
+
}
|
|
61
|
+
.den-switch-input:checked::after {
|
|
62
|
+
transform: translateX(18px);
|
|
63
|
+
}
|
|
64
|
+
.den-switch-input:focus-visible {
|
|
65
|
+
outline: 2px solid var(--accent);
|
|
66
|
+
outline-offset: 2px;
|
|
67
|
+
}
|
|
68
|
+
/* Disabled: the quiet border for the track, faint words, no pointer. */
|
|
69
|
+
.den-switch[data-disabled] {
|
|
70
|
+
color: var(--faint);
|
|
71
|
+
cursor: not-allowed;
|
|
72
|
+
}
|
|
73
|
+
.den-switch-input:disabled {
|
|
74
|
+
background-color: var(--border);
|
|
75
|
+
cursor: not-allowed;
|
|
76
|
+
}
|
|
77
|
+
.den-switch-input:disabled:checked {
|
|
78
|
+
background-color: var(--border-strong);
|
|
79
|
+
}
|
|
80
|
+
.den-switch[data-disabled] .den-switch-help {
|
|
81
|
+
color: var(--faint);
|
|
82
|
+
}
|
|
83
|
+
@media (prefers-reduced-motion: reduce) {
|
|
84
|
+
.den-switch-input,
|
|
85
|
+
.den-switch-input::after {
|
|
86
|
+
transition: none;
|
|
87
|
+
}
|
|
88
|
+
}
|
package/src/switch.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export interface SwitchModel {
|
|
2
|
+
/** The host's own words: its setting's name. None: nothing is drawn. */
|
|
3
|
+
label: string;
|
|
4
|
+
on?: boolean;
|
|
5
|
+
disabled?: boolean;
|
|
6
|
+
/** The host's own words under the label: the switch's description. */
|
|
7
|
+
help?: string;
|
|
8
|
+
/** The input's id (default: den-sw-N). */
|
|
9
|
+
id?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface SwitchOptions {
|
|
13
|
+
/** A change by the person (click, Space, Enter). */
|
|
14
|
+
onChange?: (on: boolean) => void;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface Switch {
|
|
18
|
+
/** Moves it with no call (the host's own change). */
|
|
19
|
+
set(on: boolean): void;
|
|
20
|
+
setDisabled(off: boolean): void;
|
|
21
|
+
on(): boolean;
|
|
22
|
+
destroy(): void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** <label class="den-switch">: the words, then <input role="switch">. */
|
|
26
|
+
export declare function switchHtml(model: SwitchModel): string;
|
|
27
|
+
|
|
28
|
+
/** The switch's input, or the .den-switch around it. */
|
|
29
|
+
export declare function hydrateSwitch(
|
|
30
|
+
el: HTMLElement | null,
|
|
31
|
+
opts?: SwitchOptions,
|
|
32
|
+
): Switch;
|
package/src/switch.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The switch (issue 551): a labelled on/off control, role=switch, with a
|
|
3
|
+
* disabled state and help text. The label and the help are the host's own
|
|
4
|
+
* words (the name of its setting, what it does), as a page's name in the
|
|
5
|
+
* rail is; the switch adds no words of its own. On and off are its state
|
|
6
|
+
* (aria-checked through the checkbox), which a screen reader says in its
|
|
7
|
+
* own language. Pure builder, runs in Node too:
|
|
8
|
+
*
|
|
9
|
+
* switchHtml({ label, on, disabled, help, id })
|
|
10
|
+
* <label class="den-switch" for=id>: the label (and the help under
|
|
11
|
+
* it, its description), then <input type="checkbox" role="switch">.
|
|
12
|
+
* No label: nothing is drawn (a switch must have a name). No id: one
|
|
13
|
+
* of the kit's own (den-sw-N).
|
|
14
|
+
*
|
|
15
|
+
* In the page:
|
|
16
|
+
*
|
|
17
|
+
* const sw = hydrateSwitch(inputOrLabel, { onChange: (on) => … });
|
|
18
|
+
* A change (a click on the switch or its words, Space, Enter) calls
|
|
19
|
+
* onChange(on). The host keeps the state: sw.set(on) moves it with no
|
|
20
|
+
* call; sw.setDisabled(off); sw.on(); sw.destroy().
|
|
21
|
+
*
|
|
22
|
+
* The look is switch.css: link it after tokens.css. 44px tall, so a
|
|
23
|
+
* phone's tap is the whole row.
|
|
24
|
+
*/
|
|
25
|
+
import { esc } from "./strings.js";
|
|
26
|
+
|
|
27
|
+
let seq = 0;
|
|
28
|
+
|
|
29
|
+
/** The switch's markup (see the top of this file). */
|
|
30
|
+
export function switchHtml(o = {}) {
|
|
31
|
+
const label = o.label == null ? "" : String(o.label);
|
|
32
|
+
if (!label.trim()) return "";
|
|
33
|
+
const id = o.id ? String(o.id) : `den-sw-${++seq}`;
|
|
34
|
+
const help = o.help == null ? "" : String(o.help);
|
|
35
|
+
const helpId = `${id}-help`;
|
|
36
|
+
// Named by the label alone (aria-labelledby): the help inside the same
|
|
37
|
+
// <label> would else be read as part of its name.
|
|
38
|
+
const labelId = `${id}-label`;
|
|
39
|
+
return (
|
|
40
|
+
`<label class="den-switch" for="${esc(id)}"${o.disabled ? " data-disabled" : ""}>` +
|
|
41
|
+
`<span class="den-switch-text"><span class="den-switch-label" id="${esc(labelId)}">${esc(label)}</span>` +
|
|
42
|
+
(help
|
|
43
|
+
? `<span class="den-switch-help" id="${esc(helpId)}">${esc(help)}</span>`
|
|
44
|
+
: "") +
|
|
45
|
+
"</span>" +
|
|
46
|
+
`<input type="checkbox" role="switch" class="den-switch-input" id="${esc(id)}"` +
|
|
47
|
+
` aria-labelledby="${esc(labelId)}"` +
|
|
48
|
+
(help ? ` aria-describedby="${esc(helpId)}"` : "") +
|
|
49
|
+
(o.on ? " checked" : "") +
|
|
50
|
+
(o.disabled ? " disabled" : "") +
|
|
51
|
+
" data-den-switch></label>"
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** The switch in the page (see the top of this file). */
|
|
56
|
+
export function hydrateSwitch(el, opts = {}) {
|
|
57
|
+
const input = el?.matches?.("input[data-den-switch]")
|
|
58
|
+
? el
|
|
59
|
+
: el?.querySelector?.("input[data-den-switch]");
|
|
60
|
+
const label = input?.closest(".den-switch");
|
|
61
|
+
const onChange = () => opts.onChange?.(input.checked);
|
|
62
|
+
// Space is the checkbox's own; Enter toggles it too (a switch's keys).
|
|
63
|
+
const onKey = (e) => {
|
|
64
|
+
if (e.key !== "Enter" || e.isComposing || input.disabled) return;
|
|
65
|
+
e.preventDefault();
|
|
66
|
+
input.click();
|
|
67
|
+
};
|
|
68
|
+
input?.addEventListener("change", onChange);
|
|
69
|
+
input?.addEventListener("keydown", onKey);
|
|
70
|
+
return {
|
|
71
|
+
set(on) {
|
|
72
|
+
if (input) input.checked = Boolean(on);
|
|
73
|
+
},
|
|
74
|
+
setDisabled(off) {
|
|
75
|
+
if (!input) return;
|
|
76
|
+
input.disabled = Boolean(off);
|
|
77
|
+
label?.toggleAttribute("data-disabled", Boolean(off));
|
|
78
|
+
},
|
|
79
|
+
on: () => Boolean(input?.checked),
|
|
80
|
+
destroy() {
|
|
81
|
+
input?.removeEventListener("change", onChange);
|
|
82
|
+
input?.removeEventListener("keydown", onKey);
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
}
|