Skip to content

Commit

Permalink
Merge pull request #84 from primer/new-css-vars-docs
Browse files Browse the repository at this point in the history
Add docs for `new-css-color-vars` linter
  • Loading branch information
langermank authored Oct 9, 2023
2 parents 35f0ffe + 56c7371 commit fa87e16
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ ESLint rules for Primer React
- [no-system-props](https://github.com/primer/eslint-plugin-primer-react/blob/main/docs/rules/no-system-props.md)
- [a11y-tooltip-interactive-trigger](https://github.com/primer/eslint-plugin-primer-react/blob/main/docs/rules/a11y-tooltip-interactive-trigger.md)
- [a11y-explicit-heading](https://github.com/primer/eslint-plugin-primer-react/blob/main/docs/rules/a11y-explicit-heading.md)
- [new-css-color-vars](https://github.com/primer/eslint-plugin-primer-react/blob/main/docs/rules/new-css-color-vars.md)
35 changes: 35 additions & 0 deletions docs/rules/new-css-color-vars.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
## Upgrade legacy color CSS variables to Primitives v8 in sx prop

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.

## Rule Details

This rule looks inside the `sx` prop for the following properties:

```
'bg',
'backgroundColor',
'color',
'borderColor',
'borderTopColor',
'borderRightColor',
'borderBottomColor',
'borderLeftColor',
'border',
'boxShadow',
'caretColor'
```

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.

👎 Examples of **incorrect** code for this rule

```jsx
<Button sx={{color: 'var(--color-fg-muted)'}}>Test</Button>
```

👍 Examples of **correct** code for this rule:

```jsx
<Button sx={{color: 'var(--fgColor-muted, var(--color-fg-muted))'}}>Test</Button>
```

0 comments on commit fa87e16

Please sign in to comment.