@n1kname/components 0.68.1 → 0.69.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@n1kname/components",
3
- "version": "0.68.1",
3
+ "version": "0.69.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -33,10 +33,12 @@
33
33
  "./cardlist.js": "./src/cardlist.js",
34
34
  "./filtersheet.js": "./src/filtersheet.js",
35
35
  "./activefilters.js": "./src/activefilters.js",
36
- "./viewmenu.js": "./src/viewmenu.js"
36
+ "./viewmenu.js": "./src/viewmenu.js",
37
+ "./rangeposition.js": "./src/rangeposition.js",
38
+ "./rangeposition.css": "./src/rangeposition.css"
37
39
  },
38
40
  "dependencies": {
39
- "@n1kname/charts": "0.15.0"
41
+ "@n1kname/charts": "0.16.0"
40
42
  },
41
43
  "peerDependencies": {
42
44
  "@n1kname/tokens": "^0.11.2",
@@ -7,10 +7,14 @@
7
7
  * Fill it at build time with `items`, or at runtime with setCards() from cardlist.js, which also
8
8
  * has setCardState() for loading, empty and failed, and removeCard(), which slides a card out and
9
9
  * closes the gap. Fires `card-open` and `card-action` with the item's id. The page sorts.
10
+ *
11
+ * With `columns`, every card also carries a few figures by key (now, target, lowest), lined up in
12
+ * columns between the title and the actions under a header row of the labels. Below 640px they
13
+ * wrap into a line under the chips, each with its label. New in 0.69.0.
10
14
  */
11
15
  import './controls.css';
12
16
  import './cardlist.css';
13
- import { cardHTML, placeholdersHTML } from './cardlist.js';
17
+ import { cardHTML, placeholdersHTML, columnsHeadHTML } from './cardlist.js';
14
18
 
15
19
  interface Chip {
16
20
  icon?: string;
@@ -21,19 +25,39 @@ interface Chip {
21
25
  */
22
26
  tone?: 'neutral' | 'good' | 'action' | 'live' | 'history';
23
27
  }
28
+ interface Column {
29
+ /** The key of the figure in each item's `figures`. */
30
+ key: string;
31
+ /** Short: "Now", "Target", "Lowest". Heads the column, and says the figure on a phone. */
32
+ label: string;
33
+ /** Figures are right-aligned, so their digits line up; left for a word. */
34
+ align?: 'left' | 'right';
35
+ }
36
+ interface Figure {
37
+ value: string | number;
38
+ /** A small second line, such as when it was: "Sep 2023". */
39
+ sub?: string;
40
+ /** good: in the item's favour, in the status-good tint, as the good chip. */
41
+ tone?: 'neutral' | 'good';
42
+ }
24
43
  interface Item {
25
44
  id: string;
26
45
  title: string;
27
46
  subtitle?: string;
28
47
  href?: string;
48
+ /** HTML in place of the dial (a photo, a figure, a sparkline), put in as it is. */
49
+ lead?: string;
50
+ /** By column key. A column the item has no figure for shows a dash. */
51
+ figures?: Record<string, Figure>;
29
52
  score?: number | null;
30
53
  scoreText?: string;
31
54
  /**
32
55
  * 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
56
+ * needing you soon (band, ring, pulses once). live: your process, moving (ring). good: in the
57
+ * person's favour, such as a price at or under its target (green ring and tint). history: closed
34
58
  * or set aside (the words step down). Pair each with a chip of the same tone that says it.
35
59
  */
36
- state?: 'action' | 'live' | 'history';
60
+ state?: 'action' | 'live' | 'good' | 'history';
37
61
  /** They weighed in themselves: a status, a note, a rating. A spine. */
38
62
  reviewed?: boolean;
39
63
  /** New since they last looked: a dot before the title, and "New" said with it. */
@@ -54,19 +78,25 @@ interface Props {
54
78
  level?: 2 | 3 | 4 | 5;
55
79
  /** Actions show on hover or focus where a pointer hovers; always on touch. Off: always shown. */
56
80
  reveal?: boolean;
81
+ /** Figure columns every card shares, between the title and the actions. */
82
+ columns?: Column[];
83
+ /** The header row of the column labels. Off: each figure shows its label above it instead. */
84
+ columnHeader?: boolean;
57
85
  /** Starts with placeholder cards; setCards() or setCardState() ends it. */
58
86
  loading?: boolean;
59
87
  loadingCards?: number;
60
88
  id?: string;
61
89
  }
62
- const { items = [], label, good = 7, warning = 5, max = 10, level = 3, reveal = false, loading = false, loadingCards = 4, id } = Astro.props;
90
+ const { items = [], label, good = 7, warning = 5, max = 10, level = 3, reveal = false, columns = [], columnHeader = true, loading = false, loadingCards = 4, id } = Astro.props;
63
91
  const hasEmpty = Astro.slots.has('empty');
64
- const html = loading ? placeholdersHTML(loadingCards) : items.map((i) => cardHTML(i, { good, warning, max, level })).join('');
92
+ const cols = columns.map(({ key, label, align }) => ({ key, label, ...(align ? { align } : {}) }));
93
+ const html = loading ? placeholdersHTML(loadingCards, cols.length) : items.map((i) => cardHTML(i, { good, warning, max, level, columns: cols })).join('');
65
94
  const state = loading ? 'loading' : items.length === 0 && hasEmpty ? 'empty' : 'ready';
66
95
  ---
67
96
 
68
- <div class="card-list-wrap" data-state={state}>
69
- <ul class:list={['card-list', { reveal }]} id={id} aria-label={label} data-card-list data-good={good} data-warning={warning} data-max={max} data-level={level} aria-busy={loading ? 'true' : undefined} data-filled={items.length ? '' : undefined} set:html={html} />
97
+ <div class:list={['card-list-wrap', { 'has-columns': cols.length, 'cell-labels': cols.length && !columnHeader }]} data-state={state} style={cols.length ? `--card-cols: ${cols.length}` : undefined}>
98
+ {cols.length > 0 && columnHeader && <Fragment set:html={columnsHeadHTML(cols)} />}
99
+ <ul class:list={['card-list', { reveal }]} id={id} aria-label={label} data-card-list data-good={good} data-warning={warning} data-max={max} data-level={level} data-columns={cols.length ? JSON.stringify(cols) : undefined} aria-busy={loading ? 'true' : undefined} data-filled={items.length ? '' : undefined} set:html={html} />
70
100
  {hasEmpty && <div class="state empty" data-state-for="empty"><slot name="empty" /></div>}
71
101
  {Astro.slots.has('failed') && <div class="state failed" data-state-for="failed"><slot name="failed" /></div>}
72
102
  </div>
@@ -174,7 +174,9 @@ const shown = start === 'all' ? all : (periods.find((p) => p.value === start)?.l
174
174
  border-radius: var(--radius-md);
175
175
  background: var(--c-surface);
176
176
  color: var(--c-text);
177
- box-shadow: 0 12px 32px rgb(0 0 0 / 0.18);
177
+ box-shadow:
178
+ 0 1px 2px oklch(0 0 0 / 0.08),
179
+ 0 12px 32px oklch(0 0 0 / 0.22);
178
180
  /* It opens on the spring from the control it belongs to, and leaves quicker. */
179
181
  opacity: 0;
180
182
  transform: translateY(-4px) scale(0.98);
@@ -0,0 +1,41 @@
1
+ ---
2
+ /**
3
+ * Where one value sits in its range: a band from the period's low to its high, a dot for the
4
+ * value and a dashed tick for a reference such as a target, the low and high under the band, and
5
+ * a key that says the dot and the tick in words. For one value read against its own history, such
6
+ * as today's price against the last 90 days. For many rows of estimates, use RangeBars.
7
+ *
8
+ * Fill it at build time with the props, or at runtime with setRangePosition() from
9
+ * rangeposition.js. Leave `low` out to hold its room until then. New in 0.69.0.
10
+ */
11
+ import './rangeposition.css';
12
+ import { rangePositionHTML } from './rangeposition.js';
13
+
14
+ interface Props {
15
+ low?: number;
16
+ high?: number;
17
+ value?: number;
18
+ /** A level to read the value against, such as a target. A dashed tick. */
19
+ reference?: number;
20
+ /** Words for a number, such as a price. Build time only; at runtime pass `format` to setRangePosition(). */
21
+ format?: (v: number) => string;
22
+ /** Names the dot, the tick and the band in the key and for a screen reader. */
23
+ valueLabel?: string;
24
+ referenceLabel?: string;
25
+ rangeLabel?: string;
26
+ /** good: the value is in the person's favour, and the dot turns the status green. */
27
+ tone?: 'neutral' | 'good';
28
+ id?: string;
29
+ }
30
+ const { id, ...opts } = Astro.props;
31
+ const html = rangePositionHTML(opts);
32
+ ---
33
+
34
+ <div class="range-position" id={id} data-range-position set:html={html} />
35
+
36
+ <style>
37
+ /* Room for the scale, the ends and one line of key, so nothing moves when it's filled. */
38
+ .range-position {
39
+ min-height: 76px;
40
+ }
41
+ </style>
@@ -59,6 +59,7 @@ const { label, options, value = options[0]?.value ?? null, id } = Astro.props;
59
59
  color: var(--c-text-secondary);
60
60
  font: inherit;
61
61
  font-size: var(--text-body-sm);
62
+ white-space: nowrap;
62
63
  cursor: pointer;
63
64
  transition: color var(--motion-hover) var(--ease-hover);
64
65
  }
@@ -81,19 +81,37 @@ const panelId = `${id ?? 'view-menu'}-panel`;
81
81
  }
82
82
 
83
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. */
84
+ * the closed popover would override the browser's own rule that hides it. As wide as its
85
+ * controls need, from 300px up to 480px, never wider than the window less 8px a side. It floats
86
+ * over the list, often over a card's own ring, so it takes the strong hairline and a shadow. */
85
87
  .vm-panel {
86
88
  position: fixed;
87
89
  inset: auto;
88
90
  margin: 0;
89
- width: min(300px, calc(100vw - 16px));
91
+ width: max-content;
92
+ min-width: min(300px, calc(100vw - 16px));
93
+ max-width: min(480px, calc(100vw - 16px));
90
94
  gap: var(--sp-2);
91
95
  padding: var(--sp-4);
92
- border: 1px solid var(--c-border);
96
+ border: 1px solid var(--c-border-strong);
93
97
  border-radius: var(--radius-md);
94
98
  background: var(--c-surface);
95
99
  color: var(--c-text);
96
- box-shadow: 0 12px 32px oklch(0 0 0 / 0.18);
100
+ box-shadow:
101
+ 0 1px 2px oklch(0 0 0 / 0.08),
102
+ 0 12px 32px oklch(0 0 0 / 0.22);
103
+ }
104
+
105
+ /* A Segmented in the panel spans it, its options sharing the width (a longer label takes more),
106
+ * and scrolls sideways rather than wrap a label when a phone is too narrow for them. */
107
+ .vm-panel :global(.segmented) {
108
+ max-width: 100%;
109
+ overflow-x: auto;
110
+ scrollbar-width: none;
111
+ }
112
+
113
+ .vm-panel :global(.segmented > button) {
114
+ flex: 1 1 0;
97
115
  }
98
116
 
99
117
  .vm-panel:popover-open {
package/src/cardlist.css CHANGED
@@ -15,6 +15,8 @@
15
15
  * A state sets its parts; hover only swaps --edge for --edge-hover and adds the lift. */
16
16
  .card {
17
17
  --none: 0 0 0 0 transparent;
18
+ /* The card's own surface, which a state may tint; chips and figures mix their tints on it. */
19
+ --card-bg: var(--c-surface);
18
20
  position: relative;
19
21
  display: grid;
20
22
  grid-template-columns: auto minmax(0, 1fr) auto;
@@ -27,7 +29,7 @@
27
29
  padding: var(--sp-4) var(--sp-5);
28
30
  border: 1px solid var(--edge, var(--c-border));
29
31
  border-radius: var(--radius-lg);
30
- background: var(--c-surface);
32
+ background: var(--card-bg);
31
33
  box-shadow: var(--band, var(--none)), var(--spine, var(--none)), var(--ring, var(--none)), var(--halo, var(--none)), var(--lift, var(--none));
32
34
  transition:
33
35
  border-color var(--motion-hover) var(--ease-hover),
@@ -56,6 +58,26 @@
56
58
  --halo: 0 0 0 3px color-mix(in oklab, var(--c-item-live) 20%, transparent);
57
59
  }
58
60
 
61
+ /* Good: in the person's favour, such as a price at or under its target. A ring and a light tint
62
+ * of the status green, never a band down one side, and the good chip says it in words. Its
63
+ * secondary words take the green's hue at their own lightness, so they still read at AA. */
64
+ .card-item[data-state='good'] .card {
65
+ --card-bg: color-mix(in oklab, var(--c-status-good) 9%, var(--c-surface));
66
+ --card-ink-2: var(--c-text-secondary);
67
+ --card-ink-2: oklch(from var(--c-text-secondary) l c 150);
68
+ --edge: var(--c-status-good);
69
+ --edge-hover: var(--c-status-good);
70
+ --ring: inset 0 0 0 1px var(--c-status-good);
71
+ }
72
+
73
+ .card-item[data-state='good'] :is(.card-sub, .card-figure-sub, .fact-chip) {
74
+ color: var(--card-ink-2);
75
+ }
76
+
77
+ .card-item[data-state='good'] .fact-chip.good {
78
+ color: var(--c-text);
79
+ }
80
+
59
81
  /* Action (weight 5): your process, needing you soon. The ring, a band, and the filled chip. */
60
82
  .card-item[data-state='action'] .card {
61
83
  --edge: var(--c-item-action);
@@ -209,7 +231,7 @@
209
231
 
210
232
  /* Something in the item's favour. The page decides what; the chip only says good. */
211
233
  .fact-chip.good {
212
- background: color-mix(in oklab, var(--c-status-good) 16%, var(--c-surface));
234
+ background: color-mix(in oklab, var(--c-status-good) 16%, var(--card-bg, var(--c-surface)));
213
235
  color: var(--c-text);
214
236
  }
215
237
 
@@ -290,7 +312,7 @@
290
312
  position: absolute;
291
313
  inset: 4px;
292
314
  border-radius: 50%;
293
- background: var(--c-surface);
315
+ background: var(--card-bg, var(--c-surface));
294
316
  }
295
317
 
296
318
  .score-dial > span {
@@ -331,6 +353,214 @@
331
353
  }
332
354
  }
333
355
 
356
+ /* ---- Figure columns (CardList `columns`): a few numbers every card shares ---- */
357
+ .card-figures {
358
+ margin: 0;
359
+ }
360
+
361
+ /* Top-aligned, so labels and values each share a line across the card whatever has a small line. */
362
+ .card-figure {
363
+ display: grid;
364
+ align-content: start;
365
+ min-width: 0;
366
+ }
367
+
368
+ .card-figure.right {
369
+ justify-items: end;
370
+ text-align: right;
371
+ }
372
+
373
+ .card-figure.left {
374
+ justify-items: start;
375
+ text-align: left;
376
+ }
377
+
378
+ .card-figure dd {
379
+ margin: 0;
380
+ }
381
+
382
+ .card-figure-label {
383
+ font-size: var(--text-caption);
384
+ color: var(--c-text-muted);
385
+ white-space: nowrap;
386
+ }
387
+
388
+ .card-figure-value,
389
+ .card-figure.none dd {
390
+ color: var(--c-text);
391
+ font-weight: 600;
392
+ font-variant-numeric: tabular-nums;
393
+ white-space: nowrap;
394
+ }
395
+
396
+ .card-figure.none dd {
397
+ color: var(--c-text-muted);
398
+ font-weight: 400;
399
+ }
400
+
401
+ .card-figure-sub {
402
+ font-size: var(--text-caption);
403
+ color: var(--c-text-secondary);
404
+ font-variant-numeric: tabular-nums;
405
+ white-space: nowrap;
406
+ }
407
+
408
+ /* In the item's favour: the good chip's tint behind the figure, its digits where they'd be. */
409
+ .card-figure.good .card-figure-value {
410
+ margin-inline: -6px;
411
+ padding: 0 6px;
412
+ border-radius: var(--radius-sm);
413
+ background: color-mix(in oklab, var(--c-status-good) 16%, var(--card-bg, var(--c-surface)));
414
+ }
415
+
416
+ .card-item.placeholder .card-figure .bar {
417
+ width: 6ch;
418
+ }
419
+
420
+ /* 640px and up: the figures sit in columns lined up down the list. The wrap is the grid and each
421
+ * level down (list, item, card, figures) a subgrid of it, so every card shares its column lines
422
+ * with the header row of labels. */
423
+ @media (min-width: 640px) {
424
+ .card-list-wrap.has-columns {
425
+ display: grid;
426
+ grid-template-columns: auto minmax(0, 1fr) repeat(var(--card-cols, 1), auto) auto;
427
+ column-gap: var(--sp-4);
428
+ row-gap: var(--sp-1);
429
+ }
430
+
431
+ .card-list-wrap.has-columns > *,
432
+ .card-list-wrap.has-columns .card-item {
433
+ grid-column: 1 / -1;
434
+ }
435
+
436
+ .card-list-wrap.has-columns :is(.card-list, .card-item, .card, .card-cols-head, .card-figures) {
437
+ display: grid;
438
+ grid-template-columns: subgrid;
439
+ column-gap: inherit;
440
+ }
441
+
442
+ .card-list-wrap.has-columns[data-state='empty'] > .card-list,
443
+ .card-list-wrap.has-columns[data-state='failed'] > .card-list {
444
+ display: none;
445
+ }
446
+
447
+ .card-list-wrap.has-columns .card {
448
+ grid-column: 1 / -1;
449
+ grid-template-areas: none;
450
+ }
451
+
452
+ .card-list-wrap.has-columns .card-lead {
453
+ grid-column: 1;
454
+ grid-row: 1 / 3;
455
+ }
456
+
457
+ .card-list-wrap.has-columns .card-head {
458
+ grid-column: 2;
459
+ grid-row: 1;
460
+ align-self: end;
461
+ }
462
+
463
+ .card-list-wrap.has-columns .card-chips {
464
+ grid-column: 2;
465
+ grid-row: 2;
466
+ align-self: start;
467
+ }
468
+
469
+ .card-list-wrap.has-columns .card:not(:has(.card-chips)) .card-head {
470
+ grid-row: 1 / 3;
471
+ align-self: center;
472
+ }
473
+
474
+ .card-list-wrap.has-columns .card-figures {
475
+ grid-column: 3 / -2;
476
+ grid-row: 1 / 3;
477
+ align-self: center;
478
+ }
479
+
480
+ .card-list-wrap.has-columns .card-actions {
481
+ grid-column: -2 / -1;
482
+ grid-row: 1 / 3;
483
+ }
484
+
485
+ /* The header row: the labels over their columns, in from the card's edge as the figures are. */
486
+ .card-cols-head .card-figures {
487
+ grid-row: auto;
488
+ }
489
+
490
+ .card-cols-head .card-figure-label.right {
491
+ text-align: right;
492
+ }
493
+
494
+ /* With the header row, each figure's own label is for screen readers only. */
495
+ .card-list-wrap.has-columns:not(.cell-labels) .card-list .card-figure-label {
496
+ position: absolute;
497
+ width: 1px;
498
+ height: 1px;
499
+ overflow: hidden;
500
+ clip-path: inset(50%);
501
+ white-space: nowrap;
502
+ }
503
+ }
504
+
505
+ .card-cols-head {
506
+ display: none;
507
+ }
508
+
509
+ @media (min-width: 640px) {
510
+ .card-list-wrap.has-columns > .card-cols-head {
511
+ display: grid;
512
+ }
513
+
514
+ .card-list-wrap.has-columns[data-state='empty'] > .card-cols-head,
515
+ .card-list-wrap.has-columns[data-state='failed'] > .card-cols-head,
516
+ .card-list-wrap.has-columns:has(> .card-list:empty) > .card-cols-head {
517
+ display: none;
518
+ }
519
+ }
520
+
521
+ /* Below 640px: the figures wrap into a line under the chips, each with its label. */
522
+ @media (max-width: 639px) {
523
+ .card-list-wrap.has-columns .card {
524
+ grid-template-areas:
525
+ 'lead head head'
526
+ 'chips chips actions'
527
+ 'figs figs figs';
528
+ }
529
+
530
+ .card-list-wrap.has-columns .card:has(.card-chips) .card-actions {
531
+ align-self: center;
532
+ }
533
+
534
+ .card-list-wrap.has-columns .card:not(:has(.card-chips)) {
535
+ grid-template-areas:
536
+ 'lead head head'
537
+ 'figs figs actions';
538
+ }
539
+
540
+ .card-list-wrap.has-columns .card-figures {
541
+ grid-area: figs;
542
+ display: flex;
543
+ flex-wrap: wrap;
544
+ align-items: baseline;
545
+ gap: var(--sp-1) var(--sp-4);
546
+ }
547
+
548
+ .card-list-wrap.has-columns .card-figure {
549
+ display: flex;
550
+ align-items: baseline;
551
+ column-gap: 6px;
552
+ text-align: left;
553
+ }
554
+
555
+ .card-list-wrap.has-columns .card-figure.good .card-figure-value {
556
+ margin-inline: 0;
557
+ }
558
+
559
+ .card-list-wrap.has-columns .card-figure.none {
560
+ display: none;
561
+ }
562
+ }
563
+
334
564
  /* ---- States, as DataTable's ---- */
335
565
  .card-list-wrap > .state {
336
566
  display: none;
package/src/cardlist.js CHANGED
@@ -10,19 +10,27 @@
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?, 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.
13
+ // An item: { id, title, subtitle?, href?, lead?, score?, scoreText?, state?, reviewed?, unseen?,
14
+ // chips?: [{ icon?, label, tone? }], figures?: { [key]: { value, sub?, tone? } },
15
+ // actions?: [{ action, icon, label, pressed? }] }. Text is escaped; `lead` is HTML, put in as it
16
+ // is, in place of the dial. `href` makes the title a link, otherwise it's a button that fires
17
+ // `card-open`. The page sorts; the list keeps the order given.
18
+ //
19
+ // Figures: a list whose cards share a few numbers (now, target, lowest) gives CardList `columns`,
20
+ // [{ key, label, align? }], and each item its `figures` by key. They sit in columns between the
21
+ // title and the actions, lined up down the list, under a header row of the labels. Below 640px they
22
+ // wrap into a line under the chips, each with its label. setCards() reads the columns from the list;
23
+ // cardHTML() takes them as `columns`. A figure's tone 'good' tints it, as the good chip.
17
24
  //
18
25
  // State follows one rule: hue says what kind of thing it is, weight says how much it needs you.
19
26
  // state: 'action' your process, needing you soon: a band, a ring, and the page's filled chip
20
27
  // state: 'live' your process, moving: a ring
28
+ // state: 'good' in the person's favour (a price at or under its target): a green ring and tint
21
29
  // unseen: true new since the person last looked: a dot before the title
22
30
  // reviewed: true they weighed in themselves: a spine
23
31
  // state: 'history' closed or set aside: the words step down a level
24
32
  // 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
33
+ // itself in words, in a chip the page writes (tone 'action', 'live', 'good' or 'history'), so colour never
26
34
  // carries it alone. An action card pulses once on the first fill, so the eye finds it.
27
35
  import { ICONS } from './icons';
28
36
  import { snapshot, flip } from './flip.js';
@@ -42,8 +50,35 @@ export const dialHTML = (score, opts = {}) => {
42
50
  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>`;
43
51
  };
44
52
 
45
- const STATES = new Set(['action', 'live', 'history']);
53
+ const STATES = new Set(['action', 'live', 'good', 'history']);
46
54
  const TONES = new Set(['good', 'action', 'live', 'history']);
55
+ const FIGURE_TONES = new Set(['good']);
56
+
57
+ const alignOf = (c) => (c.align === 'left' ? 'left' : 'right');
58
+
59
+ /** The figures of one card, a <dl> in the list's columns. A missing figure shows a dash. */
60
+ export const figuresHTML = (figures = {}, columns = []) =>
61
+ `<dl class="card-figures">` +
62
+ columns
63
+ .map((c) => {
64
+ const f = figures?.[c.key];
65
+ const has = f && f.value !== null && f.value !== undefined && f.value !== '';
66
+ const tone = has && FIGURE_TONES.has(f.tone) ? ` ${f.tone}` : '';
67
+ const value = has ? `<span class="card-figure-value">${esc(f.value)}</span>` : `<span aria-hidden="true">–</span><span class="card-vh">None</span>`;
68
+ return (
69
+ `<div class="card-figure ${alignOf(c)}${tone}${has ? '' : ' none'}" data-col="${esc(c.key)}">` +
70
+ `<dt class="card-figure-label">${esc(c.label)}</dt>` +
71
+ `<dd>${value}</dd>` +
72
+ (has && f.sub ? `<dd class="card-figure-sub">${esc(f.sub)}</dd>` : '') +
73
+ `</div>`
74
+ );
75
+ })
76
+ .join('') +
77
+ `</dl>`;
78
+
79
+ /** The header row of the labels, for a list with columns. Hidden from screen readers: each figure says its own. */
80
+ export const columnsHeadHTML = (columns = []) =>
81
+ `<div class="card-cols-head" aria-hidden="true"><div class="card-figures">${columns.map((c) => `<span class="card-figure-label ${alignOf(c)}">${esc(c.label)}</span>`).join('')}</div></div>`;
47
82
 
48
83
  export const cardHTML = (item, opts = {}) => {
49
84
  // "New: " is said with the title, since the dot before it is only drawn.
@@ -64,21 +99,31 @@ export const cardHTML = (item, opts = {}) => {
64
99
  `<div class="card-lead">${item.lead ?? dialHTML(item.score, { ...opts, text: item.scoreText })}</div>` +
65
100
  `<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>` +
66
101
  (chips ? `<ul class="card-chips">${chips}</ul>` : '') +
102
+ (opts.columns?.length ? figuresHTML(item.figures, opts.columns) : '') +
67
103
  (actions ? `<div class="card-actions">${actions}</div>` : '') +
68
104
  `</article></li>`
69
105
  );
70
106
  };
71
107
 
72
- export const placeholdersHTML = (n) =>
73
- Array.from({ length: n }, () => `<li class="card-item placeholder" aria-hidden="true"><div class="card"><div class="card-lead"><span class="score-dial none"></span></div><div class="card-head"><span class="bar wide"></span><span class="bar"></span></div><ul class="card-chips"><li class="bar chip"></li><li class="bar chip"></li></ul></div></li>`).join('');
108
+ export const placeholdersHTML = (n, columns = 0) => {
109
+ const figures = columns ? `<div class="card-figures">${'<div class="card-figure right"><span class="bar"></span></div>'.repeat(columns)}</div>` : '';
110
+ return Array.from({ length: n }, () => `<li class="card-item placeholder" aria-hidden="true"><div class="card"><div class="card-lead"><span class="score-dial none"></span></div><div class="card-head"><span class="bar wide"></span><span class="bar"></span></div><ul class="card-chips"><li class="bar chip"></li><li class="bar chip"></li></ul>${figures}</div></li>`).join('');
111
+ };
74
112
 
75
- const opts = (root) => ({ good: Number(root.dataset.good ?? 7), warning: Number(root.dataset.warning ?? 5), max: Number(root.dataset.max ?? 10), level: Number(root.dataset.level ?? 3) });
113
+ const columnsOf = (root) => {
114
+ try {
115
+ return root.dataset.columns ? JSON.parse(root.dataset.columns) : undefined;
116
+ } catch {
117
+ return undefined;
118
+ }
119
+ };
120
+ const opts = (root) => ({ good: Number(root.dataset.good ?? 7), warning: Number(root.dataset.warning ?? 5), max: Number(root.dataset.max ?? 10), level: Number(root.dataset.level ?? 3), columns: columnsOf(root) });
76
121
  const wrapOf = (root) => root.closest('.card-list-wrap');
77
122
 
78
123
  /** 'loading' shows placeholder cards (after 300ms), 'empty' and 'failed' their slots, 'ready' the cards. */
79
124
  export const setCardState = (root, state, { cards = 4 } = {}) => {
80
125
  if (state === 'loading') {
81
- root.innerHTML = placeholdersHTML(cards);
126
+ root.innerHTML = placeholdersHTML(cards, columnsOf(root)?.length ?? 0);
82
127
  root.setAttribute('aria-busy', 'true');
83
128
  } else root.removeAttribute('aria-busy');
84
129
  const wrap = wrapOf(root);
package/src/icons.ts CHANGED
@@ -139,6 +139,51 @@ export const ICONS = {
139
139
  '<rect width="18" height="18" x="3" y="3" rx="2"/><path d="M9 3v18"/>',
140
140
  x:
141
141
  '<path d="M18 6 6 18"/><path d="m6 6 12 12"/>',
142
+ // The kinds of thing on a wish list or a price tracker: a screen, storage, a lamp, the cat,
143
+ // groceries, and a price itself.
144
+ tv: '<path d="m17 2-5 5-5-5"/><rect width="20" height="15" x="2" y="7" rx="2"/>',
145
+ 'hard-drive':
146
+ '<path d="M10 16h.01"/><path d="M2.212 11.577a2 2 0 0 0-.212.896V18a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-5.527a2 2 0 0 0-.212-.896L18.55 5.11A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z"/><path d="M21.946 12.013H2.054"/><path d="M6 16h.01"/>',
147
+ lightbulb:
148
+ '<path d="M15 14c.2-1 .7-1.7 1.5-2.5 1-.9 1.5-2.2 1.5-3.5A6 6 0 0 0 6 8c0 1 .2 2.2 1.5 3.5.7.7 1.3 1.5 1.5 2.5"/><path d="M9 18h6"/><path d="M10 22h4"/>',
149
+ cat:
150
+ '<path d="M12 5c.67 0 1.35.09 2 .26 1.78-2 5.03-2.84 6.42-2.26 1.4.58-.42 7-.42 7 .57 1.07 1 2.24 1 3.44C21 17.9 16.97 21 12 21s-9-3-9-7.56c0-1.25.5-2.4 1-3.44 0 0-1.89-6.42-.5-7 1.39-.58 4.72.23 6.5 2.23A9.04 9.04 0 0 1 12 5Z"/><path d="M8 14v.5"/><path d="M16 14v.5"/><path d="M11.25 16.25h1.5L12 17l-.75-.75Z"/>',
151
+ 'shopping-basket':
152
+ '<path d="m15 11-1 9"/><path d="m19 11-4-7"/><path d="M2 11h20"/><path d="m3.5 11 1.6 7.4a2 2 0 0 0 2 1.6h9.8a2 2 0 0 0 2-1.6l1.7-7.4"/><path d="M4.5 15.5h15"/><path d="m5 11 4-7"/><path d="m9 11 1 9"/>',
153
+ tag:
154
+ '<path d="M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z"/><circle cx="7.5" cy="7.5" r=".5" fill="currentColor"/>',
155
+ // Card actions and a figure's direction: edit it, open the shop's page, the price went down, and
156
+ // the stand-in for a missing picture.
157
+ pencil:
158
+ '<path d="M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z"/><path d="m15 5 4 4"/>',
159
+ 'external-link':
160
+ '<path d="M15 3h6v6"/><path d="M10 14 21 3"/><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/>',
161
+ 'trending-down': '<path d="M16 17h6v-6"/><path d="m22 17-8.5-8.5-5 5L2 7"/>',
162
+ image:
163
+ '<rect width="18" height="18" x="3" y="3" rx="2" ry="2"/><circle cx="9" cy="9" r="2"/><path d="m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21"/>',
164
+ // Category chips on a price tracker: what kind of thing an item is.
165
+ apple:
166
+ '<path d="M12 6.528V3a1 1 0 0 1 1-1h0"/><path d="M18.237 21A15 15 0 0 0 22 11a6 6 0 0 0-10-4.472A6 6 0 0 0 2 11a15.1 15.1 0 0 0 3.763 10 3 3 0 0 0 3.648.648 5.5 5.5 0 0 1 5.178 0A3 3 0 0 0 18.237 21"/>',
167
+ 'lamp-desk':
168
+ '<path d="M10.293 2.293a1 1 0 0 1 1.414 0l2.5 2.5 5.994 1.227a1 1 0 0 1 .506 1.687l-7 7a1 1 0 0 1-1.687-.506l-1.227-5.994-2.5-2.5a1 1 0 0 1 0-1.414z"/><path d="m14.207 4.793-3.414 3.414"/><path d="M3 20a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v1a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1z"/><path d="m9.086 6.5-4.793 4.793a1 1 0 0 0-.18 1.17L7 18"/>',
169
+ 'cooking-pot':
170
+ '<path d="M2 12h20"/><path d="M20 12v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-8"/><path d="m4 8 16-4"/><path d="m8.86 6.78-.45-1.81a2 2 0 0 1 1.45-2.43l1.94-.48a2 2 0 0 1 2.43 1.46l.45 1.8"/>',
171
+ utensils:
172
+ '<path d="M3 2v7c0 1.1.9 2 2 2h4a2 2 0 0 0 2-2V2"/><path d="M7 2v20"/><path d="M21 15V2a5 5 0 0 0-5 5v6c0 1.1.9 2 2 2h3Zm0 0v7"/>',
173
+ monitor:
174
+ '<rect width="20" height="14" x="2" y="3" rx="2"/><line x1="8" x2="16" y1="21" y2="21"/><line x1="12" x2="12" y1="17" y2="21"/>',
175
+ refrigerator:
176
+ '<path d="M5 6a4 4 0 0 1 4-4h6a4 4 0 0 1 4 4v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6Z"/><path d="M5 10h14"/><path d="M15 7v6"/>',
177
+ 'washing-machine':
178
+ '<path d="M3 6h3"/><path d="M17 6h.01"/><rect width="18" height="20" x="3" y="2" rx="2"/><circle cx="12" cy="13" r="5"/><path d="M12 18a2.5 2.5 0 0 0 0-5 2.5 2.5 0 0 1 0-5"/>',
179
+ armchair:
180
+ '<path d="M19 9V6a2 2 0 0 0-2-2H7a2 2 0 0 0-2 2v3"/><path d="M3 16a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-5a2 2 0 0 0-4 0v1.5a.5.5 0 0 1-.5.5h-9a.5.5 0 0 1-.5-.5V11a2 2 0 0 0-4 0z"/><path d="M5 18v2"/><path d="M19 18v2"/>',
181
+ dog:
182
+ '<path d="M11.25 16.25h1.5L12 17z"/><path d="M16 14v.5"/><path d="M4.42 11.247A13.152 13.152 0 0 0 4 14.556C4 18.728 7.582 21 12 21s8-2.272 8-6.444a11.702 11.702 0 0 0-.493-3.309"/><path d="M8 14v.5"/><path d="M8.5 8.5c-.384 1.05-1.083 2.028-2.344 2.5-1.931.722-3.576-.297-3.656-1-.113-.994 1.177-6.53 4-7 1.923-.321 3.651.845 3.651 2.235A7.497 7.497 0 0 1 14 5.277c0-1.39 1.844-2.598 3.767-2.277 2.823.47 4.113 6.006 4 7-.08.703-1.725 1.722-3.656 1-1.261-.472-1.855-1.45-2.239-2.5"/>',
183
+ coffee:
184
+ '<path d="M10 2v2"/><path d="M14 2v2"/><path d="M16 8a1 1 0 0 1 1 1v8a4 4 0 0 1-4 4H7a4 4 0 0 1-4-4V9a1 1 0 0 1 1-1h14a4 4 0 1 1 0 8h-1"/><path d="M6 2v2"/>',
185
+ milk:
186
+ '<path d="M8 2h8"/><path d="M9 2v2.789a4 4 0 0 1-.672 2.219l-.656.984A4 4 0 0 0 7 10.212V20a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2v-9.789a4 4 0 0 0-.672-2.219l-.656-.984A4 4 0 0 1 15 4.788V2"/><path d="M7 15a6.472 6.472 0 0 1 5 0 6.47 6.47 0 0 0 5 0"/>',
142
187
  } as const;
143
188
 
144
189
  export type IconName = keyof typeof ICONS;
package/src/period.js CHANGED
@@ -156,7 +156,7 @@ export const wirePeriodPicker = (root) => {
156
156
  }
157
157
  const r = root.getBoundingClientRect();
158
158
  const w = list.offsetWidth;
159
- list.style.top = `${r.bottom + 6}px`;
159
+ list.style.top = `${r.bottom + 8}px`;
160
160
  list.style.left = `${Math.max(16, Math.min(r.right - w, innerWidth - w - 16))}px`;
161
161
  // After the browser has finished opening it, which would otherwise keep focus on the button.
162
162
  requestAnimationFrame(() => (list.querySelector('[aria-pressed="true"]') ?? list.querySelector('.option'))?.focus());
@@ -0,0 +1,99 @@
1
+ /*
2
+ * RangePosition: where one value sits in its range. Plain classes, not scoped, because
3
+ * setRangePosition() writes it at runtime. RangePosition imports this file.
4
+ */
5
+ .rp {
6
+ --rp-dot: var(--c-text);
7
+ display: grid;
8
+ gap: var(--sp-1);
9
+ font-size: var(--text-caption);
10
+ font-variant-numeric: tabular-nums;
11
+ }
12
+
13
+ /* The marks sit 8px in from each side, so a dot at either end stays whole. */
14
+ .rp-scale {
15
+ position: relative;
16
+ height: 24px;
17
+ margin-inline: 8px;
18
+ }
19
+
20
+ .rp-track,
21
+ .rp-band {
22
+ position: absolute;
23
+ top: 9px;
24
+ height: 6px;
25
+ border-radius: 999px;
26
+ }
27
+
28
+ .rp-track {
29
+ left: 0;
30
+ right: 0;
31
+ background: var(--c-border);
32
+ }
33
+
34
+ .rp-band {
35
+ min-width: 6px;
36
+ background: color-mix(in oklab, var(--c-chart-2) 55%, var(--c-border));
37
+ }
38
+
39
+ /* A reference is dashed, as a reference line in a chart. */
40
+ .rp-ref {
41
+ position: absolute;
42
+ top: 0;
43
+ bottom: 0;
44
+ margin-left: -1px;
45
+ border-left: 2px dashed var(--c-text-muted);
46
+ }
47
+
48
+ .rp-dot {
49
+ position: absolute;
50
+ top: 4px;
51
+ width: 16px;
52
+ height: 16px;
53
+ margin-left: -8px;
54
+ border-radius: 50%;
55
+ background: var(--rp-dot);
56
+ box-shadow: 0 0 0 3px var(--card-bg, var(--c-surface));
57
+ }
58
+
59
+ .rp-dot.good,
60
+ .rp-key-dot.good {
61
+ --rp-dot: var(--c-status-good);
62
+ }
63
+
64
+ .rp-ends {
65
+ display: flex;
66
+ justify-content: space-between;
67
+ gap: var(--sp-2);
68
+ margin-inline: 8px;
69
+ color: var(--c-text-secondary);
70
+ white-space: nowrap;
71
+ }
72
+
73
+ .rp-key {
74
+ display: flex;
75
+ flex-wrap: wrap;
76
+ gap: var(--sp-1) var(--sp-4);
77
+ margin: var(--sp-1) 0 0;
78
+ color: var(--c-text-secondary);
79
+ }
80
+
81
+ .rp-key-item {
82
+ display: inline-flex;
83
+ align-items: center;
84
+ gap: 6px;
85
+ }
86
+
87
+ .rp-key-dot {
88
+ --rp-dot: var(--c-text);
89
+ width: 10px;
90
+ height: 10px;
91
+ border-radius: 50%;
92
+ background: var(--rp-dot);
93
+ }
94
+
95
+ .rp-key-ref {
96
+ width: 0;
97
+ height: 12px;
98
+ border-left: 2px dashed var(--c-text-muted);
99
+ }
@@ -0,0 +1,65 @@
1
+ // Drives RangePosition: where one value sits in its range. A track, a band from the period's low
2
+ // to its high, a dot for the value and a dashed tick for a reference such as a target, with the
3
+ // low and high under the band's ends and a key that names the dot and the tick in words. The same
4
+ // markup at build time (RangePosition's props) and at runtime (setRangePosition).
5
+ //
6
+ // import { setRangePosition } from '@n1kname/components/rangeposition.js';
7
+ // setRangePosition(box, { low: 2399, high: 2649, value: 2449, reference: 2420, format: euro, tone: undefined });
8
+ //
9
+ // Options: { low, high, value, reference?, format?, valueLabel?, referenceLabel?, rangeLabel?,
10
+ // tone?: 'good' }. `format` turns a number into its words ("€2.449"); text is escaped. The scale
11
+ // runs from the lowest to the highest of the four, so a value or target outside the band still
12
+ // shows. tone 'good' turns the dot the status green, for a value in the person's favour; the key
13
+ // and the label still say it.
14
+ const esc = (s) => String(s ?? '').replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
15
+
16
+ const clamp = (v) => Math.max(0, Math.min(100, v));
17
+
18
+ export const rangePositionHTML = ({
19
+ low,
20
+ high,
21
+ value,
22
+ reference = null,
23
+ format = (v) => String(v),
24
+ valueLabel = 'Today',
25
+ referenceLabel = 'Target',
26
+ rangeLabel = 'Range',
27
+ tone,
28
+ } = {}) => {
29
+ const has = (v) => typeof v === 'number' && Number.isFinite(v);
30
+ if (!has(low) || !has(high)) return '';
31
+ const ends = [low, high, value, reference].filter(has);
32
+ const min = Math.min(...ends);
33
+ const max = Math.max(...ends);
34
+ const span = max - min || 1;
35
+ const at = (v) => clamp(((v - min) / span) * 100);
36
+ const f = (v) => esc(format(v));
37
+ const said = [
38
+ has(value) ? `${valueLabel} ${format(value)}.` : '',
39
+ `${rangeLabel} ${format(low)} to ${format(high)}.`,
40
+ has(reference) ? `${referenceLabel} ${format(reference)}.` : '',
41
+ ]
42
+ .filter(Boolean)
43
+ .join(' ');
44
+ const good = tone === 'good' ? ' good' : '';
45
+ return (
46
+ `<div class="rp" role="img" aria-label="${esc(said)}">` +
47
+ `<div class="rp-scale" aria-hidden="true">` +
48
+ `<span class="rp-track"></span>` +
49
+ `<span class="rp-band" style="left:${at(low)}%;width:${at(high) - at(low)}%"></span>` +
50
+ (has(reference) ? `<span class="rp-ref" style="left:${at(reference)}%"></span>` : '') +
51
+ (has(value) ? `<span class="rp-dot${good}" style="left:${at(value)}%"></span>` : '') +
52
+ `</div>` +
53
+ `<div class="rp-ends" aria-hidden="true" style="padding-inline:${at(low)}% ${100 - at(high)}%"><span>${f(low)}</span><span>${f(high)}</span></div>` +
54
+ `<p class="rp-key" aria-hidden="true">` +
55
+ (has(value) ? `<span class="rp-key-item"><span class="rp-key-dot${good}"></span>${esc(valueLabel)} ${f(value)}</span>` : '') +
56
+ (has(reference) ? `<span class="rp-key-item"><span class="rp-key-ref"></span>${esc(referenceLabel)} ${f(reference)}</span>` : '') +
57
+ `</p>` +
58
+ `</div>`
59
+ );
60
+ };
61
+
62
+ /** Fills a RangePosition (or any box) at runtime. */
63
+ export const setRangePosition = (box, opts) => {
64
+ box.innerHTML = rangePositionHTML(opts);
65
+ };
package/src/viewmenu.js CHANGED
@@ -30,14 +30,19 @@ export const wireViewMenu = (root) => {
30
30
  control.before(caption);
31
31
  }
32
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.
33
+ // 8px under the button, its right edge on the button's, kept on screen. Placed by its right
34
+ // edge before it shows (beforetoggle), so it never flashes elsewhere, since its width follows its
35
+ // controls and isn't known until then. Once shown, if it would run off the left, it moves in.
35
36
  const place = () => {
36
37
  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`;
38
+ const vw = document.documentElement.clientWidth;
39
+ panel.style.top = `${b.bottom + 8}px`;
40
+ panel.style.left = 'auto';
41
+ panel.style.right = `${Math.max(8, vw - b.right)}px`;
42
+ if (panel.matches(':popover-open') && panel.getBoundingClientRect().left < 8) {
43
+ panel.style.right = 'auto';
44
+ panel.style.left = '8px';
45
+ }
41
46
  };
42
47
  panel.addEventListener('beforetoggle', (e) => {
43
48
  if (e.newState !== 'open') return;
@@ -48,6 +53,7 @@ export const wireViewMenu = (root) => {
48
53
  panel.addEventListener('toggle', (e) => {
49
54
  const open = e.newState === 'open';
50
55
  button.setAttribute('aria-expanded', String(open));
56
+ if (open) place();
51
57
  if (!open) {
52
58
  removeEventListener('resize', place);
53
59
  removeEventListener('scroll', place, { capture: true });