stillwind 0.12.0 → 0.14.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/CHANGELOG.md +76 -0
- package/README.md +1 -1
- package/css/builtin-utilities/tw-borders.css +59 -59
- package/css/builtin-utilities/tw-effects.css +53 -53
- package/css/builtin-utilities/tw-typography.css +13 -13
- package/dist/class-object-C87DR3v2.js +6 -0
- package/dist/class-object-C87DR3v2.js.map +1 -0
- package/dist/class-object-CR0QHoF9.d.ts +10 -0
- package/dist/{class-string-DQmH4PZX.d.ts → class-string-BlClX8JK.d.ts} +2 -2
- package/dist/class-string-CiNTVHYm.js +6 -0
- package/dist/{class-string-CrQnTRvI.js.map → class-string-CiNTVHYm.js.map} +1 -1
- package/dist/{formats-Ctf2WFc-.js → formats-DP9B9SG6.js} +228 -113
- package/dist/formats-DP9B9SG6.js.map +1 -0
- package/dist/{formats-aeLCNAXl.d.ts → formats-NBNjMP5R.d.ts} +34 -12
- package/dist/frameworks/alpine.d.ts +5 -3
- package/dist/frameworks/alpine.js +3 -1
- package/dist/frameworks/alpine.js.map +1 -1
- package/dist/frameworks/astro.d.ts +3 -3
- package/dist/frameworks/astro.js +1 -1
- package/dist/frameworks/lit.d.ts +5 -3
- package/dist/frameworks/lit.js +3 -1
- package/dist/frameworks/lit.js.map +1 -1
- package/dist/frameworks/preact.d.ts +3 -3
- package/dist/frameworks/preact.js +1 -1
- package/dist/frameworks/qwik.d.ts +3 -3
- package/dist/frameworks/qwik.js +1 -1
- package/dist/frameworks/react.d.ts +2 -2
- package/dist/frameworks/react.js +1 -1
- package/dist/frameworks/solid.d.ts +3 -3
- package/dist/frameworks/solid.js +1 -1
- package/dist/frameworks/svelte.d.ts +3 -3
- package/dist/frameworks/svelte.js +1 -1
- package/dist/frameworks/vanilla.d.ts +5 -3
- package/dist/frameworks/vanilla.js +6 -1
- package/dist/frameworks/vanilla.js.map +1 -0
- package/dist/frameworks/vue.d.ts +3 -3
- package/dist/frameworks/vue.js +1 -1
- package/dist/{index-uw1R9t_P.d.ts → index-DpaDcczW.d.ts} +150 -50
- package/dist/macro/index.d.ts +2 -2
- package/dist/macro/index.js +1 -1
- package/dist/runtime/development.d.ts +16 -8
- package/dist/runtime/development.js +57 -21
- package/dist/runtime/development.js.map +1 -1
- package/dist/runtime/index.d.ts +2 -2
- package/dist/runtime/index.js +1 -1
- package/dist/{style-Bzuux32Y.js → style-dMBm8aX_.js} +6 -3
- package/dist/style-dMBm8aX_.js.map +1 -0
- package/docs/at-rules/apply.md +1 -1
- package/docs/at-rules/custom-variant.md +1 -1
- package/docs/at-rules/slot.md +1 -1
- package/docs/at-rules/stillwind-property.md +1 -1
- package/docs/at-rules/stillwind-registry.md +7 -7
- package/docs/at-rules/stillwind-require-properties.md +1 -1
- package/docs/at-rules/stillwind-undef-arbitrary-property.md +1 -1
- package/docs/at-rules/stillwind-undef-utility.md +1 -1
- package/docs/at-rules/stillwind-undef-variant.md +1 -1
- package/docs/at-rules/theme.md +5 -5
- package/docs/at-rules/utility.md +43 -4
- package/docs/at-rules/variant.md +1 -1
- package/docs/concepts/css-ordering.md +47 -7
- package/docs/concepts/how-styles-compile.md +8 -8
- package/docs/errors/SW10006.md +34 -0
- package/docs/errors/SW11001.md +4 -2
- package/docs/errors/index.md +1 -1
- package/docs/guides/migrating-from-tailwind.md +52 -9
- package/docs/guides/reusable-styles.md +2 -2
- package/docs/guides/style.md +1 -4
- package/docs/integrations.md +20 -1
- package/docs/lints/ambiguous-style-base-order.md +3 -1
- package/docs/lints/conflicting-provider-properties.md +3 -0
- package/docs/lints/conflicting-utilities.md +9 -0
- package/docs/lints/cyclic-style-order.md +68 -0
- package/docs/lints/index.md +14 -10
- package/docs/lints/interfering-imported-style-base.md +13 -22
- package/docs/lints/{invalid-cva-config.md → invalid-recipe-config.md} +8 -8
- package/docs/lints/{invalid-cva-input.md → invalid-recipe-input.md} +9 -9
- package/docs/lints/multiple-style-forwards.md +59 -0
- package/docs/lints/partial-utility-override.md +77 -0
- package/docs/lints/utility-class-selector.md +72 -0
- package/docs/llms.txt +8 -4
- package/docs/macros/index.md +1 -1
- package/docs/macros/recipe.md +246 -0
- package/docs/macros/style.md +62 -0
- package/docs/macros/when.md +1 -1
- package/package.json +7 -7
- package/skills/stillwind/SKILL.md +1 -1
- package/dist/class-object-CXvJOi2z.d.ts +0 -9
- package/dist/class-object-CzD1oMD_.js +0 -6
- package/dist/class-object-CzD1oMD_.js.map +0 -1
- package/dist/class-string-CrQnTRvI.js +0 -6
- package/dist/formats-Ctf2WFc-.js.map +0 -1
- package/dist/style-Bzuux32Y.js.map +0 -1
- package/docs/errors/SW11002.md +0 -65
- package/docs/macros/cva.md +0 -155
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: "invalid-
|
|
3
|
-
description: "Reports && or a ternary inside a style.
|
|
2
|
+
title: "invalid-recipe-input"
|
|
3
|
+
description: "Reports && or a ternary inside a style.recipe() value."
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
# invalid-
|
|
6
|
+
# invalid-recipe-input
|
|
7
7
|
|
|
8
8
|
This rule reports a runtime condition, such as `&&` or a ternary, inside the base
|
|
9
|
-
or an option value of [`style.
|
|
9
|
+
or an option value of [`style.recipe()`](https://stillwind.dev/docs/macros/recipe). The compiler generates
|
|
10
10
|
every value when it creates the factory, so the condition cannot choose a style.
|
|
11
11
|
|
|
12
12
|
## Reported
|
|
13
13
|
|
|
14
14
|
```tsx
|
|
15
15
|
declare const active: boolean;
|
|
16
|
-
style.
|
|
16
|
+
style.recipe(active && "bg-blue-500");
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
> invalid-
|
|
19
|
+
> invalid-recipe-input: style.recipe() values require static utilities, arrays, CSS variants, or custom properties; utility inputs cannot use `&&` or ternary expressions
|
|
20
20
|
>
|
|
21
|
-
> Example:2:
|
|
21
|
+
> Example:2:14
|
|
22
22
|
|
|
23
23
|
## Fixed
|
|
24
24
|
|
|
25
25
|
```tsx
|
|
26
26
|
declare const active: boolean;
|
|
27
|
-
const button = style.
|
|
27
|
+
const button = style.recipe("", {
|
|
28
28
|
variants: {
|
|
29
29
|
active: {
|
|
30
30
|
true: "bg-blue-500",
|
|
@@ -42,7 +42,7 @@ button({ active });
|
|
|
42
42
|
- Stored [`style()`](https://stillwind.dev/docs/macros/style) results, refs, animations, and `class`
|
|
43
43
|
fields are not accepted either. Use them in `style()` instead.
|
|
44
44
|
|
|
45
|
-
See [`style.
|
|
45
|
+
See [`style.recipe()`](https://stillwind.dev/docs/macros/recipe#style-values).
|
|
46
46
|
|
|
47
47
|
## Rule settings
|
|
48
48
|
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "multiple-style-forwards"
|
|
3
|
+
description: "Reports a style() call with more than one style.forward() argument."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# multiple-style-forwards
|
|
7
|
+
|
|
8
|
+
This rule reports a `style()` call that has more than one
|
|
9
|
+
[`style.forward()`](https://stillwind.dev/docs/macros/style#forward-props-to-a-components-element)
|
|
10
|
+
argument. The call is valid, but the forwarded values combine in two different
|
|
11
|
+
ways:
|
|
12
|
+
|
|
13
|
+
- Inline styles and custom properties apply in argument order. A later value
|
|
14
|
+
replaces an earlier value with the same name.
|
|
15
|
+
- Classes are joined in the class attribute. As with several base styles, the
|
|
16
|
+
CSS order of the files that generated them decides which class wins. The
|
|
17
|
+
argument order does not decide it.
|
|
18
|
+
|
|
19
|
+
## Reported
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
import { style } from "stillwind/react";
|
|
23
|
+
|
|
24
|
+
export const Panel = ({ outer, inner }: PanelProps) => (
|
|
25
|
+
<div {...style("p-4", style.forward(outer), style.forward(inner))} />
|
|
26
|
+
);
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
> multiple-style-forwards: this call has more than one style.forward() argument; CSS order, not argument order, decides which forwarded class wins
|
|
30
|
+
>
|
|
31
|
+
> Example:4:47
|
|
32
|
+
|
|
33
|
+
## Fixed
|
|
34
|
+
|
|
35
|
+
```tsx
|
|
36
|
+
import { style } from "stillwind/react";
|
|
37
|
+
|
|
38
|
+
export const Panel = ({ outer, inner }: PanelProps) => (
|
|
39
|
+
<div {...style("p-4", style.forward(outer))}>
|
|
40
|
+
<div {...style(style.forward(inner))} />
|
|
41
|
+
</div>
|
|
42
|
+
);
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## How to fix
|
|
46
|
+
|
|
47
|
+
- Forward each set of props to its own element.
|
|
48
|
+
- When one element must receive both sets, make sure that their classes do not
|
|
49
|
+
set the same properties, and suppress the finding.
|
|
50
|
+
|
|
51
|
+
## Rule settings
|
|
52
|
+
|
|
53
|
+
| Preset | Severity |
|
|
54
|
+
| --- | --- |
|
|
55
|
+
| `recommended` | warn |
|
|
56
|
+
| `strict` | deny |
|
|
57
|
+
| `stylistic` | off |
|
|
58
|
+
|
|
59
|
+
[Configure lint](https://stillwind.dev/docs/configuration#lint) to change the severity or options.
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "partial-utility-override"
|
|
3
|
+
description: "Reports a utility that overrides another utility of the same family but leaves some of its properties in place, such as the line height of text-sm."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# partial-utility-override
|
|
7
|
+
|
|
8
|
+
This rule reports a utility that overrides an earlier utility of the same family,
|
|
9
|
+
when the earlier utility also sets a property that the later utility does not set.
|
|
10
|
+
That property keeps the value of the earlier utility.
|
|
11
|
+
|
|
12
|
+
For example, `text-sm` sets `font-size` and `line-height`, and `text-[0.8rem]`
|
|
13
|
+
sets only `font-size`. When `text-[0.8rem]` overrides `text-sm`, the font size
|
|
14
|
+
changes, but the line height of `text-sm` remains. tailwind-merge removes the
|
|
15
|
+
whole `text-sm` in this case, so code written for `cn()` can look different after
|
|
16
|
+
migration.
|
|
17
|
+
|
|
18
|
+
The rule checks these overrides:
|
|
19
|
+
|
|
20
|
+
- A utility of the call overrides a utility of a base, as in
|
|
21
|
+
`style(base, "text-[0.8rem]")`.
|
|
22
|
+
- A utility under a JavaScript condition overrides a utility that is written
|
|
23
|
+
before it under fewer conditions, as in
|
|
24
|
+
`style("text-sm", compact && "text-[0.8rem]")`.
|
|
25
|
+
- A variant option or a compound value of
|
|
26
|
+
[`style.recipe()`](https://stillwind.dev/docs/macros/recipe) overrides a utility of the base value of
|
|
27
|
+
the same slot.
|
|
28
|
+
|
|
29
|
+
The rule compares only utilities of the same family, such as `text-*`, under the
|
|
30
|
+
same CSS variants. `px-4` with `pl-2` is not reported, because the other side of
|
|
31
|
+
the padding is meant to remain.
|
|
32
|
+
|
|
33
|
+
## Reported
|
|
34
|
+
|
|
35
|
+
```tsx
|
|
36
|
+
import { style } from "stillwind/react";
|
|
37
|
+
|
|
38
|
+
const label = style("text-sm font-medium");
|
|
39
|
+
export const compact = style(label, "text-[0.8rem]");
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
> partial-utility-override: `text-[0.8rem]` overrides `text-sm`, but `text-sm` also sets `line-height`, which `text-[0.8rem]` does not set
|
|
43
|
+
>
|
|
44
|
+
> Example:4:38
|
|
45
|
+
>
|
|
46
|
+
> Example:3:22: overridden utility
|
|
47
|
+
|
|
48
|
+
## Fixed
|
|
49
|
+
|
|
50
|
+
```tsx
|
|
51
|
+
import { style } from "stillwind/react";
|
|
52
|
+
|
|
53
|
+
const label = style("text-sm font-medium");
|
|
54
|
+
export const compact = style(label, "text-[0.8rem]/5");
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## How to fix
|
|
58
|
+
|
|
59
|
+
- Set the remaining properties in the same layer, such as the line height in
|
|
60
|
+
`text-[0.8rem]/5`.
|
|
61
|
+
- Or use a utility that sets the same properties, such as `text-xs` in place of
|
|
62
|
+
`text-[0.8rem]`.
|
|
63
|
+
- If the remaining value is what you want, keep the code and turn the rule off
|
|
64
|
+
for that line.
|
|
65
|
+
|
|
66
|
+
[conflicting-utilities](https://stillwind.dev/docs/lints/conflicting-utilities) reports utilities that
|
|
67
|
+
compete in one layer, where the code does not show which one wins.
|
|
68
|
+
|
|
69
|
+
## Rule settings
|
|
70
|
+
|
|
71
|
+
| Preset | Severity |
|
|
72
|
+
| --- | --- |
|
|
73
|
+
| `recommended` | warn |
|
|
74
|
+
| `strict` | deny |
|
|
75
|
+
| `stylistic` | off |
|
|
76
|
+
|
|
77
|
+
[Configure lint](https://stillwind.dev/docs/configuration#lint) to change the severity or options.
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "utility-class-selector"
|
|
3
|
+
description: "Reports a selector that tests the class attribute for a utility name, such as [class*='size-']."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# utility-class-selector
|
|
7
|
+
|
|
8
|
+
This rule reports a selector variant that tests the `class` attribute for a utility
|
|
9
|
+
name, such as `[class*='size-']` or `.border-b`. Stillwind writes generated class
|
|
10
|
+
names, not utility names, to the `class` attribute. Such a test therefore does not see
|
|
11
|
+
the utilities of an element that `style()` styles.
|
|
12
|
+
|
|
13
|
+
Component libraries such as shadcn/ui use this test to apply a default size to an icon
|
|
14
|
+
unless the icon sets its own size. In Stillwind, `:not([class*='size-'])` always
|
|
15
|
+
matches, so the default replaces the size that the icon sets.
|
|
16
|
+
|
|
17
|
+
## Reported
|
|
18
|
+
|
|
19
|
+
```tsx
|
|
20
|
+
function Button(props: ButtonProps) {
|
|
21
|
+
return (
|
|
22
|
+
<button
|
|
23
|
+
{...style(
|
|
24
|
+
"inline-flex items-center gap-2 [&_svg:not([class*='size-'])]:size-4",
|
|
25
|
+
style.forward(props),
|
|
26
|
+
)}
|
|
27
|
+
/>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
> utility-class-selector: `[class*='size-']` tests the class attribute for a utility name, but Stillwind writes generated class names, so it does not see the utilities of an element
|
|
33
|
+
>
|
|
34
|
+
> Example:5:41
|
|
35
|
+
|
|
36
|
+
## Fixed
|
|
37
|
+
|
|
38
|
+
```tsx
|
|
39
|
+
function Button(props: ButtonProps) {
|
|
40
|
+
return (
|
|
41
|
+
<button
|
|
42
|
+
{...style("inline-flex items-center gap-2 [:where(&_svg)]:size-4", style.forward(props))}
|
|
43
|
+
/>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
`:where()` gives the rule zero specificity. A class on the icon that sets the same
|
|
49
|
+
property, such as the class of `style("size-6")`, then wins over the default.
|
|
50
|
+
|
|
51
|
+
## How to fix
|
|
52
|
+
|
|
53
|
+
- For a variant such as `[&_svg:not([class*='size-'])]:size-4`, whose utility has the
|
|
54
|
+
root that the test names, use `[:where(&_svg)]:size-4`. The automatic fix makes
|
|
55
|
+
this change.
|
|
56
|
+
- Without `&`, include the `*:` or `**:` variant before it in `:where()`, because the
|
|
57
|
+
class of `*:` keeps the specificity of one class. The automatic fix changes
|
|
58
|
+
`*:[svg:not([class*=size-])]:size-8` to `[:where(&>svg)]:size-8`, `**:` to `&_svg`,
|
|
59
|
+
and `[svg:not([class*=size-])]:size-7` without `*:` to `[:where(&:is(svg))]:size-7`.
|
|
60
|
+
- For other tests, such as `[.border-b]:pb-6`, pass the state in another way. For
|
|
61
|
+
example, add a prop, or set the property on the element where the caller adds the
|
|
62
|
+
utility.
|
|
63
|
+
|
|
64
|
+
## Rule settings
|
|
65
|
+
|
|
66
|
+
| Preset | Severity |
|
|
67
|
+
| --- | --- |
|
|
68
|
+
| `recommended` | warn |
|
|
69
|
+
| `strict` | deny |
|
|
70
|
+
| `stylistic` | off |
|
|
71
|
+
|
|
72
|
+
[Configure lint](https://stillwind.dev/docs/configuration#lint) to change the severity or options.
|
package/docs/llms.txt
CHANGED
|
@@ -56,8 +56,8 @@ Index of the Markdown pages bundled in `docs/`. Paths are relative to this file.
|
|
|
56
56
|
- [SW10003: Invalid Unicode string](errors/SW10003.md): A string used to generate CSS or resolve a module contains a lone Unicode surrogate.
|
|
57
57
|
- [SW10004: Unconsumed macro use](errors/SW10004.md): A ref method, ref condition, or animation call is stored or passed somewhere other than directly in style().
|
|
58
58
|
- [SW10005: Untransformed macro reference](errors/SW10005.md): The style function is used as a value instead of being called.
|
|
59
|
+
- [SW10006: Unavailable style.forward()](errors/SW10006.md): style.forward() is used through an entrypoint that does not provide it.
|
|
59
60
|
- [SW11001: Style composition cycle](errors/SW11001.md): Two styles use each other as a base.
|
|
60
|
-
- [SW11002: CSS module ordering cycle](errors/SW11002.md): Two modules each build styles on a base from the other module.
|
|
61
61
|
- [SW11003: Unavailable style base](errors/SW11003.md): The compiled CSS of a base style is missing from the build.
|
|
62
62
|
- [SW12001: Incompatible declaration assignment](errors/SW12001.md): A variable that holds one ref or animation is assigned a different one.
|
|
63
63
|
- [SW12002: Declaration identities unavailable](errors/SW12002.md): The compiler cannot tell which refs or animations a value can hold.
|
|
@@ -140,6 +140,7 @@ Index of the Markdown pages bundled in `docs/`. Paths are relative to this file.
|
|
|
140
140
|
- [clamped-value](lints/clamped-value.md): Reports a value outside the range that the browser uses, such as opacity above 1.
|
|
141
141
|
- [conflicting-provider-properties](lints/conflicting-provider-properties.md): Reports a container or anchor property that a ref method and a utility both set.
|
|
142
142
|
- [conflicting-utilities](lints/conflicting-utilities.md): Reports utilities that set the same CSS property under the same conditions, such as p-2 p-4.
|
|
143
|
+
- [cyclic-style-order](lints/cyclic-style-order.md): Reports files that import values from each other, so their CSS order cannot follow both.
|
|
143
144
|
- [document-scoped-selector](lints/document-scoped-selector.md): Reports a selector variant that styles the whole document instead of the element.
|
|
144
145
|
- [duplicate-definition](lints/duplicate-definition.md): Reports a utility or variant definition that replaces an earlier one with the same name.
|
|
145
146
|
- [duplicate-utility](lints/duplicate-utility.md): Reports the same utility written twice under the same conditions.
|
|
@@ -155,14 +156,14 @@ Index of the Markdown pages bundled in `docs/`. Paths are relative to this file.
|
|
|
155
156
|
- [invalid-css-directive](lints/invalid-css-directive.md): Reports a malformed or unsupported Stillwind directive in your stylesheet.
|
|
156
157
|
- [invalid-css-import](lints/invalid-css-import.md): Reports a stylesheet import that cannot be resolved.
|
|
157
158
|
- [invalid-css-input](lints/invalid-css-input.md): Reports a style.css() argument that is not a utility known at build time.
|
|
158
|
-
- [invalid-cva-config](lints/invalid-cva-config.md): Reports an unknown or malformed field in a style.cva() configuration.
|
|
159
|
-
- [invalid-cva-input](lints/invalid-cva-input.md): Reports && or a ternary inside a style.cva() value.
|
|
160
159
|
- [invalid-keyframes-definition](lints/invalid-keyframes-definition.md): Reports a style.keyframes() frame key that is not a keyframe position, such as middle.
|
|
161
160
|
- [invalid-keyframes-use](lints/invalid-keyframes-use.md): Reports an animation applied with an argument that is not a string of options.
|
|
162
161
|
- [invalid-keyframes-variant](lints/invalid-keyframes-variant.md): Reports a state or container variant around a style.keyframes() definition.
|
|
163
162
|
- [invalid-lint-suppression](lints/invalid-lint-suppression.md): Reports a malformed suppression comment or an unknown rule name in one.
|
|
164
163
|
- [invalid-marker-use](lints/invalid-marker-use.md): Reports a marker class such as group with a variant or the important modifier.
|
|
165
164
|
- [invalid-media-query](lints/invalid-media-query.md): Reports a condition in style.media() that is not a media query, such as hover.
|
|
165
|
+
- [invalid-recipe-config](lints/invalid-recipe-config.md): Reports an unknown or malformed field in a style.recipe() configuration.
|
|
166
|
+
- [invalid-recipe-input](lints/invalid-recipe-input.md): Reports && or a ternary inside a style.recipe() value.
|
|
166
167
|
- [invalid-ref-input](lints/invalid-ref-input.md): Reports a style.ref() label or ref method argument that is not a literal.
|
|
167
168
|
- [invalid-rule-group-input](lints/invalid-rule-group-input.md): Reports a class field, custom property, or ref inside an object with variant keys.
|
|
168
169
|
- [invalid-runtime-condition](lints/invalid-runtime-condition.md): Reports a runtime CSS condition that the compiler cannot compile in its position.
|
|
@@ -179,6 +180,7 @@ Index of the Markdown pages bundled in `docs/`. Paths are relative to this file.
|
|
|
179
180
|
- [missing-document-target](lints/missing-document-target.md): Reports a style.css() utility without a selector to apply to.
|
|
180
181
|
- [missing-ref-attachment](lints/missing-ref-attachment.md): Reports asContainer() or asAnchor() in a call that does not attach the ref.
|
|
181
182
|
- [missing-view-transition-name](lints/missing-view-transition-name.md): Reports a view transition applied without .for().
|
|
183
|
+
- [multiple-style-forwards](lints/multiple-style-forwards.md): Reports a style() call with more than one style.forward() argument.
|
|
182
184
|
- [mutating-macro-argument](lints/mutating-macro-argument.md): Reports a state update inside an argument of style() or another macro.
|
|
183
185
|
- [no-arbitrary-breakpoints](lints/no-arbitrary-breakpoints.md): Reports viewport widths written as arbitrary values, such as min-[713px]:.
|
|
184
186
|
- [no-arbitrary-colors](lints/no-arbitrary-colors.md): Reports colors written as arbitrary values, such as bg-[#123456].
|
|
@@ -189,6 +191,7 @@ Index of the Markdown pages bundled in `docs/`. Paths are relative to this file.
|
|
|
189
191
|
- [no-restricted-length-units](lints/no-restricted-length-units.md): Reports length units that your project forbids for some properties, such as px for width.
|
|
190
192
|
- [no-restricted-theme-tokens](lints/no-restricted-theme-tokens.md): Reports utilities that use theme tokens that your project reserves, such as the default palette.
|
|
191
193
|
- [no-restricted-utilities](lints/no-restricted-utilities.md): Reports utilities that your project forbids, by name.
|
|
194
|
+
- [partial-utility-override](lints/partial-utility-override.md): Reports a utility that overrides another utility of the same family but leaves some of its properties in place, such as the line height of text-sm.
|
|
192
195
|
- [prefer-canonical-utilities](lints/prefer-canonical-utilities.md): Suggests standard utility spellings and combines equivalent utilities.
|
|
193
196
|
- [prefer-direct-styling](lints/prefer-direct-styling.md): Reports a selector variant that styles another element, such as [&_button]:.
|
|
194
197
|
- [prefer-logical-properties](lints/prefer-logical-properties.md): Reports a physical property that has a logical form, such as ml-4 for ms-4.
|
|
@@ -207,6 +210,7 @@ Index of the Markdown pages bundled in `docs/`. Paths are relative to this file.
|
|
|
207
210
|
- [unsatisfiable-variants](lints/unsatisfiable-variants.md): Reports variants that can never match together, such as portrait:landscape:.
|
|
208
211
|
- [unused-lint-suppression](lints/unused-lint-suppression.md): Reports a suppression comment that suppresses no finding.
|
|
209
212
|
- [unverified-style-base](lints/unverified-style-base.md): Reports a base style whose source the CLI cannot find from its type.
|
|
213
|
+
- [utility-class-selector](lints/utility-class-selector.md): Reports a selector that tests the class attribute for a utility name, such as [class*='size-'].
|
|
210
214
|
|
|
211
215
|
## macros
|
|
212
216
|
|
|
@@ -214,9 +218,9 @@ Index of the Markdown pages bundled in `docs/`. Paths are relative to this file.
|
|
|
214
218
|
- [style.ref() and ref methods](macros/ref/index.md): Name an element with a ref, and style other elements from its state, size, or anchor position.
|
|
215
219
|
- [style.anchorScope()](macros/anchor-scope.md): Limit where an anchor name is visible, so that each component instance uses its own anchor.
|
|
216
220
|
- [style.css()](macros/css.md): Compile utilities into a CSS string that you place yourself, such as in a shadow root.
|
|
217
|
-
- [style.cva()](macros/cva.md): Create a factory that selects compiled styles by option, with the configuration of class-variance-authority.
|
|
218
221
|
- [style.keyframes()](macros/keyframes.md): Define keyframes in a component, and apply them with animation options in style().
|
|
219
222
|
- [style.media()](macros/media.md): Turn named breakpoints and other media variants into a media query string for JavaScript.
|
|
223
|
+
- [style.recipe()](macros/recipe.md): Create a factory that selects compiled styles by option, with the configuration of class-variance-authority.
|
|
220
224
|
- [ref.asAnchor()](macros/ref/as-anchor.md): Make the element that has a ref a named anchor for CSS anchor positioning.
|
|
221
225
|
- [ref.asContainer()](macros/ref/as-container.md): Make the element that has a ref a named container for ref.at() queries.
|
|
222
226
|
- [ref.at()](macros/ref/at.md): Style an element with a container query on the element that has a ref.
|
package/docs/macros/index.md
CHANGED
|
@@ -19,7 +19,7 @@ and it shows the generated JavaScript and CSS for its examples.
|
|
|
19
19
|
| [`style.when()`](https://stillwind.dev/docs/macros/when) | Reuse a variant sequence, such as a ref condition | [Element relationships](https://stillwind.dev/docs/guides/element-relationships) |
|
|
20
20
|
| [`style.media()`](https://stillwind.dev/docs/macros/media) | Use a named breakpoint as a media query in JavaScript | [Responsive styles](https://stillwind.dev/docs/guides/responsive-styles) |
|
|
21
21
|
| [`style.css()`](https://stillwind.dev/docs/macros/css) | Compile utilities into a CSS string for a shadow root | [Web Components](https://stillwind.dev/docs/guides/web-components) |
|
|
22
|
-
| [`style.
|
|
22
|
+
| [`style.recipe()`](https://stillwind.dev/docs/macros/recipe) | Migrate components that use `cva` | [Migrating from Tailwind CSS](https://stillwind.dev/docs/guides/migrating-from-tailwind) |
|
|
23
23
|
|
|
24
24
|
Import the macros from the entrypoint of your framework, such as
|
|
25
25
|
`stillwind/react`. The examples on these pages use React.
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "style.recipe()"
|
|
3
|
+
description: "Create a factory that selects compiled styles by option, with the configuration of class-variance-authority."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# style.recipe()
|
|
7
|
+
|
|
8
|
+
`style.recipe(base?, config?)` creates a factory with the configuration format
|
|
9
|
+
of `cva` from [Class Variance Authority](https://cva.style/). With `slots`, it
|
|
10
|
+
also accepts the slot configuration of
|
|
11
|
+
[tailwind-variants](https://www.tailwind-variants.org/). The compiler generates
|
|
12
|
+
the CSS for every option at build time. Calling the factory selects the
|
|
13
|
+
compiled classes for the chosen options and returns props for an element.
|
|
14
|
+
|
|
15
|
+
`style.recipe()` exists mainly to migrate existing CVA and tailwind-variants
|
|
16
|
+
components. For new
|
|
17
|
+
components, see [Reusable styles](https://stillwind.dev/docs/guides/reusable-styles).
|
|
18
|
+
|
|
19
|
+
## Example
|
|
20
|
+
|
|
21
|
+
### Source
|
|
22
|
+
|
|
23
|
+
```tsx
|
|
24
|
+
import { style } from "stillwind/react";
|
|
25
|
+
|
|
26
|
+
export const button = style.recipe("inline-flex rounded-md", {
|
|
27
|
+
variants: {
|
|
28
|
+
size: {
|
|
29
|
+
small: "px-2 py-1",
|
|
30
|
+
large: "px-4 py-2",
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
defaultVariants: {
|
|
34
|
+
size: "small",
|
|
35
|
+
},
|
|
36
|
+
compoundVariants: [
|
|
37
|
+
{
|
|
38
|
+
size: "large",
|
|
39
|
+
class: "font-medium",
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
export const props = button({ size: "large" });
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Compiled code
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import { stillwindClassNameObjectRecipe } from "stillwind/runtime";
|
|
51
|
+
|
|
52
|
+
export const button = stillwindClassNameObjectRecipe("sw_6tzpq", {
|
|
53
|
+
variants: {
|
|
54
|
+
size: {
|
|
55
|
+
small: "sw_gzwci",
|
|
56
|
+
large: "sw_w6696",
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
defaultVariants: {
|
|
60
|
+
size: "small",
|
|
61
|
+
},
|
|
62
|
+
compoundVariants: [
|
|
63
|
+
{
|
|
64
|
+
size: "large",
|
|
65
|
+
class: "sw_v1iw3",
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
export const props = button({ size: "large" });
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Generated CSS
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
```css
|
|
77
|
+
.sw_6tzpq {
|
|
78
|
+
display: inline-flex;
|
|
79
|
+
border-radius: var(--radius-md);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.sw_gzwci {
|
|
83
|
+
padding-inline: calc(var(--spacing) * 2);
|
|
84
|
+
padding-block: calc(var(--spacing) * 1);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.sw_w6696 {
|
|
88
|
+
padding-inline: calc(var(--spacing) * 4);
|
|
89
|
+
padding-block: calc(var(--spacing) * 2);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.sw_v1iw3 {
|
|
93
|
+
--tw-font-weight: var(--font-weight-medium);
|
|
94
|
+
font-weight: var(--font-weight-medium);
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Configuration
|
|
99
|
+
|
|
100
|
+
Write the configuration as an object literal in the call:
|
|
101
|
+
|
|
102
|
+
| Field | Value |
|
|
103
|
+
| ------------------ | ---------------------------------------------------------------------------------- |
|
|
104
|
+
| `variants` | Each option name maps each value to a style |
|
|
105
|
+
| `defaultVariants` | The value that each option uses when the call passes `undefined` |
|
|
106
|
+
| `compoundVariants` | Entries that add `class` when every listed option matches |
|
|
107
|
+
| `slots` | Each slot name maps to the style of that element part |
|
|
108
|
+
| `compoundSlots` | Entries that add `class` to every slot in `slots` when every listed option matches |
|
|
109
|
+
|
|
110
|
+
`class` and `className` cannot be option names, because the factory uses them
|
|
111
|
+
for classes from other stylesheets. An option with the values `true` and
|
|
112
|
+
`false` accepts booleans.
|
|
113
|
+
|
|
114
|
+
Use `VariantProps<typeof button>` from your framework's entrypoint to type the
|
|
115
|
+
options.
|
|
116
|
+
|
|
117
|
+
## Style values
|
|
118
|
+
|
|
119
|
+
The base and each option value accept utility strings, arrays, objects with
|
|
120
|
+
variant keys, `true`, `false`, `null`, `undefined`, and custom properties.
|
|
121
|
+
|
|
122
|
+
They do not accept `&&`, ternaries, stored [`style()`](https://stillwind.dev/docs/macros/style)
|
|
123
|
+
results, refs, animations, or `class` fields. To choose a style at runtime,
|
|
124
|
+
pass a different option to the factory.
|
|
125
|
+
[invalid-recipe-input](https://stillwind.dev/docs/lints/invalid-recipe-input) reports these values, and
|
|
126
|
+
[invalid-recipe-config](https://stillwind.dev/docs/lints/invalid-recipe-config) reports a malformed
|
|
127
|
+
configuration.
|
|
128
|
+
|
|
129
|
+
A custom property value can be an expression. The factory evaluates it once,
|
|
130
|
+
when the factory is created. Custom properties stay in the inline style, so a
|
|
131
|
+
later option can replace them.
|
|
132
|
+
|
|
133
|
+
## Calling the factory
|
|
134
|
+
|
|
135
|
+
| Option value | Result |
|
|
136
|
+
| ------------ | ------------------------------------- |
|
|
137
|
+
| `undefined` | Uses the value from `defaultVariants` |
|
|
138
|
+
| `null` | Adds nothing for that option |
|
|
139
|
+
| A value | Adds the style of that value |
|
|
140
|
+
|
|
141
|
+
The result combines, in order: the base, the selected values in the order of
|
|
142
|
+
the keys of `variants`, every matching compound variant in array order, and the
|
|
143
|
+
`class` or `className` from the call. The option values are not passed to the
|
|
144
|
+
element. Each call returns a new props object.
|
|
145
|
+
|
|
146
|
+
The factory takes a [`style.forward()`](https://stillwind.dev/docs/macros/style#forward-props-to-a-components-element)
|
|
147
|
+
value as its second argument. The forwarded classes come last, and the
|
|
148
|
+
forwarded inline style applies on top of the result:
|
|
149
|
+
|
|
150
|
+
```tsx
|
|
151
|
+
export function Button({ variant, className, style: inline }: ButtonProps) {
|
|
152
|
+
return <button {...button({ variant }, style.forward({ className, style: inline }))} />;
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
The factory does not merge utilities at runtime. When two selected styles set
|
|
157
|
+
the same property, the compiler's CSS order decides which one wins.
|
|
158
|
+
|
|
159
|
+
The props that the factory returns cannot be passed to `style()` as a base.
|
|
160
|
+
|
|
161
|
+
## Slots
|
|
162
|
+
|
|
163
|
+
A component often styles several elements, such as a root, an icon, and a label.
|
|
164
|
+
`slots` names these parts. Each recipe with slots also has a `base` slot, which
|
|
165
|
+
receives the first argument of `style.recipe()`:
|
|
166
|
+
|
|
167
|
+
```tsx
|
|
168
|
+
import { style } from "stillwind/react";
|
|
169
|
+
|
|
170
|
+
export const card = style.recipe("flex items-center rounded-md", {
|
|
171
|
+
slots: {
|
|
172
|
+
icon: "size-4",
|
|
173
|
+
label: "text-sm",
|
|
174
|
+
},
|
|
175
|
+
variants: {
|
|
176
|
+
size: {
|
|
177
|
+
small: {
|
|
178
|
+
base: "p-2",
|
|
179
|
+
icon: "size-3",
|
|
180
|
+
},
|
|
181
|
+
large: "p-4",
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
compoundVariants: [
|
|
185
|
+
{
|
|
186
|
+
size: "large",
|
|
187
|
+
class: {
|
|
188
|
+
label: "text-lg",
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
],
|
|
192
|
+
compoundSlots: [
|
|
193
|
+
{
|
|
194
|
+
slots: ["icon", "label"],
|
|
195
|
+
size: "small",
|
|
196
|
+
class: "gap-1",
|
|
197
|
+
},
|
|
198
|
+
],
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
export function Card({ size, className }: CardProps) {
|
|
202
|
+
const { base, icon, label } = card({ size, className });
|
|
203
|
+
return (
|
|
204
|
+
<div {...base()}>
|
|
205
|
+
<span {...icon()} />
|
|
206
|
+
<span {...label()}>Title</span>
|
|
207
|
+
</div>
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
With `slots`, an option value or a compound `class` or `className` value can be
|
|
213
|
+
an object whose keys all name slots. Each key adds its style to that slot. Any
|
|
214
|
+
other value applies to the `base` slot. A slot name cannot be empty, cannot
|
|
215
|
+
start with `--` or end with `:`, and cannot be `class` or `className`, because
|
|
216
|
+
those keys have other meanings in a style value.
|
|
217
|
+
|
|
218
|
+
Calling the factory returns one function for each slot. Each slot function
|
|
219
|
+
returns props for its element. A slot receives, in order:
|
|
220
|
+
|
|
221
|
+
1. For the `base` slot, the first argument of `style.recipe()`.
|
|
222
|
+
2. Its value in `slots`.
|
|
223
|
+
3. Its part of each selected option value.
|
|
224
|
+
4. Its part of each matching compound variant.
|
|
225
|
+
5. The `class` of each matching `compoundSlots` entry that lists it.
|
|
226
|
+
6. For the `base` slot, the classes and the `style.forward()` value passed to
|
|
227
|
+
the factory.
|
|
228
|
+
7. The classes and the `style.forward()` value passed to the slot function.
|
|
229
|
+
|
|
230
|
+
A slot function also accepts option values, which replace the values passed to
|
|
231
|
+
the factory for that slot only, as in `icon({ size: "large" })`.
|
|
232
|
+
|
|
233
|
+
`style.recipe()` does not support the `extend` field of tailwind-variants.
|
|
234
|
+
[invalid-recipe-config](https://stillwind.dev/docs/lints/invalid-recipe-config) reports it and unknown
|
|
235
|
+
slot names.
|
|
236
|
+
|
|
237
|
+
## Generated code
|
|
238
|
+
|
|
239
|
+
The compiler creates the factory with a helper from `stillwind/runtime`, such as
|
|
240
|
+
`stillwindClassNameObjectRecipe` for React, together with the compiled class names.
|
|
241
|
+
Factory calls stay ordinary JavaScript.
|
|
242
|
+
The development build checks the selected values and the classes from other
|
|
243
|
+
stylesheets.
|
|
244
|
+
|
|
245
|
+
See [Migrating from Tailwind CSS](https://stillwind.dev/docs/guides/migrating-from-tailwind#cva) to
|
|
246
|
+
convert existing `cva` calls.
|
package/docs/macros/style.md
CHANGED
|
@@ -17,6 +17,7 @@ other frameworks receive `class` and `style`. Spread the result onto the element
|
|
|
17
17
|
- [Base styles](#base-styles)
|
|
18
18
|
- [Argument order](#argument-order)
|
|
19
19
|
- [How props combine at runtime](#how-props-combine-at-runtime)
|
|
20
|
+
- [Forward props to a component's element](#forward-props-to-a-components-element)
|
|
20
21
|
- [Side effects in arguments](#side-effects-in-arguments)
|
|
21
22
|
|
|
22
23
|
## Inputs
|
|
@@ -208,6 +209,67 @@ combines the inputs:
|
|
|
208
209
|
- A later custom property replaces an earlier one with the same name.
|
|
209
210
|
- Custom properties apply on top of an inline style.
|
|
210
211
|
|
|
212
|
+
## Forward props to a component's element
|
|
213
|
+
|
|
214
|
+
`style.forward()` passes the class and style props that a component receives to
|
|
215
|
+
the `style()` call of its element. Write it as one argument of the call:
|
|
216
|
+
|
|
217
|
+
```tsx
|
|
218
|
+
import { style } from "stillwind/react";
|
|
219
|
+
|
|
220
|
+
export function Card({ className, style: inline, ...props }: CardProps) {
|
|
221
|
+
return <div {...props} {...style("rounded p-4", style.forward({ className, style: inline }))} />;
|
|
222
|
+
}
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
The forwarded props apply after every other argument:
|
|
226
|
+
|
|
227
|
+
- Forwarded classes come after the component's own classes.
|
|
228
|
+
- Forwarded custom properties and inline style declarations replace the
|
|
229
|
+
component's ones with the same name.
|
|
230
|
+
- An inline style object is merged with an object, and a string is joined with
|
|
231
|
+
a string. When one is a string and the other is an object, Vue receives
|
|
232
|
+
both in an array. The other frameworks receive one string.
|
|
233
|
+
|
|
234
|
+
`style.forward()` reads the `class`, `className`, and `style` keys, so pass the
|
|
235
|
+
props under the names that your framework uses. When both class keys are
|
|
236
|
+
present, it joins them. Class values accept strings, arrays, and objects, as in
|
|
237
|
+
`style()`. Inline style strings are not parsed into objects.
|
|
238
|
+
|
|
239
|
+
You can also pass all props, as in `style.forward(props)`. In that form, make
|
|
240
|
+
sure that no prop that comes after the result replaces its `className` or
|
|
241
|
+
`style`:
|
|
242
|
+
|
|
243
|
+
```tsx
|
|
244
|
+
// Wrong: props.className replaces the merged class.
|
|
245
|
+
<div {...style("p-4", style.forward(props))} {...props} />
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
`style.forward()` cannot be inside a variant object. A
|
|
249
|
+
[`style.recipe()`](https://stillwind.dev/docs/macros/recipe) factory takes it as its second argument. The
|
|
250
|
+
Lit, Alpine, and vanilla entrypoints do not provide `style.forward()`.
|
|
251
|
+
|
|
252
|
+
A Vue component with one root element does not need `style.forward()`. Vue
|
|
253
|
+
adds the `class` and `style` attributes that the component receives to its root
|
|
254
|
+
element, after the root's own classes and styles. A `style()` result that is
|
|
255
|
+
passed to such a component therefore works like a forwarded one: the caller's
|
|
256
|
+
classes come after the component's classes, and the caller's inline styles and
|
|
257
|
+
custom properties replace the root's ones with the same name. Vue does not add
|
|
258
|
+
these attributes when the component sets `inheritAttrs: false` or renders
|
|
259
|
+
several root nodes. In those components, pass `useAttrs()` or `$attrs` to
|
|
260
|
+
`style.forward()` in the call of the element that should receive them.
|
|
261
|
+
|
|
262
|
+
A call can have several `style.forward()` arguments. Their inline styles and
|
|
263
|
+
custom properties apply in argument order, so a later value replaces an earlier
|
|
264
|
+
one. Their classes are joined, and as with several bases, the CSS order decides
|
|
265
|
+
which class wins, not the argument order.
|
|
266
|
+
[multiple-style-forwards](https://stillwind.dev/docs/lints/multiple-style-forwards) reports such
|
|
267
|
+
calls.
|
|
268
|
+
|
|
269
|
+
When a module passes a `style()` result to an imported component, the CSS of
|
|
270
|
+
the component's module comes first, so the caller's utilities win. See
|
|
271
|
+
[CSS ordering](https://stillwind.dev/docs/concepts/css-ordering#files-that-pass-styles-to-components).
|
|
272
|
+
|
|
211
273
|
## Side effects in arguments
|
|
212
274
|
|
|
213
275
|
The compiler can evaluate arguments in any order, and it can skip arguments
|
package/docs/macros/when.md
CHANGED
|
@@ -119,7 +119,7 @@ refer to one stored variant. A choice at runtime, such as
|
|
|
119
119
|
`[active ? cardHover : cardFocus]`, does not work, because the compiler
|
|
120
120
|
expands the variants at build time. Write a key for each stored variant instead.
|
|
121
121
|
|
|
122
|
-
[`style.
|
|
122
|
+
[`style.recipe()`](https://stillwind.dev/docs/macros/recipe) values and [`.in()`](https://stillwind.dev/docs/macros/ref/in)
|
|
123
123
|
do not accept a stored variant.
|
|
124
124
|
|
|
125
125
|
## Output
|