Skip to content

Commit 56c7371

Browse files
committed
add docs
1 parent 35f0ffe commit 56c7371

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@ ESLint rules for Primer React
3434
- [no-system-props](https://github.com/primer/eslint-plugin-primer-react/blob/main/docs/rules/no-system-props.md)
3535
- [a11y-tooltip-interactive-trigger](https://github.com/primer/eslint-plugin-primer-react/blob/main/docs/rules/a11y-tooltip-interactive-trigger.md)
3636
- [a11y-explicit-heading](https://github.com/primer/eslint-plugin-primer-react/blob/main/docs/rules/a11y-explicit-heading.md)
37+
- [new-css-color-vars](https://github.com/primer/eslint-plugin-primer-react/blob/main/docs/rules/new-css-color-vars.md)

docs/rules/new-css-color-vars.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
## Upgrade legacy color CSS variables to Primitives v8 in sx prop
2+
3+
CSS variables are allowed within the `sx` prop in Primer React components. However, the legacy color CSS variables are deprecated in favor of the new CSS variables introduced in Primitives v8. This rule will warn you if you are using the deprecated color CSS variables in the `sx` prop, and autofix it including a fallback to the old value.
4+
5+
## Rule Details
6+
7+
This rule looks inside the `sx` prop for the following properties:
8+
9+
```
10+
'bg',
11+
'backgroundColor',
12+
'color',
13+
'borderColor',
14+
'borderTopColor',
15+
'borderRightColor',
16+
'borderBottomColor',
17+
'borderLeftColor',
18+
'border',
19+
'boxShadow',
20+
'caretColor'
21+
```
22+
23+
The rule references a static JSON file called `css-variable-map.json` that matches the old color CSS variables to a new one based on the property. We only check `sx` because `stylelint` is used to lint other forms of CSS-in-JS.
24+
25+
👎 Examples of **incorrect** code for this rule
26+
27+
```jsx
28+
<Button sx={{color: 'var(--color-fg-muted)'}}>Test</Button>
29+
```
30+
31+
👍 Examples of **correct** code for this rule:
32+
33+
```jsx
34+
<Button sx={{color: 'var(--fgColor-muted, var(--color-fg-muted))'}}>Test</Button>
35+
```

0 commit comments

Comments
 (0)