@n1kname/components 0.17.2 → 0.19.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.17.2",
3
+ "version": "0.19.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -14,6 +14,7 @@
14
14
  "./dotrows.js": "./src/dotrows.js",
15
15
  "./rangebars.js": "./src/rangebars.js",
16
16
  "./daystrips.js": "./src/daystrips.js",
17
+ "./yearcalendar.js": "./src/yearcalendar.js",
17
18
  "./period.js": "./src/period.js",
18
19
  "./search.js": "./src/search.js",
19
20
  "./chips.js": "./src/chips.js",
@@ -22,12 +23,14 @@
22
23
  "./facts.js": "./src/facts.js",
23
24
  "./legend.js": "./src/legend.js",
24
25
  "./sidepanel.js": "./src/sidepanel.js",
26
+ "./mapstage.js": "./src/mapstage.js",
25
27
  "./match.css": "./src/match.css"
26
28
  },
27
29
  "dependencies": {
28
- "@n1kname/charts": "0.9.1"
30
+ "@n1kname/charts": "0.11.0"
29
31
  },
30
32
  "peerDependencies": {
33
+ "@n1kname/tokens": "^0.5.0",
31
34
  "astro": "^7.4.4"
32
35
  },
33
36
  "publishConfig": {
@@ -42,5 +45,7 @@
42
45
  "src",
43
46
  "THIRD_PARTY.md"
44
47
  ],
45
- "scripts": {}
48
+ "scripts": {
49
+ "check": "node src/yearcalendar.test.mjs"
50
+ }
46
51
  }
@@ -0,0 +1,150 @@
1
+ ---
2
+ /**
3
+ * A panel over a map: the surface, a little see-through and blurred, so the map reads under its
4
+ * edge and the words keep their contrast. Put it inside a MapStage.
5
+ *
6
+ * top-left, top-right, bottom-left, bottom-right a corner: controls, a legend
7
+ * head the page's title, in MapStage's `head` slot: the stage places it (fill mode) or
8
+ * lays it out as a plain header (framed, and on a phone)
9
+ * side the right edge, full height, scrolling inside when taller. It goes in MapStage's
10
+ * `aside` slot, and below 760px it stops floating and follows the map on the page.
11
+ *
12
+ * `layout="row"` lines controls up and wraps them (Segmenteds, a FloatToggle); `stack`, the default,
13
+ * stacks its content with room around it. Give it a `label` and it is a named group.
14
+ *
15
+ * A side panel can be put away with a FloatToggle. It fires `float-toggle` with { open }, so the
16
+ * map can fit what it shows to the room the panels leave (room() in mapstage.js).
17
+ */
18
+ interface Props {
19
+ place: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' | 'side' | 'head';
20
+ layout?: 'row' | 'stack';
21
+ /** Names the panel for a screen reader: "Map controls". A row of controls becomes a group. */
22
+ label?: string;
23
+ as?: 'div' | 'aside' | 'section';
24
+ id?: string;
25
+ [key: string]: unknown;
26
+ }
27
+
28
+ const { place, layout = 'stack', label, as: Tag = place === 'side' ? 'aside' : 'div', id, class: className, ...rest } = Astro.props;
29
+ const role = label && layout === 'row' && Tag === 'div' ? 'group' : undefined;
30
+ ---
31
+
32
+ <Tag class:list={['float', place, layout, className]} id={id} data-float={place} role={role} aria-label={label} {...rest}><slot /></Tag>
33
+
34
+ <script>
35
+ import { wireFloatToggles } from './mapstage.js';
36
+ wireFloatToggles();
37
+ </script>
38
+
39
+ <style>
40
+ /* The surface at 93%: over any map, pure black and white included, every text token keeps AA
41
+ (tokens' check.mjs, "heat and map panels"). */
42
+ .float {
43
+ position: absolute;
44
+ z-index: 2;
45
+ border: 1px solid var(--c-border);
46
+ border-radius: var(--radius-lg);
47
+ background: color-mix(in srgb, var(--c-surface) 93%, transparent);
48
+ -webkit-backdrop-filter: blur(12px) saturate(1.2);
49
+ backdrop-filter: blur(12px) saturate(1.2);
50
+ box-shadow: 0 8px 28px rgb(0 0 0 / 0.16);
51
+ color: var(--c-text);
52
+ }
53
+
54
+ .row {
55
+ display: flex;
56
+ flex-wrap: wrap;
57
+ align-items: center;
58
+ gap: var(--sp-2);
59
+ padding: var(--sp-2);
60
+ }
61
+
62
+ .stack {
63
+ display: grid;
64
+ align-content: start;
65
+ gap: var(--sp-4);
66
+ padding: var(--sp-3) var(--sp-4);
67
+ }
68
+
69
+ /* Corners leave room at the far side for the map's own buttons. */
70
+ .top-left,
71
+ .top-right,
72
+ .bottom-left,
73
+ .bottom-right {
74
+ max-width: calc(100% - var(--sp-3) * 2 - 48px);
75
+ }
76
+
77
+ /* Under the title when it floats too (MapStage fill mode sets the room it takes). */
78
+ .top-left {
79
+ top: calc(var(--sp-3) + var(--map-stage-head-room, 0px));
80
+ left: var(--sp-3);
81
+ }
82
+
83
+ .top-right {
84
+ top: var(--sp-3);
85
+ right: var(--sp-3);
86
+ }
87
+
88
+ .bottom-left {
89
+ bottom: var(--sp-3);
90
+ left: var(--sp-3);
91
+ }
92
+
93
+ .bottom-right {
94
+ bottom: var(--sp-3);
95
+ right: var(--sp-3);
96
+ }
97
+
98
+ .side {
99
+ top: var(--sp-3);
100
+ right: var(--sp-3);
101
+ width: var(--float-side-width, 300px);
102
+ max-height: calc(100% - var(--sp-3) * 2);
103
+ overflow-y: auto;
104
+ overscroll-behavior: contain;
105
+ gap: var(--sp-5);
106
+ padding: var(--sp-4);
107
+ }
108
+
109
+ .side[data-closed] {
110
+ display: none;
111
+ }
112
+
113
+ /* On a phone the map keeps the width, and the side panel follows it on the page, always open:
114
+ FloatToggle hides itself there, so nothing can be put away out of reach. */
115
+ @media (max-width: 760px) {
116
+ .side,
117
+ .side[data-closed] {
118
+ position: static;
119
+ display: grid;
120
+ width: auto;
121
+ max-height: none;
122
+ margin-top: var(--sp-4);
123
+ background: var(--c-surface);
124
+ box-shadow: none;
125
+ -webkit-backdrop-filter: none;
126
+ backdrop-filter: none;
127
+ }
128
+ }
129
+
130
+ /* Where the blur isn't drawn, the panel is solid instead. */
131
+ @supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
132
+ .float {
133
+ background: var(--c-surface);
134
+ }
135
+ }
136
+
137
+ @media (prefers-reduced-transparency: reduce) {
138
+ .float {
139
+ background: var(--c-surface);
140
+ -webkit-backdrop-filter: none;
141
+ backdrop-filter: none;
142
+ }
143
+ }
144
+
145
+ @media (forced-colors: active) {
146
+ .float {
147
+ border-color: CanvasText;
148
+ }
149
+ }
150
+ </style>
@@ -0,0 +1,60 @@
1
+ ---
2
+ /**
3
+ * Puts a side FloatPanel away and brings it back. Sits in a row of map controls, the same height
4
+ * as a Segmented. Hidden below 760px, where the side panel follows the map and is always open.
5
+ */
6
+ interface Props {
7
+ /** The side panel's id. */
8
+ for: string;
9
+ /** Open when the page loads. */
10
+ open?: boolean;
11
+ [key: string]: unknown;
12
+ }
13
+
14
+ const { for: target, open = true, class: className, ...rest } = Astro.props;
15
+ ---
16
+
17
+ <button type="button" class:list={['float-toggle', className]} aria-controls={target} aria-expanded={String(open)} data-float-toggle={target} {...rest}><slot /></button>
18
+
19
+ <style>
20
+ .float-toggle {
21
+ min-height: 40px;
22
+ padding: 0 var(--sp-3);
23
+ border: 1px solid var(--c-border);
24
+ border-radius: var(--radius-md);
25
+ background: var(--c-surface);
26
+ color: var(--c-text-secondary);
27
+ font: inherit;
28
+ font-size: var(--text-body-sm);
29
+ cursor: pointer;
30
+ transition:
31
+ color var(--motion-hover) var(--ease-hover),
32
+ border-color var(--motion-hover) var(--ease-hover);
33
+ }
34
+
35
+ .float-toggle:hover,
36
+ .float-toggle[aria-expanded='true'] {
37
+ color: var(--c-text);
38
+ }
39
+
40
+ .float-toggle[aria-expanded='true'] {
41
+ border-color: var(--c-border-strong);
42
+ }
43
+
44
+ .float-toggle:focus-visible {
45
+ outline: 2px solid var(--c-focus);
46
+ outline-offset: 2px;
47
+ }
48
+
49
+ @media (max-width: 760px) {
50
+ .float-toggle {
51
+ display: none;
52
+ }
53
+ }
54
+
55
+ @media (pointer: coarse) {
56
+ .float-toggle {
57
+ min-height: 44px;
58
+ }
59
+ }
60
+ </style>
@@ -0,0 +1,284 @@
1
+ ---
2
+ /**
3
+ * A page that is one big map, in one of two modes:
4
+ *
5
+ * framed the default. The map sits in the content column under the page's header, at least
6
+ * 28rem tall and otherwise down to the bottom of the window, with a border and radius.
7
+ * fill the map covers the whole column: past its gutters, from the top of the column to the
8
+ * bottom of the window, up to the side nav. The page's title floats over it, from the
9
+ * `head` slot. Put the stage first in the column, with nothing above it. Below 760px it
10
+ * falls back to framed, with the title above the map.
11
+ *
12
+ * What goes with the map floats over it in FloatPanels, put in the default slot; a side panel goes
13
+ * in the `aside` slot, so on a phone it can leave the map and follow it on the page. The title goes
14
+ * in the `head` slot, as a FloatPanel with place="head" holding a compact PageHeader: it comes
15
+ * before the map in the page, so the h1 is the first thing read. `head` says how it floats in fill
16
+ * mode: on a band that fades into the map (`scrim`, the default), or in a panel like the others
17
+ * (`box`). Every panel at the top starts below it. In framed mode, and on a phone, it is a plain
18
+ * header above the map.
19
+ *
20
+ * Give the map to MapLibre (or any canvas map) by the id: new maplibregl.Map({ container: id }).
21
+ * While it reads, or when it has nothing, a message covers it: setStage() in mapstage.js picks one.
22
+ * Hover cards in a MapLibre popup with className 'place-card' wear the charts' pointer card.
23
+ *
24
+ * The framed height comes from custom properties a page can set: --map-stage-offset (what sits
25
+ * above it: the header and the page title, 10.5rem), --map-stage-min (28rem), and below 1024px
26
+ * --map-stage-offset-narrow and --map-stage-min-narrow (14rem and 26rem). --map-stage-height
27
+ * overrides them all, for a map that is one part of a page. In fill mode --map-stage-fill-offset
28
+ * (0) and, from 760 to 1023px, --map-stage-fill-offset-narrow (57px, the shell's top bar) are what
29
+ * sits above the column, and --map-stage-bleed (the shell's --layout-gutter) is how far it reaches
30
+ * past each side of the column.
31
+ */
32
+ import '@n1kname/charts/pointer.css';
33
+
34
+ interface Props {
35
+ /** The map element's id, for the map library. */
36
+ id: string;
37
+ /** What the map shows, for a screen reader: "Routes in November". */
38
+ label: string;
39
+ /** In the column under the header, or over the whole column. */
40
+ mode?: 'framed' | 'fill';
41
+ /** In fill mode, how the title floats: on a band that fades into the map (the default), or in a panel. */
42
+ head?: 'box' | 'scrim';
43
+ /** Shown over the map while it reads. Shown from the start; setStage(stage, 'ready') hides it. */
44
+ loading?: string;
45
+ /** Shown over the map when it has nothing to show. */
46
+ empty?: string;
47
+ /** Shown instead of the map when it can't start, such as without WebGL. */
48
+ failed?: string;
49
+ [key: string]: unknown;
50
+ }
51
+
52
+ const { id, label, mode = 'framed', head = 'scrim', loading, empty, failed, class: className, ...rest } = Astro.props;
53
+ // Rendered, not just asked: a slot filled by an expression that renders nothing still "has" it.
54
+ const headHtml = Astro.slots.has('head') ? (await Astro.slots.render('head')).trim() : '';
55
+ const hasHead = headHtml !== '';
56
+ ---
57
+
58
+ <div
59
+ class:list={['map-stage', className]}
60
+ data-map-stage
61
+ data-mode={mode}
62
+ data-head={hasHead ? head : undefined}
63
+ data-loading={loading ? '' : undefined}
64
+ {...rest}
65
+ >
66
+ {hasHead && <div class="head" set:html={headHtml} />}
67
+ <div class="frame">
68
+ <div id={id} class="map" role="region" aria-label={label}></div>
69
+ {loading && <p class="over" data-over="loading" role="status"><span>{loading}</span></p>}
70
+ {empty && <p class="over" data-over="empty" hidden><span>{empty}</span></p>}
71
+ {failed && <p class="over" data-over="failed" hidden><span>{failed}</span></p>}
72
+ <slot />
73
+ </div>
74
+ <slot name="aside" />
75
+ </div>
76
+
77
+ <script>
78
+ // In fill mode the title floats over the map, and the panels at the top start below it: the room
79
+ // it takes, as --map-stage-head-room, measured from the stage's top inset. In a box, the panels
80
+ // stack --sp-2 under the title's box; on a scrim, they start --sp-4 under the band's lower edge,
81
+ // where its fade ends, so no panel sits under it. Nothing while the title doesn't float.
82
+ document.querySelectorAll<HTMLElement>('[data-map-stage][data-head]').forEach((stage) => {
83
+ const head = stage.querySelector<HTMLElement>(':scope > .head')!;
84
+ const px = (name: string, fallback: number) => parseFloat(getComputedStyle(stage).getPropertyValue(name)) || fallback;
85
+ const measure = () => {
86
+ if (getComputedStyle(head).position !== 'absolute') return stage.style.setProperty('--map-stage-head-room', '0px');
87
+ const scrim = stage.dataset.head === 'scrim';
88
+ // The band itself, or the panel that holds the title (Astro can put a script first in the slot).
89
+ const edge = scrim ? head : (head.querySelector<HTMLElement>(':scope > :not(script, style)') ?? head);
90
+ const room = edge.getBoundingClientRect().bottom - stage.getBoundingClientRect().top - px('--sp-3', 12) + (scrim ? px('--sp-4', 16) : px('--sp-2', 8));
91
+ stage.style.setProperty('--map-stage-head-room', `${Math.round(room)}px`);
92
+ };
93
+ new ResizeObserver(measure).observe(head);
94
+ matchMedia('(max-width: 760px)').addEventListener('change', measure);
95
+ measure();
96
+ });
97
+ </script>
98
+
99
+ <style>
100
+ /* The wrapper holds the title, the frame and a side panel, which floats over the frame's right
101
+ edge on a wide screen and comes after it on a phone. */
102
+ .map-stage {
103
+ position: relative;
104
+ }
105
+
106
+ .frame {
107
+ position: relative;
108
+ height: var(--map-stage-height, max(var(--map-stage-min, 28rem), calc(100dvh - var(--map-stage-offset, 10.5rem))));
109
+ }
110
+
111
+ @media (max-width: 1023px) {
112
+ .frame {
113
+ height: var(--map-stage-height, max(var(--map-stage-min-narrow, 26rem), calc(100dvh - var(--map-stage-offset-narrow, 14rem))));
114
+ }
115
+ }
116
+
117
+ /* Absolute over MapLibre's own position: relative on the same element. */
118
+ .frame > .map {
119
+ position: absolute;
120
+ inset: 0;
121
+ border: 1px solid var(--c-border);
122
+ border-radius: var(--radius-lg);
123
+ background: var(--c-surface-sunken, var(--c-bg));
124
+ overflow: hidden;
125
+ transition: opacity var(--motion-base) var(--ease-out);
126
+ }
127
+
128
+ .map-stage[data-loading] .map {
129
+ opacity: 0.5;
130
+ }
131
+
132
+ /* The title, when it doesn't float: a plain header above the map, unboxed, as a page header
133
+ stands. In framed mode, and in fill mode on a phone. */
134
+ .head {
135
+ margin-bottom: var(--sp-5);
136
+ }
137
+
138
+ .head :global(.float) {
139
+ position: static;
140
+ max-width: none;
141
+ padding: 0;
142
+ border: 0;
143
+ background: none;
144
+ box-shadow: none;
145
+ -webkit-backdrop-filter: none;
146
+ backdrop-filter: none;
147
+ }
148
+
149
+ /* Fill: the whole column, past its gutters and down to the window's bottom, with no frame of its
150
+ own. From 760px up; narrower, it is framed. */
151
+ @media (min-width: 761px) {
152
+ .map-stage[data-mode='fill'] {
153
+ margin-inline: calc(-1 * var(--map-stage-bleed, var(--layout-gutter, 0px)));
154
+ }
155
+
156
+ .map-stage[data-mode='fill'] .frame {
157
+ height: calc(100dvh - var(--map-stage-fill-offset, 0px));
158
+ }
159
+
160
+ .map-stage[data-mode='fill'] .map,
161
+ .map-stage[data-mode='fill'] .over {
162
+ border: 0;
163
+ border-radius: 0;
164
+ }
165
+
166
+ .map-stage[data-mode='fill'] .head {
167
+ position: absolute;
168
+ top: var(--sp-3);
169
+ left: var(--sp-3);
170
+ z-index: 3;
171
+ max-width: calc(100% - var(--sp-3) * 2 - 48px);
172
+ margin: 0;
173
+ }
174
+
175
+ /* In a panel, like everything else over the map. */
176
+ .map-stage[data-mode='fill'][data-head='box'] .head :global(.float) {
177
+ padding: var(--sp-3) var(--sp-4);
178
+ border: 1px solid var(--c-border);
179
+ background: color-mix(in srgb, var(--c-surface) 93%, transparent);
180
+ -webkit-backdrop-filter: blur(12px) saturate(1.2);
181
+ backdrop-filter: blur(12px) saturate(1.2);
182
+ box-shadow: 0 8px 28px rgb(0 0 0 / 0.16);
183
+ }
184
+
185
+ /* On a band across the top of the map: the page's own background, solid behind the words and
186
+ --sp-3 below them, then fading out over --sp-5, so the title reads as the page's and the map
187
+ runs on under it. Its height is the title row's; the panels start below it (head-room). */
188
+ .map-stage[data-mode='fill'][data-head='scrim'] .head {
189
+ top: 0;
190
+ left: 0;
191
+ right: 0;
192
+ max-width: none;
193
+ padding: var(--sp-4) var(--sp-5) calc(var(--sp-3) + var(--sp-5));
194
+ background: linear-gradient(
195
+ to bottom,
196
+ color-mix(in srgb, var(--c-bg) 95%, transparent) 0,
197
+ color-mix(in srgb, var(--c-bg) 95%, transparent) calc(100% - var(--sp-5)),
198
+ transparent 100%
199
+ );
200
+ pointer-events: none;
201
+ }
202
+
203
+ .map-stage[data-mode='fill'][data-head='scrim'] .head :global(*) {
204
+ pointer-events: auto;
205
+ }
206
+
207
+ /* The band spans the map, so everything at its top starts below it: the side panel, a
208
+ top-right panel, and the map's own buttons in the top corners. */
209
+ .map-stage[data-mode='fill'][data-head='scrim'] > :global(.side) {
210
+ top: calc(var(--sp-3) + var(--map-stage-head-room, 0px));
211
+ max-height: calc(100% - var(--map-stage-head-room, 0px) - var(--sp-3) * 2);
212
+ }
213
+
214
+ .map-stage[data-mode='fill'][data-head='scrim'] .frame > :global(.top-right) {
215
+ top: calc(var(--sp-3) + var(--map-stage-head-room, 0px));
216
+ }
217
+
218
+ .map-stage[data-mode='fill'][data-head='scrim'] :global(.maplibregl-ctrl-top-left),
219
+ .map-stage[data-mode='fill'][data-head='scrim'] :global(.maplibregl-ctrl-top-right) {
220
+ top: var(--map-stage-head-room, 0px);
221
+ }
222
+ }
223
+
224
+ @media (min-width: 761px) and (max-width: 1023px) {
225
+ .map-stage[data-mode='fill'] .frame {
226
+ height: calc(100dvh - var(--map-stage-fill-offset-narrow, 57px));
227
+ }
228
+ }
229
+
230
+ /* Fill falls back to framed on a phone: room above for the title, as a page has. */
231
+ @media (max-width: 760px) {
232
+ .map-stage[data-mode='fill'] {
233
+ padding-top: var(--sp-5);
234
+ }
235
+ }
236
+
237
+ /* What covers the map while it reads, or when it has nothing: a veil that dims the map, and
238
+ the words on a solid chip, because no veil keeps text readable over every map under it. */
239
+ .over {
240
+ position: absolute;
241
+ inset: 0;
242
+ z-index: 1;
243
+ display: grid;
244
+ place-items: center;
245
+ margin: 0;
246
+ padding: var(--sp-4);
247
+ border-radius: var(--radius-lg);
248
+ background: color-mix(in srgb, var(--c-bg) 55%, transparent);
249
+ pointer-events: none;
250
+ }
251
+
252
+ .over[hidden] {
253
+ display: none;
254
+ }
255
+
256
+ .over span {
257
+ max-width: 40ch;
258
+ padding: var(--sp-2) var(--sp-3);
259
+ border: 1px solid var(--c-border);
260
+ border-radius: var(--radius-md);
261
+ background: var(--c-surface);
262
+ color: var(--c-text-secondary);
263
+ font-size: var(--text-body-sm);
264
+ line-height: var(--leading-body-sm);
265
+ text-align: center;
266
+ }
267
+
268
+ /* The hover card: the charts' pointer card, without MapLibre's own box and tip. */
269
+ .map-stage :global(.place-card .maplibregl-popup-content) {
270
+ padding: 0;
271
+ background: none;
272
+ box-shadow: none;
273
+ }
274
+
275
+ .map-stage :global(.place-card .maplibregl-popup-tip) {
276
+ display: none;
277
+ }
278
+
279
+ @media (prefers-reduced-motion: reduce) {
280
+ .frame > .map {
281
+ transition: none;
282
+ }
283
+ }
284
+ </style>
@@ -8,6 +8,9 @@
8
8
  * title or else the lede, gets a highlighter that sweeps in once. A page that writes its title
9
9
  * or lede once its data arrives wraps those words in <mark> itself; the sweep plays as they
10
10
  * land.
11
+ *
12
+ * `compact` is the header made small enough to float over a map (MapStage fill mode): the title
13
+ * at the h3 size, a shorter rule, and the actions beside it in one row while there is room.
11
14
  */
12
15
  import './highlight.css';
13
16
 
@@ -23,8 +26,10 @@ interface Props {
23
26
  rule?: boolean;
24
27
  /** Words in the title or lede to highlight. */
25
28
  mark?: string;
29
+ /** Small enough to float over a map. */
30
+ compact?: boolean;
26
31
  }
27
- const { eyebrow, title, lede, meta, ids = {}, rule = false, mark } = Astro.props;
32
+ const { eyebrow, title, lede, meta, ids = {}, rule = false, mark, compact = false } = Astro.props;
28
33
 
29
34
  // The text around the marked words, or the text alone when they aren't in it.
30
35
  const split = (text?: string) => {
@@ -35,7 +40,7 @@ const inTitle = split(title);
35
40
  const inLede = inTitle ? null : split(lede);
36
41
  ---
37
42
 
38
- <header class="page-header">
43
+ <header class:list={['page-header', { compact }]}>
39
44
  <div class="text">
40
45
  {(eyebrow || ids.eyebrow) && <p class="eyebrow" id={ids.eyebrow}>{eyebrow}</p>}
41
46
  <h1 id={ids.title}>{inTitle ? <>{inTitle[0]}<mark>{inTitle[1]}</mark>{inTitle[2]}</> : title}</h1>
@@ -125,4 +130,30 @@ const inLede = inTitle ? null : split(lede);
125
130
  flex-wrap: wrap;
126
131
  gap: var(--sp-2);
127
132
  }
133
+
134
+ /* Over a map: the title a step down, the rule shorter and closer, the actions centred beside it. */
135
+ .compact {
136
+ align-items: center;
137
+ gap: var(--sp-3) var(--sp-5);
138
+ }
139
+
140
+ .compact .text {
141
+ flex: 0 1 auto;
142
+ }
143
+
144
+ .compact h1 {
145
+ font-size: var(--text-h3);
146
+ line-height: var(--leading-h3);
147
+ letter-spacing: var(--tracking-h3);
148
+ }
149
+
150
+ .compact .rule {
151
+ width: var(--sp-6);
152
+ height: 4px;
153
+ margin: var(--sp-2) 0 0;
154
+ }
155
+
156
+ .compact .lede {
157
+ min-height: 0;
158
+ }
128
159
  </style>
@@ -9,7 +9,10 @@
9
9
  * Back steps back through it; "all" is no parameter at all. The periods are known at build time
10
10
  * (`periods`) or set later from script with setPeriods() from period.js, such as years read from
11
11
  * an API. Each change fires `period-change` on the element, with the period as `detail.value`
12
- * ("all" for all of them).
12
+ * ("all" for all of them) and the words shown for it as `detail.label`.
13
+ *
14
+ * A period is a string, or { value, label } when the button should say something other than what
15
+ * the address keeps: "Nov 2026" shown, "2026-11" in ?month= and in the event.
13
16
  *
14
17
  * Keyboard: Tab reaches each part; in the list, the arrow keys move through the periods and
15
18
  * Escape closes it.
@@ -17,11 +20,11 @@
17
20
  interface Props {
18
21
  /** The address parameter that holds the choice. Leave it out to keep the choice in the page. */
19
22
  param?: string;
20
- /** Periods known at build time, oldest first. */
21
- periods?: string[];
23
+ /** Periods known at build time, oldest first: strings, or { value, label }. */
24
+ periods?: (string | { value: string; label?: string })[];
22
25
  /** The words for a choice covering every period, such as "All years". Leave it out for none. */
23
26
  all?: string;
24
- /** The period chosen when the address says nothing: "all", or one of the periods. Default: all if there is one, otherwise the newest. */
27
+ /** The period chosen when the address says nothing: "all", or one of the periods' values. Default: all if there is one, otherwise the newest. */
25
28
  initial?: string;
26
29
  /** The words a screen reader hears. */
27
30
  labels?: { name?: string; previous?: string; next?: string; list?: string };
@@ -29,12 +32,13 @@ interface Props {
29
32
  id?: string;
30
33
  }
31
34
 
32
- const { param, periods = [], all, initial, labels = {}, id = 'period' } = Astro.props;
35
+ const { param, periods: given = [], all, initial, labels = {}, id = 'period' } = Astro.props;
36
+ const periods = given.map((p) => (typeof p === 'object' ? { value: String(p.value), label: String(p.label ?? p.value) } : { value: String(p), label: String(p) }));
33
37
  const words = { name: 'Period', previous: 'Previous', next: 'Next', list: 'Choose a period', ...labels };
34
38
  const chevron = (d: string) =>
35
39
  `<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="${d}"/></svg>`;
36
- const start = initial ?? (all ? 'all' : periods.at(-1));
37
- const shown = start === 'all' ? all : start;
40
+ const start = initial ?? (all ? 'all' : periods.at(-1)?.value);
41
+ const shown = start === 'all' ? all : (periods.find((p) => p.value === start)?.label ?? start);
38
42
  ---
39
43
 
40
44
  <div
@@ -57,8 +61,8 @@ const shown = start === 'all' ? all : start;
57
61
  <div class="periods">
58
62
  {
59
63
  [...periods].reverse().map((p) => (
60
- <button type="button" class="option" data-value={p}>
61
- {p}
64
+ <button type="button" class="option" data-value={p.value}>
65
+ {p.label}
62
66
  </button>
63
67
  ))
64
68
  }