@n1kname/components 0.20.0 → 0.21.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 +1 -1
- package/src/Timeline.astro +226 -62
package/package.json
CHANGED
package/src/Timeline.astro
CHANGED
|
@@ -1,134 +1,298 @@
|
|
|
1
1
|
---
|
|
2
2
|
/**
|
|
3
|
-
* A project timeline:
|
|
4
|
-
*
|
|
5
|
-
*
|
|
3
|
+
* A project timeline: a marker and a line down the left, and each entry's period, title and text
|
|
4
|
+
* beside it. The period sits above the title, small, so a year, a phase or a name all read the
|
|
5
|
+
* same, and the text keeps the width.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
7
|
+
* Entries up to `current` are done (filled markers on a solid line); `current` is now (a marker
|
|
8
|
+
* with a halo); any after it are still to come (hollow markers on a dashed line). By default the
|
|
9
|
+
* last entry is now. An entry can carry an icon, shown in a soft disc of the accent.
|
|
10
|
+
*
|
|
11
|
+
* Once, as each entry comes into view, its marker settles in, its text rises and its line draws on
|
|
12
|
+
* to the next. Nothing moves under reduced motion, and without script everything is simply there.
|
|
8
13
|
*/
|
|
14
|
+
import type { IconName } from './icons';
|
|
15
|
+
import Icon from './Icon.astro';
|
|
16
|
+
|
|
9
17
|
interface Entry {
|
|
10
18
|
period: string;
|
|
11
19
|
label: string;
|
|
12
20
|
body: string;
|
|
21
|
+
/** What the step was, from the icon set: users, search, route, … */
|
|
22
|
+
icon?: IconName;
|
|
13
23
|
}
|
|
14
24
|
|
|
15
25
|
interface Props {
|
|
16
26
|
entries: Entry[];
|
|
27
|
+
/** Which entry is now, 0 first. The last by default; false for a history that is over. */
|
|
28
|
+
current?: number | false;
|
|
17
29
|
}
|
|
18
30
|
|
|
19
|
-
const { entries } = Astro.props;
|
|
31
|
+
const { entries, current = entries.length - 1 } = Astro.props;
|
|
32
|
+
const icons = entries.some((e) => e.icon);
|
|
33
|
+
const state = (i: number) => (current === false || i < current ? 'done' : i === current ? 'current' : 'next');
|
|
20
34
|
---
|
|
21
35
|
|
|
22
|
-
<ol class="timeline">
|
|
36
|
+
<ol class="timeline" data-icons={icons ? '' : undefined} data-timeline>
|
|
23
37
|
{
|
|
24
38
|
entries.map((e, i) => (
|
|
25
|
-
<li
|
|
26
|
-
<span class="
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
39
|
+
<li data-state={state(i)} aria-current={state(i) === 'current' ? 'step' : undefined} data-to={i < entries.length - 1 ? state(i + 1) : undefined}>
|
|
40
|
+
<span class="marker" aria-hidden="true">
|
|
41
|
+
{e.icon && <Icon name={e.icon} size={16} />}
|
|
42
|
+
</span>
|
|
43
|
+
<div class="content">
|
|
44
|
+
<p class="period">{e.period}</p>
|
|
45
|
+
<p class="label">{e.label}</p>
|
|
30
46
|
<p class="text">{e.body}</p>
|
|
31
47
|
</div>
|
|
32
48
|
</li>
|
|
33
49
|
))
|
|
34
50
|
}
|
|
35
51
|
</ol>
|
|
52
|
+
<script is:inline>
|
|
53
|
+
// Before the first paint, so entries waiting to arrive never show and then vanish.
|
|
54
|
+
(function (list) {
|
|
55
|
+
if (list && 'IntersectionObserver' in window && !matchMedia('(prefers-reduced-motion: reduce)').matches) list.classList.add('arrive');
|
|
56
|
+
})(document.currentScript && document.currentScript.previousElementSibling);
|
|
57
|
+
</script>
|
|
58
|
+
|
|
59
|
+
<script>
|
|
60
|
+
// Each entry arrives once, as it comes into view. Entries that come into view together follow
|
|
61
|
+
// one another a beat apart.
|
|
62
|
+
document.querySelectorAll<HTMLElement>('[data-timeline].arrive').forEach((list) => {
|
|
63
|
+
const seen = new IntersectionObserver(
|
|
64
|
+
(entries) => {
|
|
65
|
+
entries
|
|
66
|
+
.filter((e) => e.isIntersecting)
|
|
67
|
+
.forEach((e, k) => {
|
|
68
|
+
const li = e.target as HTMLElement;
|
|
69
|
+
li.style.setProperty('--d', `${k * 110}ms`);
|
|
70
|
+
li.classList.add('in');
|
|
71
|
+
seen.unobserve(li);
|
|
72
|
+
});
|
|
73
|
+
},
|
|
74
|
+
{ threshold: 0.25, rootMargin: '0px 0px -8% 0px' },
|
|
75
|
+
);
|
|
76
|
+
list.querySelectorAll('li').forEach((li) => seen.observe(li));
|
|
77
|
+
});
|
|
78
|
+
</script>
|
|
36
79
|
|
|
37
80
|
<style>
|
|
38
81
|
.timeline {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
82
|
+
/* The marker's size and how far it sits down the first line, so the line can meet it. */
|
|
83
|
+
--m: 12px;
|
|
84
|
+
--mt: 4px;
|
|
85
|
+
--col: 16px;
|
|
86
|
+
--gap: var(--sp-6);
|
|
87
|
+
--done: var(--c-accent);
|
|
88
|
+
--rail-done: color-mix(in oklab, var(--c-accent) 45%, var(--c-border));
|
|
89
|
+
--rail-next: var(--c-border-strong);
|
|
42
90
|
list-style: none;
|
|
43
91
|
margin: var(--sp-5) 0 var(--sp-7);
|
|
44
92
|
padding: 0;
|
|
45
93
|
}
|
|
46
94
|
|
|
47
|
-
|
|
95
|
+
.timeline[data-icons] {
|
|
96
|
+
--m: 32px;
|
|
97
|
+
--mt: 0px;
|
|
98
|
+
--col: 32px;
|
|
99
|
+
}
|
|
100
|
+
|
|
48
101
|
li {
|
|
49
|
-
display: grid;
|
|
50
|
-
grid-column: 1 / -1;
|
|
51
|
-
grid-template-columns: subgrid;
|
|
52
|
-
padding-bottom: var(--sp-6);
|
|
53
102
|
position: relative;
|
|
103
|
+
display: grid;
|
|
104
|
+
grid-template-columns: var(--col) minmax(0, 1fr);
|
|
105
|
+
column-gap: var(--sp-4);
|
|
106
|
+
padding-bottom: var(--gap);
|
|
54
107
|
}
|
|
55
108
|
|
|
56
109
|
li:last-child {
|
|
57
110
|
padding-bottom: 0;
|
|
58
111
|
}
|
|
59
112
|
|
|
60
|
-
/*
|
|
61
|
-
|
|
62
|
-
position: relative;
|
|
63
|
-
width: 20px;
|
|
64
|
-
margin-top: 3px;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
.rail::before {
|
|
113
|
+
/* The line from this marker to the next, a small gap clear of each. */
|
|
114
|
+
li:not(:last-child)::before {
|
|
68
115
|
content: '';
|
|
69
116
|
position: absolute;
|
|
70
|
-
inset-inline-start:
|
|
71
|
-
top:
|
|
72
|
-
|
|
73
|
-
|
|
117
|
+
inset-inline-start: calc(var(--col) / 2 - 1px);
|
|
118
|
+
top: calc(var(--mt) + var(--m) + 6px);
|
|
119
|
+
bottom: calc(6px - var(--mt));
|
|
120
|
+
width: 2px;
|
|
121
|
+
border-radius: 1px;
|
|
122
|
+
background: var(--rail-done);
|
|
123
|
+
transform-origin: top;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/* On to what's still to come: dashed, and quieter. */
|
|
127
|
+
li[data-to='next']::before {
|
|
128
|
+
background: repeating-linear-gradient(to bottom, var(--rail-next) 0 4px, transparent 4px 9px);
|
|
129
|
+
opacity: 0.7;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/* ── Markers ─────────────────────────────────────────────────────────────── */
|
|
133
|
+
.marker {
|
|
134
|
+
position: relative;
|
|
135
|
+
display: grid;
|
|
136
|
+
place-items: center;
|
|
137
|
+
width: var(--m);
|
|
138
|
+
height: var(--m);
|
|
139
|
+
margin-top: var(--mt);
|
|
140
|
+
justify-self: center;
|
|
74
141
|
border-radius: var(--radius-full);
|
|
75
|
-
|
|
142
|
+
background: var(--done);
|
|
143
|
+
color: var(--c-text-accent);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
.marker :global(svg) {
|
|
147
|
+
display: block;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/* Now: a halo round it, so it reads as where things stand. */
|
|
151
|
+
[data-state='current'] .marker {
|
|
152
|
+
box-shadow: 0 0 0 4px color-mix(in oklab, var(--c-accent) 28%, transparent);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/* Still to come: hollow. */
|
|
156
|
+
[data-state='next'] .marker {
|
|
76
157
|
background: var(--c-bg);
|
|
158
|
+
box-shadow: inset 0 0 0 2px var(--c-border-strong);
|
|
77
159
|
}
|
|
78
160
|
|
|
79
|
-
|
|
80
|
-
|
|
161
|
+
/* With icons: a soft disc of the accent for what's done, the accent itself for now. */
|
|
162
|
+
[data-icons] [data-state='done'] .marker {
|
|
163
|
+
background: color-mix(in oklab, var(--c-accent) 16%, var(--c-surface));
|
|
81
164
|
}
|
|
82
165
|
|
|
83
|
-
.
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
166
|
+
[data-icons] [data-state='current'] .marker {
|
|
167
|
+
background: var(--c-accent);
|
|
168
|
+
color: var(--c-on-accent);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
[data-icons] [data-state='next'] .marker {
|
|
172
|
+
color: var(--c-text-muted);
|
|
173
|
+
box-shadow: inset 0 0 0 1.5px var(--c-border-strong);
|
|
91
174
|
}
|
|
92
175
|
|
|
93
|
-
|
|
94
|
-
|
|
176
|
+
/* ── Text ────────────────────────────────────────────────────────────────── */
|
|
177
|
+
.content {
|
|
178
|
+
min-width: 0;
|
|
95
179
|
}
|
|
96
180
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
padding-top:
|
|
181
|
+
/* With icons, the period sits level with the middle of the disc. */
|
|
182
|
+
[data-icons] .content {
|
|
183
|
+
padding-top: calc((var(--m) - var(--text-caption) * 1.5) / 2);
|
|
100
184
|
}
|
|
101
185
|
|
|
102
|
-
.
|
|
186
|
+
.content p {
|
|
103
187
|
max-width: none;
|
|
188
|
+
margin: 0;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
.period {
|
|
192
|
+
font-family: var(--font-body);
|
|
193
|
+
font-size: var(--text-caption);
|
|
194
|
+
line-height: 1.5;
|
|
195
|
+
font-weight: 600;
|
|
196
|
+
letter-spacing: 0.02em;
|
|
197
|
+
font-variant-numeric: tabular-nums;
|
|
198
|
+
color: var(--c-text-muted);
|
|
104
199
|
}
|
|
105
200
|
|
|
106
|
-
|
|
107
|
-
|
|
201
|
+
[data-state='current'] .period {
|
|
202
|
+
color: var(--c-text-accent);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
.label {
|
|
206
|
+
margin-top: 2px;
|
|
207
|
+
font-family: var(--font-body);
|
|
208
|
+
font-size: var(--text-sub);
|
|
209
|
+
line-height: var(--leading-sub);
|
|
210
|
+
letter-spacing: var(--tracking-sub);
|
|
211
|
+
font-weight: 600;
|
|
212
|
+
color: var(--c-text);
|
|
108
213
|
}
|
|
109
214
|
|
|
110
215
|
.text {
|
|
216
|
+
margin-top: var(--sp-1);
|
|
217
|
+
color: var(--c-text-secondary);
|
|
218
|
+
text-wrap: pretty;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
[data-state='next'] .text {
|
|
111
222
|
color: var(--c-text-muted);
|
|
112
223
|
}
|
|
113
224
|
|
|
114
|
-
/*
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
225
|
+
/* ── Arriving, once ─────────────────────────────────────────────────────────
|
|
226
|
+
Only on a page whose script has run and that allows motion, so the timeline is never hidden
|
|
227
|
+
without it. The marker settles on the spring, the text rises a little, then the line draws on
|
|
228
|
+
to the next entry. Now's halo ripples out twice. */
|
|
229
|
+
.arrive li:not(.in) .marker {
|
|
230
|
+
opacity: 0;
|
|
231
|
+
transform: scale(0.4);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
.arrive li:not(.in) .content {
|
|
235
|
+
opacity: 0;
|
|
236
|
+
transform: translateY(6px);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
.arrive li:not(.in)::before {
|
|
240
|
+
transform: scaleY(0);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/* The transitions belong to arriving only: going back to waiting is instant. */
|
|
244
|
+
.arrive li.in .marker {
|
|
245
|
+
transition:
|
|
246
|
+
opacity var(--motion-base) var(--ease-out) var(--d, 0ms),
|
|
247
|
+
transform var(--motion-spring) var(--ease-spring) var(--d, 0ms);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
.arrive li.in .content {
|
|
251
|
+
transition:
|
|
252
|
+
opacity var(--motion-gentle) var(--ease-out) calc(var(--d, 0ms) + 60ms),
|
|
253
|
+
transform var(--motion-gentle) var(--ease-out) calc(var(--d, 0ms) + 60ms);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
.arrive li.in::before {
|
|
257
|
+
transition: transform 520ms var(--ease-soft) calc(var(--d, 0ms) + 200ms);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
.arrive [data-state='current'].in .marker::after {
|
|
261
|
+
content: '';
|
|
262
|
+
position: absolute;
|
|
263
|
+
inset: 0;
|
|
264
|
+
border-radius: inherit;
|
|
265
|
+
box-shadow: 0 0 0 2px var(--c-accent);
|
|
266
|
+
opacity: 0;
|
|
267
|
+
animation: ripple 1100ms var(--ease-out) calc(var(--d, 0ms) + 260ms) 2;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
@keyframes ripple {
|
|
271
|
+
from {
|
|
272
|
+
opacity: 0.6;
|
|
273
|
+
transform: scale(1);
|
|
118
274
|
}
|
|
119
275
|
|
|
120
|
-
|
|
121
|
-
|
|
276
|
+
to {
|
|
277
|
+
opacity: 0;
|
|
278
|
+
transform: scale(2.2);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
@media (forced-colors: active) {
|
|
283
|
+
.marker {
|
|
284
|
+
forced-color-adjust: none;
|
|
285
|
+
background: CanvasText;
|
|
286
|
+
color: Canvas;
|
|
122
287
|
}
|
|
123
288
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
289
|
+
[data-state='next'] .marker {
|
|
290
|
+
background: Canvas;
|
|
291
|
+
box-shadow: inset 0 0 0 2px CanvasText;
|
|
127
292
|
}
|
|
128
293
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
grid-column: 2;
|
|
294
|
+
li:not(:last-child)::before {
|
|
295
|
+
background: CanvasText;
|
|
132
296
|
}
|
|
133
297
|
}
|
|
134
298
|
</style>
|