@n1kname/components 0.13.0 → 0.14.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.13.0",
3
+ "version": "0.14.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -8,6 +8,7 @@
8
8
  "./type.css": "./src/type.css",
9
9
  "./marks.css": "./src/marks.css",
10
10
  "./page-change.css": "./src/page-change.css",
11
+ "./highlight.css": "./src/highlight.css",
11
12
  "./icons": "./src/icons.ts",
12
13
  "./datatable.js": "./src/datatable.js",
13
14
  "./dotrows.js": "./src/dotrows.js",
@@ -0,0 +1,160 @@
1
+ ---
2
+ /**
3
+ * One pill, two actions: the link half opens it (a mail client, say), the half on the right
4
+ * copies the value, because a recruiter often wants the address rather than an app opening. Each
5
+ * half is its own control with its own focus ring; a hairline marks where one ends. The pill
6
+ * lifts and presses as one, so it never comes apart at the seam.
7
+ *
8
+ * The copy half is rendered hidden and shown from script only where the clipboard is there to
9
+ * use, so nobody sees a button that does nothing. The check arrives on the spring; "Copied" is
10
+ * read out from a separate live region, since a changing button label is not announced reliably.
11
+ */
12
+ import Tag from './Tag.astro';
13
+ import type { IconName } from './icons';
14
+
15
+ interface Props {
16
+ href: string;
17
+ /** What gets copied, such as the email address. */
18
+ value: string;
19
+ /** What is copied, for the accessible name: "Copy email address". */
20
+ what: string;
21
+ icon?: IconName;
22
+ }
23
+
24
+ const { href, value, what, icon } = Astro.props;
25
+ // Lucide's copy and check, drawn the way Icon draws at 15px.
26
+ const svg = { width: 15, height: 15, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', 'stroke-width': 1.75, 'stroke-linecap': 'round', 'stroke-linejoin': 'round', 'aria-hidden': 'true' } as const;
27
+ ---
28
+
29
+ <span class="copy-tag">
30
+ <Tag href={href} icon={icon} tone="accent" still><slot /></Tag>
31
+ <button class="copy" type="button" data-copy={value} aria-label={`Copy ${what}`} hidden>
32
+ <span class="ico">
33
+ <svg class="c1" {...svg}><rect width="14" height="14" x="8" y="8" rx="2" ry="2" /><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2" /></svg>
34
+ <svg class="c2" {...svg}><path d="M20 6 9 17l-5-5" /></svg>
35
+ </span>
36
+ <span class="sr-only" role="status"></span>
37
+ </button>
38
+ </span>
39
+
40
+ <style>
41
+ .copy-tag {
42
+ display: inline-flex;
43
+ transition:
44
+ translate var(--motion-spring) var(--ease-spring),
45
+ scale var(--motion-base) var(--ease-out);
46
+ }
47
+
48
+ @media (hover: hover) {
49
+ .copy-tag:hover {
50
+ translate: 0 -2px;
51
+ }
52
+ }
53
+
54
+ .copy-tag:has(:active) {
55
+ scale: 0.97;
56
+ transition-duration: var(--motion-spring), 80ms;
57
+ }
58
+
59
+ @media (prefers-reduced-motion: reduce) {
60
+ .copy-tag {
61
+ translate: none !important;
62
+ scale: none !important;
63
+ }
64
+ }
65
+
66
+ /* Square inner corners only once the copy half is there to meet. */
67
+ .copy-tag:has(.copy:not([hidden])) :global(a.tag) {
68
+ border-start-end-radius: 0;
69
+ border-end-end-radius: 0;
70
+ }
71
+
72
+ .copy {
73
+ display: inline-flex;
74
+ align-items: center;
75
+ padding: 5px var(--sp-3);
76
+ border-radius: var(--radius-full);
77
+ border-start-start-radius: 0;
78
+ border-end-start-radius: 0;
79
+ border: 1px solid transparent;
80
+ background: var(--c-surface-tint);
81
+ color: var(--c-text-accent);
82
+ box-shadow: inset 1px 0 0 color-mix(in oklab, var(--c-text-accent) 22%, transparent);
83
+ cursor: pointer;
84
+ }
85
+
86
+ .copy[hidden] {
87
+ display: none;
88
+ }
89
+
90
+ .copy-tag :global(a.tag),
91
+ .copy {
92
+ transition: background-color var(--motion-hover) var(--ease-hover);
93
+ }
94
+
95
+ .copy-tag :global(a.tag:hover),
96
+ .copy:hover {
97
+ border-color: transparent;
98
+ background: color-mix(in oklab, var(--c-surface-tint), var(--c-accent) 14%);
99
+ }
100
+
101
+ .ico {
102
+ position: relative;
103
+ width: 15px;
104
+ height: 15px;
105
+ }
106
+
107
+ .ico svg {
108
+ position: absolute;
109
+ inset: 0;
110
+ transition:
111
+ opacity var(--motion-fast) var(--ease-out),
112
+ scale var(--motion-fast) var(--ease-out);
113
+ }
114
+
115
+ .c2,
116
+ .done .c1 {
117
+ opacity: 0;
118
+ scale: 0.6;
119
+ }
120
+
121
+ .done .c2 {
122
+ opacity: 1;
123
+ scale: 1;
124
+ transition:
125
+ opacity var(--motion-fast) var(--ease-out),
126
+ scale var(--motion-spring) var(--ease-spring);
127
+ }
128
+
129
+ .sr-only {
130
+ position: absolute;
131
+ width: 1px;
132
+ height: 1px;
133
+ overflow: hidden;
134
+ clip-path: inset(50%);
135
+ white-space: nowrap;
136
+ }
137
+ </style>
138
+
139
+ <script>
140
+ document.querySelectorAll<HTMLButtonElement>('.copy-tag button[data-copy]').forEach((button) => {
141
+ if (!navigator.clipboard) return;
142
+ button.hidden = false;
143
+ const status = button.querySelector('[role="status"]')!;
144
+ let timer = 0;
145
+ button.addEventListener('click', async () => {
146
+ try {
147
+ await navigator.clipboard.writeText(button.dataset.copy!);
148
+ } catch {
149
+ return;
150
+ }
151
+ button.classList.add('done');
152
+ status.textContent = 'Copied';
153
+ clearTimeout(timer);
154
+ timer = window.setTimeout(() => {
155
+ button.classList.remove('done');
156
+ status.textContent = '';
157
+ }, 2000);
158
+ });
159
+ });
160
+ </script>
@@ -0,0 +1,16 @@
1
+ ---
2
+ /**
3
+ * Highlights the words a heading or lede is about, with a band that sweeps in once. Give each
4
+ * mark its place with `n` when there are several, so they sweep one after the other. The look and
5
+ * the timing live in highlight.css, shared with PageHeader.
6
+ */
7
+ import './highlight.css';
8
+
9
+ interface Props {
10
+ /** This mark's place among the marks on the page, from 0. */
11
+ n?: number;
12
+ }
13
+ const { n = 0 } = Astro.props;
14
+ ---
15
+
16
+ <mark class="highlight" style={`--n: ${n}`}><slot /></mark>
@@ -0,0 +1,116 @@
1
+ ---
2
+ /**
3
+ * A card that is one link, such as a case on an index: a picture in the "media" slot and the
4
+ * argument beside it, or above it once the card is narrow. The whole card is the target.
5
+ *
6
+ * Under a real pointer the card lifts 2px and its picture leans in 2% inside its frame; a press
7
+ * gives a little; the spring brings both back. `transition` names the picture for a
8
+ * cross-document view transition, so it can grow into the same picture on the page it opens
9
+ * (give that one the same name, with view-transition-class: media; page-change.css animates it).
10
+ * Under reduced motion nothing moves, and only the edge and the fill answer the hover.
11
+ */
12
+ interface Props {
13
+ href: string;
14
+ /** A view-transition-name for the picture, unique on the page. */
15
+ transition?: string;
16
+ }
17
+
18
+ const { href, transition } = Astro.props;
19
+ const hasMedia = Astro.slots.has('media');
20
+ ---
21
+
22
+ <a class="link-card" href={href}>
23
+ <div class:list={['layout', { 'has-media': hasMedia }]}>
24
+ {
25
+ hasMedia && (
26
+ <div class="media" style={transition ? `view-transition-name: ${transition}; view-transition-class: media` : undefined}>
27
+ <slot name="media" />
28
+ </div>
29
+ )
30
+ }
31
+ <div class="body"><slot /></div>
32
+ </div>
33
+ </a>
34
+
35
+ <style>
36
+ .link-card {
37
+ container-type: inline-size;
38
+ display: block;
39
+ padding: var(--sp-6) var(--sp-7);
40
+ background: var(--c-surface);
41
+ border: 1px solid var(--c-border);
42
+ border-radius: var(--radius-lg);
43
+ color: inherit;
44
+ text-decoration: none;
45
+ transition:
46
+ border-color var(--motion-hover) var(--ease-hover),
47
+ background-color var(--motion-hover) var(--ease-hover),
48
+ translate var(--motion-spring) var(--ease-spring),
49
+ scale var(--motion-base) var(--ease-out);
50
+ }
51
+
52
+ /* Picture left, argument right. The picture's column is fixed rather than fractional, so the
53
+ * text measure does not shift between cards. Below 640px of card it stacks; the card is the
54
+ * container, so the layout inside it can ask. */
55
+ .has-media {
56
+ display: grid;
57
+ gap: var(--sp-5);
58
+ }
59
+
60
+ @container (min-width: 640px) {
61
+ .has-media {
62
+ grid-template-columns: 280px minmax(0, 1fr);
63
+ gap: var(--sp-6);
64
+ align-items: start;
65
+ }
66
+ }
67
+
68
+ .media {
69
+ overflow: hidden;
70
+ border-radius: var(--radius-sm);
71
+ }
72
+
73
+ .media > :global(*) {
74
+ display: block;
75
+ width: 100%;
76
+ transition: scale var(--motion-spring) var(--ease-spring);
77
+ }
78
+
79
+ .body {
80
+ min-width: 0;
81
+ }
82
+
83
+ .link-card:hover {
84
+ border-color: var(--c-accent-edge);
85
+ background: var(--c-surface-tint);
86
+ }
87
+
88
+ @media (hover: hover) {
89
+ .link-card:hover {
90
+ translate: 0 -2px;
91
+ }
92
+
93
+ .link-card:hover .media > :global(*) {
94
+ scale: 1.02;
95
+ }
96
+ }
97
+
98
+ .link-card:active {
99
+ scale: 0.99;
100
+ transition-duration: var(--motion-hover), var(--motion-hover), var(--motion-spring), 80ms;
101
+ }
102
+
103
+ @media (prefers-reduced-motion: reduce) {
104
+ .link-card,
105
+ .media > :global(*) {
106
+ translate: none !important;
107
+ scale: none !important;
108
+ }
109
+ }
110
+
111
+ @media (max-width: 560px) {
112
+ .link-card {
113
+ padding: var(--sp-5);
114
+ }
115
+ }
116
+ </style>
@@ -9,6 +9,8 @@
9
9
  * or lede once its data arrives wraps those words in <mark> itself; the sweep plays as they
10
10
  * land.
11
11
  */
12
+ import './highlight.css';
13
+
12
14
  interface Props {
13
15
  eyebrow?: string;
14
16
  title: string;
@@ -103,50 +105,19 @@ const inLede = inTitle ? null : split(lede);
103
105
  background: var(--c-accent);
104
106
  }
105
107
 
106
- /* A highlighter behind the words that answer the question. It sits low, like a pen, wraps
107
- * line by line, and is mixed into the page colour rather than see-through, so it holds up in
108
- * dark. It sweeps in once, a moment after the words land. */
109
- .text :global(mark) {
110
- --sweep: color-mix(in oklab, var(--c-accent) 32%, var(--c-bg));
111
- --band: 0.42em;
112
- padding-inline: 0.08em;
113
- margin-inline: -0.08em;
114
- background: linear-gradient(var(--sweep), var(--sweep)) no-repeat 0 88% / 100% var(--band);
115
- color: inherit;
116
- box-decoration-break: clone;
117
- -webkit-box-decoration-break: clone;
118
- }
119
-
120
- /* In the smaller lede the band is wider and stronger, and the figure takes the body colour,
121
- * so it reads as clearly as it does in a headline. */
108
+ /* The highlighter itself is highlight.css. In the smaller lede the band is wider and stronger,
109
+ * and the figure takes the body colour, so it reads as clearly as it does in a headline. */
122
110
  .lede :global(mark) {
123
- --sweep: color-mix(in oklab, var(--c-accent) 42%, var(--c-bg));
124
- --band: 0.6em;
111
+ --highlight: color-mix(in oklab, var(--c-accent) 42%, var(--c-bg));
112
+ --highlight-band: 0.6em;
125
113
  color: var(--c-text);
126
114
  }
127
115
 
128
- @media (prefers-reduced-motion: no-preference) {
129
- .text :global(mark) {
130
- animation: sweep 700ms var(--ease-out) 300ms both;
131
- }
132
- }
133
-
134
- @keyframes sweep {
135
- from {
136
- background-size: 0% var(--band);
137
- }
138
- }
139
-
140
116
  @media (forced-colors: active) {
141
117
  .rule {
142
118
  background: CanvasText;
143
119
  }
144
120
 
145
- .text :global(mark) {
146
- background: none;
147
- text-decoration: underline 0.2em;
148
- text-underline-offset: 0.1em;
149
- }
150
121
  }
151
122
 
152
123
  .actions {
@@ -0,0 +1,68 @@
1
+ ---
2
+ /**
3
+ * Lets something settle in once, as it comes a little way into view: it rises 24px and fades in.
4
+ * Only what starts below the fold is held back, so nothing on screen at load ever disappears.
5
+ * Items that arrive together go 90ms apart. A jump past items (an anchor, a fast fling) shows the
6
+ * ones it skipped at once, so nothing is left hidden above.
7
+ *
8
+ * Hidden only once the script has armed it, so without script, or with reduced motion, it is
9
+ * simply there. Each item fires `reveal` with its delay in `detail`, for a page that wants to
10
+ * start something of its own as it arrives.
11
+ */
12
+ interface Props {
13
+ /** The element to render, such as "li" for a row of a list. */
14
+ as?: string;
15
+ class?: string;
16
+ [attr: string]: unknown;
17
+ }
18
+
19
+ const { as: Element = 'div', class: className, ...rest } = Astro.props;
20
+ ---
21
+
22
+ <Element class:list={[className]} data-reveal {...rest}><slot /></Element>
23
+
24
+ <style is:global>
25
+ [data-reveal].reveal-armed {
26
+ opacity: 0;
27
+ translate: 0 24px;
28
+ transition:
29
+ opacity 600ms var(--ease-out),
30
+ translate 900ms var(--ease-soft);
31
+ transition-delay: var(--reveal-delay, 0ms);
32
+ }
33
+
34
+ [data-reveal].reveal-armed.reveal-in {
35
+ opacity: 1;
36
+ translate: 0 0;
37
+ }
38
+ </style>
39
+
40
+ <script>
41
+ if (matchMedia('(prefers-reduced-motion: no-preference)').matches) {
42
+ const items = [...document.querySelectorAll<HTMLElement>('[data-reveal]')].filter(
43
+ (el) => el.getBoundingClientRect().top > innerHeight,
44
+ );
45
+ const show = (el: HTMLElement, delay: number) => {
46
+ el.style.setProperty('--reveal-delay', `${delay}ms`);
47
+ el.classList.add('reveal-in');
48
+ el.dispatchEvent(new CustomEvent('reveal', { detail: { delay } }));
49
+ io.unobserve(el);
50
+ };
51
+ const io = new IntersectionObserver(
52
+ (entries) => {
53
+ entries
54
+ .filter((e) => e.isIntersecting)
55
+ .forEach((e, i) => {
56
+ const el = e.target as HTMLElement;
57
+ items.slice(0, items.indexOf(el)).filter((s) => !s.classList.contains('reveal-in')).forEach((s) => show(s, 0));
58
+ show(el, i * 90);
59
+ });
60
+ },
61
+ { rootMargin: '0px 0px -12% 0px' },
62
+ );
63
+ items.forEach((el) => {
64
+ el.classList.add('reveal-armed');
65
+ io.observe(el);
66
+ });
67
+ }
68
+ </script>
package/src/Tag.astro CHANGED
@@ -8,6 +8,9 @@
8
8
  * quiet → this is a descriptor, not something to click
9
9
  * warm → a warm tag: how something was done
10
10
  * cool → the cool tag: what something was about
11
+ *
12
+ * A linked tag lifts 2px under a real pointer and gives under a press, and the spring brings it
13
+ * back. `still` turns that off, for a tag inside something that moves as a whole (CopyTag).
11
14
  */
12
15
  import Icon from './Icon.astro';
13
16
  import type { IconName } from './icons';
@@ -17,13 +20,15 @@ interface Props {
17
20
  href?: string;
18
21
  tone?: 'accent' | 'quiet' | 'warm' | 'cool';
19
22
  small?: boolean;
23
+ /** No lift or press, for a linked tag inside something that moves as a whole. */
24
+ still?: boolean;
20
25
  }
21
26
 
22
- const { icon, href, tone = 'quiet', small = false } = Astro.props;
27
+ const { icon, href, tone = 'quiet', small = false, still = false } = Astro.props;
23
28
  const Tag = href ? 'a' : 'span';
24
29
  ---
25
30
 
26
- <Tag class:list={['tag', tone, { small }]} href={href}>
31
+ <Tag class:list={['tag', tone, { small, still }]} href={href}>
27
32
  {icon && <Icon name={icon} size={15} />}
28
33
  <slot />
29
34
  </Tag>
@@ -72,7 +77,27 @@ const Tag = href ? 'a' : 'span';
72
77
  a.tag {
73
78
  transition:
74
79
  border-color var(--motion-hover) var(--ease-hover),
75
- background-color var(--motion-hover) var(--ease-hover);
80
+ background-color var(--motion-hover) var(--ease-hover),
81
+ translate var(--motion-spring) var(--ease-spring),
82
+ scale var(--motion-base) var(--ease-out);
83
+ }
84
+
85
+ @media (hover: hover) {
86
+ a.tag:not(.still):hover {
87
+ translate: 0 -2px;
88
+ }
89
+ }
90
+
91
+ a.tag:not(.still):active {
92
+ scale: 0.97;
93
+ transition-duration: var(--motion-hover), var(--motion-hover), var(--motion-spring), 80ms;
94
+ }
95
+
96
+ @media (prefers-reduced-motion: reduce) {
97
+ a.tag {
98
+ translate: none !important;
99
+ scale: none !important;
100
+ }
76
101
  }
77
102
 
78
103
  a.quiet:hover {
@@ -0,0 +1,44 @@
1
+ /*
2
+ * The highlighter: a band behind the words a page is about. It sits low, like a pen, wraps line
3
+ * by line, and is mixed into the page colour rather than see-through, so it holds up in dark. It
4
+ * sweeps in once, a moment after the words land; several marks go one after the other, by --n.
5
+ *
6
+ * Used by Highlight and PageHeader. A page that writes its words once its data arrives can wrap
7
+ * them in <mark class="highlight"> itself, and the sweep plays as they land.
8
+ *
9
+ * --highlight the band colour
10
+ * --highlight-band its height
11
+ * --highlight-delay before the first mark sweeps (300ms)
12
+ * --highlight-step between one mark and the next (450ms)
13
+ */
14
+ :where(mark.highlight, .page-header .text mark) {
15
+ --highlight: color-mix(in oklab, var(--c-accent) 32%, var(--c-bg));
16
+ --highlight-band: 0.42em;
17
+ padding-inline: 0.08em;
18
+ margin-inline: -0.08em;
19
+ background: linear-gradient(var(--highlight), var(--highlight)) no-repeat 0 88% / 100% var(--highlight-band);
20
+ color: inherit;
21
+ box-decoration-break: clone;
22
+ -webkit-box-decoration-break: clone;
23
+ }
24
+
25
+ @media (prefers-reduced-motion: no-preference) {
26
+ :where(mark.highlight, .page-header .text mark) {
27
+ animation: highlight 700ms var(--ease-out)
28
+ calc(var(--highlight-delay, 300ms) + var(--n, 0) * var(--highlight-step, 450ms)) both;
29
+ }
30
+ }
31
+
32
+ @keyframes highlight {
33
+ from {
34
+ background-size: 0% var(--highlight-band);
35
+ }
36
+ }
37
+
38
+ @media (forced-colors: active) {
39
+ :where(mark.highlight, .page-header .text mark) {
40
+ background: none;
41
+ text-decoration: underline 0.2em;
42
+ text-underline-offset: 0.1em;
43
+ }
44
+ }
@@ -1,6 +1,7 @@
1
1
  /*
2
- * Moving between pages: a short cross-fade of the whole page, and PageNav's pill gliding from
3
- * the link you left to the one you arrived at, on the spring. For a site whose pages are
2
+ * Moving between pages: a short cross-fade of the whole page, PageNav's pill gliding from the
3
+ * link you left to the one you arrived at, and a picture with view-transition-class: media (a
4
+ * LinkCard's, say) growing into the picture of the same name on the next page, all on the spring. For a site whose pages are
4
5
  * separate documents. Import once, per site, on every page: both pages must opt in.
5
6
  *
6
7
  * A browser without cross-document view transitions simply changes the page, and under
@@ -34,4 +35,23 @@
34
35
  width: 100%;
35
36
  height: 100%;
36
37
  }
38
+
39
+ /* A picture that carries over, such as a case thumbnail becoming that case's header image. */
40
+ ::view-transition-group(*.media) {
41
+ animation-duration: var(--motion-spring);
42
+ animation-timing-function: var(--ease-spring);
43
+ }
44
+
45
+ /* The two pictures rarely share a shape (a 16:9 thumbnail, a 20:9 header), so each fills the
46
+ * moving frame and is cropped to it, rather than stretched. */
47
+ ::view-transition-image-pair(*.media) {
48
+ overflow: hidden;
49
+ border-radius: var(--radius-lg);
50
+ }
51
+
52
+ ::view-transition-old(*.media),
53
+ ::view-transition-new(*.media) {
54
+ height: 100%;
55
+ object-fit: cover;
56
+ }
37
57
  }