@codingsteve01/ember 1.6.0 → 1.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 +2 -0
- package/js/nav-flyout.d.ts +2 -0
- package/js/nav-flyout.js +9 -8
- package/js/theme.js +4 -2
- package/package.json +1 -2
package/README.md
CHANGED
|
@@ -4,6 +4,8 @@ A shared look for calm dashboards: design tokens, base CSS, components, a light/
|
|
|
4
4
|
theme, small figures (sparkline, split bar, stat tile) and a token check. Framework-free; runs in Nuxt as well
|
|
5
5
|
as in plain JavaScript without a bundler. Design rules: [PRINCIPLES.md](PRINCIPLES.md).
|
|
6
6
|
|
|
7
|
+
See every component live: [example page](https://codingsteve01.github.io/design-ember/example/).
|
|
8
|
+
|
|
7
9
|
## Install
|
|
8
10
|
|
|
9
11
|
The package `@codingsteve01/ember` is public on npmjs and needs neither a registry setting nor a token:
|
package/js/nav-flyout.d.ts
CHANGED
|
@@ -13,6 +13,8 @@ export interface FlyoutMenu {
|
|
|
13
13
|
items: FlyoutItem[];
|
|
14
14
|
/** Shown when `items` is empty (loading, none yet); without it an empty menu does not open. */
|
|
15
15
|
empty?: string;
|
|
16
|
+
/** What a screen reader hears after an alert count; default 'needs action'. */
|
|
17
|
+
alertText?: string;
|
|
16
18
|
}
|
|
17
19
|
export function flyoutPlacement(options: {
|
|
18
20
|
anchor: { top: number };
|
package/js/nav-flyout.js
CHANGED
|
@@ -19,29 +19,29 @@ const countHtml = (n, alert) =>
|
|
|
19
19
|
? `<span class="nav-flyout-count${alert ? ' is-alert' : ''}" aria-hidden="true">${n > 99 ? '99+' : n}</span>`
|
|
20
20
|
: '';
|
|
21
21
|
// With a count, the link names it in words: the colour alone does not reach a screen reader.
|
|
22
|
-
const countLabel = (label, n, alert) =>
|
|
23
|
-
n > 0 ? ` aria-label="${esc(`${label}: ${n}${alert ?
|
|
22
|
+
const countLabel = (label, n, alert, alertText) =>
|
|
23
|
+
n > 0 ? ` aria-label="${esc(`${label}: ${n}${alert ? `, ${alertText}` : ''}`)}"` : '';
|
|
24
24
|
|
|
25
25
|
// Every link is out of the tab order: Tab walks the main items, the arrow keys walk the sub views. The full label is
|
|
26
26
|
// the tooltip, since a long one ends in an ellipsis.
|
|
27
|
-
const linkHtml = (i, sub = false) => {
|
|
27
|
+
const linkHtml = (i, alertText, sub = false) => {
|
|
28
28
|
const n = Number(i.count) || 0;
|
|
29
29
|
const current = i.current ? ' aria-current="page"' : '';
|
|
30
30
|
return (
|
|
31
31
|
`<a class="nav-flyout-item${sub ? ' is-sub' : ''}" href="${esc(i.href)}" tabindex="-1" title="${esc(i.label)}"` +
|
|
32
|
-
`${current}${countLabel(i.label, n, i.alert)}><span class="nav-flyout-label">${esc(i.label)}</span>` +
|
|
32
|
+
`${current}${countLabel(i.label, n, i.alert, alertText)}><span class="nav-flyout-label">${esc(i.label)}</span>` +
|
|
33
33
|
`${countHtml(n, i.alert)}</a>`
|
|
34
34
|
);
|
|
35
35
|
};
|
|
36
36
|
|
|
37
37
|
// The parts of a sub view (third level), indented beneath it in named groups; a group name is no stop.
|
|
38
|
-
const partsHtml = groups =>
|
|
38
|
+
const partsHtml = (groups, alertText) =>
|
|
39
39
|
groups?.length
|
|
40
40
|
? `<div class="nav-flyout-sub">${groups
|
|
41
41
|
.map(
|
|
42
42
|
g =>
|
|
43
43
|
(g.label ? `<div class="nav-flyout-group">${esc(g.label)}</div>` : '') +
|
|
44
|
-
g.items.map(i => linkHtml(i, true)).join(''),
|
|
44
|
+
g.items.map(i => linkHtml(i, alertText, true)).join(''),
|
|
45
45
|
)
|
|
46
46
|
.join('')}</div>`
|
|
47
47
|
: '';
|
|
@@ -50,10 +50,11 @@ const partsHtml = groups =>
|
|
|
50
50
|
* Inner HTML of the flyout: the main item's name, then one link per sub view, the shown one marked as current. A sub
|
|
51
51
|
* view may carry a count (grey, red with `alert` where it waits for action), as it does in the unfolded navigation,
|
|
52
52
|
* and its own parts (`children: [{ label, items }]`). With nothing to list, `empty` says why (loading, none yet).
|
|
53
|
+
* `alertText` is what a screen reader hears after an alert count, in the product's language.
|
|
53
54
|
*/
|
|
54
|
-
export function flyoutHtml({ title, items, empty }) {
|
|
55
|
+
export function flyoutHtml({ title, items, empty, alertText = 'needs action' }) {
|
|
55
56
|
const body = items.length
|
|
56
|
-
? items.map(i => linkHtml(i) + partsHtml(i.children)).join('')
|
|
57
|
+
? items.map(i => linkHtml(i, alertText) + partsHtml(i.children, alertText)).join('')
|
|
57
58
|
: empty
|
|
58
59
|
? `<p class="nav-flyout-empty">${esc(empty)}</p>`
|
|
59
60
|
: '';
|
package/js/theme.js
CHANGED
|
@@ -15,14 +15,16 @@ export function applyTheme(theme, doc = document) {
|
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* Wires a toggle button. `onChange(theme)` runs after every switch, for whatever paints resolved colours
|
|
18
|
-
* (charts: call applyChartTheme and redraw). The button gets aria-pressed and a label for the next state
|
|
18
|
+
* (charts: call applyChartTheme and redraw). The button gets aria-pressed and a label for the next state, in English
|
|
19
|
+
* unless it carries its own words as data-label-dark and data-label-light.
|
|
19
20
|
*/
|
|
20
21
|
export function initThemeToggle(button, onChange = () => {}, doc = document, win = window) {
|
|
21
22
|
const sync = () => {
|
|
22
23
|
const theme = effectiveTheme(doc, win);
|
|
23
24
|
if (button) {
|
|
24
25
|
button.setAttribute('aria-pressed', String(theme === 'dark'));
|
|
25
|
-
|
|
26
|
+
const { labelDark = 'Show dark', labelLight = 'Show light' } = button.dataset;
|
|
27
|
+
button.title = theme === 'light' ? labelDark : labelLight;
|
|
26
28
|
button.dataset.theme = theme;
|
|
27
29
|
}
|
|
28
30
|
onChange(theme);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codingsteve01/ember",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "Ember: design tokens, base CSS, components, theme toggle and chart theme for calm dashboards",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
"url": "git+https://github.com/CodingSteve01/design-ember.git"
|
|
10
10
|
},
|
|
11
11
|
"publishConfig": {
|
|
12
|
-
"registry": "https://registry.npmjs.org",
|
|
13
12
|
"access": "public"
|
|
14
13
|
},
|
|
15
14
|
"files": [
|