@n1kname/components 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/THIRD_PARTY.md +13 -0
- package/package.json +28 -3
- package/src/Button.astro +121 -0
- package/src/Cluster.astro +23 -0
- package/src/Columns.astro +42 -0
- package/src/DataTable.astro +187 -0
- package/src/Donut.astro +126 -0
- package/src/EmptyState.astro +55 -0
- package/src/Figure.astro +97 -0
- package/src/Grid.astro +31 -0
- package/src/Icon.astro +27 -0
- package/src/OutcomeTable.astro +136 -0
- package/src/PageHeader.astro +82 -0
- package/src/Quote.astro +87 -0
- package/src/RankedBars.astro +128 -0
- package/src/SidePanel.astro +140 -0
- package/src/Split.astro +43 -0
- package/src/Stack.astro +20 -0
- package/src/Stat.astro +58 -0
- package/src/StatStrip.astro +20 -0
- package/src/Tag.astro +86 -0
- package/src/Timeline.astro +134 -0
- package/src/datatable.js +43 -0
- package/src/icons.ts +69 -0
- package/src/type.css +29 -0
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nikki Veldhuis
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/THIRD_PARTY.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Third-party notices
|
|
2
|
+
|
|
3
|
+
## Lucide
|
|
4
|
+
|
|
5
|
+
The icon paths in `packages/components/src/icons.ts` come from [Lucide](https://lucide.dev/).
|
|
6
|
+
|
|
7
|
+
ISC License
|
|
8
|
+
|
|
9
|
+
Copyright (c) for portions of Lucide are held by Cole Bemis 2013-2022 as part of Feather (MIT). All other copyright (c) for Lucide are held by Lucide Contributors 2022.
|
|
10
|
+
|
|
11
|
+
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
package/package.json
CHANGED
|
@@ -1,6 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@n1kname/components",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
"./*.astro": "./src/*.astro",
|
|
8
|
+
"./type.css": "./src/type.css",
|
|
9
|
+
"./icons": "./src/icons.ts",
|
|
10
|
+
"./datatable.js": "./src/datatable.js"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@n1kname/charts": "0.1.0"
|
|
14
|
+
},
|
|
15
|
+
"peerDependencies": {
|
|
16
|
+
"astro": "^7.4.4"
|
|
17
|
+
},
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
},
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/n1kname/design-system.git",
|
|
24
|
+
"directory": "packages/components"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"src",
|
|
28
|
+
"THIRD_PARTY.md"
|
|
29
|
+
],
|
|
30
|
+
"scripts": {}
|
|
6
31
|
}
|
package/src/Button.astro
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* A button, or a link that looks like one. Uses the real elements, so focus, tab order,
|
|
4
|
+
* Enter and Space come from the browser: never add a positive tabindex.
|
|
5
|
+
*
|
|
6
|
+
* primary the one main action in a view
|
|
7
|
+
* secondary everything else
|
|
8
|
+
* quiet low-emphasis actions beside content
|
|
9
|
+
*
|
|
10
|
+
* `selected` is for a toggle, and sets aria-pressed. Pass any other attribute through,
|
|
11
|
+
* such as id, type or disabled.
|
|
12
|
+
*/
|
|
13
|
+
interface Props {
|
|
14
|
+
variant?: 'primary' | 'secondary' | 'quiet';
|
|
15
|
+
href?: string;
|
|
16
|
+
selected?: boolean;
|
|
17
|
+
disabled?: boolean;
|
|
18
|
+
type?: 'button' | 'submit' | 'reset';
|
|
19
|
+
[key: string]: unknown;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const { variant = 'secondary', href, selected, disabled, type = 'button', class: className, ...rest } = Astro.props;
|
|
23
|
+
const Tag = href ? 'a' : 'button';
|
|
24
|
+
const attrs = href ? { href } : { type, disabled, 'aria-pressed': selected === undefined ? undefined : String(selected) };
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
<Tag class:list={['button', variant, className]} {...attrs} {...rest}><slot /></Tag>
|
|
28
|
+
|
|
29
|
+
<style>
|
|
30
|
+
.button {
|
|
31
|
+
display: inline-flex;
|
|
32
|
+
align-items: center;
|
|
33
|
+
justify-content: center;
|
|
34
|
+
gap: var(--sp-2);
|
|
35
|
+
min-height: 40px;
|
|
36
|
+
padding: var(--sp-2) var(--sp-4);
|
|
37
|
+
border: 1px solid transparent;
|
|
38
|
+
border-radius: var(--radius-sm);
|
|
39
|
+
font-family: var(--font-body);
|
|
40
|
+
font-size: var(--text-body-sm);
|
|
41
|
+
font-weight: 600;
|
|
42
|
+
line-height: 1.3;
|
|
43
|
+
text-decoration: none;
|
|
44
|
+
white-space: nowrap;
|
|
45
|
+
cursor: pointer;
|
|
46
|
+
transition:
|
|
47
|
+
background-color var(--motion-hover) var(--ease-hover),
|
|
48
|
+
border-color var(--motion-hover) var(--ease-hover),
|
|
49
|
+
color var(--motion-hover) var(--ease-hover),
|
|
50
|
+
transform var(--motion-fast) var(--ease-out);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/* A fingertip needs more room than a pointer. */
|
|
54
|
+
@media (pointer: coarse) {
|
|
55
|
+
.button {
|
|
56
|
+
min-height: 44px;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.primary {
|
|
61
|
+
background: var(--c-accent);
|
|
62
|
+
color: var(--c-on-accent);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.primary:hover {
|
|
66
|
+
background: var(--c-accent-hover);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.secondary {
|
|
70
|
+
background: var(--c-surface);
|
|
71
|
+
border-color: var(--c-border-strong);
|
|
72
|
+
color: var(--c-text);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.secondary:hover {
|
|
76
|
+
border-color: var(--c-accent-edge);
|
|
77
|
+
color: var(--c-text-accent);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.quiet {
|
|
81
|
+
background: transparent;
|
|
82
|
+
color: var(--c-text-secondary);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.quiet:hover {
|
|
86
|
+
background: var(--c-surface-hover);
|
|
87
|
+
color: var(--c-text);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.button[aria-pressed='true'] {
|
|
91
|
+
background: var(--c-surface-tint);
|
|
92
|
+
border-color: var(--c-accent-edge);
|
|
93
|
+
color: var(--c-text-accent);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
.button:focus-visible {
|
|
97
|
+
outline: 2px solid var(--c-focus);
|
|
98
|
+
outline-offset: 2px;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.button:active:not(:disabled) {
|
|
102
|
+
transform: scale(0.97);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.button:disabled {
|
|
106
|
+
opacity: 0.5;
|
|
107
|
+
cursor: not-allowed;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
@media (prefers-reduced-motion: reduce) {
|
|
111
|
+
.button:active:not(:disabled) {
|
|
112
|
+
transform: none;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
@media (forced-colors: active) {
|
|
117
|
+
.button {
|
|
118
|
+
border-color: ButtonText;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
</style>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
---
|
|
2
|
+
/** Things in a row that wrap when they run out of room, such as tags and buttons. */
|
|
3
|
+
interface Props {
|
|
4
|
+
gap?: number;
|
|
5
|
+
justify?: 'start' | 'between' | 'end';
|
|
6
|
+
as?: string;
|
|
7
|
+
}
|
|
8
|
+
const { gap = 2, justify = 'start', as: Tag = 'div', class: className, ...rest } = Astro.props;
|
|
9
|
+
const justifyContent = { start: 'flex-start', between: 'space-between', end: 'flex-end' }[justify];
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
<Tag class:list={['cluster', className]} style={`--gap: var(--sp-${gap}); --justify: ${justifyContent}`} {...rest}><slot /></Tag>
|
|
13
|
+
|
|
14
|
+
<style>
|
|
15
|
+
.cluster {
|
|
16
|
+
display: flex;
|
|
17
|
+
flex-wrap: wrap;
|
|
18
|
+
align-items: center;
|
|
19
|
+
justify-content: var(--justify);
|
|
20
|
+
gap: var(--gap);
|
|
21
|
+
min-width: 0;
|
|
22
|
+
}
|
|
23
|
+
</style>
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* Parallel items side by side, for lists whose entries are peers rather than
|
|
4
|
+
* a sequence (research findings, reflections). Not for flowing argument:
|
|
5
|
+
* two columns of continuous prose make the reader scroll down then back up.
|
|
6
|
+
*
|
|
7
|
+
* In MDX, leave blank lines inside so the children still parse as markdown:
|
|
8
|
+
*
|
|
9
|
+
* <Columns>
|
|
10
|
+
*
|
|
11
|
+
* **First item.** ...
|
|
12
|
+
*
|
|
13
|
+
* **Second item.** ...
|
|
14
|
+
*
|
|
15
|
+
* </Columns>
|
|
16
|
+
*/
|
|
17
|
+
interface Props {
|
|
18
|
+
/** Minimum column width before wrapping. Lower it for four-up. */
|
|
19
|
+
min?: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const { min = 280 } = Astro.props;
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
<div class="cols" style={`--col-min: ${min}px`}>
|
|
26
|
+
<slot />
|
|
27
|
+
</div>
|
|
28
|
+
|
|
29
|
+
<style>
|
|
30
|
+
.cols {
|
|
31
|
+
display: grid;
|
|
32
|
+
grid-template-columns: repeat(auto-fit, minmax(min(100%, var(--col-min)), 1fr));
|
|
33
|
+
gap: var(--sp-5) var(--sp-6);
|
|
34
|
+
margin-block: var(--sp-5) var(--sp-7);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/* Each child is its own column, so the reading cap does not apply. */
|
|
38
|
+
.cols :global(> p) {
|
|
39
|
+
max-width: none;
|
|
40
|
+
margin: 0;
|
|
41
|
+
}
|
|
42
|
+
</style>
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* A table for reading figures: words in the body face, numbers in mono so they line up,
|
|
4
|
+
* units in the header, a real row height and sortable columns. Pass `rows` for data known
|
|
5
|
+
* at build time, or leave them out and fill it with setRows from datatable.js.
|
|
6
|
+
*/
|
|
7
|
+
interface Column {
|
|
8
|
+
label: string;
|
|
9
|
+
unit?: string;
|
|
10
|
+
/** Words are left-aligned, numbers right-aligned. */
|
|
11
|
+
align?: 'left' | 'right';
|
|
12
|
+
sortable?: boolean;
|
|
13
|
+
}
|
|
14
|
+
type Cell = string | number | null | { html: string; sort?: string | number };
|
|
15
|
+
|
|
16
|
+
interface Props {
|
|
17
|
+
columns: Column[];
|
|
18
|
+
rows?: Cell[][];
|
|
19
|
+
caption?: string;
|
|
20
|
+
/** 40px rows by default; compact is 32px, for dense tables. */
|
|
21
|
+
density?: 'default' | 'compact';
|
|
22
|
+
id?: string;
|
|
23
|
+
}
|
|
24
|
+
const { columns, rows = [], caption, density = 'default', id } = Astro.props;
|
|
25
|
+
const num = (v: number) => new Intl.NumberFormat('nl-NL').format(v);
|
|
26
|
+
const show = (c: Cell) => (c === null ? '–' : typeof c === 'number' ? num(c) : typeof c === 'string' ? c : '');
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
<div class="scroll" tabindex="0" role="region" aria-label={caption ?? 'Table'}>
|
|
30
|
+
<table class:list={['data-table', density]} id={id} data-data-table>
|
|
31
|
+
{caption && <caption>{caption}</caption>}
|
|
32
|
+
<thead>
|
|
33
|
+
<tr>
|
|
34
|
+
{
|
|
35
|
+
columns.map((c) => (
|
|
36
|
+
<th scope="col" class:list={{ left: c.align === 'left' }}>
|
|
37
|
+
{c.sortable === false ? (
|
|
38
|
+
<span class="plain">{c.label}{c.unit && <span class="unit"> {c.unit}</span>}</span>
|
|
39
|
+
) : (
|
|
40
|
+
<button type="button">{c.label}{c.unit && <span class="unit">{c.unit}</span>}</button>
|
|
41
|
+
)}
|
|
42
|
+
</th>
|
|
43
|
+
))
|
|
44
|
+
}
|
|
45
|
+
</tr>
|
|
46
|
+
</thead>
|
|
47
|
+
<tbody>
|
|
48
|
+
{
|
|
49
|
+
rows.map((row) => (
|
|
50
|
+
<tr>
|
|
51
|
+
{row.map((c, i) => {
|
|
52
|
+
const obj = c !== null && typeof c === 'object' ? c : null;
|
|
53
|
+
const sort = obj ? obj.sort : c;
|
|
54
|
+
return (
|
|
55
|
+
<td class:list={{ left: columns[i]?.align === 'left' }} data-sort={sort ?? undefined}>
|
|
56
|
+
{obj ? <Fragment set:html={obj.html} /> : show(c)}
|
|
57
|
+
</td>
|
|
58
|
+
);
|
|
59
|
+
})}
|
|
60
|
+
</tr>
|
|
61
|
+
))
|
|
62
|
+
}
|
|
63
|
+
</tbody>
|
|
64
|
+
</table>
|
|
65
|
+
</div>
|
|
66
|
+
|
|
67
|
+
<script>
|
|
68
|
+
import { makeSortable } from './datatable.js';
|
|
69
|
+
document.querySelectorAll<HTMLTableElement>('table[data-data-table]').forEach(makeSortable);
|
|
70
|
+
</script>
|
|
71
|
+
|
|
72
|
+
<style>
|
|
73
|
+
.scroll {
|
|
74
|
+
overflow-x: auto;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.data-table {
|
|
78
|
+
width: 100%;
|
|
79
|
+
min-width: 440px;
|
|
80
|
+
border-collapse: collapse;
|
|
81
|
+
font-size: var(--text-body-sm);
|
|
82
|
+
color: var(--c-text);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/* Rows can arrive at runtime, without Astro's scope, so these reach them through the table. */
|
|
86
|
+
caption {
|
|
87
|
+
padding-bottom: var(--sp-2);
|
|
88
|
+
text-align: left;
|
|
89
|
+
font-size: var(--text-caption);
|
|
90
|
+
color: var(--c-text-muted);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
th {
|
|
94
|
+
padding: 0;
|
|
95
|
+
text-align: right;
|
|
96
|
+
font-size: var(--text-caption);
|
|
97
|
+
font-weight: 600;
|
|
98
|
+
color: var(--c-text-secondary);
|
|
99
|
+
border-bottom: 1px solid var(--c-border-strong);
|
|
100
|
+
white-space: nowrap;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
th.left {
|
|
104
|
+
text-align: left;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
th button,
|
|
108
|
+
.plain {
|
|
109
|
+
all: unset;
|
|
110
|
+
display: inline-flex;
|
|
111
|
+
align-items: center;
|
|
112
|
+
gap: var(--sp-1);
|
|
113
|
+
min-height: 32px;
|
|
114
|
+
padding-right: var(--sp-3);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
th button {
|
|
118
|
+
cursor: pointer;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
th:last-child button,
|
|
122
|
+
th:last-child .plain {
|
|
123
|
+
padding-right: 0;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
th button:hover {
|
|
127
|
+
color: var(--c-text);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
th button:focus-visible {
|
|
131
|
+
outline: 2px solid var(--c-focus);
|
|
132
|
+
outline-offset: -2px;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
.unit {
|
|
136
|
+
font-weight: 400;
|
|
137
|
+
color: var(--c-text-muted);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/* Only the sorted column shows an arrow. */
|
|
141
|
+
th[aria-sort] button::after {
|
|
142
|
+
content: '↓';
|
|
143
|
+
color: var(--c-text-accent);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
th[aria-sort='ascending'] button::after {
|
|
147
|
+
content: '↑';
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
.data-table :global(td) {
|
|
151
|
+
height: 40px;
|
|
152
|
+
padding: 0 var(--sp-3) 0 0;
|
|
153
|
+
text-align: right;
|
|
154
|
+
font-family: var(--font-mono);
|
|
155
|
+
font-size: var(--text-mono);
|
|
156
|
+
font-variant-numeric: tabular-nums;
|
|
157
|
+
border-bottom: 1px solid var(--c-border);
|
|
158
|
+
white-space: nowrap;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
.compact :global(td) {
|
|
162
|
+
height: 32px;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
.data-table :global(td:last-child) {
|
|
166
|
+
padding-right: 0;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
.data-table :global(td.left) {
|
|
170
|
+
text-align: left;
|
|
171
|
+
font-family: var(--font-body);
|
|
172
|
+
font-size: var(--text-body-sm);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
.data-table :global(tbody tr) {
|
|
176
|
+
transition: background-color var(--motion-hover) var(--ease-hover);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
.data-table :global(tbody tr:hover) {
|
|
180
|
+
background: var(--c-surface-hover);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/* A row that isn't whole yet. */
|
|
184
|
+
.data-table :global(tr.faint) {
|
|
185
|
+
color: var(--c-text-muted);
|
|
186
|
+
}
|
|
187
|
+
</style>
|
package/src/Donut.astro
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* A donut as inline SVG with its labels in a list, drawn at build time. No script
|
|
4
|
+
* reaches the browser and the data stays in this page's HTML, so no shared asset
|
|
5
|
+
* ever holds it. Colours are tokens, so it follows the theme with no
|
|
6
|
+
* light plate. Labels are HTML because text inside an SVG shrinks with the column.
|
|
7
|
+
* The ring and list are hidden from screen readers: `alt` speaks for them.
|
|
8
|
+
*/
|
|
9
|
+
import { donutRing, swatch } from '@n1kname/charts/donut';
|
|
10
|
+
import Figure from './Figure.astro';
|
|
11
|
+
|
|
12
|
+
interface Slice {
|
|
13
|
+
label: string;
|
|
14
|
+
value: number;
|
|
15
|
+
valueLabel?: string;
|
|
16
|
+
/** A token, such as var(--c-chart-1). Without one, the de-emphasis tone. */
|
|
17
|
+
color?: string;
|
|
18
|
+
strong?: boolean;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface Props {
|
|
22
|
+
data: Slice[];
|
|
23
|
+
/** The text in the hole, one entry per line. */
|
|
24
|
+
title?: string[];
|
|
25
|
+
alt: string;
|
|
26
|
+
caption?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const { data, title = [], alt, caption } = Astro.props;
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
<Figure caption={caption}>
|
|
33
|
+
<div class="donut" role="img" aria-label={alt}>
|
|
34
|
+
<div class="ring" aria-hidden="true" set:html={donutRing(data, { title })} />
|
|
35
|
+
<ul aria-hidden="true">
|
|
36
|
+
{
|
|
37
|
+
data.map((d) => (
|
|
38
|
+
<li class:list={{ strong: d.strong }}>
|
|
39
|
+
<span class="key" style={`background: ${swatch(d)}`} />
|
|
40
|
+
<span class="name">{d.label}</span>
|
|
41
|
+
<span class="value">{d.valueLabel ?? d.value}</span>
|
|
42
|
+
</li>
|
|
43
|
+
))
|
|
44
|
+
}
|
|
45
|
+
</ul>
|
|
46
|
+
</div>
|
|
47
|
+
</Figure>
|
|
48
|
+
|
|
49
|
+
<style>
|
|
50
|
+
.plate {
|
|
51
|
+
background: var(--c-surface-sunken);
|
|
52
|
+
border: 1px solid var(--c-border);
|
|
53
|
+
border-radius: var(--radius-lg);
|
|
54
|
+
padding: var(--sp-6);
|
|
55
|
+
display: flex;
|
|
56
|
+
justify-content: center;
|
|
57
|
+
container-type: inline-size;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.donut {
|
|
61
|
+
width: 100%;
|
|
62
|
+
display: flex;
|
|
63
|
+
align-items: center;
|
|
64
|
+
gap: var(--sp-6);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.ring {
|
|
68
|
+
flex: 0 0 300px;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
.ring :global(svg) {
|
|
72
|
+
display: block;
|
|
73
|
+
width: 100%;
|
|
74
|
+
height: auto;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
ul {
|
|
78
|
+
flex: 1;
|
|
79
|
+
list-style: none;
|
|
80
|
+
margin: 0;
|
|
81
|
+
padding: 0;
|
|
82
|
+
display: grid;
|
|
83
|
+
gap: var(--sp-2);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
li {
|
|
87
|
+
display: grid;
|
|
88
|
+
grid-template-columns: 12px 1fr auto;
|
|
89
|
+
gap: var(--sp-2) var(--sp-3);
|
|
90
|
+
align-items: baseline;
|
|
91
|
+
font-size: var(--text-body-sm);
|
|
92
|
+
line-height: var(--leading-body-sm);
|
|
93
|
+
color: var(--c-text);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
li.strong {
|
|
97
|
+
font-weight: 600;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.key {
|
|
101
|
+
width: 12px;
|
|
102
|
+
height: 12px;
|
|
103
|
+
border-radius: 3px;
|
|
104
|
+
align-self: center;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.value {
|
|
108
|
+
font-family: var(--font-mono);
|
|
109
|
+
font-size: var(--text-mono);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
@container (max-width: 600px) {
|
|
113
|
+
.donut {
|
|
114
|
+
flex-direction: column;
|
|
115
|
+
align-items: stretch;
|
|
116
|
+
gap: var(--sp-5);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.ring {
|
|
120
|
+
flex: none;
|
|
121
|
+
width: min(100%, 280px);
|
|
122
|
+
margin-inline: auto;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
</style>
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* What a place says when it has nothing to show. Each reason gets its own words:
|
|
4
|
+
* empty nothing exists yet: say when it will
|
|
5
|
+
* filtered nothing matches: that's a result, offer a way back
|
|
6
|
+
* error it failed: say what still works
|
|
7
|
+
* An action goes in the slot. An error keeps showing the last good figures if there are any.
|
|
8
|
+
*/
|
|
9
|
+
interface Props {
|
|
10
|
+
kind?: 'empty' | 'filtered' | 'error';
|
|
11
|
+
title: string;
|
|
12
|
+
text?: string;
|
|
13
|
+
}
|
|
14
|
+
const { kind = 'empty', title, text } = Astro.props;
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
<div class:list={['empty-state', kind]} role={kind === 'error' ? 'alert' : undefined}>
|
|
18
|
+
<p class="title">{title}</p>
|
|
19
|
+
{text && <p class="text">{text}</p>}
|
|
20
|
+
{Astro.slots.has('default') && <div class="action"><slot /></div>}
|
|
21
|
+
</div>
|
|
22
|
+
|
|
23
|
+
<style>
|
|
24
|
+
.empty-state {
|
|
25
|
+
display: flex;
|
|
26
|
+
flex-direction: column;
|
|
27
|
+
gap: var(--sp-2);
|
|
28
|
+
padding: var(--sp-5);
|
|
29
|
+
border: 1px dashed var(--c-border-strong);
|
|
30
|
+
border-radius: var(--radius-md);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.error {
|
|
34
|
+
border: 1px solid var(--c-status-critical);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.title {
|
|
38
|
+
margin: 0;
|
|
39
|
+
font-size: var(--text-body-sm);
|
|
40
|
+
font-weight: 600;
|
|
41
|
+
color: var(--c-text);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.text {
|
|
45
|
+
margin: 0;
|
|
46
|
+
max-width: 60ch;
|
|
47
|
+
font-size: var(--text-caption);
|
|
48
|
+
line-height: var(--leading-caption);
|
|
49
|
+
color: var(--c-text-secondary);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.action {
|
|
53
|
+
margin-top: var(--sp-1);
|
|
54
|
+
}
|
|
55
|
+
</style>
|