@n1kname/components 0.57.1 → 0.59.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/package.json +6 -3
- package/src/ActiveFilters.astro +123 -0
- package/src/CardList.astro +15 -2
- package/src/FilterChips.astro +2 -0
- package/src/FilterSheet.astro +249 -0
- package/src/Personas.astro +313 -0
- package/src/ViewMenu.astro +130 -0
- package/src/activefilters.js +49 -0
- package/src/cardlist.css +130 -5
- package/src/cardlist.js +34 -8
- package/src/chips.js +17 -2
- package/src/filtersheet.js +70 -0
- package/src/icons.ts +3 -0
- package/src/viewmenu.js +56 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@n1kname/components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.59.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -30,13 +30,16 @@
|
|
|
30
30
|
"./controls.css": "./src/controls.css",
|
|
31
31
|
"./controls.js": "./src/controls.js",
|
|
32
32
|
"./cardlist.css": "./src/cardlist.css",
|
|
33
|
-
"./cardlist.js": "./src/cardlist.js"
|
|
33
|
+
"./cardlist.js": "./src/cardlist.js",
|
|
34
|
+
"./filtersheet.js": "./src/filtersheet.js",
|
|
35
|
+
"./activefilters.js": "./src/activefilters.js",
|
|
36
|
+
"./viewmenu.js": "./src/viewmenu.js"
|
|
34
37
|
},
|
|
35
38
|
"dependencies": {
|
|
36
39
|
"@n1kname/charts": "0.15.0"
|
|
37
40
|
},
|
|
38
41
|
"peerDependencies": {
|
|
39
|
-
"@n1kname/tokens": "^0.
|
|
42
|
+
"@n1kname/tokens": "^0.10.0",
|
|
40
43
|
"astro": "^7.4.4"
|
|
41
44
|
},
|
|
42
45
|
"publishConfig": {
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* What's narrowing the list, as pills that each take their filter off, and Clear all. Hidden while
|
|
4
|
+
* nothing is set. Put it under the filters, above the result: when filters fold into a sheet on a
|
|
5
|
+
* phone, this is where the person still sees what's on. Fill it with setActiveFilters() from
|
|
6
|
+
* activefilters.js; fires `filter-remove` with the key, and `filters-clear`.
|
|
7
|
+
*/
|
|
8
|
+
interface Props {
|
|
9
|
+
/** Names the set of pills for a screen reader: "Active filters". */
|
|
10
|
+
label?: string;
|
|
11
|
+
/** Said before each pill's label: "Remove filter: Remote". */
|
|
12
|
+
remove?: string;
|
|
13
|
+
clear?: string;
|
|
14
|
+
/** Where focus goes when the last filter is removed from the keyboard: an element id, such as the search field. */
|
|
15
|
+
returnFocus?: string;
|
|
16
|
+
id?: string;
|
|
17
|
+
}
|
|
18
|
+
const { label = 'Active filters', remove = 'Remove filter', clear = 'Clear all', returnFocus, id } = Astro.props;
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
<div class="active-filters" id={id} data-active-filters data-remove={remove} data-return-focus={returnFocus} hidden>
|
|
22
|
+
<ul class="af-list" data-af-list aria-label={label}></ul>
|
|
23
|
+
<button type="button" class="af-clear" data-af-clear>{clear}</button>
|
|
24
|
+
</div>
|
|
25
|
+
|
|
26
|
+
<script>
|
|
27
|
+
import { wireActiveFilters } from './activefilters.js';
|
|
28
|
+
document.querySelectorAll<HTMLElement>('[data-active-filters]').forEach(wireActiveFilters);
|
|
29
|
+
</script>
|
|
30
|
+
|
|
31
|
+
<style>
|
|
32
|
+
.active-filters {
|
|
33
|
+
display: flex;
|
|
34
|
+
flex-wrap: wrap;
|
|
35
|
+
align-items: center;
|
|
36
|
+
gap: var(--sp-2);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.active-filters[hidden] {
|
|
40
|
+
display: none;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/* A real flex list, not display: contents, which drops the list's semantics in Safari. */
|
|
44
|
+
.af-list {
|
|
45
|
+
display: flex;
|
|
46
|
+
flex-wrap: wrap;
|
|
47
|
+
gap: var(--sp-2);
|
|
48
|
+
margin: 0;
|
|
49
|
+
padding: 0;
|
|
50
|
+
list-style: none;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.af-list :global(.af-pill) {
|
|
54
|
+
display: inline-flex;
|
|
55
|
+
align-items: center;
|
|
56
|
+
gap: 6px;
|
|
57
|
+
min-height: 28px;
|
|
58
|
+
padding: 0 var(--sp-2) 0 var(--sp-3);
|
|
59
|
+
border: 0;
|
|
60
|
+
border-radius: 999px;
|
|
61
|
+
background: var(--c-surface-sunken);
|
|
62
|
+
color: var(--c-text);
|
|
63
|
+
font: inherit;
|
|
64
|
+
font-size: var(--text-caption);
|
|
65
|
+
cursor: pointer;
|
|
66
|
+
transition: background var(--motion-fast) var(--ease-out);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/* Only a pill that wasn't there before pops in; the rest stay put. */
|
|
70
|
+
.af-list :global(.af-pill.enter) {
|
|
71
|
+
animation: af-in var(--motion-base) var(--ease-out);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.af-list :global(.af-pill svg) {
|
|
75
|
+
color: var(--c-text-muted);
|
|
76
|
+
transition: color var(--motion-fast) var(--ease-out);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.af-list :global(.af-pill:hover) {
|
|
80
|
+
background: var(--c-surface-hover);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.af-list :global(.af-pill:hover svg) {
|
|
84
|
+
color: var(--c-text);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.af-clear {
|
|
88
|
+
padding: var(--sp-1);
|
|
89
|
+
border: 0;
|
|
90
|
+
background: none;
|
|
91
|
+
color: var(--c-text-secondary);
|
|
92
|
+
font: inherit;
|
|
93
|
+
font-size: var(--text-caption);
|
|
94
|
+
text-decoration: underline;
|
|
95
|
+
text-underline-offset: 3px;
|
|
96
|
+
cursor: pointer;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.af-clear:hover {
|
|
100
|
+
color: var(--c-text);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
.af-list :global(.af-pill:focus-visible),
|
|
104
|
+
.af-clear:focus-visible {
|
|
105
|
+
outline: 2px solid var(--c-focus);
|
|
106
|
+
outline-offset: 2px;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
@keyframes af-in {
|
|
110
|
+
from {
|
|
111
|
+
opacity: 0;
|
|
112
|
+
transform: scale(0.94);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
@media (prefers-reduced-motion: reduce) {
|
|
117
|
+
.af-list :global(.af-pill),
|
|
118
|
+
.af-list :global(.af-pill.enter) {
|
|
119
|
+
animation: none;
|
|
120
|
+
transition: none;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
</style>
|
package/src/CardList.astro
CHANGED
|
@@ -15,8 +15,11 @@ import { cardHTML, placeholdersHTML } from './cardlist.js';
|
|
|
15
15
|
interface Chip {
|
|
16
16
|
icon?: string;
|
|
17
17
|
label: string;
|
|
18
|
-
/**
|
|
19
|
-
|
|
18
|
+
/**
|
|
19
|
+
* good: something in the item's favour, in the status-good tint. The page decides what.
|
|
20
|
+
* action, live, history: an item state in words, to sit with the card's `state`.
|
|
21
|
+
*/
|
|
22
|
+
tone?: 'neutral' | 'good' | 'action' | 'live' | 'history';
|
|
20
23
|
}
|
|
21
24
|
interface Item {
|
|
22
25
|
id: string;
|
|
@@ -25,6 +28,16 @@ interface Item {
|
|
|
25
28
|
href?: string;
|
|
26
29
|
score?: number | null;
|
|
27
30
|
scoreText?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Hue says what kind of thing it is, weight says how much it needs you. action: your process,
|
|
33
|
+
* needing you soon (band, ring, pulses once). live: your process, moving (ring). history: closed
|
|
34
|
+
* or set aside (the words step down). Pair each with a chip of the same tone that says it.
|
|
35
|
+
*/
|
|
36
|
+
state?: 'action' | 'live' | 'history';
|
|
37
|
+
/** They weighed in themselves: a status, a note, a rating. A spine. */
|
|
38
|
+
reviewed?: boolean;
|
|
39
|
+
/** New since they last looked: a dot before the title, and "New" said with it. */
|
|
40
|
+
unseen?: boolean;
|
|
28
41
|
chips?: Chip[];
|
|
29
42
|
actions?: { action: string; icon: string; label: string; pressed?: boolean }[];
|
|
30
43
|
}
|
package/src/FilterChips.astro
CHANGED
|
@@ -99,6 +99,8 @@ const list = all ? [{ value: 'all', label: all, count: options.every((o) => o.co
|
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
.filter-chips :global(.n) {
|
|
102
|
+
/* inline-block so a changed count can roll in (chips.js) */
|
|
103
|
+
display: inline-block;
|
|
102
104
|
color: var(--c-text-muted);
|
|
103
105
|
font-weight: 400;
|
|
104
106
|
font-variant-numeric: tabular-nums;
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* The second rank of filters. Where there's room its groups sit in a row; on a phone they fold
|
|
4
|
+
* behind one "Filters" button, with a badge for how many are set, that opens them in a bottom
|
|
5
|
+
* sheet with Clear all and a button that says what closing shows ("Show 12 jobs"). Put
|
|
6
|
+
* FilterChips (or Segmented) groups in the slot; each needs its `label`, which becomes its caption
|
|
7
|
+
* in the sheet. The main filter stays outside, always in view. Update it with setFilterSheet() from
|
|
8
|
+
* filtersheet.js; fires `filters-clear`.
|
|
9
|
+
*/
|
|
10
|
+
import { ICONS } from './icons';
|
|
11
|
+
|
|
12
|
+
interface Props {
|
|
13
|
+
/** The button and the sheet's heading: "Filters". */
|
|
14
|
+
label?: string;
|
|
15
|
+
/** Clear all, in the sheet. */
|
|
16
|
+
clear?: string;
|
|
17
|
+
/** The closing button's words until setFilterSheet() gives a count. */
|
|
18
|
+
done?: string;
|
|
19
|
+
id?: string;
|
|
20
|
+
}
|
|
21
|
+
const { label = 'Filters', clear = 'Clear all', done = 'Show results', id } = Astro.props;
|
|
22
|
+
const headingId = `${id ?? 'filter-sheet'}-heading`;
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
<div class="filter-sheet" id={id} data-filter-sheet data-label={label}>
|
|
26
|
+
<div class="fs-row" data-fs-home><slot /></div>
|
|
27
|
+
|
|
28
|
+
<button type="button" class="fs-open" data-fs-open aria-haspopup="dialog" aria-expanded="false" aria-label={label}>
|
|
29
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" set:html={ICONS['sliders-horizontal']} />
|
|
30
|
+
<span>{label}</span>
|
|
31
|
+
<span class="fs-count" data-fs-count hidden></span>
|
|
32
|
+
<svg class="fs-chevron" xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" set:html={ICONS['chevron-down']} />
|
|
33
|
+
</button>
|
|
34
|
+
|
|
35
|
+
<dialog class="fs-sheet" data-fs-sheet aria-labelledby={headingId}>
|
|
36
|
+
<div class="fs-inner">
|
|
37
|
+
<span class="fs-grabber" aria-hidden="true"></span>
|
|
38
|
+
<div class="fs-head">
|
|
39
|
+
<h2 class="fs-title" id={headingId}>{label}</h2>
|
|
40
|
+
<button type="button" class="fs-clear" data-fs-clear>{clear}</button>
|
|
41
|
+
</div>
|
|
42
|
+
<div class="fs-body" data-fs-body></div>
|
|
43
|
+
<button type="button" class="fs-done" data-fs-done>{done}</button>
|
|
44
|
+
</div>
|
|
45
|
+
</dialog>
|
|
46
|
+
</div>
|
|
47
|
+
|
|
48
|
+
<script>
|
|
49
|
+
import { wireFilterSheet } from './filtersheet.js';
|
|
50
|
+
document.querySelectorAll<HTMLElement>('[data-filter-sheet]').forEach(wireFilterSheet);
|
|
51
|
+
</script>
|
|
52
|
+
|
|
53
|
+
<style>
|
|
54
|
+
.filter-sheet {
|
|
55
|
+
display: contents;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/* Groups are kept apart by more space between them than inside them, so no divider is needed
|
|
59
|
+
* and a row that wraps still reads. */
|
|
60
|
+
.fs-row {
|
|
61
|
+
display: flex;
|
|
62
|
+
flex-wrap: wrap;
|
|
63
|
+
align-items: center;
|
|
64
|
+
gap: var(--sp-2) var(--sp-5);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.fs-open {
|
|
68
|
+
display: none;
|
|
69
|
+
/* The root is display: contents, so in a grid page this button is a grid item: keep it a pill
|
|
70
|
+
* rather than letting it stretch the full width. */
|
|
71
|
+
justify-self: start;
|
|
72
|
+
align-items: center;
|
|
73
|
+
gap: var(--sp-2);
|
|
74
|
+
min-height: 32px;
|
|
75
|
+
padding: 0 var(--sp-3);
|
|
76
|
+
border: 1px solid var(--c-border);
|
|
77
|
+
border-radius: 999px;
|
|
78
|
+
background: var(--c-surface);
|
|
79
|
+
color: var(--c-text-secondary);
|
|
80
|
+
font: inherit;
|
|
81
|
+
font-size: var(--text-caption);
|
|
82
|
+
cursor: pointer;
|
|
83
|
+
transition:
|
|
84
|
+
background var(--motion-base) var(--ease-out),
|
|
85
|
+
border-color var(--motion-base) var(--ease-out);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.fs-open:hover {
|
|
89
|
+
border-color: var(--c-border-strong);
|
|
90
|
+
color: var(--c-text);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.fs-open:focus-visible {
|
|
94
|
+
outline: 2px solid var(--c-focus);
|
|
95
|
+
outline-offset: 2px;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.fs-count {
|
|
99
|
+
min-width: 18px;
|
|
100
|
+
height: 18px;
|
|
101
|
+
padding: 0 5px;
|
|
102
|
+
border-radius: 999px;
|
|
103
|
+
background: var(--c-text);
|
|
104
|
+
color: var(--c-bg);
|
|
105
|
+
font-family: var(--font-mono);
|
|
106
|
+
font-size: 0.6875rem;
|
|
107
|
+
font-weight: 600;
|
|
108
|
+
line-height: 18px;
|
|
109
|
+
text-align: center;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
.fs-count[hidden] {
|
|
113
|
+
display: none;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.fs-chevron {
|
|
117
|
+
color: var(--c-text-muted);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
@media (max-width: 639px) {
|
|
121
|
+
.fs-row {
|
|
122
|
+
display: none;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
.fs-open {
|
|
126
|
+
display: inline-flex;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/* ---- The sheet: from the bottom edge, clear of the home indicator ---- */
|
|
131
|
+
.fs-sheet {
|
|
132
|
+
width: 100%;
|
|
133
|
+
max-width: 100%;
|
|
134
|
+
max-height: min(85dvh, 640px);
|
|
135
|
+
margin: auto 0 0;
|
|
136
|
+
padding: 0;
|
|
137
|
+
border: 0;
|
|
138
|
+
border-radius: var(--radius-xl) var(--radius-xl) 0 0;
|
|
139
|
+
background: var(--c-surface);
|
|
140
|
+
color: var(--c-text);
|
|
141
|
+
box-shadow: 0 -12px 40px oklch(0 0 0 / 0.25);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
.fs-sheet[open] {
|
|
145
|
+
animation: fs-up var(--motion-slow) var(--ease-out);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
.fs-sheet::backdrop {
|
|
149
|
+
background: oklch(0.12 0.02 45 / 0.45);
|
|
150
|
+
animation: fs-fade var(--motion-slow) var(--ease-out);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
.fs-inner {
|
|
154
|
+
display: grid;
|
|
155
|
+
gap: var(--sp-5);
|
|
156
|
+
padding: var(--sp-3) max(var(--sp-5), env(safe-area-inset-right, 0px)) calc(var(--sp-5) + env(safe-area-inset-bottom, 0px)) max(var(--sp-5), env(safe-area-inset-left, 0px));
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
.fs-grabber {
|
|
160
|
+
justify-self: center;
|
|
161
|
+
width: 40px;
|
|
162
|
+
height: 4px;
|
|
163
|
+
border-radius: 2px;
|
|
164
|
+
background: var(--c-border);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
.fs-head {
|
|
168
|
+
display: flex;
|
|
169
|
+
align-items: center;
|
|
170
|
+
justify-content: space-between;
|
|
171
|
+
gap: var(--sp-3);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
.fs-title {
|
|
175
|
+
margin: 0;
|
|
176
|
+
font-family: var(--font-display);
|
|
177
|
+
font-size: var(--text-h3);
|
|
178
|
+
line-height: var(--leading-h3);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
.fs-clear {
|
|
182
|
+
border: 0;
|
|
183
|
+
background: none;
|
|
184
|
+
color: var(--c-text-accent);
|
|
185
|
+
font: inherit;
|
|
186
|
+
font-size: var(--text-body-sm);
|
|
187
|
+
text-decoration: underline;
|
|
188
|
+
text-underline-offset: 3px;
|
|
189
|
+
cursor: pointer;
|
|
190
|
+
padding: var(--sp-1);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
.fs-body {
|
|
194
|
+
display: grid;
|
|
195
|
+
gap: var(--sp-5);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
.fs-body :global(.fs-section) {
|
|
199
|
+
display: grid;
|
|
200
|
+
gap: var(--sp-2);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
.fs-body :global(.fs-caption) {
|
|
204
|
+
margin: 0;
|
|
205
|
+
color: var(--c-text-muted);
|
|
206
|
+
font-size: var(--text-caption);
|
|
207
|
+
font-weight: 600;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
.fs-done {
|
|
211
|
+
min-height: 44px;
|
|
212
|
+
border: 0;
|
|
213
|
+
border-radius: var(--radius-md);
|
|
214
|
+
background: var(--c-text);
|
|
215
|
+
color: var(--c-bg);
|
|
216
|
+
font: inherit;
|
|
217
|
+
font-weight: 600;
|
|
218
|
+
cursor: pointer;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
.fs-clear:focus-visible,
|
|
222
|
+
.fs-done:focus-visible {
|
|
223
|
+
outline: 2px solid var(--c-focus);
|
|
224
|
+
outline-offset: 2px;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
@keyframes fs-up {
|
|
228
|
+
from {
|
|
229
|
+
transform: translateY(100%);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
@keyframes fs-fade {
|
|
234
|
+
from {
|
|
235
|
+
opacity: 0;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
@media (prefers-reduced-motion: reduce) {
|
|
240
|
+
.fs-sheet[open],
|
|
241
|
+
.fs-sheet::backdrop {
|
|
242
|
+
animation: none;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
.fs-open {
|
|
246
|
+
transition: none;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
</style>
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* The people a service is for, side by side: each with an avatar disc, a name, a line on who they
|
|
4
|
+
* are, what they need, and a job story or quote in their voice. For a page that compares roles,
|
|
5
|
+
* such as the four on a story map.
|
|
6
|
+
*
|
|
7
|
+
* Deliberately not cards: open columns with a hairline between them, so a page that already has
|
|
8
|
+
* boxes doesn't get more. The quote hangs on a rule in the person's tone. A list, each person a
|
|
9
|
+
* heading, their notes and their quote, read in order. Up to four columns; below 640px wide two,
|
|
10
|
+
* below 420px one, with a rule above each person instead.
|
|
11
|
+
*
|
|
12
|
+
* Once, as it comes into view, the people rise in one after another. Nothing moves under reduced
|
|
13
|
+
* motion, and without script they are simply there.
|
|
14
|
+
*/
|
|
15
|
+
import Icon from './Icon.astro';
|
|
16
|
+
import type { IconName } from './icons';
|
|
17
|
+
|
|
18
|
+
type Tone = 'accent' | 'cool' | 'quiet';
|
|
19
|
+
|
|
20
|
+
interface Person {
|
|
21
|
+
/** "Driver", "Fleet manager". */
|
|
22
|
+
name: string;
|
|
23
|
+
/** Under the name: who they are, in a few words. */
|
|
24
|
+
role?: string;
|
|
25
|
+
icon?: IconName;
|
|
26
|
+
tone?: Tone;
|
|
27
|
+
/** What they need to do, in a sentence. */
|
|
28
|
+
needs?: string;
|
|
29
|
+
/** In their voice: a job story or a real quote, without the quotation marks. */
|
|
30
|
+
quote?: string;
|
|
31
|
+
/** Over the quote, such as "Job story". */
|
|
32
|
+
quoteLabel?: string;
|
|
33
|
+
/** More labelled lines, such as { label: 'Later', text: '…' }. */
|
|
34
|
+
notes?: { label: string; text: string }[];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
interface Props {
|
|
38
|
+
/** What the people are, for a screen reader: the list is named by it. */
|
|
39
|
+
title: string;
|
|
40
|
+
people: Person[];
|
|
41
|
+
/** The label over each person's needs. */
|
|
42
|
+
needsLabel?: string;
|
|
43
|
+
caption?: string;
|
|
44
|
+
class?: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const { title, people, needsLabel = 'Needs', caption, class: className } = Astro.props;
|
|
48
|
+
const tones: Tone[] = ['accent', 'cool'];
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
<figure class:list={['personas', className]} data-personas>
|
|
52
|
+
<ul aria-label={title} style={`--cols: ${Math.min(4, Math.max(1, people.length))}`}>
|
|
53
|
+
{
|
|
54
|
+
people.map((p, i) => (
|
|
55
|
+
<li class="person" data-tone={p.tone ?? tones[i % tones.length]} style={`--i: ${i}`}>
|
|
56
|
+
<span class="avatar" aria-hidden="true">
|
|
57
|
+
<Icon name={p.icon ?? 'users'} size={26} />
|
|
58
|
+
</span>
|
|
59
|
+
<h3 class="name">{p.name}</h3>
|
|
60
|
+
{p.role && <p class="role">{p.role}</p>}
|
|
61
|
+
<dl>
|
|
62
|
+
{p.needs && (
|
|
63
|
+
<div>
|
|
64
|
+
<dt>{needsLabel}</dt>
|
|
65
|
+
<dd>{p.needs}</dd>
|
|
66
|
+
</div>
|
|
67
|
+
)}
|
|
68
|
+
{p.notes?.map((n) => (
|
|
69
|
+
<div>
|
|
70
|
+
<dt>{n.label}</dt>
|
|
71
|
+
<dd>{n.text}</dd>
|
|
72
|
+
</div>
|
|
73
|
+
))}
|
|
74
|
+
</dl>
|
|
75
|
+
{p.quote && (
|
|
76
|
+
<blockquote>
|
|
77
|
+
{p.quoteLabel && <span class="quote-label">{p.quoteLabel}</span>}
|
|
78
|
+
<p>“{p.quote}”</p>
|
|
79
|
+
</blockquote>
|
|
80
|
+
)}
|
|
81
|
+
</li>
|
|
82
|
+
))
|
|
83
|
+
}
|
|
84
|
+
</ul>
|
|
85
|
+
{caption && <figcaption>{caption}</figcaption>}
|
|
86
|
+
</figure>
|
|
87
|
+
|
|
88
|
+
<script is:inline>
|
|
89
|
+
// Before the first paint, so people waiting to arrive never show and then vanish.
|
|
90
|
+
(() => {
|
|
91
|
+
const all = document.querySelectorAll('[data-personas]:not(.arrive)');
|
|
92
|
+
const fig = all[all.length - 1];
|
|
93
|
+
if (!fig || !('IntersectionObserver' in window) || matchMedia('(prefers-reduced-motion: reduce)').matches) return;
|
|
94
|
+
fig.classList.add('arrive');
|
|
95
|
+
const io = new IntersectionObserver(
|
|
96
|
+
(entries) => {
|
|
97
|
+
for (const e of entries) {
|
|
98
|
+
if (!e.isIntersecting) continue;
|
|
99
|
+
e.target.classList.add('in');
|
|
100
|
+
io.unobserve(e.target);
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
{ rootMargin: '0px 0px -15% 0px' },
|
|
104
|
+
);
|
|
105
|
+
io.observe(fig);
|
|
106
|
+
})();
|
|
107
|
+
</script>
|
|
108
|
+
|
|
109
|
+
<style>
|
|
110
|
+
.personas {
|
|
111
|
+
min-width: 0;
|
|
112
|
+
margin: var(--sp-7) 0;
|
|
113
|
+
container-type: inline-size;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
[data-tone='accent'] {
|
|
117
|
+
--edge: var(--c-accent-edge);
|
|
118
|
+
--soft: var(--c-surface-tint);
|
|
119
|
+
--mark: var(--c-accent);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
[data-tone='cool'] {
|
|
123
|
+
--edge: color-mix(in oklab, var(--c-tag-cool-text) 55%, transparent);
|
|
124
|
+
--soft: var(--c-tag-cool-bg);
|
|
125
|
+
--mark: var(--c-tag-cool-text);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
[data-tone='quiet'] {
|
|
129
|
+
--edge: var(--c-diagram-edge);
|
|
130
|
+
--soft: var(--c-surface);
|
|
131
|
+
--mark: var(--c-text-secondary);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
ul {
|
|
135
|
+
display: grid;
|
|
136
|
+
grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
|
|
137
|
+
margin: 0;
|
|
138
|
+
padding: 0;
|
|
139
|
+
list-style: none;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
.person {
|
|
143
|
+
display: flex;
|
|
144
|
+
flex-direction: column;
|
|
145
|
+
gap: var(--sp-3);
|
|
146
|
+
min-width: 0;
|
|
147
|
+
margin: 0;
|
|
148
|
+
padding: var(--sp-2) var(--sp-5);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/* Open columns: a hairline between people, nothing around them. */
|
|
152
|
+
.person + .person {
|
|
153
|
+
border-left: 1px solid var(--c-border);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
.person:first-child {
|
|
157
|
+
padding-left: 0;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
.person:last-child {
|
|
161
|
+
padding-right: 0;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
.avatar {
|
|
165
|
+
display: grid;
|
|
166
|
+
place-items: center;
|
|
167
|
+
width: 56px;
|
|
168
|
+
height: 56px;
|
|
169
|
+
border-radius: 50%;
|
|
170
|
+
background: var(--soft);
|
|
171
|
+
border: 1.5px solid var(--edge);
|
|
172
|
+
color: var(--mark);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
.name {
|
|
176
|
+
margin: var(--sp-1) 0 0;
|
|
177
|
+
font-family: var(--font-display);
|
|
178
|
+
font-weight: 600;
|
|
179
|
+
font-size: var(--text-sub);
|
|
180
|
+
line-height: var(--leading-sub);
|
|
181
|
+
color: var(--c-text);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
.role {
|
|
185
|
+
margin: calc(-1 * var(--sp-2)) 0 0;
|
|
186
|
+
font-size: var(--text-caption);
|
|
187
|
+
line-height: var(--leading-caption);
|
|
188
|
+
color: var(--c-text-muted);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
dl {
|
|
192
|
+
display: flex;
|
|
193
|
+
flex-direction: column;
|
|
194
|
+
gap: var(--sp-3);
|
|
195
|
+
margin: 0;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
dt,
|
|
199
|
+
.quote-label {
|
|
200
|
+
display: block;
|
|
201
|
+
margin-bottom: 2px;
|
|
202
|
+
font-size: var(--text-caption);
|
|
203
|
+
font-weight: 600;
|
|
204
|
+
color: var(--c-text-secondary);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
dd {
|
|
208
|
+
margin: 0;
|
|
209
|
+
font-size: var(--text-body-sm);
|
|
210
|
+
line-height: var(--leading-body-sm);
|
|
211
|
+
color: var(--c-text);
|
|
212
|
+
text-wrap: pretty;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/* The person's voice: hung on a rule in their tone, at the foot of the column. */
|
|
216
|
+
blockquote {
|
|
217
|
+
margin: auto 0 0;
|
|
218
|
+
padding: var(--sp-1) 0 var(--sp-1) var(--sp-3);
|
|
219
|
+
border-left: 2px solid var(--mark);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
blockquote p {
|
|
223
|
+
margin: 0;
|
|
224
|
+
font-family: var(--font-display);
|
|
225
|
+
font-style: italic;
|
|
226
|
+
font-size: var(--text-body-sm);
|
|
227
|
+
line-height: var(--leading-body-sm);
|
|
228
|
+
color: var(--c-text);
|
|
229
|
+
text-wrap: pretty;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/* Narrow overrides repeat the sibling selector, so they outweigh the open-column rule above
|
|
233
|
+
* (scoped styles count every class twice). */
|
|
234
|
+
@container (max-width: 640px) {
|
|
235
|
+
ul {
|
|
236
|
+
grid-template-columns: repeat(min(var(--cols), 2), minmax(0, 1fr));
|
|
237
|
+
row-gap: var(--sp-6);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
.person,
|
|
241
|
+
.person + .person {
|
|
242
|
+
padding: 0 var(--sp-4);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
.person:nth-child(odd),
|
|
246
|
+
.person + .person:nth-child(odd) {
|
|
247
|
+
padding-left: 0;
|
|
248
|
+
border-left: 0;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
.person:nth-child(even),
|
|
252
|
+
.person + .person:nth-child(even) {
|
|
253
|
+
padding-right: 0;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
@container (max-width: 420px) {
|
|
258
|
+
ul {
|
|
259
|
+
grid-template-columns: minmax(0, 1fr);
|
|
260
|
+
row-gap: 0;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
.person,
|
|
264
|
+
.person + .person,
|
|
265
|
+
.person + .person:nth-child(odd),
|
|
266
|
+
.person + .person:nth-child(even) {
|
|
267
|
+
padding: var(--sp-5) 0;
|
|
268
|
+
border-left: 0;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
.person + .person,
|
|
272
|
+
.person + .person:nth-child(odd),
|
|
273
|
+
.person + .person:nth-child(even) {
|
|
274
|
+
border-top: 1px solid var(--c-border);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
.person:first-child {
|
|
278
|
+
padding-top: 0;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
figcaption {
|
|
283
|
+
margin-top: var(--sp-4);
|
|
284
|
+
font-size: var(--text-caption);
|
|
285
|
+
line-height: var(--leading-caption);
|
|
286
|
+
color: var(--c-text-muted);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/* Arriving: the people rise in, 90ms apart. */
|
|
290
|
+
.arrive .person {
|
|
291
|
+
opacity: 0;
|
|
292
|
+
translate: 0 12px;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
.arrive.in .person {
|
|
296
|
+
opacity: 1;
|
|
297
|
+
translate: 0 0;
|
|
298
|
+
transition:
|
|
299
|
+
opacity var(--motion-reveal, 500ms) var(--ease-out),
|
|
300
|
+
translate var(--motion-reveal, 500ms) var(--ease-out);
|
|
301
|
+
transition-delay: calc(var(--i) * 90ms);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
@media (forced-colors: active) {
|
|
305
|
+
.avatar {
|
|
306
|
+
border-color: CanvasText;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
blockquote {
|
|
310
|
+
border-left-color: CanvasText;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
</style>
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* How the result is shown, behind one button that says what's set: "View: Score · 30 days". Sort
|
|
4
|
+
* and period live here so the filters above stay about what's in the list, not how it's laid out.
|
|
5
|
+
* Put the controls in the slot (Segmented, each with its `label`, which becomes its caption). The
|
|
6
|
+
* panel is a native popover: a click outside or Escape closes it. Keep the button's words current
|
|
7
|
+
* with setViewMenu() from viewmenu.js.
|
|
8
|
+
*/
|
|
9
|
+
import { ICONS } from './icons';
|
|
10
|
+
|
|
11
|
+
interface Props {
|
|
12
|
+
/** The button's lead word, and the panel's name: "View". */
|
|
13
|
+
label?: string;
|
|
14
|
+
/** What's set, until setViewMenu() says: "Newest · 30 days". */
|
|
15
|
+
summary?: string;
|
|
16
|
+
id?: string;
|
|
17
|
+
}
|
|
18
|
+
const { label = 'View', summary = '', id } = Astro.props;
|
|
19
|
+
const panelId = `${id ?? 'view-menu'}-panel`;
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
<div class="view-menu" id={id} data-view-menu>
|
|
23
|
+
<button type="button" class="vm-button" data-vm-button popovertarget={panelId} aria-expanded="false" aria-haspopup="true">
|
|
24
|
+
<span class="vm-label">{label}:</span>
|
|
25
|
+
<span class="vm-summary" data-vm-summary>{summary}</span>
|
|
26
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" set:html={ICONS['chevron-down']} />
|
|
27
|
+
</button>
|
|
28
|
+
<div class="vm-panel" id={panelId} popover data-vm-panel role="group" aria-label={label}>
|
|
29
|
+
<slot />
|
|
30
|
+
</div>
|
|
31
|
+
</div>
|
|
32
|
+
|
|
33
|
+
<script>
|
|
34
|
+
import { wireViewMenu } from './viewmenu.js';
|
|
35
|
+
document.querySelectorAll<HTMLElement>('[data-view-menu]').forEach(wireViewMenu);
|
|
36
|
+
</script>
|
|
37
|
+
|
|
38
|
+
<style>
|
|
39
|
+
.view-menu {
|
|
40
|
+
display: inline-flex;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.vm-button {
|
|
44
|
+
display: inline-flex;
|
|
45
|
+
align-items: center;
|
|
46
|
+
gap: var(--sp-2);
|
|
47
|
+
min-height: 36px;
|
|
48
|
+
padding: 0 var(--sp-3);
|
|
49
|
+
border: 1px solid var(--c-border);
|
|
50
|
+
border-radius: var(--radius-md);
|
|
51
|
+
background: var(--c-surface);
|
|
52
|
+
color: var(--c-text-secondary);
|
|
53
|
+
font: inherit;
|
|
54
|
+
font-size: var(--text-body-sm);
|
|
55
|
+
cursor: pointer;
|
|
56
|
+
transition: border-color var(--motion-fast) var(--ease-out);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.vm-button:hover,
|
|
60
|
+
.vm-button[aria-expanded='true'] {
|
|
61
|
+
border-color: var(--c-border-strong);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.vm-button:focus-visible {
|
|
65
|
+
outline: 2px solid var(--c-focus);
|
|
66
|
+
outline-offset: 2px;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.vm-summary {
|
|
70
|
+
color: var(--c-text);
|
|
71
|
+
font-weight: 500;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.vm-button svg {
|
|
75
|
+
color: var(--c-text-muted);
|
|
76
|
+
transition: transform var(--motion-fast) var(--ease-out);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.vm-button[aria-expanded='true'] svg {
|
|
80
|
+
transform: rotate(180deg);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/* In the top layer, placed by viewmenu.js. Its layout applies only while open: a display set on
|
|
84
|
+
* the closed popover would override the browser's own rule that hides it. */
|
|
85
|
+
.vm-panel {
|
|
86
|
+
position: fixed;
|
|
87
|
+
inset: auto;
|
|
88
|
+
margin: 0;
|
|
89
|
+
width: min(300px, calc(100vw - 16px));
|
|
90
|
+
gap: var(--sp-2);
|
|
91
|
+
padding: var(--sp-4);
|
|
92
|
+
border: 1px solid var(--c-border);
|
|
93
|
+
border-radius: var(--radius-md);
|
|
94
|
+
background: var(--c-surface);
|
|
95
|
+
color: var(--c-text);
|
|
96
|
+
box-shadow: 0 12px 32px oklch(0 0 0 / 0.18);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.vm-panel:popover-open {
|
|
100
|
+
display: grid;
|
|
101
|
+
animation: vm-in var(--motion-fast) var(--ease-out);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
.vm-panel :global(.vm-caption) {
|
|
105
|
+
margin: 0;
|
|
106
|
+
color: var(--c-text-muted);
|
|
107
|
+
font-size: var(--text-caption);
|
|
108
|
+
font-weight: 600;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.vm-panel :global(.vm-caption:not(:first-child)) {
|
|
112
|
+
margin-top: var(--sp-2);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
@keyframes vm-in {
|
|
116
|
+
from {
|
|
117
|
+
opacity: 0;
|
|
118
|
+
transform: translateY(-4px) scale(0.98);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
@media (prefers-reduced-motion: reduce) {
|
|
123
|
+
.vm-panel:popover-open,
|
|
124
|
+
.vm-button,
|
|
125
|
+
.vm-button svg {
|
|
126
|
+
animation: none;
|
|
127
|
+
transition: none;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
</style>
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Drives ActiveFilters: what's narrowing the list, as pills that each take their filter off, and
|
|
2
|
+
// Clear all. Shown only while something is set. The page owns the filters: it listens, changes its
|
|
3
|
+
// state, and calls setActiveFilters() again.
|
|
4
|
+
//
|
|
5
|
+
// import { setActiveFilters } from '@n1kname/components/activefilters.js';
|
|
6
|
+
// setActiveFilters(bar, [{ key: 'where', label: 'Remote' }, { key: 'q', label: '"designer"' }]);
|
|
7
|
+
// bar.addEventListener('filter-remove', (e) => drop(e.detail.key));
|
|
8
|
+
// bar.addEventListener('filters-clear', () => dropAll());
|
|
9
|
+
//
|
|
10
|
+
// Removing a pill keeps keyboard focus in the bar: it lands on the pill that took the removed one's
|
|
11
|
+
// place, or on Clear all, or, with nothing left, on the element named by `data-return-focus`.
|
|
12
|
+
import { ICONS } from './icons';
|
|
13
|
+
|
|
14
|
+
const esc = (s) => String(s).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
15
|
+
const X = `<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${ICONS.x}</svg>`;
|
|
16
|
+
|
|
17
|
+
export const setActiveFilters = (root, filters = []) => {
|
|
18
|
+
const list = root.querySelector('[data-af-list]');
|
|
19
|
+
if (!list) return;
|
|
20
|
+
const remove = root.dataset.remove || 'Remove filter';
|
|
21
|
+
const had = new Set([...list.querySelectorAll('.af-pill')].map((p) => p.dataset.key));
|
|
22
|
+
list.innerHTML = filters
|
|
23
|
+
.map((f) => `<li><button type="button" class="af-pill${had.has(f.key) ? '' : ' enter'}" data-key="${esc(f.key)}" aria-label="${esc(remove)}: ${esc(f.label)}"><span>${esc(f.label)}</span>${X}</button></li>`)
|
|
24
|
+
.join('');
|
|
25
|
+
root.hidden = filters.length === 0;
|
|
26
|
+
// Put focus back where the person was, if they removed something with the keyboard.
|
|
27
|
+
const at = root.dataset.focusAt;
|
|
28
|
+
if (at === undefined) return;
|
|
29
|
+
delete root.dataset.focusAt;
|
|
30
|
+
const pills = list.querySelectorAll('.af-pill');
|
|
31
|
+
const target = pills[Math.min(Number(at), pills.length - 1)] ?? (filters.length ? root.querySelector('[data-af-clear]') : document.getElementById(root.dataset.returnFocus ?? ''));
|
|
32
|
+
target?.focus();
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const wireActiveFilters = (root) => {
|
|
36
|
+
root.addEventListener('click', (e) => {
|
|
37
|
+
const pill = e.target.closest('.af-pill');
|
|
38
|
+
if (pill) {
|
|
39
|
+
const pills = [...root.querySelectorAll('.af-pill')];
|
|
40
|
+
if (pill === document.activeElement) root.dataset.focusAt = String(pills.indexOf(pill));
|
|
41
|
+
root.dispatchEvent(new CustomEvent('filter-remove', { detail: { key: pill.dataset.key } }));
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (e.target.closest('[data-af-clear]')) {
|
|
45
|
+
if (e.target.closest('[data-af-clear]') === document.activeElement) root.dataset.focusAt = '0';
|
|
46
|
+
root.dispatchEvent(new CustomEvent('filters-clear'));
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
};
|
package/src/cardlist.css
CHANGED
|
@@ -10,7 +10,11 @@
|
|
|
10
10
|
list-style: none;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
/* The edge and the shadow are built from parts, so a state, hover and a second state stack instead
|
|
14
|
+
* of overriding each other: --edge is the border, then band, spine, ring, halo and lift as shadows.
|
|
15
|
+
* A state sets its parts; hover only swaps --edge for --edge-hover and adds the lift. */
|
|
13
16
|
.card {
|
|
17
|
+
--none: 0 0 0 0 transparent;
|
|
14
18
|
position: relative;
|
|
15
19
|
display: grid;
|
|
16
20
|
grid-template-columns: auto minmax(0, 1fr) auto;
|
|
@@ -21,19 +25,110 @@
|
|
|
21
25
|
column-gap: var(--sp-4);
|
|
22
26
|
row-gap: var(--sp-2);
|
|
23
27
|
padding: var(--sp-4) var(--sp-5);
|
|
24
|
-
border: 1px solid var(--c-border);
|
|
28
|
+
border: 1px solid var(--edge, var(--c-border));
|
|
25
29
|
border-radius: var(--radius-lg);
|
|
26
30
|
background: var(--c-surface);
|
|
31
|
+
box-shadow: var(--band, var(--none)), var(--spine, var(--none)), var(--ring, var(--none)), var(--halo, var(--none)), var(--lift, var(--none));
|
|
27
32
|
transition:
|
|
28
33
|
border-color var(--motion-hover) var(--ease-hover),
|
|
29
34
|
transform var(--motion-hover) var(--ease-hover),
|
|
30
|
-
box-shadow var(--motion-
|
|
35
|
+
box-shadow var(--motion-base) var(--ease-out);
|
|
31
36
|
}
|
|
32
37
|
|
|
33
38
|
.card-item:not(.placeholder) .card:hover {
|
|
34
|
-
border-color: var(--c-border-strong);
|
|
39
|
+
border-color: var(--edge-hover, var(--c-border-strong));
|
|
35
40
|
transform: translateY(-1px);
|
|
36
|
-
|
|
41
|
+
--lift: 0 2px 8px oklch(0 0 0 / 0.06);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/* ---- Item states: hue says what kind of thing it is, weight says how much it needs you ---- */
|
|
45
|
+
|
|
46
|
+
/* Reviewed (weight 2): they weighed in themselves. A quiet spine. */
|
|
47
|
+
.card-item[data-reviewed] .card {
|
|
48
|
+
--spine: inset 3px 0 0 0 var(--c-item-reviewed);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/* Live (weight 4): your process, moving. A ring in the process teal. */
|
|
52
|
+
.card-item[data-state='live'] .card {
|
|
53
|
+
--edge: var(--c-item-live);
|
|
54
|
+
--edge-hover: var(--c-item-live);
|
|
55
|
+
--ring: inset 0 0 0 1px var(--c-item-live);
|
|
56
|
+
--halo: 0 0 0 3px color-mix(in oklab, var(--c-item-live) 20%, transparent);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/* Action (weight 5): your process, needing you soon. The ring, a band, and the filled chip. */
|
|
60
|
+
.card-item[data-state='action'] .card {
|
|
61
|
+
--edge: var(--c-item-action);
|
|
62
|
+
--edge-hover: var(--c-item-action);
|
|
63
|
+
--band: inset 5px 0 0 0 var(--c-item-action);
|
|
64
|
+
--ring: inset 0 0 0 1px var(--c-item-action);
|
|
65
|
+
--halo: 0 0 0 3px color-mix(in oklab, var(--c-item-action) 26%, transparent);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.card-item[data-state='live']:not(.placeholder) .card:hover,
|
|
69
|
+
.card-item[data-state='action']:not(.placeholder) .card:hover {
|
|
70
|
+
--halo: 0 0 0 4px color-mix(in oklab, var(--c-item-live) 32%, transparent);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/* Once, on the first fill, so the eye finds it. Never loops. */
|
|
74
|
+
.card-item.pulse .card::before {
|
|
75
|
+
content: '';
|
|
76
|
+
position: absolute;
|
|
77
|
+
inset: -1px;
|
|
78
|
+
border-radius: inherit;
|
|
79
|
+
pointer-events: none;
|
|
80
|
+
animation: card-pulse var(--motion-reveal) var(--ease-out) var(--motion-slow) 1 both;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
@keyframes card-pulse {
|
|
84
|
+
from {
|
|
85
|
+
box-shadow: 0 0 0 0 color-mix(in oklab, var(--c-item-action) 55%, transparent);
|
|
86
|
+
}
|
|
87
|
+
to {
|
|
88
|
+
box-shadow: 0 0 0 12px color-mix(in oklab, var(--c-item-action) 0%, transparent);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/* History (weight 1): closed or set aside. Every word steps down one ink level and the dial goes
|
|
93
|
+
* quiet, rather than fading, so what's left still reads at AA. */
|
|
94
|
+
.card-item[data-state='history'] .card-title,
|
|
95
|
+
.card-item[data-state='history'] .card-open {
|
|
96
|
+
color: var(--c-text-secondary);
|
|
97
|
+
font-weight: 500;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.card-item[data-state='history'] .card-sub {
|
|
101
|
+
color: var(--c-text-muted);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
.card-item[data-state='history'] .score-dial {
|
|
105
|
+
--dial: var(--c-border-strong);
|
|
106
|
+
color: var(--c-text-muted);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/* New (weight 3): new since the person last looked. A dot before the title, like unread mail. */
|
|
110
|
+
.card-item[data-unseen] .card-title {
|
|
111
|
+
display: flex;
|
|
112
|
+
align-items: center;
|
|
113
|
+
gap: var(--sp-2);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.card-item[data-unseen] .card-title::before {
|
|
117
|
+
content: '';
|
|
118
|
+
flex: none;
|
|
119
|
+
width: 8px;
|
|
120
|
+
height: 8px;
|
|
121
|
+
border-radius: 50%;
|
|
122
|
+
background: var(--c-item-new);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
.card-vh {
|
|
126
|
+
position: absolute;
|
|
127
|
+
width: 1px;
|
|
128
|
+
height: 1px;
|
|
129
|
+
overflow: hidden;
|
|
130
|
+
clip-path: inset(50%);
|
|
131
|
+
white-space: nowrap;
|
|
37
132
|
}
|
|
38
133
|
|
|
39
134
|
.card:focus-within:has(.card-open:focus-visible) {
|
|
@@ -122,6 +217,35 @@
|
|
|
122
217
|
color: var(--c-status-good);
|
|
123
218
|
}
|
|
124
219
|
|
|
220
|
+
/* The item states in words. Live: a tint of the process teal. Action: the teal, filled, the
|
|
221
|
+
* heaviest chip there is. History: an outline only, so it recedes. */
|
|
222
|
+
.fact-chip.live {
|
|
223
|
+
background: var(--c-item-live-bg);
|
|
224
|
+
color: var(--c-text);
|
|
225
|
+
font-weight: 600;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
.fact-chip.live svg {
|
|
229
|
+
color: var(--c-item-live);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
.fact-chip.action {
|
|
233
|
+
background: var(--c-item-action);
|
|
234
|
+
color: var(--c-item-action-ink);
|
|
235
|
+
font-weight: 600;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
.fact-chip.action svg {
|
|
239
|
+
color: var(--c-item-action-ink);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
.fact-chip.history {
|
|
243
|
+
background: transparent;
|
|
244
|
+
outline: 1px dashed var(--c-border-strong);
|
|
245
|
+
outline-offset: -1px;
|
|
246
|
+
color: var(--c-item-history);
|
|
247
|
+
}
|
|
248
|
+
|
|
125
249
|
.card-actions {
|
|
126
250
|
grid-area: actions;
|
|
127
251
|
position: relative;
|
|
@@ -279,7 +403,8 @@
|
|
|
279
403
|
transform: none;
|
|
280
404
|
}
|
|
281
405
|
|
|
282
|
-
.card-item.enter
|
|
406
|
+
.card-item.enter,
|
|
407
|
+
.card-item.pulse .card::before {
|
|
283
408
|
animation: none;
|
|
284
409
|
}
|
|
285
410
|
|
package/src/cardlist.js
CHANGED
|
@@ -10,9 +10,20 @@
|
|
|
10
10
|
// list.addEventListener('card-open', (e) => open(e.detail.id));
|
|
11
11
|
// list.addEventListener('card-action', (e) => act(e.detail.id, e.detail.action, e.detail.button));
|
|
12
12
|
//
|
|
13
|
-
// An item: { id, title, subtitle?, href?, score?, scoreText?,
|
|
14
|
-
// actions?: [{ action, icon, label, pressed? }] }. Text is
|
|
15
|
-
// otherwise it's a button that fires `card-open`. The page
|
|
13
|
+
// An item: { id, title, subtitle?, href?, score?, scoreText?, state?, reviewed?, unseen?,
|
|
14
|
+
// chips?: [{ icon?, label, tone? }], actions?: [{ action, icon, label, pressed? }] }. Text is
|
|
15
|
+
// escaped; `href` makes the title a link, otherwise it's a button that fires `card-open`. The page
|
|
16
|
+
// sorts; the list keeps the order given.
|
|
17
|
+
//
|
|
18
|
+
// State follows one rule: hue says what kind of thing it is, weight says how much it needs you.
|
|
19
|
+
// state: 'action' your process, needing you soon: a band, a ring, and the page's filled chip
|
|
20
|
+
// state: 'live' your process, moving: a ring
|
|
21
|
+
// unseen: true new since the person last looked: a dot before the title
|
|
22
|
+
// reviewed: true they weighed in themselves: a spine
|
|
23
|
+
// state: 'history' closed or set aside: the words step down a level
|
|
24
|
+
// They stack: a live item someone reviewed shows the ring and the spine. Each state also says
|
|
25
|
+
// itself in words, in a chip the page writes (tone 'action', 'live' or 'history'), so colour never
|
|
26
|
+
// carries it alone. An action card pulses once on the first fill, so the eye finds it.
|
|
16
27
|
import { ICONS } from './icons';
|
|
17
28
|
import { snapshot, flip } from './flip.js';
|
|
18
29
|
|
|
@@ -31,16 +42,25 @@ export const dialHTML = (score, opts = {}) => {
|
|
|
31
42
|
return `<span class="score-dial ${scoreTone(score, opts)}" style="--p:${Math.max(0, Math.min(1, score / max))}" role="img" aria-label="Score ${esc(text)} out of ${max}"><span>${esc(text)}</span></span>`;
|
|
32
43
|
};
|
|
33
44
|
|
|
45
|
+
const STATES = new Set(['action', 'live', 'history']);
|
|
46
|
+
const TONES = new Set(['good', 'action', 'live', 'history']);
|
|
47
|
+
|
|
34
48
|
export const cardHTML = (item, opts = {}) => {
|
|
49
|
+
// "New: " is said with the title, since the dot before it is only drawn.
|
|
50
|
+
const name = `${item.unseen ? '<span class="card-vh">New: </span>' : ''}${esc(item.title)}`;
|
|
35
51
|
const title = item.href
|
|
36
|
-
? `<a class="card-open" href="${esc(item.href)}">${
|
|
37
|
-
: `<button type="button" class="card-open">${
|
|
38
|
-
const chips = (item.chips ?? []).map((c) => `<li class="fact-chip${c.tone
|
|
52
|
+
? `<a class="card-open" href="${esc(item.href)}">${name}</a>`
|
|
53
|
+
: `<button type="button" class="card-open">${name}</button>`;
|
|
54
|
+
const chips = (item.chips ?? []).map((c) => `<li class="fact-chip${TONES.has(c.tone) ? ` ${c.tone}` : ''}">${c.icon ? svg(c.icon) : ''}<span>${esc(c.label)}</span></li>`).join('');
|
|
39
55
|
const actions = (item.actions ?? [])
|
|
40
56
|
.map((a) => `<button type="button" class="icon-button" data-action="${esc(a.action)}" aria-label="${esc(a.label)}" title="${esc(a.label)}"${a.pressed === undefined ? '' : ` aria-pressed="${a.pressed}"`}>${svg(a.icon, 18, 1.75)}</button>`)
|
|
41
57
|
.join('');
|
|
58
|
+
const marks =
|
|
59
|
+
(STATES.has(item.state) ? ` data-state="${item.state}"` : '') +
|
|
60
|
+
(item.reviewed ? ' data-reviewed' : '') +
|
|
61
|
+
(item.unseen ? ' data-unseen' : '');
|
|
42
62
|
return (
|
|
43
|
-
`<li class="card-item" data-key="${esc(item.id)}"><article class="card">` +
|
|
63
|
+
`<li class="card-item" data-key="${esc(item.id)}"${marks}><article class="card">` +
|
|
44
64
|
`<div class="card-lead">${item.lead ?? dialHTML(item.score, { ...opts, text: item.scoreText })}</div>` +
|
|
45
65
|
`<div class="card-head"><h${opts.level ?? 3} class="card-title">${title}</h${opts.level ?? 3}>${item.subtitle ? `<p class="card-sub">${esc(item.subtitle)}</p>` : ''}</div>` +
|
|
46
66
|
(chips ? `<ul class="card-chips">${chips}</ul>` : '') +
|
|
@@ -75,7 +95,11 @@ export const setCards = (root, items) => {
|
|
|
75
95
|
if (wrap) wrap.dataset.state = items.length === 0 && wrap.querySelector('[data-state-for="empty"]') ? 'empty' : 'ready';
|
|
76
96
|
if (first) {
|
|
77
97
|
root.dataset.filled = '';
|
|
78
|
-
if (!reduced())
|
|
98
|
+
if (!reduced()) {
|
|
99
|
+
[...root.children].slice(0, 12).forEach((li, i) => { li.style.setProperty('--i', i); li.classList.add('enter'); });
|
|
100
|
+
// Once per page: the action cards pulse as they arrive, so the eye finds what needs it.
|
|
101
|
+
root.querySelectorAll('.card-item[data-state="action"]').forEach((li) => li.classList.add('pulse'));
|
|
102
|
+
}
|
|
79
103
|
} else flip(root, before);
|
|
80
104
|
};
|
|
81
105
|
|
|
@@ -100,6 +124,8 @@ export const removeCard = (root, id) =>
|
|
|
100
124
|
});
|
|
101
125
|
|
|
102
126
|
export const wireCards = (root) => {
|
|
127
|
+
// A list filled at build time gets its one pulse when the page wires it.
|
|
128
|
+
if (root.dataset.filled !== undefined && !reduced()) root.querySelectorAll('.card-item[data-state="action"]').forEach((li) => li.classList.add('pulse'));
|
|
103
129
|
root.addEventListener('click', (e) => {
|
|
104
130
|
const li = e.target.closest('.card-item');
|
|
105
131
|
if (!li || li.classList.contains('placeholder')) return;
|
package/src/chips.js
CHANGED
|
@@ -11,6 +11,17 @@
|
|
|
11
11
|
import { ICONS } from './icons';
|
|
12
12
|
|
|
13
13
|
const esc = (s) => String(s).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
14
|
+
const reduced = () => matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
15
|
+
const token = (name, fallback) => getComputedStyle(document.documentElement).getPropertyValue(name).trim() || fallback;
|
|
16
|
+
|
|
17
|
+
// A count that changes rolls in from just above, so the eye catches which ones moved.
|
|
18
|
+
const tick = (n) => {
|
|
19
|
+
if (reduced()) return;
|
|
20
|
+
n.animate([{ opacity: 0, transform: 'translateY(-4px)' }, { opacity: 1, transform: 'none' }], {
|
|
21
|
+
duration: parseFloat(token('--motion-base', '180ms')) || 180,
|
|
22
|
+
easing: token('--ease-out', 'ease-out'),
|
|
23
|
+
});
|
|
24
|
+
};
|
|
14
25
|
|
|
15
26
|
const button = (o, selected) =>
|
|
16
27
|
`<button type="button" data-value="${esc(o.value)}" aria-pressed="${selected === o.value}"${o.count === 0 && selected !== o.value ? ' disabled' : ''} style="--chip:${o.color ?? 'var(--c-accent)'}">` +
|
|
@@ -22,7 +33,8 @@ export const setChips = (root, options, selected = 'all') => {
|
|
|
22
33
|
const now = [...root.querySelectorAll('button[data-value]')].map((b) => b.dataset.value);
|
|
23
34
|
if (now.join('|') === list.map((o) => o.value).join('|')) {
|
|
24
35
|
// The first counts after a load land without the fade, so chips don't seem to switch on.
|
|
25
|
-
|
|
36
|
+
const first = !root.dataset.counted;
|
|
37
|
+
if (first) {
|
|
26
38
|
root.dataset.counted = '';
|
|
27
39
|
root.classList.add('settling');
|
|
28
40
|
requestAnimationFrame(() => requestAnimationFrame(() => root.classList.remove('settling')));
|
|
@@ -30,7 +42,10 @@ export const setChips = (root, options, selected = 'all') => {
|
|
|
30
42
|
root.querySelectorAll('button[data-value]').forEach((b, i) => {
|
|
31
43
|
const o = list[i];
|
|
32
44
|
const n = b.querySelector('.n');
|
|
33
|
-
if (n && o.count !== undefined
|
|
45
|
+
if (n && o.count !== undefined && n.textContent !== String(o.count)) {
|
|
46
|
+
n.textContent = String(o.count);
|
|
47
|
+
if (!first) tick(n);
|
|
48
|
+
}
|
|
34
49
|
b.disabled = o.count === 0 && selected !== o.value;
|
|
35
50
|
b.setAttribute('aria-pressed', String(o.value === selected));
|
|
36
51
|
});
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// Drives FilterSheet: the second rank of filters, in a row where there's room and behind one
|
|
2
|
+
// "Filters" button on a phone, which opens them in a bottom sheet. The groups themselves are moved
|
|
3
|
+
// into the sheet and back, so the page's own listeners on them (chips-change, segment-change) keep
|
|
4
|
+
// working and nothing is rendered twice.
|
|
5
|
+
//
|
|
6
|
+
// import { setFilterSheet } from '@n1kname/components/filtersheet.js';
|
|
7
|
+
// setFilterSheet(sheet, { active: 2, done: 'Show 12 jobs' });
|
|
8
|
+
// sheet.addEventListener('filters-clear', () => clearSecondFilters());
|
|
9
|
+
//
|
|
10
|
+
// `active` is how many of its groups are set, for the button's badge. `done` names what closing
|
|
11
|
+
// shows. Fires `filters-clear` from its Clear all.
|
|
12
|
+
|
|
13
|
+
const PHONE = '(max-width: 639px)';
|
|
14
|
+
|
|
15
|
+
export const setFilterSheet = (root, { active, done } = {}) => {
|
|
16
|
+
const count = root.querySelector('[data-fs-count]');
|
|
17
|
+
if (count && active !== undefined) {
|
|
18
|
+
count.textContent = active ? String(active) : '';
|
|
19
|
+
count.hidden = !active;
|
|
20
|
+
root.querySelector('[data-fs-open]')?.setAttribute('aria-label', `${root.dataset.label}${active ? `, ${active} set` : ''}`);
|
|
21
|
+
}
|
|
22
|
+
const doneButton = root.querySelector('[data-fs-done]');
|
|
23
|
+
if (doneButton && done) doneButton.textContent = done;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const wireFilterSheet = (root) => {
|
|
27
|
+
const home = root.querySelector('[data-fs-home]');
|
|
28
|
+
const sheet = root.querySelector('[data-fs-sheet]');
|
|
29
|
+
const body = root.querySelector('[data-fs-body]');
|
|
30
|
+
if (!home || !sheet || !body) return;
|
|
31
|
+
let groups = [];
|
|
32
|
+
|
|
33
|
+
// Each group gets a caption from its own name in the sheet, where there's no row to give context.
|
|
34
|
+
const open = () => {
|
|
35
|
+
groups = [...home.children];
|
|
36
|
+
body.replaceChildren(
|
|
37
|
+
...groups.map((g) => {
|
|
38
|
+
const section = document.createElement('section');
|
|
39
|
+
section.className = 'fs-section';
|
|
40
|
+
const name = g.getAttribute('aria-label');
|
|
41
|
+
if (name) {
|
|
42
|
+
const caption = document.createElement('p');
|
|
43
|
+
caption.className = 'fs-caption';
|
|
44
|
+
caption.setAttribute('aria-hidden', 'true');
|
|
45
|
+
caption.textContent = name;
|
|
46
|
+
section.append(caption);
|
|
47
|
+
}
|
|
48
|
+
section.append(g);
|
|
49
|
+
return section;
|
|
50
|
+
}),
|
|
51
|
+
);
|
|
52
|
+
sheet.showModal();
|
|
53
|
+
root.querySelector('[data-fs-open]')?.setAttribute('aria-expanded', 'true');
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const restore = () => {
|
|
57
|
+
home.append(...groups);
|
|
58
|
+
body.replaceChildren();
|
|
59
|
+
root.querySelector('[data-fs-open]')?.setAttribute('aria-expanded', 'false');
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
root.querySelector('[data-fs-open]')?.addEventListener('click', open);
|
|
63
|
+
root.querySelector('[data-fs-done]')?.addEventListener('click', () => sheet.close());
|
|
64
|
+
root.querySelector('[data-fs-clear]')?.addEventListener('click', () => root.dispatchEvent(new CustomEvent('filters-clear')));
|
|
65
|
+
// A tap on the dimmed page behind the sheet closes it, as Escape does.
|
|
66
|
+
sheet.addEventListener('click', (e) => { if (e.target === sheet) sheet.close(); });
|
|
67
|
+
sheet.addEventListener('close', restore);
|
|
68
|
+
// Turned to landscape or widened past the phone layout: the row is back, so the sheet goes.
|
|
69
|
+
matchMedia(PHONE).addEventListener('change', (e) => { if (!e.matches && sheet.open) sheet.close(); });
|
|
70
|
+
};
|
package/src/icons.ts
CHANGED
|
@@ -76,6 +76,9 @@ export const ICONS = {
|
|
|
76
76
|
workflow:
|
|
77
77
|
'<rect width="8" height="8" x="3" y="3" rx="2"/><path d="M7 11v4a2 2 0 0 0 2 2h4"/><rect width="8" height="8" x="13" y="13" rx="2"/>',
|
|
78
78
|
'chevron-down': '<path d="m6 9 6 6 6-6"/>',
|
|
79
|
+
// More filters live here (FilterSheet's button on a phone).
|
|
80
|
+
'sliders-horizontal':
|
|
81
|
+
'<path d="M21 4h-7"/><path d="M10 4H3"/><path d="M21 12h-9"/><path d="M8 12H3"/><path d="M21 20h-5"/><path d="M12 20H3"/><path d="M14 2v4"/><path d="M8 10v4"/><path d="M16 18v4"/>',
|
|
79
82
|
'arrow-right': '<path d="M5 12h14"/><path d="m12 5 7 7-7 7"/>',
|
|
80
83
|
quote:
|
|
81
84
|
'<path d="M16 3a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2h1a1 1 0 0 1 1 1v1a2 2 0 0 1-2 2 1 1 0 0 0-1 1v2a1 1 0 0 0 1 1 6 6 0 0 0 6-6V5a2 2 0 0 0-2-2z"/><path d="M5 3a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2h1a1 1 0 0 1 1 1v1a2 2 0 0 1-2 2 1 1 0 0 0-1 1v2a1 1 0 0 0 1 1 6 6 0 0 0 6-6V5a2 2 0 0 0-2-2z"/>',
|
package/src/viewmenu.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// Drives ViewMenu: how the result is shown (sort, period), behind one button that says what's set.
|
|
2
|
+
// The panel is a native popover, so a click outside or Escape closes it; this only places it under
|
|
3
|
+
// its button and keeps the button's words current.
|
|
4
|
+
//
|
|
5
|
+
// import { setViewMenu } from '@n1kname/components/viewmenu.js';
|
|
6
|
+
// setViewMenu(menu, 'Score · 30 days');
|
|
7
|
+
//
|
|
8
|
+
// The controls inside are the page's own (Segmented, say), each with its label, which becomes its
|
|
9
|
+
// caption in the panel; listen to them as usual.
|
|
10
|
+
|
|
11
|
+
export const setViewMenu = (root, summary) => {
|
|
12
|
+
const out = root.querySelector('[data-vm-summary]');
|
|
13
|
+
if (out && summary !== undefined) out.textContent = summary;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const wireViewMenu = (root) => {
|
|
17
|
+
const button = root.querySelector('[data-vm-button]');
|
|
18
|
+
const panel = root.querySelector('[data-vm-panel]');
|
|
19
|
+
if (!button || !panel) return;
|
|
20
|
+
|
|
21
|
+
// A caption over each control from its own name, hidden from screen readers, which already
|
|
22
|
+
// hear the group's label.
|
|
23
|
+
for (const control of [...panel.children]) {
|
|
24
|
+
const name = control.getAttribute('aria-label');
|
|
25
|
+
if (!name || control.previousElementSibling?.classList.contains('vm-caption')) continue;
|
|
26
|
+
const caption = document.createElement('p');
|
|
27
|
+
caption.className = 'vm-caption';
|
|
28
|
+
caption.setAttribute('aria-hidden', 'true');
|
|
29
|
+
caption.textContent = name;
|
|
30
|
+
control.before(caption);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Under the button, its right edge on the button's, kept on screen. Placed before it shows
|
|
34
|
+
// (beforetoggle), so it never flashes elsewhere; its width is set in CSS, so it's known then.
|
|
35
|
+
const place = () => {
|
|
36
|
+
const b = button.getBoundingClientRect();
|
|
37
|
+
const w = panel.offsetWidth || Math.min(300, innerWidth - 16);
|
|
38
|
+
const left = Math.max(8, Math.min(b.right - w, innerWidth - w - 8));
|
|
39
|
+
panel.style.top = `${b.bottom + 6}px`;
|
|
40
|
+
panel.style.left = `${left}px`;
|
|
41
|
+
};
|
|
42
|
+
panel.addEventListener('beforetoggle', (e) => {
|
|
43
|
+
if (e.newState !== 'open') return;
|
|
44
|
+
place();
|
|
45
|
+
addEventListener('resize', place);
|
|
46
|
+
addEventListener('scroll', place, { passive: true, capture: true });
|
|
47
|
+
});
|
|
48
|
+
panel.addEventListener('toggle', (e) => {
|
|
49
|
+
const open = e.newState === 'open';
|
|
50
|
+
button.setAttribute('aria-expanded', String(open));
|
|
51
|
+
if (!open) {
|
|
52
|
+
removeEventListener('resize', place);
|
|
53
|
+
removeEventListener('scroll', place, { capture: true });
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
};
|