stillwind 0.7.0 → 0.8.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/css/builtin-variants/sw-conditional.css +10 -1
- package/dist/{class-object-D7ZGJOf_.d.ts → class-object-BaK8uudd.d.ts} +2 -2
- package/dist/class-object-DNcjzcfH.js +6 -0
- package/dist/{class-object-D24FFYqO.js.map → class-object-DNcjzcfH.js.map} +1 -1
- package/dist/{class-string-CQHnc9GN.d.ts → class-string-C5YFtXQn.d.ts} +2 -2
- package/dist/class-string-KnYInbiw.js +6 -0
- package/dist/{class-string-Db8-oI4q.js.map → class-string-KnYInbiw.js.map} +1 -1
- package/dist/{cva-BwX07CFw.js → formats-Ctf2WFc-.js} +87 -2
- package/dist/formats-Ctf2WFc-.js.map +1 -0
- package/dist/formats-aeLCNAXl.d.ts +73 -0
- package/dist/frameworks/alpine.d.ts +3 -3
- package/dist/frameworks/alpine.js +1 -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 +3 -3
- package/dist/frameworks/lit.js +1 -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 +3 -3
- package/dist/frameworks/vanilla.js +1 -1
- package/dist/frameworks/vue.d.ts +3 -3
- package/dist/frameworks/vue.js +1 -1
- package/dist/{index-RwVFpxhE.d.ts → index-DBpgaaD7.d.ts} +54 -5
- package/dist/macro/index.d.ts +2 -2
- package/dist/macro/index.js +1 -1
- package/dist/runtime/development.d.ts +47 -0
- package/dist/{development-J-JCSIm0.js → runtime/development.js} +41 -5
- package/dist/runtime/development.js.map +1 -0
- package/dist/runtime/index.d.ts +2 -0
- package/dist/runtime/index.js +1 -0
- package/dist/{style-fTQbsVWZ.js → style-BE8vuLiO.js} +4 -1
- package/dist/style-BE8vuLiO.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 +1 -1
- 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 +4 -4
- package/docs/at-rules/variant.md +1 -1
- package/docs/cli.md +4 -1
- package/docs/concepts/css-ordering.md +4 -4
- package/docs/concepts/how-styles-compile.md +3 -3
- package/docs/configuration.md +16 -16
- package/docs/editors.md +2 -1
- package/docs/errors/SW10004.md +2 -1
- package/docs/guides/reusable-styles.md +5 -0
- package/docs/guides/style.md +32 -0
- package/docs/guides/tailwind-compatibility.md +10 -9
- package/docs/lints/ambiguous-style-base-order.md +2 -0
- package/docs/lints/conflicting-utilities.md +43 -1
- package/docs/lints/index.md +1 -0
- package/docs/lints/interfering-imported-style-base.md +21 -3
- package/docs/lints/invalid-stored-variant.md +52 -0
- package/docs/macros/cva.md +5 -4
- package/docs/macros/index.md +1 -0
- package/docs/macros/ref/at.md +1 -1
- package/docs/macros/ref/condition.md +2 -1
- package/docs/macros/ref/in.md +1 -1
- package/docs/macros/ref/index.md +2 -1
- package/docs/macros/style.md +34 -8
- package/docs/macros/view-transition.md +1 -1
- package/docs/macros/when.md +129 -0
- package/package.json +10 -26
- package/dist/class-object-D24FFYqO.js +0 -6
- package/dist/class-string-Db8-oI4q.js +0 -6
- package/dist/cva-BwX07CFw.js.map +0 -1
- package/dist/cva-DSpDNBYi.d.ts +0 -9
- package/dist/development-DttPQc71.d.ts +0 -27
- package/dist/development-J-JCSIm0.js.map +0 -1
- package/dist/runtime/class-name-object-development.d.ts +0 -10
- package/dist/runtime/class-name-object-development.js +0 -18
- package/dist/runtime/class-name-object-development.js.map +0 -1
- package/dist/runtime/class-name-object.d.ts +0 -16
- package/dist/runtime/class-name-object.js +0 -31
- package/dist/runtime/class-name-object.js.map +0 -1
- package/dist/runtime/class-object-development.d.ts +0 -10
- package/dist/runtime/class-object-development.js +0 -18
- package/dist/runtime/class-object-development.js.map +0 -1
- package/dist/runtime/class-object.d.ts +0 -16
- package/dist/runtime/class-object.js +0 -31
- package/dist/runtime/class-object.js.map +0 -1
- package/dist/runtime/class-string-development.d.ts +0 -10
- package/dist/runtime/class-string-development.js +0 -18
- package/dist/runtime/class-string-development.js.map +0 -1
- package/dist/runtime/class-string.d.ts +0 -16
- package/dist/runtime/class-string.js +0 -31
- package/dist/runtime/class-string.js.map +0 -1
- package/dist/shared-B9IQXU6P.d.ts +0 -32
- package/dist/style-fTQbsVWZ.js.map +0 -1
package/docs/configuration.md
CHANGED
|
@@ -163,11 +163,11 @@ export default defineConfig({
|
|
|
163
163
|
});
|
|
164
164
|
```
|
|
165
165
|
|
|
166
|
-
| Preset | Contents
|
|
167
|
-
| ------------- |
|
|
168
|
-
| `recommended` | Invalid input, conflicting styles, and other likely mistakes
|
|
169
|
-
| `strict` | Every `recommended` rule as an error, and unused suppression comments
|
|
170
|
-
| `stylistic` | Preferred spellings and
|
|
166
|
+
| Preset | Contents |
|
|
167
|
+
| ------------- | -------------------------------------------------------------------------------------------------------------- |
|
|
168
|
+
| `recommended` | Invalid input, conflicting styles, and other likely mistakes |
|
|
169
|
+
| `strict` | Every `recommended` rule as an error, and unused suppression comments |
|
|
170
|
+
| `stylistic` | Preferred spellings, utility sorting, and conflict checks in every writing mode; combine it with `recommended` |
|
|
171
171
|
|
|
172
172
|
The [lint rule reference](lints/index.md) shows the severity of each rule in
|
|
173
173
|
`recommended`. Each rule page shows its severity in every preset.
|
|
@@ -222,17 +222,17 @@ const rules = {
|
|
|
222
222
|
};
|
|
223
223
|
```
|
|
224
224
|
|
|
225
|
-
| Rule | Options
|
|
226
|
-
| ---------------------------- |
|
|
227
|
-
| `conflicting-utilities` | `allowShorthandOverrides`: allows the supported overrides between shorthand and longhand utilities; defaults to `false`
|
|
228
|
-
| `invalid-marker-use` | `ignoredClasses`: marker class names that the rule ignores
|
|
229
|
-
| `no-arbitrary-spacing` | `properties`: properties to check in addition to margin, padding, and gap
|
|
230
|
-
| `no-restricted-utilities` | `utilities`: utility patterns, each with an optional message
|
|
231
|
-
| `no-restricted-declarations` | `rules`: patterns for properties and values; every matching entry applies
|
|
232
|
-
| `no-restricted-length-units` | `rules`: property patterns and the units to `disallow`; the last matching entry applies
|
|
233
|
-
| `no-restricted-theme-tokens` | `tokens`: patterns for theme custom properties; required when the rule is on
|
|
234
|
-
| `prefer-canonical-utilities` | `pxToRem` and `collapse` default to `true`; `logicalToPhysical` defaults to `false`; `preserveSpecificity` defaults to `true`. See the [rule options](lints/prefer-canonical-utilities.md#options).
|
|
235
|
-
| `prefer-variant-directive` | `pxToRem`: treats `px` and `rem` in media queries as equal at 16px per `rem`; defaults to `false`
|
|
225
|
+
| Rule | Options |
|
|
226
|
+
| ---------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
227
|
+
| `conflicting-utilities` | `allowShorthandOverrides`: allows the supported overrides between shorthand and longhand utilities; defaults to `false`. `writingModes`: writing modes in which physical and logical utilities are compared; defaults to `["horizontal-tb"]` |
|
|
228
|
+
| `invalid-marker-use` | `ignoredClasses`: marker class names that the rule ignores |
|
|
229
|
+
| `no-arbitrary-spacing` | `properties`: properties to check in addition to margin, padding, and gap |
|
|
230
|
+
| `no-restricted-utilities` | `utilities`: utility patterns, each with an optional message |
|
|
231
|
+
| `no-restricted-declarations` | `rules`: patterns for properties and values; every matching entry applies |
|
|
232
|
+
| `no-restricted-length-units` | `rules`: property patterns and the units to `disallow`; the last matching entry applies |
|
|
233
|
+
| `no-restricted-theme-tokens` | `tokens`: patterns for theme custom properties; required when the rule is on |
|
|
234
|
+
| `prefer-canonical-utilities` | `pxToRem` and `collapse` default to `true`; `logicalToPhysical` defaults to `false`; `preserveSpecificity` defaults to `true`. See the [rule options](lints/prefer-canonical-utilities.md#options). |
|
|
235
|
+
| `prefer-variant-directive` | `pxToRem`: treats `px` and `rem` in media queries as equal at 16px per `rem`; defaults to `false` |
|
|
236
236
|
|
|
237
237
|
Patterns accept `*` for any text and `?` for one character. Utility and theme
|
|
238
238
|
token patterns are case-sensitive. Property and value patterns are not.
|
package/docs/editors.md
CHANGED
|
@@ -8,7 +8,8 @@ description: "Install the Stillwind extension, sort and fix on save, and connect
|
|
|
8
8
|
The Stillwind language server shows diagnostics, generated CSS, and completion
|
|
9
9
|
from the active design system while you edit. It reads the same
|
|
10
10
|
`stillwind.config.ts` as the CLI and the build, and it checks unsaved files too.
|
|
11
|
-
Create that file with [Getting started](index.md) first.
|
|
11
|
+
Create that file with [Getting started](index.md) first. The code of each diagnostic
|
|
12
|
+
links to the page on this website that explains the rule or error.
|
|
12
13
|
|
|
13
14
|
## VS Code
|
|
14
15
|
|
package/docs/errors/SW10004.md
CHANGED
|
@@ -37,4 +37,5 @@ Write the call directly where `style()` uses it:
|
|
|
37
37
|
|
|
38
38
|
You can still store and pass the definitions themselves, such as the result of
|
|
39
39
|
[`style.ref()`](../macros/ref/index.md) or [`style.keyframes()`](../macros/keyframes.md),
|
|
40
|
-
and the result of `style()`.
|
|
40
|
+
and the result of `style()`. To reuse a ref condition, store it with
|
|
41
|
+
[`style.when()`](../macros/when.md).
|
|
@@ -46,6 +46,11 @@ A base passes on its classes only. Custom properties such as
|
|
|
46
46
|
`{ "--progress": value }` in the base do not carry over, and the CLI reports
|
|
47
47
|
them. Set custom properties in the `style()` call that is spread onto the element.
|
|
48
48
|
|
|
49
|
+
Keep the inferred type of an exported base. When TypeScript emits declaration
|
|
50
|
+
files, it writes that type with `StyleResultOf` from the framework's entrypoint.
|
|
51
|
+
A type annotation such as `StyleResult<string>` hides the identity of the base,
|
|
52
|
+
and Stillwind then cannot find the styles of the base.
|
|
53
|
+
|
|
49
54
|
## Express states with variants
|
|
50
55
|
|
|
51
56
|
Set the state as an attribute, and style it with a variant:
|
package/docs/guides/style.md
CHANGED
|
@@ -63,6 +63,27 @@ export function Link() {
|
|
|
63
63
|
}
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
+
### Match any of several variants
|
|
67
|
+
|
|
68
|
+
`or(...)` applies a utility when any of its variants matches. Separate the
|
|
69
|
+
variants with commas. Each one can contain several variants separated by colons:
|
|
70
|
+
|
|
71
|
+
```tsx
|
|
72
|
+
import { style } from "stillwind/react";
|
|
73
|
+
|
|
74
|
+
export function MenuItem() {
|
|
75
|
+
return <li {...style("px-4 py-2 or(hover,focus-within,md:aria-current):bg-gray-100")}>Inbox</li>;
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
`or(hover,md:focus):p-4` is the same as `hover:p-4 md:focus:p-4`. Each
|
|
80
|
+
variant keeps the position in the stylesheet that it has when you write it alone,
|
|
81
|
+
so [CSS order](../concepts/css-ordering.md) does not change. You can also use
|
|
82
|
+
`or(...)` in an object key, such as `{ "or(hover,focus):": "underline" }`.
|
|
83
|
+
To reuse alternatives that include
|
|
84
|
+
[ref conditions](../macros/ref/condition.md), pass several arguments to
|
|
85
|
+
[`style.when()`](../macros/when.md#alternatives).
|
|
86
|
+
|
|
66
87
|
## Style states
|
|
67
88
|
|
|
68
89
|
When the element has an attribute for the state, use a variant:
|
|
@@ -125,6 +146,17 @@ export function DeleteButton() {
|
|
|
125
146
|
In this example, `dangerButton` has a red background because both background
|
|
126
147
|
rules use equally specific selectors. The order of the class names does not
|
|
127
148
|
affect the result. You can export a stored style and use it in other modules.
|
|
149
|
+
When another module adds utilities that set the same property as the imported
|
|
150
|
+
style, [interfering-imported-style-base](../lints/interfering-imported-style-base.md)
|
|
151
|
+
reports the call. Define the overriding style in the module that defines the
|
|
152
|
+
base, and import that style instead.
|
|
153
|
+
|
|
154
|
+
The order of the arguments does not affect the result either.
|
|
155
|
+
`style("bg-red-600", button)` also produces a red background, and
|
|
156
|
+
`style("p-4", "p-2")` produces the same CSS as `style("p-2", "p-4")`. To change
|
|
157
|
+
which utility wins, remove the other utility or build a new style on a base. Do
|
|
158
|
+
not reorder the arguments. See [Argument order](../macros/style.md#argument-order)
|
|
159
|
+
for the exceptions.
|
|
128
160
|
|
|
129
161
|
More specific selectors and `!important` can change which declaration wins.
|
|
130
162
|
See [CSS ordering](../concepts/css-ordering.md) for variants, conditions, and multiple
|
|
@@ -97,15 +97,16 @@ such a class in the `class` attribute, so `style("not-prose")` adds the class
|
|
|
97
97
|
|
|
98
98
|
These features have no equivalent in Tailwind CSS:
|
|
99
99
|
|
|
100
|
-
| Feature | Page
|
|
101
|
-
| --------------------------------------- |
|
|
102
|
-
| `if()` variant and `--if()` function | [Runtime conditions](runtime-conditions.md)
|
|
103
|
-
| `host:` variant | [Style the shadow host](web-components.md#style-the-shadow-host)
|
|
104
|
-
|
|
|
105
|
-
|
|
|
106
|
-
|
|
|
107
|
-
|
|
|
108
|
-
|
|
|
100
|
+
| Feature | Page |
|
|
101
|
+
| --------------------------------------- | --------------------------------------------------------------------------------- |
|
|
102
|
+
| `if()` variant and `--if()` function | [Runtime conditions](runtime-conditions.md) |
|
|
103
|
+
| `host:` variant | [Style the shadow host](web-components.md#style-the-shadow-host) |
|
|
104
|
+
| `or(...)` variant | [Match any of several variants](style.md#match-any-of-several-variants) |
|
|
105
|
+
| Keyframes defined in a component | [Animations](animations.md) |
|
|
106
|
+
| View transitions defined in a component | [View transitions](view-transitions.md) |
|
|
107
|
+
| Refs to other elements | [Element relationships](element-relationships.md) |
|
|
108
|
+
| Logical properties for axis utilities | [Logical axis utilities](../concepts/stylesheets.md#logical-axis-utilities) |
|
|
109
|
+
| Lint rules | [Checks in the editor and CI](lint-adoption.md) |
|
|
109
110
|
|
|
110
111
|
## What Stillwind does not support
|
|
111
112
|
|
|
@@ -20,6 +20,8 @@ export const props = style(first, second);
|
|
|
20
20
|
> ambiguous-style-base-order: two composition bases declare `padding`; neither base precedes the other, so which declaration wins is undefined
|
|
21
21
|
>
|
|
22
22
|
> Example:3:22
|
|
23
|
+
>
|
|
24
|
+
> reordering the style() arguments does not change which declaration wins
|
|
23
25
|
|
|
24
26
|
## Fixed
|
|
25
27
|
|
|
@@ -34,22 +34,64 @@ style("p-4");
|
|
|
34
34
|
them, such as `p-2 md:p-4`.
|
|
35
35
|
- If one utility overrides a shared style, pass the shared style as a base. See
|
|
36
36
|
[Override a style](../guides/style.md#override-a-style).
|
|
37
|
+
- If a physical utility such as `ml-4` meets a logical utility such as `mx-auto`,
|
|
38
|
+
use logical utilities for both or physical utilities for both. The writing mode
|
|
39
|
+
decides how physical and logical properties overlap.
|
|
40
|
+
|
|
41
|
+
Some pairs do not conflict because one utility reads a custom property that the
|
|
42
|
+
other utility sets to the value it writes, so the order does not change the result:
|
|
43
|
+
|
|
44
|
+
- A side utility, such as `border-t` or `divide-y`, and a style utility, such as
|
|
45
|
+
`border-dashed` or `divide-dashed`
|
|
46
|
+
- A font size utility, such as `text-sm`, and a `leading-*` utility
|
|
47
|
+
|
|
48
|
+
A physical utility and a logical utility conflict only when they set the same
|
|
49
|
+
side in one of the writing modes that `writingModes` lists. By default, the rule
|
|
50
|
+
checks horizontal writing modes only, so `px-2 pt-2` does not conflict, but
|
|
51
|
+
`mx-auto ml-4` does.
|
|
52
|
+
|
|
53
|
+
When a physical utility meets a logical utility, the finding also shows how to
|
|
54
|
+
use logical properties for both. It names a logical utility from your design
|
|
55
|
+
system that writes the same value, such as `pbs-2` for `pt-2`, with the sides of
|
|
56
|
+
horizontal left-to-right writing modes. The finding does not prefer logical
|
|
57
|
+
properties; you can also replace the logical utility with physical utilities. It
|
|
58
|
+
names no utility when `writingModes` does not include `horizontal-tb`.
|
|
37
59
|
|
|
38
60
|
## Options
|
|
39
61
|
|
|
40
62
|
`allowShorthandOverrides` allows the supported overrides between a shorthand
|
|
41
63
|
utility and a longhand utility. The rule still reports other conflicts.
|
|
42
64
|
|
|
65
|
+
`writingModes` lists the CSS `writing-mode` values in which the rule compares
|
|
66
|
+
physical and logical utilities: `horizontal-tb`, `vertical-rl`, and
|
|
67
|
+
`vertical-lr`. The rule checks both the left-to-right and the right-to-left
|
|
68
|
+
direction of each mode. `sideways-rl` and `sideways-lr` place the sides as
|
|
69
|
+
`vertical-rl` and `vertical-lr` do. The default is `["horizontal-tb"]`, and the
|
|
70
|
+
`stylistic` preset lists all three. Add the vertical modes if your pages use
|
|
71
|
+
vertical text:
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
const rules = {
|
|
75
|
+
"conflicting-utilities": {
|
|
76
|
+
writingModes: ["horizontal-tb", "vertical-rl"],
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Utilities that conflict in every writing mode, such as `p-2 px-4`, are reported
|
|
82
|
+
even when the list is empty.
|
|
83
|
+
|
|
43
84
|
## Rule settings
|
|
44
85
|
|
|
45
86
|
| Preset | Severity |
|
|
46
87
|
| --- | --- |
|
|
47
88
|
| `recommended` | warn |
|
|
48
89
|
| `strict` | deny |
|
|
49
|
-
| `stylistic` |
|
|
90
|
+
| `stylistic` | warn |
|
|
50
91
|
|
|
51
92
|
| Option | Default |
|
|
52
93
|
| --- | --- |
|
|
53
94
|
| `allowShorthandOverrides` | `false` |
|
|
95
|
+
| `writingModes` | `["horizontal-tb"]` |
|
|
54
96
|
|
|
55
97
|
[Configure lint](../configuration.md#lint) to change the severity or options.
|
package/docs/lints/index.md
CHANGED
|
@@ -44,6 +44,7 @@ report never matches.
|
|
|
44
44
|
| [invalid-ref-input](invalid-ref-input.md) | A [`style.ref()`](../macros/ref/index.md) label or ref method argument that is not a literal | deny |
|
|
45
45
|
| [invalid-rule-group-input](invalid-rule-group-input.md) | A `class` field or ref inside a variant key of [`style()`](../macros/style.md) | deny |
|
|
46
46
|
| [invalid-runtime-condition](invalid-runtime-condition.md) | A runtime CSS condition that Stillwind cannot compile | deny |
|
|
47
|
+
| [invalid-stored-variant](invalid-stored-variant.md) | A [`style.when()`](../macros/when.md) argument that is not a sequence of variants | deny |
|
|
47
48
|
| [invalid-style-composition](invalid-style-composition.md) | Inline styles or custom properties in a base style, which do not carry over | deny |
|
|
48
49
|
| [invalid-style-input](invalid-style-input.md) | A [`style()`](../macros/style.md) argument that it cannot compile, such as a number | deny |
|
|
49
50
|
| [invalid-view-transition-definition](invalid-view-transition-definition.md) | An unknown field in a [`style.viewTransition()`](../macros/view-transition.md) definition | deny |
|
|
@@ -6,8 +6,13 @@ description: "Reports an imported base style that sets the same property as anot
|
|
|
6
6
|
# interfering-imported-style-base
|
|
7
7
|
|
|
8
8
|
This rule reports a base style from another module that sets the same property as
|
|
9
|
-
another base or utility in the call, when neither is built on the other. The
|
|
10
|
-
|
|
9
|
+
another base or utility in the call, when neither is built on the other. The rule
|
|
10
|
+
reports both cases:
|
|
11
|
+
|
|
12
|
+
- Two imported bases set the same property. The order of the arguments does not
|
|
13
|
+
decide which base wins.
|
|
14
|
+
- An imported base and a utility of the call set the same property. The utility of
|
|
15
|
+
the call wins, but the rule still reports the call.
|
|
11
16
|
|
|
12
17
|
## Project files
|
|
13
18
|
|
|
@@ -23,11 +28,20 @@ export const combined = style(first, "p-4");
|
|
|
23
28
|
```tsx
|
|
24
29
|
import { first, second } from "./bases";
|
|
25
30
|
export const props = style(first, second);
|
|
31
|
+
export const padded = style(first, "p-4");
|
|
26
32
|
```
|
|
27
33
|
|
|
28
34
|
> interfering-imported-style-base: the base in `bases.ts` overlaps these declarations: `padding`
|
|
29
35
|
>
|
|
30
36
|
> Example:2:22
|
|
37
|
+
>
|
|
38
|
+
> reordering the style() arguments does not change which declaration wins
|
|
39
|
+
|
|
40
|
+
> interfering-imported-style-base: the base in `bases.ts` overlaps these declarations: `padding`
|
|
41
|
+
>
|
|
42
|
+
> Example:3:23
|
|
43
|
+
>
|
|
44
|
+
> reordering the style() arguments does not change which declaration wins
|
|
31
45
|
|
|
32
46
|
## Fixed
|
|
33
47
|
|
|
@@ -36,13 +50,17 @@ import { combined } from "./bases";
|
|
|
36
50
|
export const props = style(combined);
|
|
37
51
|
```
|
|
38
52
|
|
|
53
|
+
`combined` replaces both reported calls, because it sets `p-4` on top of `first`
|
|
54
|
+
in the module that defines `first`.
|
|
55
|
+
|
|
39
56
|
## How to fix
|
|
40
57
|
|
|
41
58
|
- In the module that defines the styles, build the overriding style on the other
|
|
42
59
|
one, as `combined` does. Then import that style.
|
|
43
60
|
- Or remove the property from one of the styles.
|
|
44
61
|
|
|
45
|
-
|
|
62
|
+
Reordering the arguments does not fix it. `style("p-4", first)` and
|
|
63
|
+
`style(second, first)` produce the same CSS and the same finding.
|
|
46
64
|
|
|
47
65
|
## Rule settings
|
|
48
66
|
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "invalid-stored-variant"
|
|
3
|
+
description: "Reports a style.when() argument that is not a sequence of variants, or a use that can refer to several stored variants."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# invalid-stored-variant
|
|
7
|
+
|
|
8
|
+
This rule reports a [`style.when()`](../macros/when.md) call whose argument is
|
|
9
|
+
not one sequence of variants. It also reports a use of a stored variant that
|
|
10
|
+
can refer to more than one `style.when()` call. The compiler expands stored
|
|
11
|
+
variants at build time, so it must know the variants exactly.
|
|
12
|
+
|
|
13
|
+
A use of an invalid stored variant adds no CSS.
|
|
14
|
+
|
|
15
|
+
## Reported
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
declare const name: string;
|
|
19
|
+
const selected = style.when(name);
|
|
20
|
+
style({ [selected]: "font-bold" });
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
> invalid-stored-variant: style.when() requires one static variant sequence: the argument is not a variant string, a ref variant, or a stored variant
|
|
24
|
+
>
|
|
25
|
+
> Example:2:29
|
|
26
|
+
|
|
27
|
+
## Fixed
|
|
28
|
+
|
|
29
|
+
```tsx
|
|
30
|
+
const selected = style.when("aria-selected");
|
|
31
|
+
style({ [selected]: "font-bold" });
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## How to fix
|
|
35
|
+
|
|
36
|
+
- Pass a string literal of variants, a ref condition, a container query, or a
|
|
37
|
+
template literal whose interpolations are ref conditions or stored variants.
|
|
38
|
+
- Declare a stored variant before another `style.when()` call uses it.
|
|
39
|
+
- To choose between stored variants at runtime, write a key for each one and
|
|
40
|
+
guard the values, such as `{ [a]: active && "p-4", [b]: !active && "p-4" }`.
|
|
41
|
+
|
|
42
|
+
See [`style.when()`](../macros/when.md#inputs).
|
|
43
|
+
|
|
44
|
+
## Rule settings
|
|
45
|
+
|
|
46
|
+
| Preset | Severity |
|
|
47
|
+
| --- | --- |
|
|
48
|
+
| `recommended` | deny |
|
|
49
|
+
| `strict` | deny |
|
|
50
|
+
| `stylistic` | off |
|
|
51
|
+
|
|
52
|
+
[Configure lint](../configuration.md#lint) to change the severity or options.
|
package/docs/macros/cva.md
CHANGED
|
@@ -44,9 +44,9 @@ export const props = button({ size: "large" });
|
|
|
44
44
|
### Compiled code
|
|
45
45
|
|
|
46
46
|
```ts
|
|
47
|
-
import {
|
|
47
|
+
import { stillwindClassNameObjectCva } from "stillwind/runtime";
|
|
48
48
|
|
|
49
|
-
export const button =
|
|
49
|
+
export const button = stillwindClassNameObjectCva("sw_ilpwh", {
|
|
50
50
|
variants: {
|
|
51
51
|
size: {
|
|
52
52
|
small: "sw_h1m4c",
|
|
@@ -145,8 +145,9 @@ The props that the factory returns cannot be passed to `style()` as a base.
|
|
|
145
145
|
|
|
146
146
|
## Generated code
|
|
147
147
|
|
|
148
|
-
The compiler creates the factory with
|
|
149
|
-
together with the compiled class names.
|
|
148
|
+
The compiler creates the factory with a helper from `stillwind/runtime`, such as
|
|
149
|
+
`stillwindClassNameObjectCva` for React, together with the compiled class names.
|
|
150
|
+
Factory calls stay ordinary JavaScript.
|
|
150
151
|
The development build checks the selected values and the classes from other
|
|
151
152
|
stylesheets.
|
|
152
153
|
|
package/docs/macros/index.md
CHANGED
|
@@ -16,6 +16,7 @@ and it shows the generated JavaScript and CSS for its examples.
|
|
|
16
16
|
| [`style.anchorScope()`](anchor-scope.md) | Limit where an anchor name is visible | [Element relationships](../guides/element-relationships.md) |
|
|
17
17
|
| [`style.keyframes()`](keyframes.md) | Define an animation in a component | [Animations](../guides/animations.md) |
|
|
18
18
|
| [`style.viewTransition()`](view-transition.md) | Style view transition snapshots and name each item | [View transitions](../guides/view-transitions.md) |
|
|
19
|
+
| [`style.when()`](when.md) | Reuse a variant sequence, such as a ref condition | [Element relationships](../guides/element-relationships.md) |
|
|
19
20
|
| [`style.media()`](media.md) | Use a named breakpoint as a media query in JavaScript | [Responsive styles](../guides/responsive-styles.md) |
|
|
20
21
|
| [`style.css()`](css.md) | Compile utilities into a CSS string for a shadow root | [Web Components](../guides/web-components.md) |
|
|
21
22
|
| [`style.cva()`](cva.md) | Migrate components that use `cva` | [Migrating from Tailwind CSS](../guides/migrating-from-tailwind.md) |
|
package/docs/macros/ref/at.md
CHANGED
|
@@ -63,7 +63,7 @@ Without a query, the condition matches whenever the styled element is inside a
|
|
|
63
63
|
container with the name.
|
|
64
64
|
|
|
65
65
|
Write the call directly as a computed key in [`style()`](../style.md).
|
|
66
|
-
|
|
66
|
+
To use it in several places, store it with [`style.when()`](../when.md).
|
|
67
67
|
|
|
68
68
|
See [Element relationships](../../guides/element-relationships.md#react-to-a-containers-size)
|
|
69
69
|
for a task-based example.
|
|
@@ -72,7 +72,8 @@ You can also write it as a variant segment inside a utility template, followed b
|
|
|
72
72
|
style(`${card("hover")}:text-blue-600`);
|
|
73
73
|
```
|
|
74
74
|
|
|
75
|
-
|
|
75
|
+
To use the same condition in several places, store it with
|
|
76
|
+
[`style.when()`](../when.md).
|
|
76
77
|
|
|
77
78
|
## Behavior
|
|
78
79
|
|
package/docs/macros/ref/in.md
CHANGED
|
@@ -75,7 +75,7 @@ Calling `.in()` more than once adds each scope as another condition, and every
|
|
|
75
75
|
condition must match.
|
|
76
76
|
|
|
77
77
|
Write the whole chain directly as a computed key in [`style()`](../style.md).
|
|
78
|
-
|
|
78
|
+
To use it in several places, store it with [`style.when()`](../when.md).
|
|
79
79
|
|
|
80
80
|
See [Element relationships](../../guides/element-relationships.md#react-to-a-siblings-state)
|
|
81
81
|
for a task-based example.
|
package/docs/macros/ref/index.md
CHANGED
|
@@ -101,7 +101,8 @@ nearest one.
|
|
|
101
101
|
| [`ref.positionAnchor()`](position-anchor.md) | A `style()` argument | Positions the styled element against the anchor |
|
|
102
102
|
|
|
103
103
|
Write each method call directly in `style()`. You cannot store the result of a
|
|
104
|
-
method call in a variable and use it later.
|
|
104
|
+
method call in a variable and use it later. To reuse a ref condition or a
|
|
105
|
+
container query, store it with [`style.when()`](../when.md).
|
|
105
106
|
|
|
106
107
|
## Generated code
|
|
107
108
|
|
package/docs/macros/style.md
CHANGED
|
@@ -85,7 +85,7 @@ export const props = style("p-4", active && "bg-blue-500", {
|
|
|
85
85
|
### Compiled code
|
|
86
86
|
|
|
87
87
|
```ts
|
|
88
|
-
import { stillwindClsx } from "stillwind/runtime
|
|
88
|
+
import { stillwindClsx } from "stillwind/runtime";
|
|
89
89
|
|
|
90
90
|
declare const active: boolean;
|
|
91
91
|
export const props = {className:stillwindClsx("sw_4td0b",(active) && ("sw_dq3t9")),style:{"--progress":"0.5"}};
|
|
@@ -126,10 +126,10 @@ export const props = style(base, "p-4 bg-blue-600 text-white");
|
|
|
126
126
|
### Compiled code
|
|
127
127
|
|
|
128
128
|
```ts
|
|
129
|
-
import {
|
|
129
|
+
import { stillwindClassNameObjectClassKey, stillwindClassNameObjectMerge, stillwindClassNameObjectToFragment } from "stillwind/runtime";
|
|
130
130
|
|
|
131
131
|
const base = {className:"sw_lqeqi"};
|
|
132
|
-
export const props =
|
|
132
|
+
export const props = stillwindClassNameObjectMerge({[stillwindClassNameObjectClassKey]:"sw_cb2cz"},stillwindClassNameObjectToFragment((base)));
|
|
133
133
|
```
|
|
134
134
|
|
|
135
135
|
### Generated CSS
|
|
@@ -153,15 +153,41 @@ The receiving call returns its own framework's props. The base's inline style an
|
|
|
153
153
|
custom properties do not carry over, and [invalid-style-composition](../lints/invalid-style-composition.md)
|
|
154
154
|
reports them. Set them in the call that receives the base.
|
|
155
155
|
|
|
156
|
-
When two independent bases in one call set the same property, their argument
|
|
157
|
-
order does not decide which one wins.
|
|
158
|
-
[ambiguous-style-base-order](../lints/ambiguous-style-base-order.md) reports
|
|
159
|
-
this case.
|
|
160
|
-
|
|
161
156
|
Store a base in a variable before you pass it. A `style()` call written
|
|
162
157
|
directly inside another call produces no CSS, and
|
|
163
158
|
[invalid-style-input](../lints/invalid-style-input.md) reports it.
|
|
164
159
|
|
|
160
|
+
## Argument order
|
|
161
|
+
|
|
162
|
+
For utilities and bases, the position of an argument does not decide which
|
|
163
|
+
declaration wins. A later argument does not override an earlier one:
|
|
164
|
+
|
|
165
|
+
| Arguments | Which CSS comes later |
|
|
166
|
+
| ------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------- |
|
|
167
|
+
| Utilities without a condition, in strings, arrays, or variant keys | The stylesheet's order of utility definitions decides. The order in the call and in each string does not. |
|
|
168
|
+
| A base and the utilities of the call | The utilities of the call. `style("p-4", base)` and `style(base, "p-4")` produce the same CSS. |
|
|
169
|
+
| Two bases | The base that is built on the other one. When neither is built on the other, the argument order does not decide. |
|
|
170
|
+
| Items with a condition | They come after the items without a condition, in the order in which you write them. |
|
|
171
|
+
|
|
172
|
+
These calls produce the same CSS, and `p-4` wins in both:
|
|
173
|
+
|
|
174
|
+
```tsx
|
|
175
|
+
style("p-2", "p-4");
|
|
176
|
+
style("p-4", "p-2");
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Custom properties in the inline style follow argument order. When two
|
|
180
|
+
arguments set the same custom property, the later one wins.
|
|
181
|
+
|
|
182
|
+
Do not reorder arguments to fix a conflict. Reordering does not change the
|
|
183
|
+
result, and it does not remove a finding of
|
|
184
|
+
[conflicting-utilities](../lints/conflicting-utilities.md),
|
|
185
|
+
[ambiguous-style-base-order](../lints/ambiguous-style-base-order.md), or
|
|
186
|
+
[interfering-imported-style-base](../lints/interfering-imported-style-base.md).
|
|
187
|
+
Remove the utility that should not apply, or build the overriding style on the
|
|
188
|
+
other style. [CSS ordering](../concepts/css-ordering.md) describes the complete
|
|
189
|
+
rules.
|
|
190
|
+
|
|
165
191
|
## How props combine at runtime
|
|
166
192
|
|
|
167
193
|
When the compiler cannot reduce a call to a plain object, a runtime helper
|
|
@@ -113,7 +113,7 @@ export const props = style(transition.for(id));
|
|
|
113
113
|
### Compiled code
|
|
114
114
|
|
|
115
115
|
```ts
|
|
116
|
-
import { stillwindViewTransitionName } from "stillwind/runtime
|
|
116
|
+
import { stillwindViewTransitionName } from "stillwind/runtime";
|
|
117
117
|
|
|
118
118
|
const transition = undefined;
|
|
119
119
|
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "style.when()"
|
|
3
|
+
description: "Store a variant sequence or alternatives, such as a ref condition, and use them in several style() calls."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# style.when()
|
|
7
|
+
|
|
8
|
+
`style.when(...variants)` stores a sequence of variants in a variable. Use the
|
|
9
|
+
variable in [`style()`](style.md) where you would write the variants.
|
|
10
|
+
This helps when several elements need the same
|
|
11
|
+
[ref condition](ref/condition.md), because a ref call must otherwise
|
|
12
|
+
be repeated in each `style()` call.
|
|
13
|
+
|
|
14
|
+
## Example
|
|
15
|
+
|
|
16
|
+
### Source
|
|
17
|
+
|
|
18
|
+
```tsx
|
|
19
|
+
import { style } from "stillwind/react";
|
|
20
|
+
|
|
21
|
+
const card = style.ref("card");
|
|
22
|
+
const cardHover = style.when(card("hover"));
|
|
23
|
+
|
|
24
|
+
export const root = style(card, "rounded-lg border");
|
|
25
|
+
export const title = style({ [cardHover]: "text-blue-600" });
|
|
26
|
+
export const arrow = style(`${cardHover}:translate-x-1`);
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Compiled code
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
const card = undefined;
|
|
33
|
+
const cardHover = undefined;
|
|
34
|
+
|
|
35
|
+
export const root = {className:"sw_hd4rc sw_card_uryy0"};
|
|
36
|
+
export const title = {className:"sw_fqux0"};
|
|
37
|
+
export const arrow = {className:"sw_zu1vf"};
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Generated CSS
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
```css
|
|
44
|
+
.sw_hd4rc {
|
|
45
|
+
border-radius: var(--radius-lg);
|
|
46
|
+
border-style: var(--tw-border-style);
|
|
47
|
+
border-width: 1px;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@media (hover: hover) {
|
|
51
|
+
.sw_fqux0:is(:where(.sw_card_uryy0):hover *) {
|
|
52
|
+
color: var(--color-blue-600);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
@media (hover: hover) {
|
|
57
|
+
.sw_zu1vf:is(:where(.sw_card_uryy0):hover *) {
|
|
58
|
+
--tw-translate-x: calc(var(--spacing) * 1);
|
|
59
|
+
translate: var(--tw-translate-x) var(--tw-translate-y);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
`title` and `arrow` change while the card is hovered, as if each one wrote
|
|
65
|
+
`card("hover")` itself.
|
|
66
|
+
|
|
67
|
+
## Inputs
|
|
68
|
+
|
|
69
|
+
Each argument is one sequence of variants, and every variant in it must match.
|
|
70
|
+
The final colon is optional.
|
|
71
|
+
|
|
72
|
+
| Form | Example |
|
|
73
|
+
| ------------------------------------------------------------- | --------------------------------------- |
|
|
74
|
+
| A string literal of variants | `style.when("hover:md")` |
|
|
75
|
+
| A [ref condition](ref/condition.md), with `.in()` | `style.when(card("hover").in(list))` |
|
|
76
|
+
| A [container query](ref/at.md) | `style.when(card.at("width >= 40rem"))` |
|
|
77
|
+
| A template literal whose interpolations are complete variants | ``style.when(`md:${card("hover")}`)`` |
|
|
78
|
+
| Another stored variant | `style.when(cardHover)` |
|
|
79
|
+
|
|
80
|
+
The rules for each variant are the same as when you write it directly in
|
|
81
|
+
`style()`. An interpolation in a template literal must be a ref condition, a
|
|
82
|
+
container query, or a stored variant, followed by `:` or at the end.
|
|
83
|
+
|
|
84
|
+
Write the call as the initial value of a variable, outside other Stillwind
|
|
85
|
+
calls. Declare a stored variant before another `style.when()` call uses it.
|
|
86
|
+
A `style()` call can use one that is declared later in the module.
|
|
87
|
+
|
|
88
|
+
[invalid-stored-variant](../lints/invalid-stored-variant.md) reports an
|
|
89
|
+
argument that is not a sequence of variants.
|
|
90
|
+
|
|
91
|
+
## Alternatives
|
|
92
|
+
|
|
93
|
+
With several arguments, the stored variant matches when any argument matches:
|
|
94
|
+
|
|
95
|
+
```tsx
|
|
96
|
+
const card = style.ref("card");
|
|
97
|
+
const active = style.when("hover", card("focus-within"));
|
|
98
|
+
|
|
99
|
+
export const title = style({ [active]: "text-blue-600" });
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
A use means the same as writing the use once for each argument, in argument
|
|
103
|
+
order. `title` is equal to
|
|
104
|
+
`style({ "hover:": "text-blue-600", [card("focus-within")]: "text-blue-600" })`.
|
|
105
|
+
Unlike an [`or(...)`](../guides/style.md#match-any-of-several-variants)
|
|
106
|
+
variant, the arguments can be ref conditions and container queries.
|
|
107
|
+
|
|
108
|
+
## Uses
|
|
109
|
+
|
|
110
|
+
Use a stored variant in these positions:
|
|
111
|
+
|
|
112
|
+
- a computed key in a `style()` object, such as `{ [cardHover]: "underline" }`;
|
|
113
|
+
- an interpolation in a utility template, followed by `:`, such as
|
|
114
|
+
`` `${cardHover}:underline` ``;
|
|
115
|
+
- the argument of another `style.when()`.
|
|
116
|
+
|
|
117
|
+
You can export the variable and import it in another module. Each use must
|
|
118
|
+
refer to one stored variant. A choice at runtime, such as
|
|
119
|
+
`[active ? cardHover : cardFocus]`, does not work, because the compiler
|
|
120
|
+
expands the variants at build time. Write a key for each stored variant instead.
|
|
121
|
+
|
|
122
|
+
[`style.cva()`](cva.md) values and [`.in()`](ref/in.md)
|
|
123
|
+
do not accept a stored variant.
|
|
124
|
+
|
|
125
|
+
## Output
|
|
126
|
+
|
|
127
|
+
The compiler replaces the call with `undefined`, and each use with the stored
|
|
128
|
+
variants. The call adds no CSS by itself. JavaScript that reads the variable at
|
|
129
|
+
runtime gets `undefined`.
|