@n1kname/components 0.1.0 → 0.3.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@n1kname/components",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -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>
@@ -17,16 +17,18 @@ interface Props {
17
17
  columns: Column[];
18
18
  rows?: Cell[][];
19
19
  caption?: string;
20
+ /** Names the table for a screen reader without a visible caption, such as the title of the figure around it. */
21
+ label?: string;
20
22
  /** 40px rows by default; compact is 32px, for dense tables. */
21
23
  density?: 'default' | 'compact';
22
24
  id?: string;
23
25
  }
24
- const { columns, rows = [], caption, density = 'default', id } = Astro.props;
26
+ const { columns, rows = [], caption, label, density = 'default', id } = Astro.props;
25
27
  const num = (v: number) => new Intl.NumberFormat('nl-NL').format(v);
26
28
  const show = (c: Cell) => (c === null ? '–' : typeof c === 'number' ? num(c) : typeof c === 'string' ? c : '');
27
29
  ---
28
30
 
29
- <div class="scroll" tabindex="0" role="region" aria-label={caption ?? 'Table'}>
31
+ <div class="scroll" tabindex="0" role="region" aria-label={caption ?? label ?? 'Table'}>
30
32
  <table class:list={['data-table', density]} id={id} data-data-table>
31
33
  {caption && <caption>{caption}</caption>}
32
34
  <thead>
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 && <p class="title">{title}</p>}
25
+ {title && <Title class="title">{title}</Title>}
23
26
  {sub && <p class="sub">{sub}</p>}
24
27
  </div>
25
28
  <slot name="actions" />
@@ -53,6 +53,8 @@ const titleId = `${id}-title`;
53
53
  background: var(--c-bg);
54
54
  color: var(--c-text);
55
55
  overflow-y: auto;
56
+ /* Scrolling past the end stays here, instead of moving the page behind it. */
57
+ overscroll-behavior: contain;
56
58
  /* It leaves but stays within reach, so it uses standard easing, and leaves quicker. */
57
59
  opacity: 0;
58
60
  transform: translateX(16px);
@@ -0,0 +1,35 @@
1
+ ---
2
+ /**
3
+ * The first stop for a keyboard: jumps past the header to the main content. Hidden until
4
+ * it has focus. Put it first in <body>, and give the main content a matching id.
5
+ */
6
+ interface Props {
7
+ /** The id of the main content, with its #. */
8
+ target?: string;
9
+ }
10
+ const { target = '#main' } = Astro.props;
11
+ ---
12
+
13
+ <a class="skip-link" href={target}>Skip to main content</a>
14
+
15
+ <style>
16
+ /* No transition: it appears on a key press, and keyboard actions shouldn't animate. */
17
+ .skip-link {
18
+ position: absolute;
19
+ top: var(--sp-2);
20
+ left: var(--sp-2);
21
+ z-index: var(--z-panel);
22
+ padding: var(--sp-2) var(--sp-3);
23
+ background: var(--c-surface);
24
+ border: 1px solid var(--c-border-strong);
25
+ border-radius: var(--radius-md);
26
+ font-size: var(--text-body-sm);
27
+ font-weight: 600;
28
+ color: var(--c-text);
29
+ transform: translateY(calc(-100% - var(--sp-3)));
30
+ }
31
+
32
+ .skip-link:focus {
33
+ transform: none;
34
+ }
35
+ </style>
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);