@n1kname/components 0.31.1 → 0.32.1

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.31.1",
3
+ "version": "0.32.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
package/src/Button.astro CHANGED
@@ -6,12 +6,16 @@
6
6
  * primary the one main action in a view
7
7
  * secondary everything else
8
8
  * quiet low-emphasis actions beside content
9
+ * danger an action that deletes or can't be undone
10
+ *
11
+ * On hover a soft light follows the pointer, and a press springs back. A trailing icon with
12
+ * class `forward` (an arrow) steps 2px ahead on hover. All of it is off under reduced motion.
9
13
  *
10
14
  * `selected` is for a toggle, and sets aria-pressed. Pass any other attribute through,
11
15
  * such as id, type or disabled.
12
16
  */
13
17
  interface Props {
14
- variant?: 'primary' | 'secondary' | 'quiet';
18
+ variant?: 'primary' | 'secondary' | 'quiet' | 'danger';
15
19
  href?: string;
16
20
  selected?: boolean;
17
21
  disabled?: boolean;
@@ -26,8 +30,27 @@ const attrs = href ? { href } : { type, disabled, 'aria-pressed': selected === u
26
30
 
27
31
  <Tag class:list={['button', variant, className]} {...attrs} {...rest}><slot /></Tag>
28
32
 
33
+ <script>
34
+ // The spotlight: one listener for the page, so buttons added later get it too.
35
+ if (!(window as any).__buttonSpot) {
36
+ (window as any).__buttonSpot = true;
37
+ document.addEventListener('pointermove', (e) => {
38
+ const b = (e.target as Element)?.closest?.('.button') as HTMLElement | null;
39
+ if (!b) return;
40
+ const r = b.getBoundingClientRect();
41
+ b.style.setProperty('--x', `${e.clientX - r.left}px`);
42
+ b.style.setProperty('--y', `${e.clientY - r.top}px`);
43
+ }, { passive: true });
44
+ }
45
+ </script>
46
+
29
47
  <style>
30
48
  .button {
49
+ --x: 50%;
50
+ --y: 50%;
51
+ --spot: rgb(255 255 255 / 0.32);
52
+ position: relative;
53
+ isolation: isolate;
31
54
  display: inline-flex;
32
55
  align-items: center;
33
56
  justify-content: center;
@@ -50,6 +73,31 @@ const attrs = href ? { href } : { type, disabled, 'aria-pressed': selected === u
50
73
  transform var(--motion-fast) var(--ease-out);
51
74
  }
52
75
 
76
+ /* The spotlight: a soft light under the pointer, fading in on hover. */
77
+ .button::before {
78
+ content: '';
79
+ position: absolute;
80
+ inset: 0;
81
+ z-index: -1;
82
+ /* Rounded with the button instead of clipped by it: overflow: hidden would let a flex row squeeze the button below its label. */
83
+ border-radius: inherit;
84
+ opacity: 0;
85
+ background: radial-gradient(120px circle at var(--x) var(--y), var(--spot), transparent 60%);
86
+ transition: opacity 200ms var(--ease-out);
87
+ }
88
+
89
+ .button:hover:not(:disabled)::before {
90
+ opacity: 1;
91
+ }
92
+
93
+ .button :global(svg.forward) {
94
+ transition: transform 200ms var(--ease-out);
95
+ }
96
+
97
+ .button:hover :global(svg.forward) {
98
+ transform: translateX(2px);
99
+ }
100
+
53
101
  /* A fingertip needs more room than a pointer. */
54
102
  @media (pointer: coarse) {
55
103
  .button {
@@ -67,6 +115,7 @@ const attrs = href ? { href } : { type, disabled, 'aria-pressed': selected === u
67
115
  }
68
116
 
69
117
  .secondary {
118
+ --spot: color-mix(in oklab, var(--c-accent) 16%, transparent);
70
119
  background: var(--c-surface);
71
120
  border-color: var(--c-border-strong);
72
121
  color: var(--c-text);
@@ -78,6 +127,7 @@ const attrs = href ? { href } : { type, disabled, 'aria-pressed': selected === u
78
127
  }
79
128
 
80
129
  .quiet {
130
+ --spot: var(--c-surface-hover);
81
131
  background: transparent;
82
132
  color: var(--c-text-secondary);
83
133
  }
@@ -87,6 +137,17 @@ const attrs = href ? { href } : { type, disabled, 'aria-pressed': selected === u
87
137
  color: var(--c-text);
88
138
  }
89
139
 
140
+ /* The page's background colour as text: light on the light theme's deep red, dark on the dark
141
+ * theme's brighter red; both pass 4.5:1. */
142
+ .danger {
143
+ background: var(--c-status-critical);
144
+ color: var(--c-bg);
145
+ }
146
+
147
+ .danger:hover {
148
+ background: color-mix(in oklab, var(--c-status-critical) 88%, var(--c-text));
149
+ }
150
+
90
151
  .button[aria-pressed='true'] {
91
152
  background: var(--c-surface-tint);
92
153
  border-color: var(--c-accent-edge);
@@ -98,8 +159,10 @@ const attrs = href ? { href } : { type, disabled, 'aria-pressed': selected === u
98
159
  outline-offset: 2px;
99
160
  }
100
161
 
162
+ /* The press springs back. */
101
163
  .button:active:not(:disabled) {
102
- transform: scale(0.97);
164
+ transform: scale(0.96);
165
+ transition: transform var(--motion-spring) var(--ease-spring);
103
166
  }
104
167
 
105
168
  .button:disabled {
@@ -108,9 +171,15 @@ const attrs = href ? { href } : { type, disabled, 'aria-pressed': selected === u
108
171
  }
109
172
 
110
173
  @media (prefers-reduced-motion: reduce) {
111
- .button:active:not(:disabled) {
174
+ .button:active:not(:disabled),
175
+ .button:hover :global(svg.forward) {
112
176
  transform: none;
113
177
  }
178
+
179
+ .button::before,
180
+ .button :global(svg.forward) {
181
+ transition: none;
182
+ }
114
183
  }
115
184
 
116
185
  @media (forced-colors: active) {
@@ -0,0 +1,91 @@
1
+ ---
2
+ /**
3
+ * Soft diagonal light drifting slowly behind a hero, in the accent, the chart teal and a warm grey.
4
+ * Pure CSS: a few blurred streaks, no canvas. It sits behind whatever holds it (give that
5
+ * `position: relative` and room), takes no pointer events and is hidden from screen readers.
6
+ * Stands still under reduced motion.
7
+ *
8
+ * whisper barely there
9
+ * subtle atmosphere that never competes with the type (default)
10
+ * present closer to a motion background; for a dark band, not behind body text
11
+ */
12
+ interface Props {
13
+ strength?: 'whisper' | 'subtle' | 'present';
14
+ class?: string;
15
+ }
16
+ const { strength = 'subtle', class: className } = Astro.props;
17
+ const streaks = [
18
+ { c: 'var(--c-accent)', top: 18, h: 3, w: 52, d: 34, delay: -4, still: 10, blur: 5 },
19
+ { c: 'var(--c-chart-2)', top: 30, h: 8, w: 40, d: 46, delay: -20, still: 60, blur: 10 },
20
+ { c: 'var(--c-border-strong)', top: 44, h: 2, w: 58, d: 30, delay: -12, still: 30, blur: 5 },
21
+ { c: 'var(--c-accent)', top: 58, h: 6, w: 36, d: 52, delay: -30, still: 90, blur: 9 },
22
+ { c: 'var(--c-chart-2)', top: 70, h: 2, w: 48, d: 38, delay: -8, still: 50, blur: 5 },
23
+ { c: 'var(--c-border-strong)', top: 82, h: 4, w: 44, d: 42, delay: -26, still: 20, blur: 5 },
24
+ ];
25
+ ---
26
+
27
+ <div class:list={['streaks', strength, className]} aria-hidden="true">
28
+ <div class="field">
29
+ {streaks.map((s) => (
30
+ <i style={`top:${s.top}%;--c:${s.c};--h:${s.h}px;--w:${s.w}%;--d:${s.d}s;--delay:${s.delay}s;--still:${s.still}%;--blur:${s.blur}px`} />
31
+ ))}
32
+ </div>
33
+ </div>
34
+
35
+ <style>
36
+ .streaks {
37
+ position: absolute;
38
+ inset: 0;
39
+ z-index: -1;
40
+ overflow: hidden;
41
+ pointer-events: none;
42
+ /* Fades out towards the edges, so it never ends in a hard line. */
43
+ mask-image: radial-gradient(ellipse 80% 90% at 50% 45%, #000 45%, transparent 100%);
44
+ }
45
+
46
+ .field {
47
+ position: absolute;
48
+ inset: -20% -10%;
49
+ transform: rotate(-22deg);
50
+ }
51
+
52
+ i {
53
+ position: absolute;
54
+ left: 0;
55
+ height: var(--h);
56
+ width: var(--w);
57
+ border-radius: 999px;
58
+ background: linear-gradient(90deg, transparent, var(--c) 45%, var(--c) 55%, transparent);
59
+ filter: blur(var(--blur));
60
+ opacity: var(--o);
61
+ animation: drift var(--d) linear infinite;
62
+ animation-delay: var(--delay);
63
+ }
64
+
65
+ .whisper { --o: 0.14; }
66
+ .subtle { --o: 0.26; }
67
+ .present { --o: 0.45; }
68
+
69
+ /* Light on a dark page needs more to be seen at all. */
70
+ :global(:root[data-theme='dark']) .whisper { --o: 0.22; }
71
+ :global(:root[data-theme='dark']) .subtle { --o: 0.38; }
72
+ :global(:root[data-theme='dark']) .present { --o: 0.6; }
73
+
74
+ @media (prefers-color-scheme: dark) {
75
+ :global(:root:not([data-theme='light'])) .whisper { --o: 0.22; }
76
+ :global(:root:not([data-theme='light'])) .subtle { --o: 0.38; }
77
+ :global(:root:not([data-theme='light'])) .present { --o: 0.6; }
78
+ }
79
+
80
+ @keyframes drift {
81
+ from { transform: translateX(-60%); }
82
+ to { transform: translateX(260%); }
83
+ }
84
+
85
+ @media (prefers-reduced-motion: reduce) {
86
+ i {
87
+ animation: none;
88
+ transform: translateX(var(--still));
89
+ }
90
+ }
91
+ </style>