stillwind 0.12.0 → 0.13.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.
Files changed (88) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/README.md +1 -1
  3. package/css/builtin-utilities/tw-borders.css +59 -59
  4. package/css/builtin-utilities/tw-effects.css +53 -53
  5. package/css/builtin-utilities/tw-typography.css +13 -13
  6. package/dist/class-object-C87DR3v2.js +6 -0
  7. package/dist/class-object-C87DR3v2.js.map +1 -0
  8. package/dist/class-object-CR0QHoF9.d.ts +10 -0
  9. package/dist/{class-string-DQmH4PZX.d.ts → class-string-BlClX8JK.d.ts} +2 -2
  10. package/dist/class-string-CiNTVHYm.js +6 -0
  11. package/dist/{class-string-CrQnTRvI.js.map → class-string-CiNTVHYm.js.map} +1 -1
  12. package/dist/{formats-Ctf2WFc-.js → formats-DP9B9SG6.js} +228 -113
  13. package/dist/formats-DP9B9SG6.js.map +1 -0
  14. package/dist/{formats-aeLCNAXl.d.ts → formats-NBNjMP5R.d.ts} +34 -12
  15. package/dist/frameworks/alpine.d.ts +5 -3
  16. package/dist/frameworks/alpine.js +3 -1
  17. package/dist/frameworks/alpine.js.map +1 -1
  18. package/dist/frameworks/astro.d.ts +3 -3
  19. package/dist/frameworks/astro.js +1 -1
  20. package/dist/frameworks/lit.d.ts +5 -3
  21. package/dist/frameworks/lit.js +3 -1
  22. package/dist/frameworks/lit.js.map +1 -1
  23. package/dist/frameworks/preact.d.ts +3 -3
  24. package/dist/frameworks/preact.js +1 -1
  25. package/dist/frameworks/qwik.d.ts +3 -3
  26. package/dist/frameworks/qwik.js +1 -1
  27. package/dist/frameworks/react.d.ts +2 -2
  28. package/dist/frameworks/react.js +1 -1
  29. package/dist/frameworks/solid.d.ts +3 -3
  30. package/dist/frameworks/solid.js +1 -1
  31. package/dist/frameworks/svelte.d.ts +3 -3
  32. package/dist/frameworks/svelte.js +1 -1
  33. package/dist/frameworks/vanilla.d.ts +5 -3
  34. package/dist/frameworks/vanilla.js +6 -1
  35. package/dist/frameworks/vanilla.js.map +1 -0
  36. package/dist/frameworks/vue.d.ts +3 -3
  37. package/dist/frameworks/vue.js +1 -1
  38. package/dist/{index-uw1R9t_P.d.ts → index-DpaDcczW.d.ts} +150 -50
  39. package/dist/macro/index.d.ts +2 -2
  40. package/dist/macro/index.js +1 -1
  41. package/dist/runtime/development.d.ts +16 -8
  42. package/dist/runtime/development.js +57 -21
  43. package/dist/runtime/development.js.map +1 -1
  44. package/dist/runtime/index.d.ts +2 -2
  45. package/dist/runtime/index.js +1 -1
  46. package/dist/{style-Bzuux32Y.js → style-dMBm8aX_.js} +6 -3
  47. package/dist/style-dMBm8aX_.js.map +1 -0
  48. package/docs/at-rules/apply.md +1 -1
  49. package/docs/at-rules/custom-variant.md +1 -1
  50. package/docs/at-rules/slot.md +1 -1
  51. package/docs/at-rules/stillwind-property.md +1 -1
  52. package/docs/at-rules/stillwind-registry.md +7 -7
  53. package/docs/at-rules/stillwind-require-properties.md +1 -1
  54. package/docs/at-rules/stillwind-undef-arbitrary-property.md +1 -1
  55. package/docs/at-rules/stillwind-undef-utility.md +1 -1
  56. package/docs/at-rules/stillwind-undef-variant.md +1 -1
  57. package/docs/at-rules/theme.md +5 -5
  58. package/docs/at-rules/utility.md +43 -4
  59. package/docs/at-rules/variant.md +1 -1
  60. package/docs/concepts/css-ordering.md +46 -7
  61. package/docs/concepts/how-styles-compile.md +8 -8
  62. package/docs/errors/SW10006.md +34 -0
  63. package/docs/errors/index.md +1 -0
  64. package/docs/guides/migrating-from-tailwind.md +52 -9
  65. package/docs/guides/reusable-styles.md +2 -2
  66. package/docs/integrations.md +20 -1
  67. package/docs/lints/conflicting-utilities.md +9 -0
  68. package/docs/lints/cyclic-style-order.md +61 -0
  69. package/docs/lints/index.md +14 -10
  70. package/docs/lints/{invalid-cva-config.md → invalid-recipe-config.md} +8 -8
  71. package/docs/lints/{invalid-cva-input.md → invalid-recipe-input.md} +9 -9
  72. package/docs/lints/multiple-style-forwards.md +59 -0
  73. package/docs/lints/partial-utility-override.md +77 -0
  74. package/docs/lints/utility-class-selector.md +72 -0
  75. package/docs/llms.txt +8 -3
  76. package/docs/macros/index.md +1 -1
  77. package/docs/macros/recipe.md +246 -0
  78. package/docs/macros/style.md +62 -0
  79. package/docs/macros/when.md +1 -1
  80. package/package.json +6 -6
  81. package/skills/stillwind/SKILL.md +1 -1
  82. package/dist/class-object-CXvJOi2z.d.ts +0 -9
  83. package/dist/class-object-CzD1oMD_.js +0 -6
  84. package/dist/class-object-CzD1oMD_.js.map +0 -1
  85. package/dist/class-string-CrQnTRvI.js +0 -6
  86. package/dist/formats-Ctf2WFc-.js.map +0 -1
  87. package/dist/style-Bzuux32Y.js.map +0 -1
  88. package/docs/macros/cva.md +0 -155
@@ -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,6 +56,7 @@ 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
61
  - [SW11002: CSS module ordering cycle](errors/SW11002.md): Two modules each build styles on a base from the other module.
61
62
  - [SW11003: Unavailable style base](errors/SW11003.md): The compiled CSS of a base style is missing from the build.
@@ -140,6 +141,7 @@ Index of the Markdown pages bundled in `docs/`. Paths are relative to this file.
140
141
  - [clamped-value](lints/clamped-value.md): Reports a value outside the range that the browser uses, such as opacity above 1.
141
142
  - [conflicting-provider-properties](lints/conflicting-provider-properties.md): Reports a container or anchor property that a ref method and a utility both set.
142
143
  - [conflicting-utilities](lints/conflicting-utilities.md): Reports utilities that set the same CSS property under the same conditions, such as p-2 p-4.
144
+ - [cyclic-style-order](lints/cyclic-style-order.md): Reports files that import values from each other, so their CSS order cannot follow both.
143
145
  - [document-scoped-selector](lints/document-scoped-selector.md): Reports a selector variant that styles the whole document instead of the element.
144
146
  - [duplicate-definition](lints/duplicate-definition.md): Reports a utility or variant definition that replaces an earlier one with the same name.
145
147
  - [duplicate-utility](lints/duplicate-utility.md): Reports the same utility written twice under the same conditions.
@@ -155,14 +157,14 @@ Index of the Markdown pages bundled in `docs/`. Paths are relative to this file.
155
157
  - [invalid-css-directive](lints/invalid-css-directive.md): Reports a malformed or unsupported Stillwind directive in your stylesheet.
156
158
  - [invalid-css-import](lints/invalid-css-import.md): Reports a stylesheet import that cannot be resolved.
157
159
  - [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
160
  - [invalid-keyframes-definition](lints/invalid-keyframes-definition.md): Reports a style.keyframes() frame key that is not a keyframe position, such as middle.
161
161
  - [invalid-keyframes-use](lints/invalid-keyframes-use.md): Reports an animation applied with an argument that is not a string of options.
162
162
  - [invalid-keyframes-variant](lints/invalid-keyframes-variant.md): Reports a state or container variant around a style.keyframes() definition.
163
163
  - [invalid-lint-suppression](lints/invalid-lint-suppression.md): Reports a malformed suppression comment or an unknown rule name in one.
164
164
  - [invalid-marker-use](lints/invalid-marker-use.md): Reports a marker class such as group with a variant or the important modifier.
165
165
  - [invalid-media-query](lints/invalid-media-query.md): Reports a condition in style.media() that is not a media query, such as hover.
166
+ - [invalid-recipe-config](lints/invalid-recipe-config.md): Reports an unknown or malformed field in a style.recipe() configuration.
167
+ - [invalid-recipe-input](lints/invalid-recipe-input.md): Reports && or a ternary inside a style.recipe() value.
166
168
  - [invalid-ref-input](lints/invalid-ref-input.md): Reports a style.ref() label or ref method argument that is not a literal.
167
169
  - [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
170
  - [invalid-runtime-condition](lints/invalid-runtime-condition.md): Reports a runtime CSS condition that the compiler cannot compile in its position.
@@ -179,6 +181,7 @@ Index of the Markdown pages bundled in `docs/`. Paths are relative to this file.
179
181
  - [missing-document-target](lints/missing-document-target.md): Reports a style.css() utility without a selector to apply to.
180
182
  - [missing-ref-attachment](lints/missing-ref-attachment.md): Reports asContainer() or asAnchor() in a call that does not attach the ref.
181
183
  - [missing-view-transition-name](lints/missing-view-transition-name.md): Reports a view transition applied without .for().
184
+ - [multiple-style-forwards](lints/multiple-style-forwards.md): Reports a style() call with more than one style.forward() argument.
182
185
  - [mutating-macro-argument](lints/mutating-macro-argument.md): Reports a state update inside an argument of style() or another macro.
183
186
  - [no-arbitrary-breakpoints](lints/no-arbitrary-breakpoints.md): Reports viewport widths written as arbitrary values, such as min-[713px]:.
184
187
  - [no-arbitrary-colors](lints/no-arbitrary-colors.md): Reports colors written as arbitrary values, such as bg-[#123456].
@@ -189,6 +192,7 @@ Index of the Markdown pages bundled in `docs/`. Paths are relative to this file.
189
192
  - [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
193
  - [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
194
  - [no-restricted-utilities](lints/no-restricted-utilities.md): Reports utilities that your project forbids, by name.
195
+ - [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
196
  - [prefer-canonical-utilities](lints/prefer-canonical-utilities.md): Suggests standard utility spellings and combines equivalent utilities.
193
197
  - [prefer-direct-styling](lints/prefer-direct-styling.md): Reports a selector variant that styles another element, such as [&_button]:.
194
198
  - [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 +211,7 @@ Index of the Markdown pages bundled in `docs/`. Paths are relative to this file.
207
211
  - [unsatisfiable-variants](lints/unsatisfiable-variants.md): Reports variants that can never match together, such as portrait:landscape:.
208
212
  - [unused-lint-suppression](lints/unused-lint-suppression.md): Reports a suppression comment that suppresses no finding.
209
213
  - [unverified-style-base](lints/unverified-style-base.md): Reports a base style whose source the CLI cannot find from its type.
214
+ - [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
215
 
211
216
  ## macros
212
217
 
@@ -214,9 +219,9 @@ Index of the Markdown pages bundled in `docs/`. Paths are relative to this file.
214
219
  - [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
220
  - [style.anchorScope()](macros/anchor-scope.md): Limit where an anchor name is visible, so that each component instance uses its own anchor.
216
221
  - [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
222
  - [style.keyframes()](macros/keyframes.md): Define keyframes in a component, and apply them with animation options in style().
219
223
  - [style.media()](macros/media.md): Turn named breakpoints and other media variants into a media query string for JavaScript.
224
+ - [style.recipe()](macros/recipe.md): Create a factory that selects compiled styles by option, with the configuration of class-variance-authority.
220
225
  - [ref.asAnchor()](macros/ref/as-anchor.md): Make the element that has a ref a named anchor for CSS anchor positioning.
221
226
  - [ref.asContainer()](macros/ref/as-container.md): Make the element that has a ref a named container for ref.at() queries.
222
227
  - [ref.at()](macros/ref/at.md): Style an element with a container query on the element that has a ref.
@@ -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.cva()`](https://stillwind.dev/docs/macros/cva) | Migrate components that use `cva` | [Migrating from Tailwind CSS](https://stillwind.dev/docs/guides/migrating-from-tailwind) |
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.
@@ -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
@@ -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.cva()`](https://stillwind.dev/docs/macros/cva) values and [`.in()`](https://stillwind.dev/docs/macros/ref/in)
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stillwind",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "description": "Write Tailwind CSS v4 utilities in components, enforce your design system, and ship static CSS",
5
5
  "keywords": [
6
6
  "alpinejs",
@@ -132,17 +132,17 @@
132
132
  "./package.json": "./package.json"
133
133
  },
134
134
  "dependencies": {
135
- "@stillwind/config": "0.12.0",
136
- "@stillwind/native": "0.12.0",
137
- "@stillwind/projection": "0.12.0"
135
+ "@stillwind/config": "0.13.0",
136
+ "@stillwind/native": "0.13.0",
137
+ "@stillwind/projection": "0.13.0"
138
138
  },
139
139
  "devDependencies": {
140
140
  "@stillwind-internal/tools-workspace": "0.0.0",
141
141
  "@types/node": "^26.6.6",
142
142
  "lit": "^3.3.3",
143
143
  "typescript": "^6.0.3",
144
- "vite": "npm:@voidzero-dev/vite-plus-core@1.6.0",
145
- "vite-plus": "1.6.0"
144
+ "vite": "npm:@voidzero-dev/vite-plus-core@8.3.8001",
145
+ "vite-plus": "1.8.0"
146
146
  },
147
147
  "peerDependencies": {
148
148
  "lit": "^3.3.0"
@@ -22,7 +22,7 @@ Markdown version of each page.
22
22
  | Migrate existing styles | `node_modules/stillwind/skills/migrate-to-stillwind/SKILL.md` |
23
23
  | Recommended practices and mistakes that produce no CSS | `docs/guides/recommended-practices.md` |
24
24
  | Utilities, variants, conditions, runtime values | `docs/guides/style.md`, `docs/macros/style.md` |
25
- | Shared styles, states, and component options | `docs/guides/reusable-styles.md`, `docs/macros/cva.md` |
25
+ | Shared styles, states, and component options | `docs/guides/reusable-styles.md`, `docs/macros/recipe.md` |
26
26
  | Breakpoints and media queries in JavaScript | `docs/guides/responsive-styles.md`, `docs/macros/media.md` |
27
27
  | Styles that depend on a parent, sibling, or anchor | `docs/guides/element-relationships.md`, `docs/macros/ref/index.md` |
28
28
  | Animations | `docs/guides/animations.md`, `docs/macros/keyframes.md` |
@@ -1,9 +0,0 @@
1
- import { StyleMacro as StyleMacro$1, StyleResult as StyleResult$1 } from "./index-uw1R9t_P.js";
2
- export type StyleProps = {
3
- class?: string;
4
- style?: Record<string, string>;
5
- };
6
- export type StyleResult<Id extends string = string> = StyleResult$1<Id, StyleProps>;
7
- export type StyleMacro = StyleMacro$1<StyleProps>;
8
- export declare const style: StyleMacro;
9
- //# sourceMappingURL=class-object-CXvJOi2z.d.ts.map
@@ -1,6 +0,0 @@
1
- import { createStyleMacro } from "./style-Bzuux32Y.js";
2
- // src/outputs/class-object.ts
3
- const style = createStyleMacro();
4
- export { style };
5
-
6
- //# sourceMappingURL=class-object-CzD1oMD_.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"class-object-CzD1oMD_.js","names":[],"sources":["../src/outputs/class-object.ts"],"sourcesContent":["import type { StyleResult as Result } from \"../macro/output.ts\";\nimport { createStyleMacro } from \"../macro/style.ts\";\nimport type { StyleMacro as Macro } from \"../macro/style.ts\";\n\nexport type StyleProps = {\n class?: string;\n style?: Record<string, string>;\n};\n\nexport type StyleResult<Id extends string = string> = Result<Id, StyleProps>;\n\nexport type StyleMacro = Macro<StyleProps>;\n\nexport const style: StyleMacro = createStyleMacro<StyleProps>();\n"],"mappings":";;AAaA,MAAa,QAAoB,iBAA6B"}
@@ -1,6 +0,0 @@
1
- import { createStyleMacro } from "./style-Bzuux32Y.js";
2
- // src/outputs/class-string.ts
3
- const style = createStyleMacro();
4
- export { style };
5
-
6
- //# sourceMappingURL=class-string-CrQnTRvI.js.map