@n1kname/components 0.28.0 → 0.29.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/AtAGlance.astro +185 -0
- package/src/SectionNav.astro +53 -10
package/package.json
CHANGED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* A long page in one look, at its top: a few labelled parts (a role, the problem, what was done,
|
|
4
|
+
* what changed), each a sentence or a short list, and the key figures under them. For a case
|
|
5
|
+
* study, so a reader who stops here still has the story, and one who reads on knows where it goes.
|
|
6
|
+
*
|
|
7
|
+
* The parts sit two across where there's room and stack where there isn't; each can lead with an
|
|
8
|
+
* icon. The figures are Facts tiles, as everywhere else. It is a section with its own heading, so
|
|
9
|
+
* it shows in a page's outline.
|
|
10
|
+
*/
|
|
11
|
+
import type { IconName } from './icons';
|
|
12
|
+
import Icon from './Icon.astro';
|
|
13
|
+
import Facts from './Facts.astro';
|
|
14
|
+
|
|
15
|
+
interface Part {
|
|
16
|
+
label: string;
|
|
17
|
+
/** Leads the label, from the icon set. One per part; the points keep their dots. */
|
|
18
|
+
icon?: IconName;
|
|
19
|
+
/** One or two sentences. */
|
|
20
|
+
text?: string;
|
|
21
|
+
/** Or a short list: two to four points. */
|
|
22
|
+
points?: string[];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface Props {
|
|
26
|
+
parts: Part[];
|
|
27
|
+
/** The figures under the parts, as Facts tiles: a value, what it counts, and an icon, in the
|
|
28
|
+
* accent by default, so they read as this block's. */
|
|
29
|
+
figures?: { value: string; label: string; icon?: IconName; unit?: string; accent?: string }[];
|
|
30
|
+
title?: string;
|
|
31
|
+
/** The heading's level, 2 by default. */
|
|
32
|
+
level?: 2 | 3;
|
|
33
|
+
id?: string;
|
|
34
|
+
class?: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const { parts, figures = [], title = 'At a glance', level = 2, id = 'at-a-glance', class: className } = Astro.props;
|
|
38
|
+
const Heading = `h${level}` as 'h2' | 'h3';
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
<section class:list={['glance', className]} aria-labelledby={`${id}-title`}>
|
|
42
|
+
<Heading class="glance-title" id={`${id}-title`}>{title}</Heading>
|
|
43
|
+
<dl class="parts">
|
|
44
|
+
{
|
|
45
|
+
parts.map((p) => (
|
|
46
|
+
<div class="part">
|
|
47
|
+
<dt>
|
|
48
|
+
{p.icon && (
|
|
49
|
+
<span class="part-icon" aria-hidden="true">
|
|
50
|
+
<Icon name={p.icon} size={16} />
|
|
51
|
+
</span>
|
|
52
|
+
)}
|
|
53
|
+
{p.label}
|
|
54
|
+
</dt>
|
|
55
|
+
<dd>
|
|
56
|
+
{p.text && <span class="text">{p.text}</span>}
|
|
57
|
+
{p.points && p.points.length > 0 && (
|
|
58
|
+
<ul>
|
|
59
|
+
{p.points.map((pt) => (
|
|
60
|
+
<li>{pt}</li>
|
|
61
|
+
))}
|
|
62
|
+
</ul>
|
|
63
|
+
)}
|
|
64
|
+
</dd>
|
|
65
|
+
</div>
|
|
66
|
+
))
|
|
67
|
+
}
|
|
68
|
+
</dl>
|
|
69
|
+
{
|
|
70
|
+
figures.length > 0 && (
|
|
71
|
+
<div class="figures">
|
|
72
|
+
<Facts items={figures.map((f) => ({ label: f.label, value: f.value, unit: f.unit, icon: f.icon, accent: f.accent ?? 'var(--c-text-accent)' }))} />
|
|
73
|
+
</div>
|
|
74
|
+
)
|
|
75
|
+
}
|
|
76
|
+
</section>
|
|
77
|
+
|
|
78
|
+
<style>
|
|
79
|
+
.glance {
|
|
80
|
+
container-type: inline-size;
|
|
81
|
+
padding: var(--sp-5) var(--sp-6) var(--sp-6);
|
|
82
|
+
background: var(--c-surface);
|
|
83
|
+
border: 1px solid var(--c-border);
|
|
84
|
+
border-radius: var(--radius-lg);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.glance-title {
|
|
88
|
+
margin: 0 0 var(--sp-4);
|
|
89
|
+
font-family: var(--font-body);
|
|
90
|
+
font-size: var(--text-overline);
|
|
91
|
+
font-weight: 600;
|
|
92
|
+
line-height: var(--leading-overline);
|
|
93
|
+
letter-spacing: var(--tracking-overline);
|
|
94
|
+
text-transform: uppercase;
|
|
95
|
+
color: var(--c-text-accent);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.parts {
|
|
99
|
+
display: grid;
|
|
100
|
+
gap: var(--sp-5) var(--sp-7);
|
|
101
|
+
margin: 0;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
@container (min-width: 640px) {
|
|
105
|
+
.parts {
|
|
106
|
+
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
.part dt {
|
|
111
|
+
display: flex;
|
|
112
|
+
align-items: center;
|
|
113
|
+
gap: var(--sp-2);
|
|
114
|
+
margin-bottom: var(--sp-1);
|
|
115
|
+
font-family: var(--font-display);
|
|
116
|
+
font-weight: 600;
|
|
117
|
+
font-size: var(--text-sub);
|
|
118
|
+
line-height: var(--leading-sub);
|
|
119
|
+
color: var(--c-text);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
.part-icon {
|
|
123
|
+
display: grid;
|
|
124
|
+
place-items: center;
|
|
125
|
+
flex: none;
|
|
126
|
+
width: 28px;
|
|
127
|
+
height: 28px;
|
|
128
|
+
border-radius: 50%;
|
|
129
|
+
background: var(--c-surface-tint);
|
|
130
|
+
color: var(--c-text-accent);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
.part dd {
|
|
134
|
+
margin: 0;
|
|
135
|
+
font-size: var(--text-body);
|
|
136
|
+
line-height: var(--leading-body);
|
|
137
|
+
color: var(--c-text-secondary);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
.text {
|
|
141
|
+
display: block;
|
|
142
|
+
text-wrap: pretty;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
ul {
|
|
146
|
+
display: grid;
|
|
147
|
+
gap: var(--sp-2);
|
|
148
|
+
margin: 0;
|
|
149
|
+
padding: 0;
|
|
150
|
+
list-style: none;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
li {
|
|
154
|
+
position: relative;
|
|
155
|
+
padding-left: var(--sp-4);
|
|
156
|
+
text-wrap: pretty;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
li::before {
|
|
160
|
+
content: '';
|
|
161
|
+
position: absolute;
|
|
162
|
+
left: 0;
|
|
163
|
+
top: 0.7em;
|
|
164
|
+
width: 6px;
|
|
165
|
+
height: 6px;
|
|
166
|
+
border-radius: 50%;
|
|
167
|
+
background: var(--c-accent);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
.text + ul {
|
|
171
|
+
margin-top: var(--sp-2);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
.figures {
|
|
175
|
+
margin-top: var(--sp-6);
|
|
176
|
+
padding-top: var(--sp-5);
|
|
177
|
+
border-top: 1px solid var(--c-border);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
@media (forced-colors: active) {
|
|
181
|
+
li::before {
|
|
182
|
+
background: CanvasText;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
</style>
|
package/src/SectionNav.astro
CHANGED
|
@@ -5,9 +5,10 @@
|
|
|
5
5
|
* margin beside the reading column.
|
|
6
6
|
*
|
|
7
7
|
* It finds where you are from the headings its links point to: the last one above the top third of
|
|
8
|
-
* the window is current, and its link gets `aria-current="location"`.
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* the window is current, and its link gets `aria-current="location"`. A marker on the rule glides to
|
|
9
|
+
* it over --motion-base, short enough to keep up with scrolling, and the text brightens as it lands;
|
|
10
|
+
* under reduced motion it moves at once. Before the first heading nothing is current. Without
|
|
11
|
+
* script it is a plain list of links.
|
|
11
12
|
*
|
|
12
13
|
* The page places it: it is sticky inside whatever holds it, so give it a column or a margin that
|
|
13
14
|
* runs the length of the text. It never hides itself, so it is always in the tab order.
|
|
@@ -34,6 +35,7 @@ const hash = (h: string) => (h.startsWith('#') ? h : `#${h}`);
|
|
|
34
35
|
|
|
35
36
|
<nav id={id} class:list={['section-nav', className]} aria-label={label} data-section-nav>
|
|
36
37
|
{title && <p class="title" aria-hidden="true">{title}</p>}
|
|
38
|
+
<span class="marker" aria-hidden="true"></span>
|
|
37
39
|
<ol>
|
|
38
40
|
{
|
|
39
41
|
items.map((item) => (
|
|
@@ -72,6 +74,31 @@ const hash = (h: string) => (h.startsWith('#') ? h : `#${h}`);
|
|
|
72
74
|
border-left: 1px solid var(--c-border);
|
|
73
75
|
}
|
|
74
76
|
|
|
77
|
+
/* Where you are: one bar on the rule that glides from section to section. */
|
|
78
|
+
.marker {
|
|
79
|
+
position: absolute;
|
|
80
|
+
top: 0;
|
|
81
|
+
left: 0;
|
|
82
|
+
width: 2px;
|
|
83
|
+
height: var(--h, 0);
|
|
84
|
+
background: var(--c-accent);
|
|
85
|
+
border-radius: 1px;
|
|
86
|
+
opacity: 0;
|
|
87
|
+
translate: 0 var(--y, 0);
|
|
88
|
+
transition:
|
|
89
|
+
translate var(--motion-base) var(--ease-out),
|
|
90
|
+
height var(--motion-base) var(--ease-out),
|
|
91
|
+
opacity var(--motion-fast) var(--ease-out);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
.marker.on {
|
|
95
|
+
opacity: 1;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.marker.still {
|
|
99
|
+
transition: none;
|
|
100
|
+
}
|
|
101
|
+
|
|
75
102
|
a {
|
|
76
103
|
display: block;
|
|
77
104
|
margin-left: -1px;
|
|
@@ -81,18 +108,17 @@ const hash = (h: string) => (h.startsWith('#') ? h : `#${h}`);
|
|
|
81
108
|
color: var(--c-text-muted);
|
|
82
109
|
text-decoration: none;
|
|
83
110
|
text-wrap: pretty;
|
|
84
|
-
transition: color var(--motion-
|
|
111
|
+
transition: color var(--motion-base) var(--ease-out);
|
|
85
112
|
}
|
|
86
113
|
|
|
87
114
|
a:hover {
|
|
88
115
|
color: var(--c-text);
|
|
89
116
|
}
|
|
90
117
|
|
|
91
|
-
/* Where you are: the text at full strength
|
|
118
|
+
/* Where you are: the text at full strength; the marker carries the bar. Its weight stays the
|
|
119
|
+
* same, so the list never reflows as the marker moves. */
|
|
92
120
|
a[aria-current] {
|
|
93
121
|
color: var(--c-text);
|
|
94
|
-
font-weight: 600;
|
|
95
|
-
border-left-color: var(--c-accent);
|
|
96
122
|
}
|
|
97
123
|
|
|
98
124
|
a:focus-visible {
|
|
@@ -102,8 +128,8 @@ const hash = (h: string) => (h.startsWith('#') ? h : `#${h}`);
|
|
|
102
128
|
}
|
|
103
129
|
|
|
104
130
|
@media (forced-colors: active) {
|
|
105
|
-
|
|
106
|
-
|
|
131
|
+
.marker {
|
|
132
|
+
background: CanvasText;
|
|
107
133
|
}
|
|
108
134
|
}
|
|
109
135
|
</style>
|
|
@@ -111,6 +137,19 @@ const hash = (h: string) => (h.startsWith('#') ? h : `#${h}`);
|
|
|
111
137
|
<script>
|
|
112
138
|
document.querySelectorAll<HTMLElement>('[data-section-nav]').forEach((nav) => {
|
|
113
139
|
const links = [...nav.querySelectorAll<HTMLAnchorElement>('a[href^="#"]')];
|
|
140
|
+
const marker = nav.querySelector<HTMLElement>('.marker');
|
|
141
|
+
let placed = false;
|
|
142
|
+
const mark = (a?: HTMLAnchorElement) => {
|
|
143
|
+
if (!marker) return;
|
|
144
|
+
marker.classList.toggle('on', !!a);
|
|
145
|
+
if (!a) return;
|
|
146
|
+
// The first time in place; after that it glides.
|
|
147
|
+
marker.classList.toggle('still', !placed);
|
|
148
|
+
marker.style.setProperty('--y', `${a.parentElement!.offsetTop}px`);
|
|
149
|
+
marker.style.setProperty('--h', `${a.parentElement!.offsetHeight}px`);
|
|
150
|
+
if (!placed) requestAnimationFrame(() => marker.classList.remove('still'));
|
|
151
|
+
placed = true;
|
|
152
|
+
};
|
|
114
153
|
const heads = links.map((a) => document.getElementById(decodeURIComponent(a.hash.slice(1))));
|
|
115
154
|
let current = -2;
|
|
116
155
|
const update = () => {
|
|
@@ -121,6 +160,7 @@ const hash = (h: string) => (h.startsWith('#') ? h : `#${h}`);
|
|
|
121
160
|
if (now === current) return;
|
|
122
161
|
current = now;
|
|
123
162
|
links.forEach((a, i) => (i === now ? a.setAttribute('aria-current', 'location') : a.removeAttribute('aria-current')));
|
|
163
|
+
mark(links[now]);
|
|
124
164
|
// Keep the current link in view when the list is taller than the window. The list scrolls
|
|
125
165
|
// itself; the page never moves for it.
|
|
126
166
|
const a = links[now];
|
|
@@ -143,7 +183,10 @@ const hash = (h: string) => (h.startsWith('#') ? h : `#${h}`);
|
|
|
143
183
|
},
|
|
144
184
|
{ passive: true },
|
|
145
185
|
);
|
|
146
|
-
addEventListener('resize',
|
|
186
|
+
addEventListener('resize', () => {
|
|
187
|
+
update();
|
|
188
|
+
mark(links[current]);
|
|
189
|
+
}, { passive: true });
|
|
147
190
|
update();
|
|
148
191
|
});
|
|
149
192
|
</script>
|