@n1kname/components 0.2.0 → 0.4.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/Caveats.astro +51 -0
- package/src/DataTable.astro +16 -4
- package/src/Figure.astro +5 -2
- package/src/Stat.astro +5 -2
- package/src/datatable.js +2 -2
package/package.json
CHANGED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* What the figures on a page rest on, and where they stop. One short point per item,
|
|
4
|
+
* read before acting on the numbers. Pass `items`, or leave them out and fill the list
|
|
5
|
+
* by `listId` once the data arrives.
|
|
6
|
+
*/
|
|
7
|
+
interface Props {
|
|
8
|
+
title: string;
|
|
9
|
+
items?: string[];
|
|
10
|
+
/** The title's heading level, so it fits the page's outline. */
|
|
11
|
+
level?: 2 | 3 | 4;
|
|
12
|
+
/** Id of the list, for a page that fills it in once its data arrives. */
|
|
13
|
+
listId?: string;
|
|
14
|
+
}
|
|
15
|
+
const { title, items = [], level = 2, listId } = Astro.props;
|
|
16
|
+
const Title = `h${level}`;
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
<section class="caveats">
|
|
20
|
+
<Title class="title">{title}</Title>
|
|
21
|
+
<ul id={listId}>{items.map((item) => <li>{item}</li>)}</ul>
|
|
22
|
+
</section>
|
|
23
|
+
|
|
24
|
+
<style>
|
|
25
|
+
.caveats {
|
|
26
|
+
padding-top: var(--sp-4);
|
|
27
|
+
border-top: 1px solid var(--c-border);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.title {
|
|
31
|
+
margin: 0;
|
|
32
|
+
font-family: var(--font-display);
|
|
33
|
+
font-weight: 600;
|
|
34
|
+
font-size: var(--text-sub);
|
|
35
|
+
line-height: var(--leading-sub);
|
|
36
|
+
color: var(--c-text);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
ul {
|
|
40
|
+
margin: var(--sp-3) 0 0;
|
|
41
|
+
padding-left: var(--sp-5);
|
|
42
|
+
max-width: var(--layout-measure);
|
|
43
|
+
font-size: var(--text-caption);
|
|
44
|
+
line-height: var(--leading-caption);
|
|
45
|
+
color: var(--c-text-secondary);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
ul :global(li + li) {
|
|
49
|
+
margin-top: var(--sp-2);
|
|
50
|
+
}
|
|
51
|
+
</style>
|
package/src/DataTable.astro
CHANGED
|
@@ -9,6 +9,8 @@ interface Column {
|
|
|
9
9
|
unit?: string;
|
|
10
10
|
/** Words are left-aligned, numbers right-aligned. */
|
|
11
11
|
align?: 'left' | 'right';
|
|
12
|
+
/** Words that can run long, such as a name or a description: they wrap, so the figures stay in view. */
|
|
13
|
+
wrap?: boolean;
|
|
12
14
|
sortable?: boolean;
|
|
13
15
|
}
|
|
14
16
|
type Cell = string | number | null | { html: string; sort?: string | number };
|
|
@@ -17,23 +19,25 @@ interface Props {
|
|
|
17
19
|
columns: Column[];
|
|
18
20
|
rows?: Cell[][];
|
|
19
21
|
caption?: string;
|
|
22
|
+
/** Names the table for a screen reader without a visible caption, such as the title of the figure around it. */
|
|
23
|
+
label?: string;
|
|
20
24
|
/** 40px rows by default; compact is 32px, for dense tables. */
|
|
21
25
|
density?: 'default' | 'compact';
|
|
22
26
|
id?: string;
|
|
23
27
|
}
|
|
24
|
-
const { columns, rows = [], caption, density = 'default', id } = Astro.props;
|
|
28
|
+
const { columns, rows = [], caption, label, density = 'default', id } = Astro.props;
|
|
25
29
|
const num = (v: number) => new Intl.NumberFormat('nl-NL').format(v);
|
|
26
30
|
const show = (c: Cell) => (c === null ? '–' : typeof c === 'number' ? num(c) : typeof c === 'string' ? c : '');
|
|
27
31
|
---
|
|
28
32
|
|
|
29
|
-
<div class="scroll" tabindex="0" role="region" aria-label={caption ?? 'Table'}>
|
|
33
|
+
<div class="scroll" tabindex="0" role="region" aria-label={caption ?? label ?? 'Table'}>
|
|
30
34
|
<table class:list={['data-table', density]} id={id} data-data-table>
|
|
31
35
|
{caption && <caption>{caption}</caption>}
|
|
32
36
|
<thead>
|
|
33
37
|
<tr>
|
|
34
38
|
{
|
|
35
39
|
columns.map((c) => (
|
|
36
|
-
<th scope="col" class:list={{ left: c.align === 'left' }}>
|
|
40
|
+
<th scope="col" class:list={{ left: c.align === 'left', wrap: c.wrap }}>
|
|
37
41
|
{c.sortable === false ? (
|
|
38
42
|
<span class="plain">{c.label}{c.unit && <span class="unit"> {c.unit}</span>}</span>
|
|
39
43
|
) : (
|
|
@@ -52,7 +56,7 @@ const show = (c: Cell) => (c === null ? '–' : typeof c === 'number' ? num(c) :
|
|
|
52
56
|
const obj = c !== null && typeof c === 'object' ? c : null;
|
|
53
57
|
const sort = obj ? obj.sort : c;
|
|
54
58
|
return (
|
|
55
|
-
<td class:list={{ left: columns[i]?.align === 'left' }} data-sort={sort ?? undefined}>
|
|
59
|
+
<td class:list={{ left: columns[i]?.align === 'left', wrap: columns[i]?.wrap }} data-sort={sort ?? undefined}>
|
|
56
60
|
{obj ? <Fragment set:html={obj.html} /> : show(c)}
|
|
57
61
|
</td>
|
|
58
62
|
);
|
|
@@ -172,6 +176,14 @@ const show = (c: Cell) => (c === null ? '–' : typeof c === 'number' ? num(c) :
|
|
|
172
176
|
font-size: var(--text-body-sm);
|
|
173
177
|
}
|
|
174
178
|
|
|
179
|
+
/* Long words wrap, and keep enough room to read. Figures never wrap. */
|
|
180
|
+
.data-table :global(td.wrap) {
|
|
181
|
+
min-width: 16ch;
|
|
182
|
+
padding-block: var(--sp-2);
|
|
183
|
+
line-height: var(--leading-caption);
|
|
184
|
+
white-space: normal;
|
|
185
|
+
}
|
|
186
|
+
|
|
175
187
|
.data-table :global(tbody tr) {
|
|
176
188
|
transition: background-color var(--motion-hover) var(--ease-hover);
|
|
177
189
|
}
|
package/src/Figure.astro
CHANGED
|
@@ -8,9 +8,12 @@ interface Props {
|
|
|
8
8
|
sub?: string;
|
|
9
9
|
caption?: string;
|
|
10
10
|
variant?: 'plate' | 'card';
|
|
11
|
+
/** Makes the title a heading at this level, for a figure that is a section of the page. */
|
|
12
|
+
level?: 2 | 3 | 4;
|
|
11
13
|
id?: string;
|
|
12
14
|
}
|
|
13
|
-
const { title, sub, caption, variant = 'plate', id } = Astro.props;
|
|
15
|
+
const { title, sub, caption, variant = 'plate', level, id } = Astro.props;
|
|
16
|
+
const Title = level ? `h${level}` : 'p';
|
|
14
17
|
---
|
|
15
18
|
|
|
16
19
|
<figure class="figure" id={id}>
|
|
@@ -19,7 +22,7 @@ const { title, sub, caption, variant = 'plate', id } = Astro.props;
|
|
|
19
22
|
(title || Astro.slots.has('actions')) && (
|
|
20
23
|
<div class="head">
|
|
21
24
|
<div class="titles">
|
|
22
|
-
{title && <
|
|
25
|
+
{title && <Title class="title">{title}</Title>}
|
|
23
26
|
{sub && <p class="sub">{sub}</p>}
|
|
24
27
|
</div>
|
|
25
28
|
<slot name="actions" />
|
package/src/Stat.astro
CHANGED
|
@@ -9,15 +9,17 @@ interface Props {
|
|
|
9
9
|
context?: string;
|
|
10
10
|
/** Id, for a page that fills the value in once its data arrives. */
|
|
11
11
|
valueId?: string;
|
|
12
|
+
/** Id of the context line, for a page that fills it in too. It keeps a line's height meanwhile. */
|
|
13
|
+
contextId?: string;
|
|
12
14
|
}
|
|
13
|
-
const { label, value = '–', context, valueId } = Astro.props;
|
|
15
|
+
const { label, value = '–', context, valueId, contextId } = Astro.props;
|
|
14
16
|
---
|
|
15
17
|
|
|
16
18
|
<div class="stat">
|
|
17
19
|
<dt>{label}</dt>
|
|
18
20
|
<dd>
|
|
19
21
|
<span class="value" id={valueId}>{value}</span>
|
|
20
|
-
{context && <small>{context}</small>}
|
|
22
|
+
{(context || contextId) && <small id={contextId}>{context}</small>}
|
|
21
23
|
</dd>
|
|
22
24
|
</div>
|
|
23
25
|
|
|
@@ -51,6 +53,7 @@ const { label, value = '–', context, valueId } = Astro.props;
|
|
|
51
53
|
small {
|
|
52
54
|
display: block;
|
|
53
55
|
margin-top: 2px;
|
|
56
|
+
min-height: 1lh;
|
|
54
57
|
font-size: var(--text-caption);
|
|
55
58
|
line-height: var(--leading-caption);
|
|
56
59
|
color: var(--c-text-muted);
|
package/src/datatable.js
CHANGED
|
@@ -10,9 +10,9 @@ export const setRows = (table, rows, rowClass = () => '') => {
|
|
|
10
10
|
.map((cells, r) => {
|
|
11
11
|
const tds = cells.map((c, i) => {
|
|
12
12
|
const v = c !== null && typeof c === 'object' ? c : { html: esc(c ?? '–'), sort: c };
|
|
13
|
-
const
|
|
13
|
+
const from = ['left', 'wrap'].filter((c) => head[i]?.classList.contains(c));
|
|
14
14
|
const sort = v.sort === null || v.sort === undefined ? '' : ` data-sort="${esc(v.sort)}"`;
|
|
15
|
-
return `<td class="${[
|
|
15
|
+
return `<td class="${[...from, v.class].filter(Boolean).join(' ')}"${sort}>${v.html}</td>`;
|
|
16
16
|
});
|
|
17
17
|
return `<tr class="${rowClass(rows[r], r)}">${tds.join('')}</tr>`;
|
|
18
18
|
})
|