@salty-css/vite 0.1.0-alpha.27 → 0.1.0-alpha.28
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 +82 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -321,6 +321,88 @@ Example usage:
|
|
|
321
321
|
styled('div', { base: { textStyle: 'headline.large', card: '20px' } });
|
|
322
322
|
```
|
|
323
323
|
|
|
324
|
+
### Template variants
|
|
325
|
+
|
|
326
|
+
Static templates can opt into named variants by switching a node from a plain styles object to a "rich" shape with `base` and `variants` keys — the same authoring API as `styled`. Variants declared at a parent node are inherited by every descendant leaf, so one declaration of `weight` on `heading` flows down to `heading.large`, `heading.small`, etc.
|
|
327
|
+
|
|
328
|
+
```ts
|
|
329
|
+
// /styles/templates.css.ts
|
|
330
|
+
import { defineTemplates } from '@salty-css/core/factories';
|
|
331
|
+
|
|
332
|
+
export default defineTemplates({
|
|
333
|
+
textStyle: {
|
|
334
|
+
heading: {
|
|
335
|
+
// Rich node: variants declared here are available to every child leaf.
|
|
336
|
+
base: {
|
|
337
|
+
fontFamily: '{fontFamily.heading}',
|
|
338
|
+
lineHeight: '1.1em',
|
|
339
|
+
},
|
|
340
|
+
variants: {
|
|
341
|
+
weight: {
|
|
342
|
+
light: { fontWeight: 300 },
|
|
343
|
+
regular: { fontWeight: 500 },
|
|
344
|
+
heavy: { fontWeight: 800 },
|
|
345
|
+
},
|
|
346
|
+
italic: {
|
|
347
|
+
true: { fontStyle: 'italic' },
|
|
348
|
+
},
|
|
349
|
+
},
|
|
350
|
+
defaultVariants: {
|
|
351
|
+
weight: 'regular',
|
|
352
|
+
},
|
|
353
|
+
compoundVariants: [
|
|
354
|
+
// Applied when ALL listed axes match.
|
|
355
|
+
{ weight: 'heavy', italic: true, css: { letterSpacing: '-0.01em' } },
|
|
356
|
+
],
|
|
357
|
+
// Leaves can be plain styles…
|
|
358
|
+
small: { fontSize: '{fontSize.heading.small}' },
|
|
359
|
+
regular: { fontSize: '{fontSize.heading.regular}' },
|
|
360
|
+
// …or rich, with their own additional variants / overrides.
|
|
361
|
+
large: {
|
|
362
|
+
base: { fontSize: '{fontSize.heading.large}' },
|
|
363
|
+
variants: {
|
|
364
|
+
weight: {
|
|
365
|
+
// Override the inherited bundle just for `large`.
|
|
366
|
+
heavy: { fontWeight: 900, letterSpacing: '-0.02em' },
|
|
367
|
+
},
|
|
368
|
+
},
|
|
369
|
+
},
|
|
370
|
+
},
|
|
371
|
+
},
|
|
372
|
+
});
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
Apply variants at the call site in either of two equivalent forms — string query or object:
|
|
376
|
+
|
|
377
|
+
```ts
|
|
378
|
+
styled('h1', {
|
|
379
|
+
base: {
|
|
380
|
+
// String form: `path@axis=value&axis=value&boolFlag`
|
|
381
|
+
textStyle: 'heading.large@weight=heavy&italic',
|
|
382
|
+
},
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
styled('h2', {
|
|
386
|
+
base: {
|
|
387
|
+
// Object form: `name` is the dot-path, the rest are axis values.
|
|
388
|
+
textStyle: { name: 'heading.large', weight: 'heavy', italic: true },
|
|
389
|
+
},
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
// No variants — existing simple usage still works.
|
|
393
|
+
styled('p', { base: { textStyle: 'heading.regular' } });
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
Behaviour worth knowing:
|
|
397
|
+
|
|
398
|
+
- **Inheritance is parent → leaf only.** A leaf sees variants from its ancestors; siblings and children are invisible.
|
|
399
|
+
- **Closest wins.** If the same axis/value bundle is declared at multiple levels, the deepest one replaces (not merges) the ancestor's bundle for that single call.
|
|
400
|
+
- **`defaultVariants` apply when the call site omits an axis.** Walked bottom-up, same closest-wins rule.
|
|
401
|
+
- **`compoundVariants` (AND) and `anyOfVariants` (OR) are accumulated top-down** across the path — every matching rule contributes.
|
|
402
|
+
- **Boolean axes accept a shorthand.** `@italic` is equivalent to `@italic=true`; in object form pass `italic: true`.
|
|
403
|
+
- **Reserved keys** inside a rich node: `base`, `variants`, `defaultVariants`, `compoundVariants`, `anyOfVariants`. Don't use `name` as an axis (reserved for the object call-site form).
|
|
404
|
+
- **Function templates** (e.g. `card: (v) => ({ … })`) don't support variants — keep them as plain functions.
|
|
405
|
+
|
|
324
406
|
## Custom fonts
|
|
325
407
|
|
|
326
408
|
Register custom fonts that will be emitted as `@font-face` declarations and exposed as a CSS variable. Mirrors the developer experience of Next.js / Astro font loaders, but generated at build time alongside the rest of your Salty CSS output.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salty-css/vite",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.28",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist/index.mjs",
|
|
6
6
|
"typings": "./dist/index.d.ts",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
}
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@salty-css/core": "^0.1.0-alpha.
|
|
37
|
+
"@salty-css/core": "^0.1.0-alpha.28",
|
|
38
38
|
"vite": "^6.4.1"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|