@n1kname/components 0.18.0 → 0.20.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 +9 -3
- package/src/Facts.astro +189 -42
- package/src/PeriodPicker.astro +13 -9
- package/src/Stat.astro +3 -0
- package/src/StatStrip.astro +5 -1
- package/src/YearCalendar.astro +207 -0
- package/src/facts.js +139 -15
- package/src/facts.test.mjs +143 -0
- package/src/period.js +36 -12
- package/src/yearcalendar.js +268 -0
- package/src/yearcalendar.test.mjs +77 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@n1kname/components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.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",
|
|
@@ -26,7 +27,7 @@
|
|
|
26
27
|
"./match.css": "./src/match.css"
|
|
27
28
|
},
|
|
28
29
|
"dependencies": {
|
|
29
|
-
"@n1kname/charts": "0.
|
|
30
|
+
"@n1kname/charts": "0.11.0"
|
|
30
31
|
},
|
|
31
32
|
"peerDependencies": {
|
|
32
33
|
"@n1kname/tokens": "^0.5.0",
|
|
@@ -44,5 +45,10 @@
|
|
|
44
45
|
"src",
|
|
45
46
|
"THIRD_PARTY.md"
|
|
46
47
|
],
|
|
47
|
-
"
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"linkedom": "0.18.12"
|
|
50
|
+
},
|
|
51
|
+
"scripts": {
|
|
52
|
+
"check": "node src/yearcalendar.test.mjs && node src/facts.test.mjs"
|
|
53
|
+
}
|
|
48
54
|
}
|
package/src/Facts.astro
CHANGED
|
@@ -1,22 +1,40 @@
|
|
|
1
1
|
---
|
|
2
2
|
/**
|
|
3
|
-
* Label and figure pairs, three ways: tiles (
|
|
4
|
-
* a line) and a list (its facts). Each figure can carry an icon and an accent of its
|
|
5
|
-
* in every form, so distance is always one colour and heart rate another.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
3
|
+
* Label and figure pairs, three ways: tiles (the figures that lead a page), pills (a thing's
|
|
4
|
+
* figures in a line) and a list (its facts). Each figure can carry an icon and an accent of its
|
|
5
|
+
* own, the same in every form, so distance is always one colour and heart rate another.
|
|
6
|
+
*
|
|
7
|
+
* A tile can also carry a unit, small after the figure, and a line under it: `context`, led by a
|
|
8
|
+
* bold `delta` when there's a change to show. The tiles balance their rows (four go 4 or 2 + 2,
|
|
9
|
+
* never 3 + 1), and the labels, figures and lines line up across a row however they wrap.
|
|
10
|
+
*
|
|
11
|
+
* Two options, off by default: the highlighter under a tile's figure, sweeping in once; and icons
|
|
12
|
+
* that draw themselves in once. Fill it at build time with `items`, or later with setFacts() and
|
|
13
|
+
* setFact() from facts.js.
|
|
8
14
|
*/
|
|
9
15
|
import type { IconName } from './icons';
|
|
10
|
-
import
|
|
16
|
+
import { factsHTML } from './facts.js';
|
|
11
17
|
import './highlight.css';
|
|
12
18
|
|
|
13
19
|
interface Fact {
|
|
14
20
|
label: string;
|
|
15
21
|
value?: string;
|
|
22
|
+
/** Small, after the figure: m³, bpm, km. */
|
|
23
|
+
unit?: string;
|
|
24
|
+
/** Tiles: the line under the figure, such as a period or a comparison. */
|
|
25
|
+
context?: string;
|
|
26
|
+
/** Tiles: a change, bold at the start of the line. The text carries its sign; the tone a quiet colour. */
|
|
27
|
+
delta?: string | { text: string; tone?: 'good' | 'bad' | 'neutral' };
|
|
16
28
|
/** What the figure measures, from the icon set: route, timer, heart-pulse, flame, … */
|
|
17
29
|
icon?: IconName;
|
|
18
30
|
/** A chart token, such as var(--c-chart-3), for the icon and the highlighter. */
|
|
19
31
|
accent?: string;
|
|
32
|
+
/** Names the fact for setFact(). */
|
|
33
|
+
key?: string;
|
|
34
|
+
/** Id on the figure, for a page that writes it itself, as with Stat. */
|
|
35
|
+
valueId?: string;
|
|
36
|
+
/** Id on the line under it. The line keeps its height meanwhile. */
|
|
37
|
+
contextId?: string;
|
|
20
38
|
}
|
|
21
39
|
interface Props {
|
|
22
40
|
items?: Fact[];
|
|
@@ -25,29 +43,28 @@ interface Props {
|
|
|
25
43
|
highlight?: boolean;
|
|
26
44
|
/** Icons that draw themselves in once, as the facts come into view. */
|
|
27
45
|
iconMotion?: boolean;
|
|
46
|
+
/** Tiles: how many lines of context to keep room for while the figures load. 1 by default. */
|
|
47
|
+
lines?: 1 | 2;
|
|
28
48
|
id?: string;
|
|
29
49
|
}
|
|
30
|
-
const { items = [], variant = 'tiles', highlight = false, iconMotion = false, id } = Astro.props;
|
|
31
|
-
const
|
|
50
|
+
const { items = [], variant = 'tiles', highlight = false, iconMotion = false, lines = 1, id } = Astro.props;
|
|
51
|
+
const { html, count, context } = factsHTML(items, { variant, highlight });
|
|
52
|
+
const hl = highlight && variant === 'tiles';
|
|
32
53
|
---
|
|
33
54
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
<
|
|
38
|
-
<
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
</div>
|
|
48
|
-
))
|
|
49
|
-
}
|
|
50
|
-
</dl>
|
|
55
|
+
{
|
|
56
|
+
variant === 'tiles' ? (
|
|
57
|
+
<div class="facts-box">
|
|
58
|
+
<dl class="facts tiles" id={id} data-facts data-variant="tiles" data-count={count} data-context={context ? '' : undefined} data-lines={lines === 2 ? '2' : undefined} data-highlight={hl ? '' : undefined} data-icon-motion={iconMotion ? '' : undefined}>
|
|
59
|
+
<Fragment set:html={html} />
|
|
60
|
+
</dl>
|
|
61
|
+
</div>
|
|
62
|
+
) : (
|
|
63
|
+
<dl class:list={['facts', variant]} id={id} data-facts data-variant={variant} data-count={count} data-icon-motion={iconMotion ? '' : undefined}>
|
|
64
|
+
<Fragment set:html={html} />
|
|
65
|
+
</dl>
|
|
66
|
+
)
|
|
67
|
+
}
|
|
51
68
|
|
|
52
69
|
<script>
|
|
53
70
|
import { arrive } from './facts.js';
|
|
@@ -59,6 +76,10 @@ const size = variant === 'tiles' ? 16 : 14;
|
|
|
59
76
|
margin: 0;
|
|
60
77
|
}
|
|
61
78
|
|
|
79
|
+
.facts :global(dd) {
|
|
80
|
+
margin: 0;
|
|
81
|
+
}
|
|
82
|
+
|
|
62
83
|
.facts :global(.fact-icon) {
|
|
63
84
|
display: inline-grid;
|
|
64
85
|
flex: none;
|
|
@@ -70,27 +91,111 @@ const size = variant === 'tiles' ? 16 : 14;
|
|
|
70
91
|
display: block;
|
|
71
92
|
}
|
|
72
93
|
|
|
73
|
-
|
|
94
|
+
.facts :global(.fact-value) {
|
|
95
|
+
font-weight: 600;
|
|
96
|
+
font-variant-numeric: tabular-nums;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/* The unit beside the figure, a step quieter. */
|
|
100
|
+
.facts :global(.fact-unit) {
|
|
101
|
+
margin-inline-start: 0.25em;
|
|
102
|
+
font-weight: 500;
|
|
103
|
+
color: var(--c-text-secondary);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
.facts :global(.fact-unit:empty) {
|
|
107
|
+
display: none;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/* ── Tiles ──────────────────────────────────────────────────────────────────
|
|
111
|
+
The strip measures itself, so it reflows in a card or a side panel as on a page. Two across
|
|
112
|
+
on a phone; wider, every tile in one row when they fit, else rows that balance: 4 as 2 + 2,
|
|
113
|
+
6 as 3 + 3, never 3 + 1. */
|
|
114
|
+
.facts-box {
|
|
115
|
+
container-type: inline-size;
|
|
116
|
+
}
|
|
117
|
+
|
|
74
118
|
.tiles {
|
|
119
|
+
--cols: 2;
|
|
120
|
+
--rows: 2;
|
|
75
121
|
display: grid;
|
|
122
|
+
grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
|
|
76
123
|
gap: var(--sp-3);
|
|
77
|
-
grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr));
|
|
78
124
|
}
|
|
79
125
|
|
|
126
|
+
.tiles[data-count='0'],
|
|
127
|
+
.tiles[data-count='1'] {
|
|
128
|
+
--cols: 1;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.tiles[data-context] {
|
|
132
|
+
--rows: 3;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/* An odd last tile on two columns takes the row, so no hole is left beside it. */
|
|
136
|
+
.tiles:is([data-count='3'], [data-count='5']) > :global(div:last-child) {
|
|
137
|
+
grid-column: span 2;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
@container (min-width: 28.5rem) {
|
|
141
|
+
.tiles:is([data-count='3'], [data-count='5'], [data-count='6']) {
|
|
142
|
+
--cols: 3;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
.tiles[data-count='3'] > :global(div:last-child) {
|
|
146
|
+
grid-column: auto;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
@container (min-width: 38.25rem) {
|
|
151
|
+
.tiles[data-count='4'] {
|
|
152
|
+
--cols: 4;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
@container (min-width: 48rem) {
|
|
157
|
+
.tiles[data-count='5'] {
|
|
158
|
+
--cols: 5;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
.tiles[data-count='5'] > :global(div:last-child) {
|
|
162
|
+
grid-column: auto;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
@container (min-width: 57.75rem) {
|
|
167
|
+
.tiles[data-count='6'] {
|
|
168
|
+
--cols: 6;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
.tiles[data-count='many'] {
|
|
173
|
+
grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr));
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/* Each tile takes its rows from the strip (subgrid): a label that wraps, or a line that runs
|
|
177
|
+
to two, moves that row in every tile beside it, so the figures share one baseline. */
|
|
80
178
|
.tiles > :global(div) {
|
|
81
179
|
display: grid;
|
|
82
|
-
|
|
180
|
+
grid-row: span var(--rows);
|
|
181
|
+
grid-template-rows: subgrid;
|
|
182
|
+
row-gap: 0;
|
|
183
|
+
align-content: start;
|
|
184
|
+
min-width: 0;
|
|
83
185
|
padding: var(--sp-4);
|
|
84
186
|
border: 1px solid var(--c-border);
|
|
85
187
|
border-radius: var(--radius-lg);
|
|
86
188
|
background: var(--c-surface);
|
|
87
189
|
}
|
|
88
190
|
|
|
191
|
+
/* A short label beside one that wraps keeps to the top of its tile. */
|
|
89
192
|
.tiles :global(dt) {
|
|
90
193
|
display: flex;
|
|
91
194
|
align-items: center;
|
|
195
|
+
align-self: start;
|
|
92
196
|
gap: var(--sp-2);
|
|
93
197
|
font-size: var(--text-caption);
|
|
198
|
+
line-height: var(--leading-caption);
|
|
94
199
|
color: var(--c-text-secondary);
|
|
95
200
|
}
|
|
96
201
|
|
|
@@ -101,25 +206,71 @@ const size = variant === 'tiles' ? 16 : 14;
|
|
|
101
206
|
background: color-mix(in oklab, var(--accent, var(--c-text-muted)) 16%, var(--c-surface));
|
|
102
207
|
}
|
|
103
208
|
|
|
104
|
-
.
|
|
105
|
-
|
|
209
|
+
/* The figure keeps a line's height while it waits, so nothing jumps when it arrives. A unit
|
|
210
|
+
that doesn't fit goes under it whole, never split from a number mid-word. */
|
|
211
|
+
.tiles :global(.fact-value) {
|
|
212
|
+
display: flex;
|
|
213
|
+
flex-wrap: wrap;
|
|
214
|
+
align-items: baseline;
|
|
215
|
+
align-self: end;
|
|
216
|
+
margin-top: var(--sp-2);
|
|
217
|
+
min-height: 1lh;
|
|
106
218
|
font-size: var(--text-h3, 1.35rem);
|
|
219
|
+
line-height: 1.2;
|
|
220
|
+
color: var(--c-text);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
.tiles :global(.fact-unit) {
|
|
224
|
+
font-size: var(--text-body-sm);
|
|
225
|
+
white-space: nowrap;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
.tiles :global(.fact-context) {
|
|
229
|
+
margin-top: 2px;
|
|
230
|
+
min-height: 1lh;
|
|
231
|
+
font-size: var(--text-caption);
|
|
232
|
+
line-height: var(--leading-caption);
|
|
233
|
+
color: var(--c-text-muted);
|
|
234
|
+
text-wrap: pretty;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/* Lines that will wrap: room for two while they wait. */
|
|
238
|
+
.tiles[data-lines='2'] :global(.fact-context) {
|
|
239
|
+
min-height: 2lh;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
.tiles:not([data-context]) :global(.fact-context) {
|
|
243
|
+
display: none;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/* The change, bold, in a quiet tone that still reads as text: 75% of the status colour, the
|
|
247
|
+
rest the text colour (5:1 or more on a tile in both themes). The text carries the sign, so
|
|
248
|
+
the colour is never the only cue. */
|
|
249
|
+
.tiles :global(.fact-delta) {
|
|
107
250
|
font-weight: 600;
|
|
108
251
|
font-variant-numeric: tabular-nums;
|
|
109
|
-
|
|
252
|
+
color: var(--c-text-secondary);
|
|
110
253
|
}
|
|
111
254
|
|
|
112
|
-
.tiles :global(
|
|
255
|
+
.tiles :global(.fact-delta[data-tone='good']) {
|
|
256
|
+
color: color-mix(in oklab, var(--c-status-good) 75%, var(--c-text));
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
.tiles :global(.fact-delta[data-tone='bad']) {
|
|
260
|
+
color: color-mix(in oklab, var(--c-status-critical) 75%, var(--c-text));
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
.tiles :global(.fact-figure mark) {
|
|
113
264
|
--highlight: color-mix(in oklab, var(--accent, var(--c-accent)) 34%, var(--c-bg));
|
|
114
265
|
}
|
|
115
266
|
|
|
116
267
|
/* The highlighter waits until the tiles are in view. */
|
|
117
|
-
.tiles:not(:global(.in)) :global(
|
|
268
|
+
.tiles:not(:global(.in)) :global(.fact-figure mark) {
|
|
118
269
|
animation: none;
|
|
119
270
|
background-size: 0% var(--highlight-band);
|
|
120
271
|
}
|
|
121
272
|
|
|
122
|
-
/* Pills: a tint of the accent. */
|
|
273
|
+
/* ── Pills: a tint of the accent. ───────────────────────────────────────────── */
|
|
123
274
|
.pills {
|
|
124
275
|
display: flex;
|
|
125
276
|
flex-wrap: wrap;
|
|
@@ -144,14 +295,11 @@ const size = variant === 'tiles' ? 16 : 14;
|
|
|
144
295
|
color: var(--c-text-secondary);
|
|
145
296
|
}
|
|
146
297
|
|
|
147
|
-
.pills :global(
|
|
148
|
-
margin: 0;
|
|
298
|
+
.pills :global(.fact-value) {
|
|
149
299
|
font-size: var(--text-body-sm);
|
|
150
|
-
font-weight: 600;
|
|
151
|
-
font-variant-numeric: tabular-nums;
|
|
152
300
|
}
|
|
153
301
|
|
|
154
|
-
/* A list: hairlines, no fills. */
|
|
302
|
+
/* ── A list: hairlines, no fills. ───────────────────────────────────────────── */
|
|
155
303
|
.list {
|
|
156
304
|
display: grid;
|
|
157
305
|
grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
|
|
@@ -174,9 +322,8 @@ const size = variant === 'tiles' ? 16 : 14;
|
|
|
174
322
|
color: var(--c-text-muted);
|
|
175
323
|
}
|
|
176
324
|
|
|
177
|
-
.list :global(
|
|
178
|
-
margin:
|
|
179
|
-
font-weight: 600;
|
|
325
|
+
.list :global(.fact-value) {
|
|
326
|
+
margin-inline-start: auto;
|
|
180
327
|
text-align: right;
|
|
181
328
|
}
|
|
182
329
|
|
package/src/PeriodPicker.astro
CHANGED
|
@@ -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
|
}
|
package/src/Stat.astro
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
---
|
|
2
2
|
/**
|
|
3
|
+
* @deprecated Since 0.20.0: use Facts tiles, which take label, value, context, valueId and
|
|
4
|
+
* contextId as the same fields, plus a unit and a change. Kept working until 1.0.
|
|
5
|
+
*
|
|
3
6
|
* One number someone reads at a glance, inside a StatStrip. The value keeps its height
|
|
4
7
|
* while a page waits, so nothing jumps when it arrives. Unknown is –, never 0.
|
|
5
8
|
*/
|
package/src/StatStrip.astro
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
---
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* @deprecated Since 0.20.0: use Facts (tiles), one fact per Stat. Kept working until 1.0.
|
|
4
|
+
*
|
|
5
|
+
* A row of Stats between two rules. Four at most: past that, you probably want a table.
|
|
6
|
+
*/
|
|
3
7
|
---
|
|
4
8
|
|
|
5
9
|
<dl class="stat-strip"><slot /></dl>
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* One year of days at a glance, a week to a column: which days had something, and how much, in
|
|
4
|
+
* steps of colour. The days are squares that share the width there is, so the year fits a phone
|
|
5
|
+
* and fills a card.
|
|
6
|
+
*
|
|
7
|
+
* It draws the empty year at build time, so the page keeps its shape; fill it with
|
|
8
|
+
* setYearCalendar from `@n1kname/components/yearcalendar.js` when the days arrive, or pass `days`
|
|
9
|
+
* to draw them now (the card and keys still need setYearCalendar). The heat ramp by default; `tone`
|
|
10
|
+
* for one colour in `levels` strengths, or `colors` for any ramp.
|
|
11
|
+
*/
|
|
12
|
+
import '@n1kname/charts/pointer.css';
|
|
13
|
+
import { calendarHTML } from './yearcalendar.js';
|
|
14
|
+
|
|
15
|
+
interface Props {
|
|
16
|
+
/** Unique on the page; setYearCalendar finds the calendar by it. */
|
|
17
|
+
id: string;
|
|
18
|
+
year: number;
|
|
19
|
+
/** ISO date → number, drawn at build time. */
|
|
20
|
+
days?: Record<string, number>;
|
|
21
|
+
/** One colour, in `levels` strengths: var(--c-chart-6). */
|
|
22
|
+
tone?: string;
|
|
23
|
+
levels?: number;
|
|
24
|
+
/** Low to high. Any CSS colours, best tokens. */
|
|
25
|
+
colors?: string[];
|
|
26
|
+
/** Where each colour after the first starts. */
|
|
27
|
+
steps?: number[];
|
|
28
|
+
/** 1 for Monday, 0 for Sunday. */
|
|
29
|
+
weekStart?: 0 | 1;
|
|
30
|
+
/** What the grid says to a screen reader: "Running in 2026: 84 days". */
|
|
31
|
+
label?: string;
|
|
32
|
+
[key: string]: unknown;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const { id, year, days, tone, levels, colors, steps, weekStart = 1, label, class: className, ...rest } = Astro.props;
|
|
36
|
+
const html = calendarHTML({ year, days, tone, levels, colors, steps, weekStart, label });
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
<div id={id} class:list={['year-calendar', className]} {...rest}><Fragment set:html={html} /></div>
|
|
40
|
+
|
|
41
|
+
<style>
|
|
42
|
+
.year-calendar {
|
|
43
|
+
container-type: inline-size;
|
|
44
|
+
position: relative;
|
|
45
|
+
/* Wide, the days stop growing at --year-calendar-cell; the frame is as wide as they need. */
|
|
46
|
+
--yc-gap: 2px;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.year-calendar :global(.yc-frame) {
|
|
50
|
+
position: relative;
|
|
51
|
+
display: grid;
|
|
52
|
+
grid-template-columns: 1rem minmax(0, 1fr);
|
|
53
|
+
grid-template-areas: '. months' 'wd grid';
|
|
54
|
+
gap: 2px 4px;
|
|
55
|
+
max-width: calc(1rem + 4px + var(--weeks) * (var(--year-calendar-cell, 16px) + var(--yc-gap)));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/* Each month's name over the week holding its first day. */
|
|
59
|
+
.year-calendar :global(.yc-months) {
|
|
60
|
+
grid-area: months;
|
|
61
|
+
position: relative;
|
|
62
|
+
height: 0.875rem;
|
|
63
|
+
font-size: 0.625rem;
|
|
64
|
+
line-height: 1;
|
|
65
|
+
color: var(--c-text-muted);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.year-calendar :global(.yc-months span) {
|
|
69
|
+
position: absolute;
|
|
70
|
+
left: var(--at);
|
|
71
|
+
white-space: nowrap;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/* On a phone the gaps would take a third of the width: a pixel each gives it to the days. */
|
|
75
|
+
@container (max-width: 480px) {
|
|
76
|
+
.year-calendar :global(.yc-frame) {
|
|
77
|
+
--yc-gap: 1px;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.year-calendar :global(.yc-grid i) {
|
|
81
|
+
border-radius: 1px;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/* Narrow, a letter each. */
|
|
86
|
+
@container (max-width: 320px) {
|
|
87
|
+
.year-calendar :global(.yc-months span) {
|
|
88
|
+
font-size: 0;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.year-calendar :global(.yc-months span)::before {
|
|
92
|
+
content: attr(data-short);
|
|
93
|
+
font-size: 0.625rem;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/* The letters take the grid's height and never set it (contain: size): when the days are
|
|
98
|
+
smaller than a letter, the rows stay as tall as the days. */
|
|
99
|
+
.year-calendar :global(.yc-wd) {
|
|
100
|
+
grid-area: wd;
|
|
101
|
+
contain: size;
|
|
102
|
+
display: grid;
|
|
103
|
+
grid-template-rows: repeat(7, minmax(0, 1fr));
|
|
104
|
+
gap: var(--yc-gap);
|
|
105
|
+
align-items: center;
|
|
106
|
+
font-size: 0.5625rem;
|
|
107
|
+
line-height: 1;
|
|
108
|
+
color: var(--c-text-muted);
|
|
109
|
+
text-align: right;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/* Each day a square: the weeks share the width and the rows follow from it. */
|
|
113
|
+
.year-calendar :global(.yc-grid) {
|
|
114
|
+
grid-area: grid;
|
|
115
|
+
min-width: 0;
|
|
116
|
+
display: grid;
|
|
117
|
+
grid-template-rows: repeat(7, auto);
|
|
118
|
+
grid-auto-columns: minmax(0, 1fr);
|
|
119
|
+
grid-auto-flow: column;
|
|
120
|
+
gap: var(--yc-gap);
|
|
121
|
+
align-content: start;
|
|
122
|
+
border-radius: 2px;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
.year-calendar :global(.yc-grid:focus-visible) {
|
|
126
|
+
outline: 2px solid var(--c-focus);
|
|
127
|
+
outline-offset: 3px;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
.year-calendar :global(.yc-grid i) {
|
|
131
|
+
aspect-ratio: 1;
|
|
132
|
+
border-radius: 2px;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
.year-calendar :global(.yc-grid .off) {
|
|
136
|
+
background: color-mix(in oklab, var(--c-text) 9%, var(--c-surface));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/* Days still to come: paler, so the year so far reads as one shape. */
|
|
140
|
+
.year-calendar :global(.yc-grid .later) {
|
|
141
|
+
background: color-mix(in oklab, var(--c-text) 4%, var(--c-surface));
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
.year-calendar :global(.yc-grid .out) {
|
|
145
|
+
visibility: hidden;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/* A hairline edge, so a pale step (the heat ramp's yellow) keeps its shape on a light surface. */
|
|
149
|
+
.year-calendar :global(.yc-grid .on) {
|
|
150
|
+
box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--c-text) 10%, transparent);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
.year-calendar :global([data-step='1']) { background: var(--yc-1); }
|
|
154
|
+
.year-calendar :global([data-step='2']) { background: var(--yc-2); }
|
|
155
|
+
.year-calendar :global([data-step='3']) { background: var(--yc-3); }
|
|
156
|
+
.year-calendar :global([data-step='4']) { background: var(--yc-4); }
|
|
157
|
+
.year-calendar :global([data-step='5']) { background: var(--yc-5); }
|
|
158
|
+
.year-calendar :global([data-step='6']) { background: var(--yc-6); }
|
|
159
|
+
.year-calendar :global([data-step='7']) { background: var(--yc-7); }
|
|
160
|
+
.year-calendar :global([data-step='8']) { background: var(--yc-8); }
|
|
161
|
+
.year-calendar :global([data-step='9']) { background: var(--yc-9); }
|
|
162
|
+
|
|
163
|
+
/* The card's figure beside its colour, and the frame round the day a little rounder. */
|
|
164
|
+
.year-calendar :global(.chart-pointer-one) {
|
|
165
|
+
display: flex;
|
|
166
|
+
align-items: center;
|
|
167
|
+
gap: var(--sp-2);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
.year-calendar :global(.chart-pointer-one i) {
|
|
171
|
+
box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--c-text) 14%, transparent);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
.year-calendar :global(.chart-pointer-cell) {
|
|
175
|
+
border-width: 1.5px;
|
|
176
|
+
border-radius: 3px;
|
|
177
|
+
margin: -1.5px 0 0 -1.5px;
|
|
178
|
+
padding: 1.5px;
|
|
179
|
+
box-sizing: content-box;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
.year-calendar :global(.chart-pointer-card) {
|
|
183
|
+
z-index: 5;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
.year-calendar :global(.yc-sr) {
|
|
187
|
+
position: absolute;
|
|
188
|
+
width: 1px;
|
|
189
|
+
height: 1px;
|
|
190
|
+
overflow: hidden;
|
|
191
|
+
clip-path: inset(50%);
|
|
192
|
+
white-space: nowrap;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
@media (forced-colors: active) {
|
|
196
|
+
.year-calendar :global(.yc-grid i) {
|
|
197
|
+
forced-color-adjust: none;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
.year-calendar :global(.yc-grid .off),
|
|
201
|
+
.year-calendar :global(.yc-grid .later) {
|
|
202
|
+
background: Canvas;
|
|
203
|
+
outline: 1px solid GrayText;
|
|
204
|
+
outline-offset: -1px;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
</style>
|