astro-nosferatu 0.1.0 → 0.2.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.
@@ -1,59 +1,214 @@
1
1
  ---
2
- import type { HTMLAttributes } from 'astro/types';
2
+ import type { HTMLAttributes } from "astro/types";
3
+ import type { ColorPalette } from "../types/components";
3
4
 
4
- interface Props extends HTMLAttributes<'button'> {
5
- variant?: 'primary' | 'secondary';
5
+ interface Props extends HTMLAttributes<"button"> {
6
+ color?: ColorPalette;
6
7
  }
7
8
 
8
- const { variant = 'primary', type = 'button', class: className, ...attrs } = Astro.props;
9
+ const {
10
+ color,
11
+ type = "button",
12
+ class: className,
13
+ "data-ui-color": _controlled,
14
+ ...attrs
15
+ } = Astro.props;
9
16
  ---
10
17
 
11
- <button type={type} class:list={['nf-button', `nf-button--${variant}`, className]} {...attrs}>
18
+ <button
19
+ {...attrs}
20
+ type={type}
21
+ data-ui-color={color}
22
+ class:list={["nf-button", className]}
23
+ >
12
24
  <slot />
13
25
  </button>
14
26
 
15
27
  <style>
16
28
  .nf-button {
29
+ --nf-button-depth: 4px;
30
+ --nf-button-lift: 0px;
31
+ --nf-button-border-width: 2px;
32
+ --nf-button-transition-duration: 0.15s;
33
+
17
34
  display: inline-flex;
18
35
  align-items: center;
19
36
  justify-content: center;
20
- gap: var(--nf-space-2);
21
- padding: var(--nf-space-2) var(--nf-space-4);
22
- border: 1px solid transparent;
23
- border-radius: var(--nf-radius-md);
24
- font-family: var(--nf-font-body);
25
- font-size: var(--nf-font-size-md);
26
- font-weight: var(--nf-font-weight-medium);
27
- line-height: var(--nf-line-height-heading);
37
+ gap: var(--nf-spacing-base-low-2);
38
+ padding-block: var(--nf-spacing-base-low-2);
39
+ padding-inline: var(--nf-spacing-base);
40
+ border: none;
41
+ border-radius: var(--nf-border-radius-base);
42
+ color: var(
43
+ --nf-button-accent-color,
44
+ light-dark(var(--nf-grey-l-80), var(--nf-grey-d-90))
45
+ );
46
+ font-family: var(--nf-font-family);
47
+ font-weight: 600;
48
+ background-color: var(
49
+ --nf-button-color,
50
+ light-dark(var(--nf-grey-l-40), var(--nf-grey-d-50))
51
+ );
52
+ box-shadow: 0px var(--nf-button-depth) 0px
53
+ var(
54
+ --nf-button-shadow-color,
55
+ light-dark(var(--nf-grey-l-70), var(--nf-grey-d-80))
56
+ );
57
+ translate: 0 var(--nf-button-lift);
28
58
  cursor: pointer;
29
- }
59
+ transition-property:
60
+ translate, box-shadow, background-color, color, border-color;
61
+ transition-duration: var(--nf-button-transition-duration);
62
+ transition-timing-function: ease-in-out;
30
63
 
31
- .nf-button:focus-visible {
32
- outline: 2px solid var(--nf-color-focus);
33
- outline-offset: 2px;
34
- }
64
+ &[data-ui-color="blue"] {
65
+ --nf-button-color: light-dark(var(--nf-blue-l-40), var(--nf-blue-d-50));
66
+ --nf-button-accent-color: light-dark(
67
+ var(--nf-blue-l-80),
68
+ var(--nf-blue-d-90)
69
+ );
70
+ --nf-button-shadow-color: light-dark(
71
+ var(--nf-blue-l-70),
72
+ var(--nf-blue-d-80)
73
+ );
74
+ }
35
75
 
36
- .nf-button:disabled {
37
- cursor: not-allowed;
38
- opacity: 0.5;
39
- }
76
+ &[data-ui-color="cyan"] {
77
+ --nf-button-color: light-dark(var(--nf-cyan-l-40), var(--nf-cyan-d-50));
78
+ --nf-button-accent-color: light-dark(
79
+ var(--nf-cyan-l-80),
80
+ var(--nf-cyan-d-90)
81
+ );
82
+ --nf-button-shadow-color: light-dark(
83
+ var(--nf-cyan-l-70),
84
+ var(--nf-cyan-d-80)
85
+ );
86
+ }
40
87
 
41
- .nf-button--primary {
42
- background-color: var(--nf-color-primary);
43
- color: var(--nf-color-on-primary);
44
- }
88
+ &[data-ui-color="green"] {
89
+ --nf-button-color: light-dark(var(--nf-green-l-40), var(--nf-green-d-50));
90
+ --nf-button-accent-color: light-dark(
91
+ var(--nf-green-l-80),
92
+ var(--nf-green-d-90)
93
+ );
94
+ --nf-button-shadow-color: light-dark(
95
+ var(--nf-green-l-70),
96
+ var(--nf-green-d-80)
97
+ );
98
+ }
45
99
 
46
- .nf-button--primary:hover:not(:disabled) {
47
- background-color: var(--nf-color-primary-hover);
48
- }
100
+ &[data-ui-color="grey"] {
101
+ --nf-button-color: light-dark(var(--nf-grey-l-40), var(--nf-grey-d-50));
102
+ --nf-button-accent-color: light-dark(
103
+ var(--nf-grey-l-80),
104
+ var(--nf-grey-d-90)
105
+ );
106
+ --nf-button-shadow-color: light-dark(
107
+ var(--nf-grey-l-70),
108
+ var(--nf-grey-d-80)
109
+ );
110
+ }
111
+
112
+ &[data-ui-color="orange"] {
113
+ --nf-button-color: light-dark(
114
+ var(--nf-orange-l-40),
115
+ var(--nf-orange-d-50)
116
+ );
117
+ --nf-button-accent-color: light-dark(
118
+ var(--nf-orange-l-80),
119
+ var(--nf-orange-d-90)
120
+ );
121
+ --nf-button-shadow-color: light-dark(
122
+ var(--nf-orange-l-70),
123
+ var(--nf-orange-d-80)
124
+ );
125
+ }
126
+
127
+ &[data-ui-color="pink"] {
128
+ --nf-button-color: light-dark(var(--nf-pink-l-40), var(--nf-pink-d-50));
129
+ --nf-button-accent-color: light-dark(
130
+ var(--nf-pink-l-80),
131
+ var(--nf-pink-d-90)
132
+ );
133
+ --nf-button-shadow-color: light-dark(
134
+ var(--nf-pink-l-70),
135
+ var(--nf-pink-d-80)
136
+ );
137
+ }
138
+
139
+ &[data-ui-color="purple"] {
140
+ --nf-button-color: light-dark(
141
+ var(--nf-purple-l-40),
142
+ var(--nf-purple-d-50)
143
+ );
144
+ --nf-button-accent-color: light-dark(
145
+ var(--nf-purple-l-80),
146
+ var(--nf-purple-d-90)
147
+ );
148
+ --nf-button-shadow-color: light-dark(
149
+ var(--nf-purple-l-70),
150
+ var(--nf-purple-d-80)
151
+ );
152
+ }
153
+
154
+ &[data-ui-color="red"] {
155
+ --nf-button-color: light-dark(var(--nf-red-l-40), var(--nf-red-d-50));
156
+ --nf-button-accent-color: light-dark(
157
+ var(--nf-red-l-80),
158
+ var(--nf-red-d-90)
159
+ );
160
+ --nf-button-shadow-color: light-dark(
161
+ var(--nf-red-l-70),
162
+ var(--nf-red-d-80)
163
+ );
164
+ }
165
+
166
+ &[data-ui-color="yellow"] {
167
+ --nf-button-color: light-dark(
168
+ var(--nf-yellow-l-40),
169
+ var(--nf-yellow-d-50)
170
+ );
171
+ --nf-button-accent-color: light-dark(
172
+ var(--nf-yellow-l-80),
173
+ var(--nf-yellow-d-90)
174
+ );
175
+ --nf-button-shadow-color: light-dark(
176
+ var(--nf-yellow-l-70),
177
+ var(--nf-yellow-d-80)
178
+ );
179
+ }
180
+
181
+ &:hover:not(:disabled),
182
+ &:focus-within:not(:disabled) {
183
+ --nf-button-depth: 3px;
184
+ --nf-button-lift: 1px;
185
+ }
186
+
187
+ &:active:not(:disabled) {
188
+ --nf-button-depth: 0px;
189
+ --nf-button-lift: 4px;
190
+ }
191
+
192
+ /* The button has no border, so the focus ring is drawn inside its edge as one */
193
+ &:focus-visible {
194
+ outline: var(--nf-button-border-width) solid
195
+ var(
196
+ --nf-button-accent-color,
197
+ light-dark(var(--nf-grey-l-80), var(--nf-grey-d-90))
198
+ );
199
+ outline-offset: calc(-1 * var(--nf-button-border-width));
200
+ }
49
201
 
50
- .nf-button--secondary {
51
- background-color: var(--nf-color-background);
52
- border-color: var(--nf-color-border);
53
- color: var(--nf-color-text);
202
+ &:disabled {
203
+ cursor: not-allowed;
204
+ opacity: 0.5;
205
+ }
54
206
  }
55
207
 
56
- .nf-button--secondary:hover:not(:disabled) {
57
- background-color: var(--nf-color-surface);
208
+ /* Keep the states and their feedback, drop the animation between them */
209
+ @media (prefers-reduced-motion: reduce) {
210
+ .nf-button {
211
+ --nf-button-transition-duration: 0s;
212
+ }
58
213
  }
59
214
  </style>
@@ -0,0 +1,286 @@
1
+ ---
2
+ import type { HTMLAttributes } from "astro/types";
3
+ import type { ColorPalette, IconComponent } from "../types/components";
4
+
5
+ interface Props extends HTMLAttributes<"div"> {
6
+ title: string;
7
+ icon?: IconComponent;
8
+ color?: ColorPalette;
9
+ }
10
+
11
+ const {
12
+ title,
13
+ icon: Icon,
14
+ color,
15
+ class: className,
16
+ "data-ui-color": _controlled,
17
+ ...attrs
18
+ } = Astro.props;
19
+
20
+ /* The body is rendered only when the slot was supplied */
21
+ const hasBody = Astro.slots.has("default");
22
+ ---
23
+
24
+ <div {...attrs} data-ui-color={color} class:list={["nf-callout", className]}>
25
+ <p class="nf-callout-title">
26
+ {Icon && (
27
+ <span class="nf-callout-icon">
28
+ <Icon />
29
+ </span>
30
+ )}
31
+ {title}
32
+ </p>
33
+ {hasBody && (
34
+ <p class="nf-callout-body">
35
+ <slot />
36
+ </p>
37
+ )}
38
+ </div>
39
+
40
+ <style>
41
+ .nf-callout {
42
+ /* 24px against the 1rem title, at the default root size */
43
+ --nf-callout-icon-size: 1.5rem;
44
+ /*
45
+ * Composed rather than taken whole from a --nf-shadow-<color> token:
46
+ * light-dark() resolves colors, not complete box-shadow values, so the
47
+ * depth comes from shadows.css and the color from the 25% tier: three
48
+ * steps below the surface in light (l-40 to l-70), three above it in
49
+ * dark (d-50 to d-80), so the shadow is the darker tint either way.
50
+ */
51
+ --nf-callout-shadow: var(--nf-shadow-depth)
52
+ var(
53
+ --nf-callout-shadow-color,
54
+ light-dark(var(--nf-grey-l-70-25), var(--nf-grey-d-80-25))
55
+ );
56
+
57
+ border: none;
58
+ border-radius: var(--nf-border-radius-base);
59
+ padding: var(--nf-spacing-base-up-2);
60
+ color: var(
61
+ --nf-callout-accent-color,
62
+ light-dark(var(--nf-grey-l-80), var(--nf-grey-d-30))
63
+ );
64
+ font-weight: 500;
65
+ background-color: var(
66
+ --nf-callout-surface-color,
67
+ light-dark(var(--nf-grey-l-40-25), var(--nf-grey-d-50-25))
68
+ );
69
+ box-shadow: var(--nf-callout-shadow);
70
+
71
+ /*
72
+ * The surface is the palette's 25% tier, so the page shows through it:
73
+ * in dark mode the panel reads dark and the accent has to be a light
74
+ * step (-d-30), not the dark one Button pairs with an opaque fill.
75
+ */
76
+ &[data-ui-color="blue"] {
77
+ --nf-callout-surface-color: light-dark(
78
+ var(--nf-blue-l-40-25),
79
+ var(--nf-blue-d-50-25)
80
+ );
81
+ --nf-callout-accent-color: light-dark(
82
+ var(--nf-blue-l-80),
83
+ var(--nf-blue-d-30)
84
+ );
85
+ --nf-callout-rule-color: light-dark(
86
+ var(--nf-blue-l-80-25),
87
+ var(--nf-blue-d-30-25)
88
+ );
89
+ --nf-callout-shadow-color: light-dark(
90
+ var(--nf-blue-l-70-25),
91
+ var(--nf-blue-d-80-25)
92
+ );
93
+ }
94
+
95
+ &[data-ui-color="cyan"] {
96
+ --nf-callout-surface-color: light-dark(
97
+ var(--nf-cyan-l-40-25),
98
+ var(--nf-cyan-d-50-25)
99
+ );
100
+ --nf-callout-accent-color: light-dark(
101
+ var(--nf-cyan-l-80),
102
+ var(--nf-cyan-d-30)
103
+ );
104
+ --nf-callout-rule-color: light-dark(
105
+ var(--nf-cyan-l-80-25),
106
+ var(--nf-cyan-d-30-25)
107
+ );
108
+ --nf-callout-shadow-color: light-dark(
109
+ var(--nf-cyan-l-70-25),
110
+ var(--nf-cyan-d-80-25)
111
+ );
112
+ }
113
+
114
+ &[data-ui-color="green"] {
115
+ --nf-callout-surface-color: light-dark(
116
+ var(--nf-green-l-40-25),
117
+ var(--nf-green-d-50-25)
118
+ );
119
+ --nf-callout-accent-color: light-dark(
120
+ var(--nf-green-l-80),
121
+ var(--nf-green-d-30)
122
+ );
123
+ --nf-callout-rule-color: light-dark(
124
+ var(--nf-green-l-80-25),
125
+ var(--nf-green-d-30-25)
126
+ );
127
+ --nf-callout-shadow-color: light-dark(
128
+ var(--nf-green-l-70-25),
129
+ var(--nf-green-d-80-25)
130
+ );
131
+ }
132
+
133
+ &[data-ui-color="grey"] {
134
+ --nf-callout-surface-color: light-dark(
135
+ var(--nf-grey-l-40-25),
136
+ var(--nf-grey-d-50-25)
137
+ );
138
+ --nf-callout-accent-color: light-dark(
139
+ var(--nf-grey-l-80),
140
+ var(--nf-grey-d-30)
141
+ );
142
+ --nf-callout-rule-color: light-dark(
143
+ var(--nf-grey-l-80-25),
144
+ var(--nf-grey-d-30-25)
145
+ );
146
+ --nf-callout-shadow-color: light-dark(
147
+ var(--nf-grey-l-70-25),
148
+ var(--nf-grey-d-80-25)
149
+ );
150
+ }
151
+
152
+ &[data-ui-color="orange"] {
153
+ --nf-callout-surface-color: light-dark(
154
+ var(--nf-orange-l-40-25),
155
+ var(--nf-orange-d-50-25)
156
+ );
157
+ --nf-callout-accent-color: light-dark(
158
+ var(--nf-orange-l-80),
159
+ var(--nf-orange-d-30)
160
+ );
161
+ --nf-callout-rule-color: light-dark(
162
+ var(--nf-orange-l-80-25),
163
+ var(--nf-orange-d-30-25)
164
+ );
165
+ --nf-callout-shadow-color: light-dark(
166
+ var(--nf-orange-l-70-25),
167
+ var(--nf-orange-d-80-25)
168
+ );
169
+ }
170
+
171
+ &[data-ui-color="pink"] {
172
+ --nf-callout-surface-color: light-dark(
173
+ var(--nf-pink-l-40-25),
174
+ var(--nf-pink-d-50-25)
175
+ );
176
+ --nf-callout-accent-color: light-dark(
177
+ var(--nf-pink-l-80),
178
+ var(--nf-pink-d-30)
179
+ );
180
+ --nf-callout-rule-color: light-dark(
181
+ var(--nf-pink-l-80-25),
182
+ var(--nf-pink-d-30-25)
183
+ );
184
+ --nf-callout-shadow-color: light-dark(
185
+ var(--nf-pink-l-70-25),
186
+ var(--nf-pink-d-80-25)
187
+ );
188
+ }
189
+
190
+ &[data-ui-color="purple"] {
191
+ --nf-callout-surface-color: light-dark(
192
+ var(--nf-purple-l-40-25),
193
+ var(--nf-purple-d-50-25)
194
+ );
195
+ --nf-callout-accent-color: light-dark(
196
+ var(--nf-purple-l-80),
197
+ var(--nf-purple-d-30)
198
+ );
199
+ --nf-callout-rule-color: light-dark(
200
+ var(--nf-purple-l-80-25),
201
+ var(--nf-purple-d-30-25)
202
+ );
203
+ --nf-callout-shadow-color: light-dark(
204
+ var(--nf-purple-l-70-25),
205
+ var(--nf-purple-d-80-25)
206
+ );
207
+ }
208
+
209
+ &[data-ui-color="red"] {
210
+ --nf-callout-surface-color: light-dark(
211
+ var(--nf-red-l-40-25),
212
+ var(--nf-red-d-50-25)
213
+ );
214
+ --nf-callout-accent-color: light-dark(
215
+ var(--nf-red-l-80),
216
+ var(--nf-red-d-30)
217
+ );
218
+ --nf-callout-rule-color: light-dark(
219
+ var(--nf-red-l-80-25),
220
+ var(--nf-red-d-30-25)
221
+ );
222
+ --nf-callout-shadow-color: light-dark(
223
+ var(--nf-red-l-70-25),
224
+ var(--nf-red-d-80-25)
225
+ );
226
+ }
227
+
228
+ &[data-ui-color="yellow"] {
229
+ --nf-callout-surface-color: light-dark(
230
+ var(--nf-yellow-l-40-25),
231
+ var(--nf-yellow-d-50-25)
232
+ );
233
+ --nf-callout-accent-color: light-dark(
234
+ var(--nf-yellow-l-80),
235
+ var(--nf-yellow-d-30)
236
+ );
237
+ --nf-callout-rule-color: light-dark(
238
+ var(--nf-yellow-l-80-25),
239
+ var(--nf-yellow-d-30-25)
240
+ );
241
+ --nf-callout-shadow-color: light-dark(
242
+ var(--nf-yellow-l-70-25),
243
+ var(--nf-yellow-d-80-25)
244
+ );
245
+ }
246
+ }
247
+
248
+ /* Not a heading element: a component cannot know its place in the outline */
249
+ .nf-callout-title {
250
+ display: flex;
251
+ align-items: flex-start;
252
+ gap: var(--nf-spacing-base-low-2);
253
+ margin: var(--nf-spacing-none);
254
+ font-size: 1rem;
255
+ font-weight: 500;
256
+ line-height: 1.2;
257
+ }
258
+
259
+ /*
260
+ * Its own box, one line of the title tall, so whatever the icon prop
261
+ * renders stays centred on the first line when the title wraps. Content
262
+ * sized in em — an icon font, an SVG at 1em — follows this box.
263
+ */
264
+ .nf-callout-icon {
265
+ display: flex;
266
+ flex: none;
267
+ align-items: center;
268
+ justify-content: center;
269
+ /* The title's own size times its line height: one line of it, exactly */
270
+ block-size: calc(1rem * 1.2);
271
+ font-size: var(--nf-callout-icon-size);
272
+ }
273
+
274
+ .nf-callout-body {
275
+ /* A <p>, so any paragraph margin the page gives it has to go */
276
+ margin-block: var(--nf-spacing-base) var(--nf-spacing-none);
277
+ border-block-start: 1px solid
278
+ var(
279
+ --nf-callout-rule-color,
280
+ light-dark(var(--nf-grey-l-80-25), var(--nf-grey-d-30-25))
281
+ );
282
+ padding-block-start: var(--nf-spacing-base);
283
+ font-size: 1rem;
284
+ font-weight: 500;
285
+ }
286
+ </style>
@@ -0,0 +1,27 @@
1
+ ---
2
+ import type { HTMLAttributes } from "astro/types";
3
+
4
+ interface Props extends HTMLAttributes<"div"> {}
5
+
6
+ const { class: className, ...attrs } = Astro.props;
7
+ ---
8
+
9
+ <div {...attrs} class:list={["nf-container", className]}>
10
+ <slot />
11
+ </div>
12
+
13
+ <style>
14
+ /*
15
+ * --nf-container-max-inline-size is deliberately never declared here, only
16
+ * read with a fallback: declaring it would put it on the element, and an
17
+ * ancestor (a layout, a consumer's wrapper) could no longer set it.
18
+ */
19
+ .nf-container {
20
+ margin-inline: auto;
21
+ inline-size: 100%;
22
+ max-inline-size: var(
23
+ --nf-container-max-inline-size,
24
+ var(--nf-container-large-size)
25
+ );
26
+ }
27
+ </style>
@@ -0,0 +1,77 @@
1
+ ---
2
+ import type { HTMLAttributes } from "astro/types";
3
+ import type { NavItem } from "../types/components";
4
+
5
+ interface Props extends HTMLAttributes<"ul"> {
6
+ items: NavItem[];
7
+ }
8
+
9
+ const { items, class: className, ...attrs } = Astro.props;
10
+ ---
11
+
12
+ <ul {...attrs} class:list={["nf-nav-items-desktop", className]}>
13
+ {items.map(({ text, href, icon: Icon, current }) => (
14
+ <li>
15
+ <a
16
+ class="nf-nav-items-desktop-link"
17
+ href={href}
18
+ aria-current={current ? "page" : undefined}
19
+ >
20
+ {Icon && (
21
+ <span class="nf-nav-items-desktop-icon" aria-hidden="true">
22
+ <Icon width="1em" height="1em" stroke-width="2" />
23
+ </span>
24
+ )}
25
+ {text}
26
+ </a>
27
+ </li>
28
+ ))}
29
+ </ul>
30
+
31
+ <style>
32
+ .nf-nav-items-desktop {
33
+ display: flex;
34
+ margin: var(--nf-spacing-none);
35
+ padding: var(--nf-spacing-none);
36
+ list-style: none;
37
+ }
38
+
39
+ .nf-nav-items-desktop-link {
40
+ /* 14px: no spacing step has it, so it is built from two that do */
41
+ --nf-nav-items-desktop-link-padding-block: calc(
42
+ var(--nf-spacing-base-low-1) + var(--nf-spacing-base-low-4)
43
+ );
44
+
45
+ display: flex;
46
+ align-items: center;
47
+ gap: var(--nf-spacing-base-low-2);
48
+ padding-block: var(--nf-nav-items-desktop-link-padding-block);
49
+ padding-inline: var(--nf-spacing-base);
50
+ color: inherit;
51
+ font-size: 1rem;
52
+ text-decoration: none;
53
+
54
+ &:focus-visible {
55
+ outline: 2px solid currentColor;
56
+ outline-offset: -2px;
57
+ }
58
+
59
+ /*
60
+ * The active color is set by an enclosing Navbar; on its own the list
61
+ * falls back to the same purple an uncolored Navbar uses.
62
+ */
63
+ &[aria-current="page"] {
64
+ color: var(
65
+ --nf-navbar-active-color,
66
+ light-dark(var(--nf-purple-l-70), var(--nf-purple-d-30))
67
+ );
68
+ }
69
+ }
70
+
71
+ /* Never squashed: in a tight row, the text gives way instead */
72
+ .nf-nav-items-desktop-icon {
73
+ display: flex;
74
+ flex: none;
75
+ font-size: 22px;
76
+ }
77
+ </style>