@n1kname/components 0.58.0 → 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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/Personas.astro +313 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@n1kname/components",
3
- "version": "0.58.0",
3
+ "version": "0.59.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -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>