@atlaskit/eslint-plugin-ui-styling-standard 0.16.2 → 0.16.4

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 (52) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/constellation/atlaskit-theme/usage.mdx +74 -55
  3. package/constellation/convert-props-syntax/usage.mdx +29 -24
  4. package/constellation/enforce-style-prop/usage.mdx +32 -26
  5. package/constellation/local-cx-xcss/usage.mdx +27 -15
  6. package/constellation/no-array-arguments/usage.mdx +12 -9
  7. package/constellation/no-classname-prop/usage.mdx +13 -5
  8. package/constellation/no-container-queries/usage.mdx +65 -16
  9. package/constellation/no-dynamic-styles/usage.mdx +16 -11
  10. package/constellation/no-exported-styles/usage.mdx +25 -30
  11. package/constellation/no-global-styles/usage.mdx +4 -3
  12. package/constellation/no-important-styles/usage.mdx +5 -3
  13. package/constellation/no-imported-style-values/usage.mdx +30 -27
  14. package/constellation/no-nested-selectors/usage.mdx +51 -18
  15. package/constellation/no-styled/usage.mdx +17 -14
  16. package/constellation/no-unsafe-selectors/usage.mdx +184 -58
  17. package/constellation/no-unsafe-values/usage.mdx +150 -48
  18. package/constellation/use-compiled/usage.mdx +8 -8
  19. package/dist/cjs/rules/no-array-arguments/index.js +3 -3
  20. package/dist/cjs/rules/no-dynamic-styles/index.js +2 -2
  21. package/dist/cjs/rules/no-imported-style-values/index.js +2 -2
  22. package/dist/cjs/rules/no-unsafe-values/index.js +2 -2
  23. package/dist/es2019/rules/no-array-arguments/index.js +2 -2
  24. package/dist/es2019/rules/no-dynamic-styles/index.js +1 -1
  25. package/dist/es2019/rules/no-imported-style-values/index.js +1 -1
  26. package/dist/es2019/rules/no-unsafe-values/index.js +1 -1
  27. package/dist/esm/rules/no-array-arguments/index.js +3 -3
  28. package/dist/esm/rules/no-dynamic-styles/index.js +2 -2
  29. package/dist/esm/rules/no-imported-style-values/index.js +2 -2
  30. package/dist/esm/rules/no-unsafe-values/index.js +2 -2
  31. package/package.json +8 -3
  32. package/src/rules/atlaskit-theme/README.md +74 -55
  33. package/src/rules/convert-props-syntax/README.md +29 -24
  34. package/src/rules/enforce-style-prop/README.md +32 -26
  35. package/src/rules/local-cx-xcss/README.md +27 -15
  36. package/src/rules/no-array-arguments/README.md +12 -9
  37. package/src/rules/no-array-arguments/index.tsx +2 -2
  38. package/src/rules/no-classname-prop/README.md +13 -5
  39. package/src/rules/no-container-queries/README.md +65 -16
  40. package/src/rules/no-dynamic-styles/README.md +16 -11
  41. package/src/rules/no-dynamic-styles/index.tsx +1 -1
  42. package/src/rules/no-exported-styles/README.md +25 -30
  43. package/src/rules/no-global-styles/README.md +4 -3
  44. package/src/rules/no-important-styles/README.md +5 -3
  45. package/src/rules/no-imported-style-values/README.md +30 -27
  46. package/src/rules/no-imported-style-values/index.tsx +1 -1
  47. package/src/rules/no-nested-selectors/README.md +51 -18
  48. package/src/rules/no-styled/README.md +17 -14
  49. package/src/rules/no-unsafe-selectors/README.md +184 -58
  50. package/src/rules/no-unsafe-values/README.md +150 -48
  51. package/src/rules/no-unsafe-values/index.tsx +1 -1
  52. package/src/rules/use-compiled/README.md +8 -8
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @atlaskit/eslint-plugin-ui-styling-standard
2
2
 
3
+ ## 0.16.4
4
+
5
+ ### Patch Changes
6
+
7
+ - [#111304](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/111304)
8
+ [`df63ad1ddca6a`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/df63ad1ddca6a) -
9
+ Updated rule docs for better clarity and consistency
10
+
11
+ ## 0.16.3
12
+
13
+ ### Patch Changes
14
+
15
+ - [#110284](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/110284)
16
+ [`34021a2db424f`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/34021a2db424f) -
17
+ Internal refactoring to improve backwards compatibility with ESLint versions lower than 8
18
+
3
19
  ## 0.16.2
4
20
 
5
21
  ### Patch Changes
@@ -1,113 +1,132 @@
1
1
  # atlaskit-theme
2
2
 
3
- This rule bans certain usages of `@atlaskit/theme` that `@compiled/react` is unable to compile. This
4
- includes `typography`, `elevation` and `skeletonShimmer`.
3
+ Blocks legacy `@atlaskit/theme` mixins that `@compiled/react` cannot compile. This includes the
4
+ `typography`, `elevation` and `skeletonShimmer` mixins.
5
5
 
6
6
  ## Examples
7
7
 
8
8
  ### Typography
9
9
 
10
- Use `<Heading>` instead of `typography`.
10
+ Don't use `typography` mixins.
11
11
 
12
- 👎 Example of **incorrect** code for this rule:
12
+ Use [typography tokens](https://atlassian.design/foundations/typography-beta/applying-typography) or
13
+ the [Heading](https://atlassian.design/components/heading) and
14
+ [Text](https://atlassian.design/components/primitives/text) components.
13
15
 
14
- ```tsx
15
- import { styled } from '@compiled/react';
16
- import { typography } from '@atlaskit/theme';
17
-
18
- export const HeadingComponent = styled.h2`
19
- ${typography.h200()};
20
- `;
21
- ```
16
+ #### Incorrect
22
17
 
23
18
  ```tsx
24
- import { styled } from '@compiled/react';
19
+ import { css } from '@compiled/react';
25
20
  import { typography } from '@atlaskit/theme';
26
21
 
27
- export const HeadingComponent = styled.h2(typography.h200());
22
+ const titleStyles = css(typography.h700());
28
23
  ```
29
24
 
30
- 👍 Example of **correct** code for this rule:
25
+ #### Correct
31
26
 
32
27
  ```tsx
33
- import { styled } from '@compiled/react';
28
+ import { css } from '@compiled/react';
29
+ import { token } from '@atlaskit/tokens';
34
30
 
35
- const HeadingComponent = styled.h2({
36
- fontSize: '20px',
31
+ const titleStyles = css({
32
+ font: token('font.heading.large'),
33
+ });
34
+
35
+ const paragraphStyles = css({
36
+ font: token('font.body.large'),
37
37
  });
38
38
  ```
39
39
 
40
40
  ```tsx
41
+ import { css } from '@compiled/react';
41
42
  import Heading from '@atlaskit/heading';
43
+ import { Stack, Text } from '@atlaskit/primitives';
42
44
  import { token } from '@atlaskit/tokens';
43
- import { styled } from '@compiled/react';
44
45
 
45
- const TitleComponent = styled.span({
46
- marginTop: token('space.150', '12px'),
47
- });
48
-
49
- export const Title = (props) => (
50
- <Heading level="h200" as="h3">
51
- <TitleComponent {...props} />
52
- </Heading>
46
+ const Component = () => (
47
+ <Stack>
48
+ <Heading size="large">Title</Heading>
49
+ <Text size="large">Lorem ipsum</Text>
50
+ </Stack>
53
51
  );
54
52
  ```
55
53
 
56
54
  ### Elevation
57
55
 
58
- We don’t support this mixin, please use tokens instead.
56
+ Don't use `elevation` mixins.
57
+
58
+ Use [elevation tokens](https://atlassian.design/foundations/elevation) instead.
59
59
 
60
- 👎 Example of **incorrect** code for this rule:
60
+ #### Incorrect
61
61
 
62
62
  ```tsx
63
- import { styled } from '@compiled/react';
63
+ import { css } from '@compiled/react';
64
64
  import { elevation } from '@atlaskit/theme';
65
65
 
66
- export const ElevationComponent = styled.div`
67
- ${elevation.e100()};
68
- `;
66
+ const cardStyles = css(elevation.e100());
69
67
  ```
70
68
 
71
- 👍 Example of **correct** code for this rule:
69
+ #### Correct
72
70
 
73
71
  ```tsx
74
72
  import { styled } from '@compiled/react';
75
73
  import { token } from '@atlaskit/tokens';
76
74
 
77
- export const TestComponent = styled.div({
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
- ),
75
+ const cardStyles = css({
76
+ backgroundColor: token('elevation.surface.raised'),
77
+ boxShadow: token('elevation.shadow.raised'),
82
78
  });
83
79
  ```
84
80
 
85
81
  ### Skeleton Shimmer
86
82
 
87
- You can preview our `@atlaskit/skeleton` (docs available to internal Atlassians only:
88
- [link](https://staging.atlassian.design/components/skeleton/examples)).
83
+ Don't use the `skeletonShimmer` mixin.
89
84
 
90
- Otherwise, please use an SVG skeleton or your own `@compiled/react` variant yourself.
85
+ Preview our [Skeleton](https://staging.atlassian.design/components/skeleton/examples) component
86
+ (internal Atlassians only).
91
87
 
92
- 👎 Example of **incorrect** code for this rule:
88
+ Otherwise:
89
+
90
+ - Use the `color.skeleton` and `color.skeleton.subtle` tokens to make your own component.
91
+ - Use `@atlassian/jira-skeletons` when working on Jira (internal Atlassians only).
92
+
93
+ #### Incorrect
93
94
 
94
95
  ```tsx
95
- import { styled } from '@compiled/react';
96
+ import { css } from '@compiled/react';
96
97
  import { skeletonShimmer } from '@atlaskit/theme/constants';
97
98
 
98
- export const SkeletonShimmerComponent = styled.div`
99
- ${skeletonShimmer};
100
- `;
99
+ const skeletonStyles = css(skeletonShimmer());
101
100
  ```
102
101
 
103
- 👍 Example of **correct** code for this rule:
102
+ #### Correct
103
+
104
+ ```tsx
105
+ import Skeleton from '@atlaskit/skeleton';
106
+
107
+ <Skeleton width="200px" height="16px" isShimmering />;
108
+ ```
104
109
 
105
110
  ```tsx
106
- export const SkeletonShimmerComponent = () => {
107
- return (
108
- <Wrapper>
109
- <object data="./skeleton.svg" type="image/svg+xml"></object>
110
- </Wrapper>
111
- );
112
- };
111
+ import { css, keyframes } from '@compiled/react';
112
+
113
+ const shimmer = keyframes({
114
+ from: { backgroundColor: token('color.skeleton') },
115
+ to: { backgroundColor: token('color.skeleton.subtle') },
116
+ });
117
+
118
+ const skeletonStyles = css({
119
+ backgroundColor: token('color.skeleton'),
120
+ animationName: shimmer,
121
+ animationDuration: '1.5s',
122
+ animationIterationCount: 'infinite',
123
+ animationTimingFunction: 'linear',
124
+ animationDirection: 'alternate',
125
+ });
126
+ ```
127
+
128
+ ```tsx
129
+ import { ListSkeleton } from '@atlassian/jira-skeletons';
130
+
131
+ <ListSkeleton numOfRows={3} />;
113
132
  ```
@@ -1,13 +1,18 @@
1
1
  # convert-props-syntax
2
2
 
3
- Convert props syntax that are unsupported by `styled-components@<4` and `@emotion/styled` to a props
4
- syntax that is supported. This is useful when used in conjunction with
5
- `no-styled-tagged-template-expression`, as output from the latter may use props syntax that results
6
- in a type error.
3
+ Blocks dynamic styling syntax that is unsupported by `styled-components@<4` and `@emotion/styled`,
4
+ and provides an autofix for converting to a supported syntax.
7
5
 
8
- These libraries do not support having an arrow function inside a CSS value:
6
+ Use this rule alongside `no-styled-tagged-template-expression`, which can output the unsupported
7
+ dynamic styling syntax.
9
8
 
10
- ```js
9
+ This rule applies only to `styled` usages from `styled-components` and `@emotion/styled`.
10
+
11
+ ## Autofix
12
+
13
+ The autofix will find style object values that are arrow functions,
14
+
15
+ ```tsx
11
16
  styled.div({
12
17
  color: ({ myColor }) => myColor,
13
18
  backgroundColor: (props) => props.someColor,
@@ -17,7 +22,7 @@ styled.div({
17
22
  However, refactoring the arrow function so that it is the argument to `styled.div` will fix the
18
23
  issue:
19
24
 
20
- ```js
25
+ ```tsx
21
26
  styled.div((props) => ({
22
27
  color: props.myColor,
23
28
  backgroundColor: props.someColor,
@@ -40,47 +45,47 @@ manually fix the output, or migrate the code to `@compiled/react`.
40
45
  Type annotations in the arrow function are not supported; you will need to remediate the lint error
41
46
  manually. For example:
42
47
 
43
- ```js
48
+ ```tsx
44
49
  type Props = {
45
- myColor: string,
46
- someColor: string,
50
+ myColor: string;
51
+ someColor: string;
47
52
  };
48
53
 
49
54
  styled.div({
50
- color: ({ myColor }: Props) => myColor,
51
- backgroundColor: (props: Props) => props.someColor,
55
+ color: ({ myColor }: Props) => myColor,
56
+ backgroundColor: (props: Props) => props.someColor,
52
57
  });
53
58
  ```
54
59
 
55
- will need to be manually refactored to
60
+ could be refactored as
56
61
 
57
- ```js
62
+ ```tsx
58
63
  type Props = {
59
- myColor: string,
60
- someColor: string,
64
+ myColor: string;
65
+ someColor: string;
61
66
  };
62
67
 
63
68
  styled.div((props: Props) => ({
64
- color: props.myColor,
65
- backgroundColor: props.someColor,
69
+ color: props.myColor,
70
+ backgroundColor: props.someColor,
66
71
  }));
67
72
  ```
68
73
 
69
- ### Special syntax in the arrow function parameter(s)
74
+ ### Special syntax in function parameters
70
75
 
71
76
  Rest elements, default values, and so on in the parameter of an arrow function will need to be
72
77
  remediated manually. For example:
73
78
 
74
- ```js
79
+ ```tsx
75
80
  styled.div({
76
81
  color: ({ myColor = '#fff' }) => myColor,
77
82
  backgroundColor: ({ myColor = '#aaa' }) => myColor,
78
83
  });
79
84
  ```
80
85
 
81
- could potentially be remediated with
86
+ could be refactored as
82
87
 
83
- ```js
88
+ ```tsx
84
89
  styled.div((props) => ({
85
90
  color: myColor ?? '#fff',
86
91
  backgroundColor: myColor ?? '#aaa',
@@ -91,7 +96,7 @@ styled.div((props) => ({
91
96
 
92
97
  ### Incorrect
93
98
 
94
- ```js
99
+ ```tsx
95
100
  import styled from 'styled-components';
96
101
 
97
102
  styled.div({
@@ -106,7 +111,7 @@ styled.div({
106
111
 
107
112
  ### Correct
108
113
 
109
- ```js
114
+ ```tsx
110
115
  import styled from '@emotion/styled';
111
116
 
112
117
  styled.div((props) => ({
@@ -1,41 +1,47 @@
1
1
  # enforce-style-prop
2
2
 
3
- This rule enforces passing dynamic CSS values to the `style` prop in JSX components.
3
+ Blocks providing static values through the `style` prop, which should only be used to provide
4
+ dynamic values (values unknown at build time).
4
5
 
5
- We only want `props.style` to be used for dynamic values that cannot be easily determined at build
6
- time, e.g. `<div style={{ width: props.width }}>`. No statics values such as numbers, strings or any
7
- other statically analysable values should be passed to the `style` attribute. Instead, static CSS
8
- values should be passed into the `css` prop in JSX components.
6
+ Use the `css` prop for providing static values instead.
9
7
 
10
8
  ## Examples
11
9
 
12
10
  ### Incorrect
13
11
 
14
12
  ```tsx
15
- function Component() {
16
- return (
17
- <div
18
- style={{
19
- margin: 0,
20
- color: 'red',
21
- }}
22
- />
23
- );
24
- }
13
+ import { token } from '@atlaskit/tokens';
14
+
15
+ const Component = () => (
16
+ <div
17
+ style={{
18
+ margin: 0,
19
+ color: token('color.text.danger'),
20
+ }}
21
+ />
22
+ );
25
23
  ```
26
24
 
27
25
  ### Correct
28
26
 
27
+ Although `token` is a function call, it is statically resolvable by Compiled and should not be used
28
+ in the `style` prop.
29
+
29
30
  ```tsx
30
- function Component(props) {
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
- }
31
+ import { css } from '@compiled/react';
32
+ import { token } from '@atlaskit/tokens';
33
+
34
+ type Props = { width: string };
35
+
36
+ const baseStyles = css({ margin: 0, color: token('color.text.danger') });
37
+
38
+ const Component = ({ width }: Props) => (
39
+ <div
40
+ css={baseStyles}
41
+ style={{
42
+ width: props.width,
43
+ '--my-nested-width': props.width,
44
+ }}
45
+ />
46
+ );
41
47
  ```
@@ -1,25 +1,37 @@
1
1
  # local-cx-xcss
2
2
 
3
- This rule ensures the `cx()` function is only used within the `xcss` prop. This aids tracking what
4
- styles are applied to a jsx element.
3
+ Blocks the `cx()` function from being used outside of the `xcss` prop. This aids tracking which
4
+ styles are applied.
5
5
 
6
- The `cx` function is checked only if it is imported from `@compiled/react` or `@atlaskit/css`.
6
+ Use the `cx()` function when passing multiple styles to the `xcss` prop. This provides more robust
7
+ type checking than the conventional array syntax:
7
8
 
8
- Passing arguments to the `cx()` function is how you compose styles (combine more than one set of
9
- styles together) with XCSS. This is a workaround for the more conventional array syntax (e.g.
10
- [in Emotion](https://emotion.sh/docs/composition)) `<div xcss={[style1, style2]} />` not giving
11
- robust enough type checking.
9
+ ```tsx
10
+ import { cssMap, cx } from '@compiled/react';
11
+ import { token } from '@atlaskit/tokens';
12
+ import { Component } from 'some-package';
13
+
14
+ const styles = cssMap({
15
+ text: { color: token('color.text') },
16
+ primary: { color: token('color.text.brand') },
17
+ });
18
+
19
+ <Component xcss={cx(isPrimary && styles.text, !isPrimary && styles.primary)} />;
20
+ ```
21
+
22
+ The `cx()` function is only checked when imported from `@compiled/react` or `@atlaskit/css`.
12
23
 
13
24
  ## Examples
14
25
 
15
26
  ### Incorrect
16
27
 
17
- ```js
18
- import { cx, cssMap } from '@compiled/react';
28
+ ```tsx
29
+ import { cssMap, cx } from '@compiled/react';
30
+ import { token } from '@atlaskit/tokens';
19
31
 
20
32
  const styles = cssMap({
21
- text: { color: 'red' },
22
- bg: { background: 'blue' },
33
+ text: { color: token('color.text') },
34
+ bg: { background: token('color.background.neutral') },
23
35
  });
24
36
 
25
37
  const joinedStyles = cx(styles.text, styles.bg);
@@ -29,12 +41,12 @@ const joinedStyles = cx(styles.text, styles.bg);
29
41
 
30
42
  ### Correct
31
43
 
32
- ```js
33
- import { cx, cssMap } from '@compiled/react';
44
+ ```tsx
45
+ import { cssMap, cx } from '@compiled/react';
34
46
 
35
47
  const styles = cssMap({
36
- text: { color: 'red' },
37
- bg: { background: 'blue' },
48
+ text: { color: token('color.text') },
49
+ bg: { background: token('color.background.neutral') },
38
50
  });
39
51
 
40
52
  <Button xcss={cx(styles.text, styles.bg)} />;
@@ -1,38 +1,42 @@
1
1
  # no-array-arguments
2
2
 
3
- This rule prevents usage of array arguments to style declaration functions.
3
+ Blocks passing array arguments to style declaration functions.
4
4
 
5
5
  ## Examples
6
6
 
7
7
  ### Incorrect
8
8
 
9
- ```js
9
+ ```tsx
10
10
  import { css } from '@compiled/react';
11
+
11
12
  const styles = css([{ width: 100 }, { height: 100 }]);
12
13
  ```
13
14
 
14
- ```js
15
+ ```tsx
15
16
  import { styled } from '@compiled/react';
17
+
16
18
  const styles = css([{ width: 100 }, ...items]);
17
19
  ```
18
20
 
19
21
  ### Correct
20
22
 
21
- ```js
23
+ ```tsx
22
24
  import { css } from '@compiled/react';
25
+
23
26
  const styles = css({ width: 100 }, { height: 100 });
24
27
  ```
25
28
 
26
- ```js
29
+ ```tsx
27
30
  import { css } from '@compiled/react';
31
+
28
32
  const styles = css({ width: 100 }, ...items);
29
33
  ```
30
34
 
31
35
  ## Options
32
36
 
33
- ### importSources
37
+ ### `importSources: string[]`
34
38
 
35
- By default, this rule will check `css` usages from:
39
+ By default, this rule will check styles using:
36
40
 
37
41
  - `@atlaskit/css`
38
42
  - `@atlaskit/primitives`
@@ -42,5 +46,4 @@ By default, this rule will check `css` usages from:
42
46
  - `@emotion/styled`
43
47
  - `styled-components`
44
48
 
45
- To change this list of libraries, you can define a custom set of `importSources`, which accepts an
46
- array of package names (strings).
49
+ Override this list with the `importSources` option, which accepts an array of package names.
@@ -1,10 +1,9 @@
1
1
  # no-classname-prop
2
2
 
3
- This rule prevents usage of the `className` prop in JSX.
3
+ Blocks the `className` prop, which encourages unsafe global styles and cannot be statically
4
+ resolved.
4
5
 
5
- Avoid `className` because it invites the use of unsafe global styles and is impossible to determine
6
- via local tooling. Use props for configuration and typical CSS-in-JS for styling or `xcss` for
7
- bounded overrides.
6
+ Use the `css` prop for styling, with props for configuration and `xcss` for bounded overrides.
8
7
 
9
8
  ## Examples
10
9
 
@@ -22,14 +21,23 @@ bounded overrides.
22
21
 
23
22
  ```tsx
24
23
  import { css } from '@compiled/react';
24
+ import { token } from '@atlaskit/tokens';
25
25
 
26
- <div css={css({ padding: '10px' })} />;
26
+ const myStyles = css({ padding: token('space.100') });
27
+
28
+ <div css={myStyles} />;
27
29
  ```
28
30
 
29
31
  ```tsx
30
32
  <MyComponent isDisabled={isDisabled} />
31
33
  ```
32
34
 
35
+ ```tsx
36
+ import { Checkbox } from '@atlaskit/checkbox';
37
+
38
+ <Checkbox xcss={{ alignItems: 'center' }} />;
39
+ ```
40
+
33
41
  ## FAQ
34
42
 
35
43
  ### What if I'm using `className` to target elements with JavaScript?
@@ -1,44 +1,94 @@
1
1
  # no-container-queries
2
2
 
3
- This rule prevents the usage of the `@container` query in style declarations.
3
+ Blocks `@container` at-rules
4
+ ([container queries](https://developer.mozilla.org/en-US/docs/Web/CSS/@container)), which are
5
+ unsafe.
4
6
 
5
- Container queries break the rules of scope and aren’t guaranteed to be deterministic or type safe
6
- and isn’t fully supported across our frontend tech stacks.
7
+ Container queries are unsafe because they:
7
8
 
8
- We suggest you explore the use alternatives such as client JavaScript-based APIs or media queries.
9
+ - break the rules of scope
10
+ - aren't deterministic
11
+ - aren't type-safe
12
+ - aren't fully supported across our frontend tech stacks
13
+
14
+ Use [media queries](https://atlassian.design/components/primitives/responsive/breakpoints/examples),
15
+ a
16
+ [WidthObserver](https://atlaskit.atlassian.com/packages/design-system/width-detector/docs/migration-guide),
17
+ or a custom [ResizeObserver](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver)
18
+ instead.
9
19
 
10
20
  ## Examples
11
21
 
12
22
  ### Incorrect
13
23
 
14
- ```js
24
+ ```tsx
15
25
  import { css } from '@compiled/react';
26
+ import { token } from '@atlaskit/tokens';
16
27
 
17
- const styles = css({
28
+ const headingStyles = css({
18
29
  '@container (width > 400px)': {
19
- h2: {
20
- fontSize: '1.5rem',
21
- },
30
+ font: token('font.heading.large'),
22
31
  },
23
32
  });
24
33
  ```
25
34
 
26
35
  ### Correct
27
36
 
28
- ```js
37
+ #### Media queries
38
+
39
+ ```tsx
29
40
  import { css } from '@compiled/react';
41
+ import { media } from '@atlaskit/primitives/responsive';
42
+ import { token } from '@atlaskit/tokens';
43
+
44
+ const headingStyles = css({
45
+ [media.above.sm]: {
46
+ font: token('font.heading.large'),
47
+ },
48
+ });
49
+ ```
50
+
51
+ #### WidthObserver
52
+
53
+ ```tsx
54
+ import { useState } from 'react';
55
+ import { css, cssMap } from '@compiled/react';
56
+ import throttle from 'lodash/throttle';
57
+ import { WidthObserver } from '@atlaskit/width-detector';
58
+ import { token } from '@atlaskit/tokens';
30
59
 
31
60
  const containerStyles = css({
32
- display: 'flex',
33
- flexDirection: 'column',
61
+ // Required for the `WidthObserver`, which is absolutely positioned
62
+ position: 'relative',
34
63
  });
64
+
65
+ const headingStyles = cssMap({
66
+ small: {
67
+ font: token('font.heading.small'),
68
+ },
69
+ large: {
70
+ font: token('font.heading.large'),
71
+ },
72
+ });
73
+
74
+ const ResponsiveH2 = () => {
75
+ const [width = 0, setWidth] = useState<number | undefined>(undefined);
76
+ const throttledSetWidth = throttle(setWidth, 50);
77
+
78
+ return (
79
+ <div css={containerStyles}>
80
+ <WidthObserver setWidth={throttledSetWidth} />
81
+ <h2 css={width < 400 ? headingStyles.small : headingStyles.large}>Title</h2>
82
+ </div>
83
+ );
84
+ };
35
85
  ```
36
86
 
37
87
  ## Options
38
88
 
39
- ### importSources
89
+ ### `importSources: string[]`
40
90
 
41
- By default, this rule will check `css` usages from:
91
+ By default, this rule will check styles using:
42
92
 
43
93
  - `@atlaskit/css`
44
94
  - `@atlaskit/primitives`
@@ -48,5 +98,4 @@ By default, this rule will check `css` usages from:
48
98
  - `@emotion/styled`
49
99
  - `styled-components`
50
100
 
51
- To change this list of libraries, you can define a custom set of `importSources`, which accepts an
52
- array of package names (strings).
101
+ Override this list with the `importSources` option, which accepts an array of package names.