@atlaskit/eslint-plugin-ui-styling-standard 0.15.0 → 0.15.1
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 +180 -172
- package/constellation/atlaskit-theme/usage.mdx +17 -17
- package/constellation/convert-props-syntax/usage.mdx +14 -14
- package/constellation/enforce-style-prop/usage.mdx +17 -17
- package/constellation/index/overview.mdx +70 -70
- package/constellation/local-cx-xcss/usage.mdx +4 -4
- package/constellation/no-array-arguments/usage.mdx +7 -7
- package/constellation/no-container-queries/usage.mdx +14 -14
- package/constellation/no-dynamic-styles/usage.mdx +19 -19
- package/constellation/no-exported-styles/usage.mdx +15 -15
- package/constellation/no-global-styles/usage.mdx +13 -13
- package/constellation/no-important-styles/usage.mdx +2 -2
- package/constellation/no-imported-style-values/usage.mdx +16 -16
- package/constellation/no-nested-selectors/usage.mdx +18 -18
- package/constellation/no-styled/usage.mdx +6 -6
- package/constellation/no-unsafe-selectors/usage.mdx +90 -90
- package/constellation/no-unsafe-values/usage.mdx +33 -33
- package/dist/cjs/index.codegen.js +1 -1
- package/dist/cjs/presets/all.codegen.js +1 -1
- package/dist/cjs/presets/recommended.codegen.js +1 -1
- package/dist/cjs/rules/index.codegen.js +1 -1
- package/dist/cjs/rules/no-unsafe-selectors/index.js +4 -1
- package/dist/cjs/rules/no-unsafe-selectors/lint-selector.js +10 -1
- package/dist/es2019/index.codegen.js +1 -1
- package/dist/es2019/presets/all.codegen.js +1 -1
- package/dist/es2019/presets/recommended.codegen.js +1 -1
- package/dist/es2019/rules/index.codegen.js +1 -1
- package/dist/es2019/rules/no-unsafe-selectors/index.js +4 -1
- package/dist/es2019/rules/no-unsafe-selectors/lint-selector.js +10 -1
- package/dist/esm/index.codegen.js +1 -1
- package/dist/esm/presets/all.codegen.js +1 -1
- package/dist/esm/presets/recommended.codegen.js +1 -1
- package/dist/esm/rules/index.codegen.js +1 -1
- package/dist/esm/rules/no-unsafe-selectors/index.js +4 -1
- package/dist/esm/rules/no-unsafe-selectors/lint-selector.js +10 -1
- package/dist/types/presets/all.codegen.d.ts +1 -1
- package/dist/types/presets/recommended.codegen.d.ts +1 -1
- package/dist/types/rules/no-unsafe-selectors/lint-selector.d.ts +1 -0
- package/dist/types-ts4.5/presets/all.codegen.d.ts +1 -1
- package/dist/types-ts4.5/presets/recommended.codegen.d.ts +1 -1
- package/dist/types-ts4.5/rules/no-unsafe-selectors/lint-selector.d.ts +1 -0
- package/package.json +2 -4
- package/src/index.codegen.tsx +3 -3
- package/src/presets/all.codegen.tsx +70 -73
- package/src/presets/recommended.codegen.tsx +70 -73
- package/src/rules/index.codegen.tsx +18 -18
- package/src/rules/no-unsafe-selectors/__tests__/no-ambiguous-pseudos.test.tsx +211 -201
- package/src/rules/no-unsafe-selectors/index.tsx +174 -177
- package/src/rules/no-unsafe-selectors/lint-selector.tsx +128 -141
- package/tsconfig.app.json +45 -45
- package/tsconfig.dev.json +43 -43
|
@@ -16,7 +16,7 @@ import { styled } from '@compiled/react';
|
|
|
16
16
|
import { typography } from '@atlaskit/theme';
|
|
17
17
|
|
|
18
18
|
export const HeadingComponent = styled.h2`
|
|
19
|
-
|
|
19
|
+
${typography.h200()};
|
|
20
20
|
`;
|
|
21
21
|
```
|
|
22
22
|
|
|
@@ -33,7 +33,7 @@ export const HeadingComponent = styled.h2(typography.h200());
|
|
|
33
33
|
import { styled } from '@compiled/react';
|
|
34
34
|
|
|
35
35
|
const HeadingComponent = styled.h2({
|
|
36
|
-
|
|
36
|
+
fontSize: '20px',
|
|
37
37
|
});
|
|
38
38
|
```
|
|
39
39
|
|
|
@@ -43,13 +43,13 @@ import { token } from '@atlaskit/tokens';
|
|
|
43
43
|
import { styled } from '@compiled/react';
|
|
44
44
|
|
|
45
45
|
const TitleComponent = styled.span({
|
|
46
|
-
|
|
46
|
+
marginTop: token('space.150', '12px'),
|
|
47
47
|
});
|
|
48
48
|
|
|
49
49
|
export const Title = (props) => (
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
<Heading level="h200" as="h3">
|
|
51
|
+
<TitleComponent {...props} />
|
|
52
|
+
</Heading>
|
|
53
53
|
);
|
|
54
54
|
```
|
|
55
55
|
|
|
@@ -64,7 +64,7 @@ import { styled } from '@compiled/react';
|
|
|
64
64
|
import { elevation } from '@atlaskit/theme';
|
|
65
65
|
|
|
66
66
|
export const ElevationComponent = styled.div`
|
|
67
|
-
|
|
67
|
+
${elevation.e100()};
|
|
68
68
|
`;
|
|
69
69
|
```
|
|
70
70
|
|
|
@@ -75,10 +75,10 @@ import { styled } from '@compiled/react';
|
|
|
75
75
|
import { token } from '@atlaskit/tokens';
|
|
76
76
|
|
|
77
77
|
export const TestComponent = styled.div({
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
78
|
+
boxShadow: token(
|
|
79
|
+
'elevation.shadow.raised',
|
|
80
|
+
'0 1px 1px rgba(9,30,66,0.25),0 0 1px 1px rgba(9,30,66,0.13)',
|
|
81
|
+
),
|
|
82
82
|
});
|
|
83
83
|
```
|
|
84
84
|
|
|
@@ -96,7 +96,7 @@ import { styled } from '@compiled/react';
|
|
|
96
96
|
import { skeletonShimmer } from '@atlaskit/theme/constants';
|
|
97
97
|
|
|
98
98
|
export const SkeletonShimmerComponent = styled.div`
|
|
99
|
-
|
|
99
|
+
${skeletonShimmer};
|
|
100
100
|
`;
|
|
101
101
|
```
|
|
102
102
|
|
|
@@ -104,10 +104,10 @@ export const SkeletonShimmerComponent = styled.div`
|
|
|
104
104
|
|
|
105
105
|
```tsx
|
|
106
106
|
export const SkeletonShimmerComponent = () => {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
107
|
+
return (
|
|
108
|
+
<Wrapper>
|
|
109
|
+
<object data="./skeleton.svg" type="image/svg+xml"></object>
|
|
110
|
+
</Wrapper>
|
|
111
|
+
);
|
|
112
112
|
};
|
|
113
113
|
```
|
|
@@ -9,8 +9,8 @@ These libraries do not support having an arrow function inside a CSS value:
|
|
|
9
9
|
|
|
10
10
|
```js
|
|
11
11
|
styled.div({
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
color: ({ myColor }) => myColor,
|
|
13
|
+
backgroundColor: (props) => props.someColor,
|
|
14
14
|
});
|
|
15
15
|
```
|
|
16
16
|
|
|
@@ -19,8 +19,8 @@ issue:
|
|
|
19
19
|
|
|
20
20
|
```js
|
|
21
21
|
styled.div((props) => ({
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
color: props.myColor,
|
|
23
|
+
backgroundColor: props.someColor,
|
|
24
24
|
}));
|
|
25
25
|
```
|
|
26
26
|
|
|
@@ -73,8 +73,8 @@ remediated manually. For example:
|
|
|
73
73
|
|
|
74
74
|
```js
|
|
75
75
|
styled.div({
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
color: ({ myColor = '#fff' }) => myColor,
|
|
77
|
+
backgroundColor: ({ myColor = '#aaa' }) => myColor,
|
|
78
78
|
});
|
|
79
79
|
```
|
|
80
80
|
|
|
@@ -82,8 +82,8 @@ could potentially be remediated with
|
|
|
82
82
|
|
|
83
83
|
```js
|
|
84
84
|
styled.div((props) => ({
|
|
85
|
-
|
|
86
|
-
|
|
85
|
+
color: myColor ?? '#fff',
|
|
86
|
+
backgroundColor: myColor ?? '#aaa',
|
|
87
87
|
}));
|
|
88
88
|
```
|
|
89
89
|
|
|
@@ -95,12 +95,12 @@ styled.div((props) => ({
|
|
|
95
95
|
import styled from 'styled-components';
|
|
96
96
|
|
|
97
97
|
styled.div({
|
|
98
|
-
|
|
99
|
-
|
|
98
|
+
color: ({ myColor }) => myColor,
|
|
99
|
+
backgroundColor: (props) => props.someColor,
|
|
100
100
|
});
|
|
101
101
|
|
|
102
102
|
styled.div({
|
|
103
|
-
|
|
103
|
+
color: `url(/tmp/${({ coolProp }) => coolProp}.png)`,
|
|
104
104
|
});
|
|
105
105
|
```
|
|
106
106
|
|
|
@@ -110,12 +110,12 @@ styled.div({
|
|
|
110
110
|
import styled from '@emotion/styled';
|
|
111
111
|
|
|
112
112
|
styled.div((props) => ({
|
|
113
|
-
|
|
114
|
-
|
|
113
|
+
color: props.myColor,
|
|
114
|
+
backgroundColor: props.someColor,
|
|
115
115
|
}));
|
|
116
116
|
|
|
117
117
|
styled.div((props) => ({
|
|
118
|
-
|
|
118
|
+
color: url(`/tmp/${coolProp}.png`),
|
|
119
119
|
}));
|
|
120
120
|
```
|
|
121
121
|
|
|
@@ -13,14 +13,14 @@ values should be passed into the `css` prop in JSX components.
|
|
|
13
13
|
|
|
14
14
|
```tsx
|
|
15
15
|
function Component() {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
return (
|
|
17
|
+
<div
|
|
18
|
+
style={{
|
|
19
|
+
margin: 0,
|
|
20
|
+
color: 'red',
|
|
21
|
+
}}
|
|
22
|
+
/>
|
|
23
|
+
);
|
|
24
24
|
}
|
|
25
25
|
```
|
|
26
26
|
|
|
@@ -28,14 +28,14 @@ function Component() {
|
|
|
28
28
|
|
|
29
29
|
```tsx
|
|
30
30
|
function Component(props) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
31
|
+
return (
|
|
32
|
+
<div
|
|
33
|
+
style={{
|
|
34
|
+
width: props.width,
|
|
35
|
+
'--my-nested-width': props.width,
|
|
36
|
+
}}
|
|
37
|
+
css={css({ margin: 0, color: 'red' })}
|
|
38
|
+
/>
|
|
39
|
+
);
|
|
40
40
|
}
|
|
41
41
|
```
|
|
@@ -54,17 +54,17 @@ future advancements like generative AI.
|
|
|
54
54
|
|
|
55
55
|
### Desired outcomes:
|
|
56
56
|
|
|
57
|
-
-
|
|
58
|
-
-
|
|
59
|
-
|
|
60
|
-
-
|
|
61
|
-
|
|
62
|
-
-
|
|
63
|
-
|
|
64
|
-
-
|
|
65
|
-
|
|
66
|
-
-
|
|
67
|
-
|
|
57
|
+
- We can make large visual changes and migrations safely and in a fraction of the time.
|
|
58
|
+
- To have the vast majority of styling code be deterministic, immutable, and bound to its scope,
|
|
59
|
+
reducing unknown visual and UX regressions.
|
|
60
|
+
- To enable teams to write tooling quicker that's better and more performant to lint, test, and
|
|
61
|
+
migrate UI code to improve current and future developer productivity and satisfaction.
|
|
62
|
+
- To enable large performance improvements for customers and developers with a zero-runtime styling
|
|
63
|
+
solution.
|
|
64
|
+
- To reduce the amount of overall custom styling code written while supporting customization without
|
|
65
|
+
without the need for hacks and technical debt.
|
|
66
|
+
- We aim to see a reduction of the “average styles per component”, reducing the effort to build and
|
|
67
|
+
maintain UIs.
|
|
68
68
|
|
|
69
69
|
## Basic principles
|
|
70
70
|
|
|
@@ -74,12 +74,12 @@ Java, Go, etc.
|
|
|
74
74
|
|
|
75
75
|
### Like other languages, styling code must be:
|
|
76
76
|
|
|
77
|
-
-
|
|
78
|
-
-
|
|
79
|
-
-
|
|
80
|
-
-
|
|
81
|
-
-
|
|
82
|
-
-
|
|
77
|
+
- type-safe
|
|
78
|
+
- static and locally analyzable
|
|
79
|
+
- reusable and composable
|
|
80
|
+
- restricted to an encapsulated scope
|
|
81
|
+
- deterministic—with styling known in isolation
|
|
82
|
+
- discoverable and readable without deep knowledge of the CSS spec
|
|
83
83
|
|
|
84
84
|
As the W3C CSS spec and wider industry grows, having our styling code meet these principles will
|
|
85
85
|
mean we can programatically evolve that a better future state.
|
|
@@ -159,20 +159,20 @@ context so both humans and tooling can read this component in a performant and d
|
|
|
159
159
|
|
|
160
160
|
1. Use `@compiled/react` or [Primitives](/components/primitives/overview) wherever possible!
|
|
161
161
|
2. Instead of dynamic styles:
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
162
|
+
1. Use static `css()` calls everywhere.
|
|
163
|
+
2. Compose styles together, turning styles on or off.
|
|
164
|
+
3. When absoluteuly necessary, use `props.style` for dynamic styles.
|
|
165
165
|
3. Instead of nested selectors or global styles:
|
|
166
|
-
|
|
167
|
-
|
|
166
|
+
1. Style components directly.
|
|
167
|
+
2. Treat everything as local scope, parents shouldn't interact with children wherever feasible.
|
|
168
168
|
4. Instead of passing raw styles around:
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
169
|
+
1. Write composable and reusable components which distribute styles with clear context.
|
|
170
|
+
2. Co-locate styles in the same file for human readability and far better tooling feasibility and
|
|
171
|
+
performance.
|
|
172
172
|
5. Instead of `styled.…`, use `const styles = css({ … });` (hoisted and static) and
|
|
173
173
|
`<div css={styles} />`.
|
|
174
|
-
|
|
175
|
-
|
|
174
|
+
1. There will be a safe way to make bounded customizations on components through the use of
|
|
175
|
+
`<Component xcss={css({ … })}>` in the future.
|
|
176
176
|
6. Instead of `...props`, be explicit with the `aria-` or `data-` props you support, or have more
|
|
177
177
|
complex spread handling. This is because `className`, `style`, and other things can be applied
|
|
178
178
|
without any knowledge, resulting in regressions in the future.
|
|
@@ -184,63 +184,63 @@ import { css } from '@compiled/react';
|
|
|
184
184
|
import { token } from '@atlaskit/tokens';
|
|
185
185
|
|
|
186
186
|
const wrapperStyles = css({
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
187
|
+
padding: token('space.200'), // eg. from mixin
|
|
188
|
+
font: token('font.body'), // eg. from mixin
|
|
189
|
+
color: token('color.text'),
|
|
190
190
|
});
|
|
191
191
|
const disabledWrapperStyles = css({
|
|
192
|
-
|
|
192
|
+
color: token('color.text.disabled'),
|
|
193
193
|
});
|
|
194
194
|
const innerWrapperStyles = css({
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
195
|
+
// eg. colocated `innerWrapperStyles` (alternatively could create a reusable `<InnerWrapper>`)
|
|
196
|
+
display: 'flex',
|
|
197
|
+
gap: token('space.100'),
|
|
198
|
+
flexDirection: 'column',
|
|
199
199
|
});
|
|
200
200
|
const buttonStyles = css({
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
201
|
+
appearance: 'none', // eg. from global styles
|
|
202
|
+
padding: `${token('space.100')} ${token('space.200')}`, // eg. from global styles
|
|
203
|
+
color: token('color.link'),
|
|
204
204
|
});
|
|
205
205
|
const disabledButtonStyles = css({
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
206
|
+
cursor: 'not-allowed', // eg. from disabledStyles
|
|
207
|
+
color: token('color.text.disabled'),
|
|
208
|
+
opacity: '70%',
|
|
209
209
|
});
|
|
210
210
|
const buttonAppearanceStyles = cssMap({
|
|
211
|
-
|
|
212
|
-
|
|
211
|
+
primary: { background: token('color.background.brand.subtlest') },
|
|
212
|
+
secondary: { background: token('color.background.success') },
|
|
213
213
|
});
|
|
214
214
|
|
|
215
215
|
export const Component = ({
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
216
|
+
disabled = false,
|
|
217
|
+
width = 100,
|
|
218
|
+
appearance = 'primary',
|
|
219
|
+
'aria-label': ariaLabel,
|
|
220
220
|
}: {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
221
|
+
disabled?: boolean;
|
|
222
|
+
width?: number;
|
|
223
|
+
appearance?: 'primary' | 'secondary';
|
|
224
|
+
'aria-label'?: string;
|
|
225
225
|
}) => (
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
226
|
+
<div
|
|
227
|
+
css={[wrapperStyles, props.disabled && disabledWrapperStyles]}
|
|
228
|
+
style={{ width: `${props.width}px` }}
|
|
229
|
+
aria-label={ariaLabel}
|
|
230
|
+
>
|
|
231
|
+
<div css={innerWrapperStyles}>
|
|
232
|
+
{/* Typically, this `<button>` should be an Atlassian Design System `<Button>` */}
|
|
233
|
+
<button
|
|
234
|
+
disabled={props.disabled}
|
|
235
|
+
css={[
|
|
236
|
+
buttonStyles,
|
|
237
|
+
buttonAppearances[props.appearance],
|
|
238
|
+
props.disabled && disabledButtonStyles,
|
|
239
|
+
]}
|
|
240
|
+
>
|
|
241
|
+
Click me
|
|
242
|
+
</button>
|
|
243
|
+
</div>
|
|
244
|
+
</div>
|
|
245
245
|
);
|
|
246
246
|
```
|
|
@@ -18,8 +18,8 @@ robust enough type checking.
|
|
|
18
18
|
import { cx, cssMap } from '@compiled/react';
|
|
19
19
|
|
|
20
20
|
const styles = cssMap({
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
text: { color: 'red' },
|
|
22
|
+
bg: { background: 'blue' },
|
|
23
23
|
});
|
|
24
24
|
|
|
25
25
|
const joinedStyles = cx(styles.text, styles.bg);
|
|
@@ -33,8 +33,8 @@ const joinedStyles = cx(styles.text, styles.bg);
|
|
|
33
33
|
import { cx, cssMap } from '@compiled/react';
|
|
34
34
|
|
|
35
35
|
const styles = cssMap({
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
text: { color: 'red' },
|
|
37
|
+
bg: { background: 'blue' },
|
|
38
38
|
});
|
|
39
39
|
|
|
40
40
|
<Button xcss={cx(styles.text, styles.bg)} />;
|
|
@@ -34,13 +34,13 @@ const styles = css({ width: 100 }, ...items);
|
|
|
34
34
|
|
|
35
35
|
By default, this rule will check `css` usages from:
|
|
36
36
|
|
|
37
|
-
-
|
|
38
|
-
-
|
|
39
|
-
-
|
|
40
|
-
-
|
|
41
|
-
-
|
|
42
|
-
-
|
|
43
|
-
-
|
|
37
|
+
- `@atlaskit/css`
|
|
38
|
+
- `@atlaskit/primitives`
|
|
39
|
+
- `@compiled/react`
|
|
40
|
+
- `@emotion/react`
|
|
41
|
+
- `@emotion/core`
|
|
42
|
+
- `@emotion/styled`
|
|
43
|
+
- `styled-components`
|
|
44
44
|
|
|
45
45
|
To change this list of libraries, you can define a custom set of `importSources`, which accepts an
|
|
46
46
|
array of package names (strings).
|
|
@@ -15,11 +15,11 @@ We suggest you explore the use alternatives such as client JavaScript-based APIs
|
|
|
15
15
|
import { css } from '@compiled/react';
|
|
16
16
|
|
|
17
17
|
const styles = css({
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
'@container (width > 400px)': {
|
|
19
|
+
h2: {
|
|
20
|
+
fontSize: '1.5rem',
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
23
|
});
|
|
24
24
|
```
|
|
25
25
|
|
|
@@ -29,8 +29,8 @@ const styles = css({
|
|
|
29
29
|
import { css } from '@compiled/react';
|
|
30
30
|
|
|
31
31
|
const containerStyles = css({
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
display: 'flex',
|
|
33
|
+
flexDirection: 'column',
|
|
34
34
|
});
|
|
35
35
|
```
|
|
36
36
|
|
|
@@ -40,13 +40,13 @@ const containerStyles = css({
|
|
|
40
40
|
|
|
41
41
|
By default, this rule will check `css` usages from:
|
|
42
42
|
|
|
43
|
-
-
|
|
44
|
-
-
|
|
45
|
-
-
|
|
46
|
-
-
|
|
47
|
-
-
|
|
48
|
-
-
|
|
49
|
-
-
|
|
43
|
+
- `@atlaskit/css`
|
|
44
|
+
- `@atlaskit/primitives`
|
|
45
|
+
- `@compiled/react`
|
|
46
|
+
- `@emotion/react`
|
|
47
|
+
- `@emotion/core`
|
|
48
|
+
- `@emotion/styled`
|
|
49
|
+
- `styled-components`
|
|
50
50
|
|
|
51
51
|
To change this list of libraries, you can define a custom set of `importSources`, which accepts an
|
|
52
52
|
array of package names (strings).
|
|
@@ -4,9 +4,9 @@ This rule prevents the use of dynamic styles (function expressions) in style dec
|
|
|
4
4
|
|
|
5
5
|
This ensures that style declarations:
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
7
|
+
- are statically analyzable
|
|
8
|
+
- can be efficiently extracted into atomic CSS
|
|
9
|
+
- are more readable, deterministic, and thus easier to maintain
|
|
10
10
|
|
|
11
11
|
## Examples
|
|
12
12
|
|
|
@@ -16,7 +16,7 @@ This ensures that style declarations:
|
|
|
16
16
|
import { styled } from '@compiled/react';
|
|
17
17
|
|
|
18
18
|
const Component = styled.div<{ width: number }>((props) => ({
|
|
19
|
-
|
|
19
|
+
width: props.width,
|
|
20
20
|
}));
|
|
21
21
|
```
|
|
22
22
|
|
|
@@ -24,7 +24,7 @@ const Component = styled.div<{ width: number }>((props) => ({
|
|
|
24
24
|
import styled from 'styled-components';
|
|
25
25
|
|
|
26
26
|
const Component = styled.div<{ width: number }>({
|
|
27
|
-
|
|
27
|
+
width: (props) => props.width,
|
|
28
28
|
});
|
|
29
29
|
```
|
|
30
30
|
|
|
@@ -32,7 +32,7 @@ const Component = styled.div<{ width: number }>({
|
|
|
32
32
|
import styled from 'styled-components';
|
|
33
33
|
|
|
34
34
|
const Container = styled.div<hasPadding>({
|
|
35
|
-
|
|
35
|
+
padding: ({ hasPadding }) => (hasPadding ? token('space.100', '8px') : token('space.0', '0px')),
|
|
36
36
|
});
|
|
37
37
|
```
|
|
38
38
|
|
|
@@ -50,7 +50,7 @@ const baseStyles = css({ padding: token('space.0') });
|
|
|
50
50
|
const hasPaddingStyles = css({ padding: token('space.100') });
|
|
51
51
|
|
|
52
52
|
const Container = ({ hasPadding = false }: { hasPadding?: boolean }) => {
|
|
53
|
-
|
|
53
|
+
return <div css={[baseStyles, hasPadding && hasPaddingStyles]} />;
|
|
54
54
|
};
|
|
55
55
|
```
|
|
56
56
|
|
|
@@ -89,7 +89,7 @@ This approach should be used as a last resort.
|
|
|
89
89
|
import { css } from '@compiled/react';
|
|
90
90
|
|
|
91
91
|
const Component = ({ width }: { width: number }) => {
|
|
92
|
-
|
|
92
|
+
return <div style={{ width }} />;
|
|
93
93
|
};
|
|
94
94
|
```
|
|
95
95
|
|
|
@@ -97,13 +97,13 @@ const Component = ({ width }: { width: number }) => {
|
|
|
97
97
|
import { css } from '@compiled/react';
|
|
98
98
|
|
|
99
99
|
const containerStyles = css({
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
100
|
+
'::before': {
|
|
101
|
+
width: 'var(--ak-example-width)',
|
|
102
|
+
},
|
|
103
103
|
});
|
|
104
104
|
|
|
105
105
|
function Example({ width }: { width: number }) {
|
|
106
|
-
|
|
106
|
+
return <div css={containerStyles} style={{ '--ak-example-width': `${width}px` }} />;
|
|
107
107
|
}
|
|
108
108
|
```
|
|
109
109
|
|
|
@@ -113,13 +113,13 @@ function Example({ width }: { width: number }) {
|
|
|
113
113
|
|
|
114
114
|
By default, this rule will check usages from:
|
|
115
115
|
|
|
116
|
-
-
|
|
117
|
-
-
|
|
118
|
-
-
|
|
119
|
-
-
|
|
120
|
-
-
|
|
121
|
-
-
|
|
122
|
-
-
|
|
116
|
+
- `@atlaskit/css`
|
|
117
|
+
- `@atlaskit/primitives`
|
|
118
|
+
- `@compiled/react`
|
|
119
|
+
- `@emotion/react`
|
|
120
|
+
- `@emotion/core`
|
|
121
|
+
- `@emotion/styled`
|
|
122
|
+
- `styled-components`
|
|
123
123
|
|
|
124
124
|
To change this list of libraries, you can define a custom set of `importSources`, which accepts an
|
|
125
125
|
array of package names (strings).
|
|
@@ -31,8 +31,8 @@ Avoid exporting any style-like objects or values for consumption as well as thes
|
|
|
31
31
|
|
|
32
32
|
```js
|
|
33
33
|
export default {
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
color: 'red',
|
|
35
|
+
margin: '0px',
|
|
36
36
|
};
|
|
37
37
|
```
|
|
38
38
|
|
|
@@ -40,15 +40,15 @@ export default {
|
|
|
40
40
|
import { css } from '@compiled/react';
|
|
41
41
|
|
|
42
42
|
const color = css({
|
|
43
|
-
|
|
43
|
+
/* */
|
|
44
44
|
});
|
|
45
45
|
|
|
46
46
|
const styles = {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
primary: {
|
|
48
|
+
text: {
|
|
49
|
+
color,
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
52
|
};
|
|
53
53
|
|
|
54
54
|
export default styles.primary.text.color;
|
|
@@ -80,13 +80,13 @@ export const Component = ({ children }) => <div css={styles}>{children}></div>;
|
|
|
80
80
|
|
|
81
81
|
By default, this rule will check `css` usages from:
|
|
82
82
|
|
|
83
|
-
-
|
|
84
|
-
-
|
|
85
|
-
-
|
|
86
|
-
-
|
|
87
|
-
-
|
|
88
|
-
-
|
|
89
|
-
-
|
|
83
|
+
- `@atlaskit/css`
|
|
84
|
+
- `@atlaskit/primitives`
|
|
85
|
+
- `@compiled/react`
|
|
86
|
+
- `@emotion/react`
|
|
87
|
+
- `@emotion/core`
|
|
88
|
+
- `@emotion/styled`
|
|
89
|
+
- `styled-components`
|
|
90
90
|
|
|
91
91
|
To change this list of libraries, you can define a custom set of `importSources`, which accepts an
|
|
92
92
|
array of package names (strings).
|