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.
package/README.md CHANGED
@@ -16,26 +16,56 @@ import 'astro-nosferatu/styles/index.css';
16
16
  ---
17
17
  ```
18
18
 
19
- `index.css` loads the tokens and puts the reset, base and typography styles in cascade layers, in this order:
19
+ `index.css` declares three cascade layers, in this order:
20
20
 
21
21
  ```
22
- nosferatu.reset < nosferatu.base < nosferatu.typography < your unlayered CSS
22
+ nosferatu.tokens < nosferatu.reset < nosferatu.typography < your unlayered CSS
23
23
  ```
24
24
 
25
25
  Any CSS you write outside a layer wins, with no `!important` or extra specificity needed.
26
26
 
27
- You can also import single files: `tokens.css`, `reset.css`, `base.css`, `typography.css`. Files imported on their own are **not** layered; only `index.css` adds the layers.
27
+ You can also import single files: `tokens.css`, `reset.css`, `typography.css`, or one token group at a time with `colors/index.css`, `shadows.css`, `spacings.css` and `borders.css`. `tokens.css` is exactly those four imports and declares nothing itself. Files imported on their own are **not** layered; only `index.css` adds the layers.
28
28
 
29
29
  ### Theming
30
30
 
31
- Every design value is a CSS custom property prefixed with `--nf-`. Override one to re-theme:
31
+ Every design value is a CSS custom property prefixed with `--nf-`. Colors come from a palette named `--nf-<hue>-<d|l>-<step>` (`d` dark mode, `l` light mode, steps 10–100). Space is the `--nf-spacing-*` scale and corners the `--nf-border-radius-*` scale, both in absolute `px`, named around a base step: `--nf-spacing-base` is `16px`, `--nf-border-radius-base` is `8px`, and `-low-N`/`-up-N` step down and up from there. Override one to re-theme:
32
32
 
33
33
  ```css
34
34
  :root {
35
- --nf-color-primary: #7c3aed;
35
+ --nf-red-l-80: var(--nf-purple-l-80);
36
+ --nf-spacing-base: 20px;
36
37
  }
37
38
  ```
38
39
 
40
+ ### Fonts
41
+
42
+ The library **names** three fonts and never loads them: Outfit for the page, Plus Jakarta Sans for `BlogArticle` prose and Geist Mono for its code. No font file ships in this package, and nothing is requested from a font host.
43
+
44
+ Install the ones you want — they are optional peer dependencies — and import them yourself:
45
+
46
+ ```sh
47
+ npm install @fontsource-variable/outfit @fontsource-variable/plus-jakarta-sans @fontsource-variable/geist-mono
48
+ ```
49
+
50
+ ```astro
51
+ ---
52
+ import '@fontsource-variable/outfit';
53
+ import '@fontsource-variable/plus-jakarta-sans';
54
+ import '@fontsource-variable/geist-mono';
55
+ import 'astro-nosferatu/styles/index.css';
56
+ ---
57
+ ```
58
+
59
+ Install nothing and every stack falls through to the system font it ends with, with no failed request. The four properties are `--nf-font-family`, `--nf-font-family-blog-post`, `--nf-font-family-code-blog-post` and `--nf-font-weight` (`400`); override any of them in unlayered CSS to use your own font:
60
+
61
+ ```css
62
+ :root {
63
+ --nf-font-family: 'Inter Variable', system-ui, sans-serif;
64
+ }
65
+ ```
66
+
67
+ `--nf-font-family` is the one property for the page's general text: `body` takes it, everything inside inherits it, and the components read it directly, so a single override moves all of them.
68
+
39
69
  ## Components
40
70
 
41
71
  ```astro
@@ -43,10 +73,12 @@ Every design value is a CSS custom property prefixed with `--nf-`. Override one
43
73
  import Button from 'astro-nosferatu/components/Button.astro';
44
74
  ---
45
75
  <Button>Save</Button>
46
- <Button variant="secondary">Cancel</Button>
76
+ <Button color="red">Delete</Button>
47
77
  ```
48
78
 
49
- Components read their values from the `--nf-*` tokens, so load `tokens.css` (or `index.css`) on the page.
79
+ `Button` takes a `color` of `blue`, `cyan`, `green`, `orange`, `pink`, `purple` (default), `red` or `yellow`, and passes every other `<button>` attribute through.
80
+
81
+ Components read their values from the `--nf-*` tokens, so load `tokens.css` (or `index.css`) on the page — it brings the palette, the shadows, the spacing and the radii together. `reset.css` sets `color-scheme: light dark`, so components that use `light-dark()` follow the reader's preferred scheme; set `color-scheme` yourself in unlayered CSS to pin one.
50
82
 
51
83
  ## License
52
84
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro-nosferatu",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "author": "renangirotto",
5
5
  "description": "Astro component library: styles and .astro components.",
6
6
  "license": "MIT",
@@ -20,15 +20,34 @@
20
20
  ],
21
21
  "exports": {
22
22
  "./components/*": "./src/components/*",
23
+ "./layouts/*": "./src/layouts/*",
24
+ "./html/*": "./src/html/*",
23
25
  "./styles/*": "./src/styles/*",
24
26
  "./package.json": "./package.json"
25
27
  },
26
28
  "files": [
27
29
  "src"
28
30
  ],
31
+ "dependencies": {
32
+ "iconoir": "^7.12.1"
33
+ },
29
34
  "peerDependencies": {
35
+ "@fontsource-variable/geist-mono": "^5.3.0",
36
+ "@fontsource-variable/outfit": "^5.3.0",
37
+ "@fontsource-variable/plus-jakarta-sans": "^5.3.0",
30
38
  "astro": "^7.0.0"
31
39
  },
40
+ "peerDependenciesMeta": {
41
+ "@fontsource-variable/geist-mono": {
42
+ "optional": true
43
+ },
44
+ "@fontsource-variable/outfit": {
45
+ "optional": true
46
+ },
47
+ "@fontsource-variable/plus-jakarta-sans": {
48
+ "optional": true
49
+ }
50
+ },
32
51
  "devDependencies": {
33
52
  "astro": "^7.4.1"
34
53
  }
@@ -0,0 +1,446 @@
1
+ ---
2
+ import type { HTMLAttributes } from "astro/types";
3
+ import type { ColorPalette, IconComponent } from "../types/components";
4
+ /*
5
+ * Iconoir is a dependency of this package, so these resolve from here under
6
+ * any package manager and the consumer installs nothing for the defaults.
7
+ */
8
+ import Plus from "iconoir/icons/regular/plus.svg";
9
+ import Minus from "iconoir/icons/regular/minus.svg";
10
+
11
+ interface Props extends HTMLAttributes<"details"> {
12
+ summary: string;
13
+ color?: ColorPalette;
14
+ /* Shown while closed, in place of the plus */
15
+ iconCollapsed?: IconComponent;
16
+ /* Shown while open, in place of the minus */
17
+ iconExpanded?: IconComponent;
18
+ }
19
+
20
+ const {
21
+ summary,
22
+ color,
23
+ iconCollapsed: Collapsed,
24
+ iconExpanded: Expanded,
25
+ class: className,
26
+ "data-ui-color": _controlled,
27
+ ...attrs
28
+ } = Astro.props;
29
+ ---
30
+
31
+ <details
32
+ {...attrs}
33
+ data-ui-color={color}
34
+ class:list={["nf-accordion", className]}
35
+ >
36
+ <summary class="nf-accordion-summary">
37
+ <span class="nf-accordion-label">{summary}</span>
38
+ {/* The summary already exposes the expanded state, so both icons are decorative */}
39
+ <span class="nf-accordion-icon" aria-hidden="true">
40
+ <span class="nf-accordion-icon-collapsed">
41
+ {Collapsed ? <Collapsed /> : <Plus width="1em" height="1em" />}
42
+ </span>
43
+ <span class="nf-accordion-icon-expanded">
44
+ {Expanded ? <Expanded /> : <Minus width="1em" height="1em" />}
45
+ </span>
46
+ </span>
47
+ </summary>
48
+ <div class="nf-accordion-content">
49
+ <slot />
50
+ </div>
51
+ </details>
52
+
53
+ <style>
54
+ .nf-accordion {
55
+ --nf-accordion-depth: 4px;
56
+ --nf-accordion-lift: 0px;
57
+ --nf-accordion-border-width: 2px;
58
+ /* 24px against the 1rem summary, at the default root size */
59
+ --nf-accordion-icon-size: 1.5rem;
60
+ --nf-accordion-transition-duration: 0.15s;
61
+ --nf-accordion-disclosure-duration: 0.3s;
62
+
63
+ /* The depth belongs to the whole panel, so it shows closed and open alike */
64
+ border-radius: var(--nf-border-radius-base);
65
+ box-shadow: 0px var(--nf-accordion-depth) 0px
66
+ var(
67
+ --nf-accordion-shadow-color,
68
+ light-dark(var(--nf-grey-l-70), var(--nf-grey-d-80))
69
+ );
70
+
71
+ &[data-ui-color="blue"] {
72
+ --nf-accordion-color: light-dark(
73
+ var(--nf-blue-l-40),
74
+ var(--nf-blue-d-50)
75
+ );
76
+ --nf-accordion-accent-color: light-dark(
77
+ var(--nf-blue-l-80),
78
+ var(--nf-blue-d-90)
79
+ );
80
+ --nf-accordion-shadow-color: light-dark(
81
+ var(--nf-blue-l-70),
82
+ var(--nf-blue-d-80)
83
+ );
84
+ --nf-accordion-rule-color: light-dark(
85
+ var(--nf-blue-l-60-25),
86
+ var(--nf-blue-d-70-25)
87
+ );
88
+ }
89
+
90
+ &[data-ui-color="cyan"] {
91
+ --nf-accordion-color: light-dark(
92
+ var(--nf-cyan-l-40),
93
+ var(--nf-cyan-d-50)
94
+ );
95
+ --nf-accordion-accent-color: light-dark(
96
+ var(--nf-cyan-l-80),
97
+ var(--nf-cyan-d-90)
98
+ );
99
+ --nf-accordion-shadow-color: light-dark(
100
+ var(--nf-cyan-l-70),
101
+ var(--nf-cyan-d-80)
102
+ );
103
+ --nf-accordion-rule-color: light-dark(
104
+ var(--nf-cyan-l-60-25),
105
+ var(--nf-cyan-d-70-25)
106
+ );
107
+ }
108
+
109
+ &[data-ui-color="green"] {
110
+ --nf-accordion-color: light-dark(
111
+ var(--nf-green-l-40),
112
+ var(--nf-green-d-50)
113
+ );
114
+ --nf-accordion-accent-color: light-dark(
115
+ var(--nf-green-l-80),
116
+ var(--nf-green-d-90)
117
+ );
118
+ --nf-accordion-shadow-color: light-dark(
119
+ var(--nf-green-l-70),
120
+ var(--nf-green-d-80)
121
+ );
122
+ --nf-accordion-rule-color: light-dark(
123
+ var(--nf-green-l-60-25),
124
+ var(--nf-green-d-70-25)
125
+ );
126
+ }
127
+
128
+ &[data-ui-color="grey"] {
129
+ --nf-accordion-color: light-dark(
130
+ var(--nf-grey-l-40),
131
+ var(--nf-grey-d-50)
132
+ );
133
+ --nf-accordion-accent-color: light-dark(
134
+ var(--nf-grey-l-80),
135
+ var(--nf-grey-d-90)
136
+ );
137
+ --nf-accordion-shadow-color: light-dark(
138
+ var(--nf-grey-l-70),
139
+ var(--nf-grey-d-80)
140
+ );
141
+ --nf-accordion-rule-color: light-dark(
142
+ var(--nf-grey-l-60-25),
143
+ var(--nf-grey-d-70-25)
144
+ );
145
+ }
146
+
147
+ &[data-ui-color="orange"] {
148
+ --nf-accordion-color: light-dark(
149
+ var(--nf-orange-l-40),
150
+ var(--nf-orange-d-50)
151
+ );
152
+ --nf-accordion-accent-color: light-dark(
153
+ var(--nf-orange-l-80),
154
+ var(--nf-orange-d-90)
155
+ );
156
+ --nf-accordion-shadow-color: light-dark(
157
+ var(--nf-orange-l-70),
158
+ var(--nf-orange-d-80)
159
+ );
160
+ --nf-accordion-rule-color: light-dark(
161
+ var(--nf-orange-l-60-25),
162
+ var(--nf-orange-d-70-25)
163
+ );
164
+ }
165
+
166
+ &[data-ui-color="pink"] {
167
+ --nf-accordion-color: light-dark(
168
+ var(--nf-pink-l-40),
169
+ var(--nf-pink-d-50)
170
+ );
171
+ --nf-accordion-accent-color: light-dark(
172
+ var(--nf-pink-l-80),
173
+ var(--nf-pink-d-90)
174
+ );
175
+ --nf-accordion-shadow-color: light-dark(
176
+ var(--nf-pink-l-70),
177
+ var(--nf-pink-d-80)
178
+ );
179
+ --nf-accordion-rule-color: light-dark(
180
+ var(--nf-pink-l-60-25),
181
+ var(--nf-pink-d-70-25)
182
+ );
183
+ }
184
+
185
+ &[data-ui-color="purple"] {
186
+ --nf-accordion-color: light-dark(
187
+ var(--nf-purple-l-40),
188
+ var(--nf-purple-d-50)
189
+ );
190
+ --nf-accordion-accent-color: light-dark(
191
+ var(--nf-purple-l-80),
192
+ var(--nf-purple-d-90)
193
+ );
194
+ --nf-accordion-shadow-color: light-dark(
195
+ var(--nf-purple-l-70),
196
+ var(--nf-purple-d-80)
197
+ );
198
+ --nf-accordion-rule-color: light-dark(
199
+ var(--nf-purple-l-60-25),
200
+ var(--nf-purple-d-70-25)
201
+ );
202
+ }
203
+
204
+ &[data-ui-color="red"] {
205
+ --nf-accordion-color: light-dark(var(--nf-red-l-40), var(--nf-red-d-50));
206
+ --nf-accordion-accent-color: light-dark(
207
+ var(--nf-red-l-80),
208
+ var(--nf-red-d-90)
209
+ );
210
+ --nf-accordion-shadow-color: light-dark(
211
+ var(--nf-red-l-70),
212
+ var(--nf-red-d-80)
213
+ );
214
+ --nf-accordion-rule-color: light-dark(
215
+ var(--nf-red-l-60-25),
216
+ var(--nf-red-d-70-25)
217
+ );
218
+ }
219
+
220
+ &[data-ui-color="yellow"] {
221
+ --nf-accordion-color: light-dark(
222
+ var(--nf-yellow-l-40),
223
+ var(--nf-yellow-d-50)
224
+ );
225
+ --nf-accordion-accent-color: light-dark(
226
+ var(--nf-yellow-l-80),
227
+ var(--nf-yellow-d-90)
228
+ );
229
+ --nf-accordion-shadow-color: light-dark(
230
+ var(--nf-yellow-l-70),
231
+ var(--nf-yellow-d-80)
232
+ );
233
+ --nf-accordion-rule-color: light-dark(
234
+ var(--nf-yellow-l-60-25),
235
+ var(--nf-yellow-d-70-25)
236
+ );
237
+ }
238
+ }
239
+
240
+ /*
241
+ * The raised control: the text at the start, the icon at the end. It has no
242
+ * shadow of its own — it slides down over the panel's shadow to read as pressed.
243
+ */
244
+ .nf-accordion-summary {
245
+ display: flex;
246
+ align-items: flex-start;
247
+ justify-content: space-between;
248
+ gap: var(--nf-spacing-base-low-2);
249
+ border: none;
250
+ /*
251
+ * Always 2px, so opening never changes the summary's height: invisible
252
+ * against the fill while closed, the rule color while open.
253
+ */
254
+ border-block-end: var(--nf-accordion-border-width) solid
255
+ var(
256
+ --nf-accordion-color,
257
+ light-dark(var(--nf-grey-l-40), var(--nf-grey-d-50))
258
+ );
259
+ border-radius: var(--nf-border-radius-base);
260
+ padding-block: var(--nf-spacing-base-low-2);
261
+ padding-inline: var(--nf-spacing-base);
262
+ color: var(
263
+ --nf-accordion-accent-color,
264
+ light-dark(var(--nf-grey-l-80), var(--nf-grey-d-90))
265
+ );
266
+ font-weight: 600;
267
+ background-color: var(
268
+ --nf-accordion-color,
269
+ light-dark(var(--nf-grey-l-40), var(--nf-grey-d-50))
270
+ );
271
+ list-style: none;
272
+ translate: 0 var(--nf-accordion-lift);
273
+ cursor: pointer;
274
+ transition-property: translate, background-color, color, border-color;
275
+ transition-duration: var(--nf-accordion-transition-duration);
276
+ transition-timing-function: ease-in-out;
277
+
278
+ /* Safari still paints the marker without this */
279
+ &::-webkit-details-marker {
280
+ display: none;
281
+ }
282
+
283
+ &:hover,
284
+ &:focus-within {
285
+ --nf-accordion-lift: 1px;
286
+ }
287
+
288
+ &:active {
289
+ --nf-accordion-lift: 4px;
290
+ }
291
+
292
+ /* Drawn inside the summary's edge, so it reads as a border on it */
293
+ &:focus-visible {
294
+ outline: var(--nf-accordion-border-width) solid
295
+ var(
296
+ --nf-accordion-accent-color,
297
+ light-dark(var(--nf-grey-l-80), var(--nf-grey-d-90))
298
+ );
299
+ outline-offset: calc(-1 * var(--nf-accordion-border-width));
300
+ }
301
+ }
302
+
303
+ /*
304
+ * After the hover and active rules on purpose: an open summary stays put
305
+ * whatever the pointer is doing, sitting on its rule with square bottom
306
+ * corners against the content below.
307
+ */
308
+ .nf-accordion[open] .nf-accordion-summary {
309
+ --nf-accordion-lift: 0px;
310
+
311
+ border-block-end-color: var(
312
+ --nf-accordion-rule-color,
313
+ light-dark(var(--nf-grey-l-60-25), var(--nf-grey-d-70-25))
314
+ );
315
+ border-end-start-radius: 0;
316
+ border-end-end-radius: 0;
317
+ }
318
+
319
+ /*
320
+ * One line of the summary tall, at the summary's own font size, so the icon
321
+ * centres on the first line when the text wraps. The icon parts carry the
322
+ * icon size, so content sized in em follows --nf-accordion-icon-size.
323
+ */
324
+ .nf-accordion-icon {
325
+ display: flex;
326
+ flex: none;
327
+ align-items: center;
328
+ block-size: 1lh;
329
+ }
330
+
331
+ .nf-accordion-icon-collapsed,
332
+ .nf-accordion-icon-expanded {
333
+ display: flex;
334
+ font-size: var(--nf-accordion-icon-size);
335
+ }
336
+
337
+ .nf-accordion-icon-expanded {
338
+ display: none;
339
+ }
340
+
341
+ .nf-accordion[open] .nf-accordion-icon-collapsed {
342
+ display: none;
343
+ }
344
+
345
+ .nf-accordion[open] .nf-accordion-icon-expanded {
346
+ display: flex;
347
+ }
348
+
349
+ /* The inside of the control: same fill, same accent, no shadow of its own */
350
+ .nf-accordion-content {
351
+ border-end-end-radius: var(--nf-border-radius-base);
352
+ border-end-start-radius: var(--nf-border-radius-base);
353
+ padding-block: var(--nf-spacing-base-low-2);
354
+ padding-inline: var(--nf-spacing-base);
355
+ color: var(
356
+ --nf-accordion-accent-color,
357
+ light-dark(var(--nf-grey-l-80), var(--nf-grey-d-90))
358
+ );
359
+ background-color: var(
360
+ --nf-accordion-color,
361
+ light-dark(var(--nf-grey-l-40), var(--nf-grey-d-50))
362
+ );
363
+ }
364
+
365
+ /*
366
+ * The whole disclosure animation, the collapsed height included, is gated
367
+ * on the two features it needs. A browser that fails the test never sees
368
+ * block-size: 0, so it keeps the plain instant <details> rather than a
369
+ * panel it cannot open.
370
+ */
371
+ @supports (block-size: calc-size(auto, size)) and selector(::details-content) {
372
+ .nf-accordion::details-content {
373
+ block-size: 0;
374
+ overflow: clip;
375
+ transition-property: block-size, content-visibility;
376
+ transition-duration: var(--nf-accordion-disclosure-duration);
377
+ transition-timing-function: ease-in-out;
378
+ transition-behavior: allow-discrete;
379
+ }
380
+
381
+ /*
382
+ * calc-size() rather than a bare auto: the component carries its own
383
+ * size interpolation instead of depending on reset.css being loaded.
384
+ */
385
+ .nf-accordion[open]::details-content {
386
+ block-size: calc-size(auto, size);
387
+ }
388
+
389
+ /*
390
+ * The content is not rendered while the panel is closed, so it has no
391
+ * previous value to transition from — @starting-style is what gives it
392
+ * one. Opening only: by the time the panel closes this box is already
393
+ * gone, and the shrinking panel is what the reader sees.
394
+ */
395
+ .nf-accordion-content {
396
+ opacity: 1;
397
+ translate: 0 0;
398
+ transition-property: opacity, translate;
399
+ transition-duration: var(--nf-accordion-disclosure-duration);
400
+ transition-timing-function: ease-in-out;
401
+ }
402
+
403
+ @starting-style {
404
+ .nf-accordion-content {
405
+ opacity: 0;
406
+ /* A travel distance, not spacing: literal rather than tokenised */
407
+ translate: 0 -8px;
408
+ }
409
+ }
410
+
411
+ /*
412
+ * Closing drops [open] at once, but the panel takes the disclosure
413
+ * duration to shrink: the summary keeps its square corners and its rule
414
+ * until then, and switches in one step when the panel is gone. A
415
+ * transition takes its timing from the state being entered, so opening —
416
+ * which enters [open], where the delay is zero — switches immediately.
417
+ * Inside @supports on purpose: without the animation the panel closes
418
+ * instantly, and so must the corners.
419
+ */
420
+ .nf-accordion-summary {
421
+ transition-property:
422
+ translate, background-color, color, border-color,
423
+ border-end-start-radius, border-end-end-radius;
424
+ transition-duration:
425
+ var(--nf-accordion-transition-duration),
426
+ var(--nf-accordion-transition-duration),
427
+ var(--nf-accordion-transition-duration), 0s, 0s, 0s;
428
+ transition-delay:
429
+ 0s, 0s, 0s, var(--nf-accordion-disclosure-duration),
430
+ var(--nf-accordion-disclosure-duration),
431
+ var(--nf-accordion-disclosure-duration);
432
+ }
433
+
434
+ .nf-accordion[open] .nf-accordion-summary {
435
+ transition-delay: 0s;
436
+ }
437
+ }
438
+
439
+ /* Keep the states and their feedback, drop the animation between them */
440
+ @media (prefers-reduced-motion: reduce) {
441
+ .nf-accordion {
442
+ --nf-accordion-transition-duration: 0s;
443
+ --nf-accordion-disclosure-duration: 0s;
444
+ }
445
+ }
446
+ </style>