@n1kname/components 0.31.1 → 0.32.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.31.1",
3
+ "version": "0.32.0",
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,28 @@ 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;
54
+ overflow: hidden;
31
55
  display: inline-flex;
32
56
  align-items: center;
33
57
  justify-content: center;
@@ -50,6 +74,29 @@ const attrs = href ? { href } : { type, disabled, 'aria-pressed': selected === u
50
74
  transform var(--motion-fast) var(--ease-out);
51
75
  }
52
76
 
77
+ /* The spotlight: a soft light under the pointer, fading in on hover. */
78
+ .button::before {
79
+ content: '';
80
+ position: absolute;
81
+ inset: 0;
82
+ z-index: -1;
83
+ opacity: 0;
84
+ background: radial-gradient(120px circle at var(--x) var(--y), var(--spot), transparent 60%);
85
+ transition: opacity 200ms var(--ease-out);
86
+ }
87
+
88
+ .button:hover:not(:disabled)::before {
89
+ opacity: 1;
90
+ }
91
+
92
+ .button :global(svg.forward) {
93
+ transition: transform 200ms var(--ease-out);
94
+ }
95
+
96
+ .button:hover :global(svg.forward) {
97
+ transform: translateX(2px);
98
+ }
99
+
53
100
  /* A fingertip needs more room than a pointer. */
54
101
  @media (pointer: coarse) {
55
102
  .button {
@@ -67,6 +114,7 @@ const attrs = href ? { href } : { type, disabled, 'aria-pressed': selected === u
67
114
  }
68
115
 
69
116
  .secondary {
117
+ --spot: color-mix(in oklab, var(--c-accent) 16%, transparent);
70
118
  background: var(--c-surface);
71
119
  border-color: var(--c-border-strong);
72
120
  color: var(--c-text);
@@ -78,6 +126,7 @@ const attrs = href ? { href } : { type, disabled, 'aria-pressed': selected === u
78
126
  }
79
127
 
80
128
  .quiet {
129
+ --spot: var(--c-surface-hover);
81
130
  background: transparent;
82
131
  color: var(--c-text-secondary);
83
132
  }
@@ -87,6 +136,17 @@ const attrs = href ? { href } : { type, disabled, 'aria-pressed': selected === u
87
136
  color: var(--c-text);
88
137
  }
89
138
 
139
+ /* The page's background colour as text: light on the light theme's deep red, dark on the dark
140
+ * theme's brighter red; both pass 4.5:1. */
141
+ .danger {
142
+ background: var(--c-status-critical);
143
+ color: var(--c-bg);
144
+ }
145
+
146
+ .danger:hover {
147
+ background: color-mix(in oklab, var(--c-status-critical) 88%, var(--c-text));
148
+ }
149
+
90
150
  .button[aria-pressed='true'] {
91
151
  background: var(--c-surface-tint);
92
152
  border-color: var(--c-accent-edge);
@@ -98,8 +158,10 @@ const attrs = href ? { href } : { type, disabled, 'aria-pressed': selected === u
98
158
  outline-offset: 2px;
99
159
  }
100
160
 
161
+ /* The press springs back. */
101
162
  .button:active:not(:disabled) {
102
- transform: scale(0.97);
163
+ transform: scale(0.96);
164
+ transition: transform var(--motion-spring) var(--ease-spring);
103
165
  }
104
166
 
105
167
  .button:disabled {
@@ -108,9 +170,15 @@ const attrs = href ? { href } : { type, disabled, 'aria-pressed': selected === u
108
170
  }
109
171
 
110
172
  @media (prefers-reduced-motion: reduce) {
111
- .button:active:not(:disabled) {
173
+ .button:active:not(:disabled),
174
+ .button:hover :global(svg.forward) {
112
175
  transform: none;
113
176
  }
177
+
178
+ .button::before,
179
+ .button :global(svg.forward) {
180
+ transition: none;
181
+ }
114
182
  }
115
183
 
116
184
  @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>