@atlaskit/eslint-plugin-ui-styling-standard 0.11.4 → 0.11.6

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 (59) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +33 -3
  3. package/constellation/atlaskit-theme/usage.mdx +113 -0
  4. package/constellation/convert-props-syntax/usage.mdx +32 -22
  5. package/constellation/enforce-style-prop/usage.mdx +21 -18
  6. package/constellation/index/overview.mdx +91 -76
  7. package/constellation/index/props.mdx +2 -9
  8. package/constellation/local-cx-xcss/usage.mdx +10 -6
  9. package/constellation/no-array-arguments/usage.mdx +10 -9
  10. package/constellation/no-classname-prop/usage.mdx +7 -4
  11. package/constellation/no-container-queries/usage.mdx +17 -15
  12. package/constellation/no-dynamic-styles/usage.mdx +26 -29
  13. package/constellation/no-exported-styles/usage.mdx +23 -18
  14. package/constellation/no-important-styles/usage.mdx +5 -3
  15. package/constellation/no-imported-style-values/usage.mdx +30 -22
  16. package/constellation/no-nested-selectors/usage.mdx +22 -20
  17. package/constellation/no-unsafe-values/usage.mdx +45 -51
  18. package/dist/cjs/index.codegen.js +1 -1
  19. package/dist/cjs/presets/all.codegen.js +2 -1
  20. package/dist/cjs/presets/recommended.codegen.js +2 -1
  21. package/dist/cjs/rules/atlaskit-theme/index.js +95 -0
  22. package/dist/cjs/rules/enforce-style-prop/index.js +39 -26
  23. package/dist/cjs/rules/index.codegen.js +3 -1
  24. package/dist/es2019/index.codegen.js +1 -1
  25. package/dist/es2019/presets/all.codegen.js +2 -1
  26. package/dist/es2019/presets/recommended.codegen.js +2 -1
  27. package/dist/es2019/rules/atlaskit-theme/index.js +85 -0
  28. package/dist/es2019/rules/enforce-style-prop/index.js +34 -19
  29. package/dist/es2019/rules/index.codegen.js +3 -1
  30. package/dist/esm/index.codegen.js +1 -1
  31. package/dist/esm/presets/all.codegen.js +2 -1
  32. package/dist/esm/presets/recommended.codegen.js +2 -1
  33. package/dist/esm/rules/atlaskit-theme/index.js +89 -0
  34. package/dist/esm/rules/enforce-style-prop/index.js +39 -26
  35. package/dist/esm/rules/index.codegen.js +3 -1
  36. package/dist/types/index.codegen.d.ts +2 -0
  37. package/dist/types/presets/all.codegen.d.ts +2 -1
  38. package/dist/types/presets/recommended.codegen.d.ts +2 -1
  39. package/dist/types/rules/atlaskit-theme/index.d.ts +3 -0
  40. package/dist/types/rules/index.codegen.d.ts +1 -0
  41. package/dist/types-ts4.5/index.codegen.d.ts +2 -0
  42. package/dist/types-ts4.5/presets/all.codegen.d.ts +2 -1
  43. package/dist/types-ts4.5/presets/recommended.codegen.d.ts +2 -1
  44. package/dist/types-ts4.5/rules/atlaskit-theme/index.d.ts +3 -0
  45. package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -0
  46. package/package.json +3 -3
  47. package/scripts/codegen.tsx +3 -10
  48. package/src/index.codegen.tsx +3 -3
  49. package/src/presets/all.codegen.tsx +66 -69
  50. package/src/presets/recommended.codegen.tsx +66 -69
  51. package/src/rules/atlaskit-theme/README.md +109 -0
  52. package/src/rules/atlaskit-theme/__tests__/test.ts +122 -0
  53. package/src/rules/atlaskit-theme/index.ts +136 -0
  54. package/src/rules/enforce-style-prop/__tests__/rule.test.tsx +18 -0
  55. package/src/rules/enforce-style-prop/index.tsx +42 -23
  56. package/src/rules/index.codegen.tsx +15 -13
  57. package/src/rules/no-exported-styles/index.tsx +1 -1
  58. package/src/rules/no-imported-style-values/index.tsx +1 -1
  59. package/tsconfig.app.json +3 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @atlaskit/eslint-plugin-ui-styling-standard
2
2
 
3
+ ## 0.11.6
4
+
5
+ ### Patch Changes
6
+
7
+ - [#97707](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/97707)
8
+ [`764c0805b3c1`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/764c0805b3c1) -
9
+ Moved compiled/atlaskit-theme eslint rule to UI styling standard
10
+
11
+ ## 0.11.5
12
+
13
+ ### Patch Changes
14
+
15
+ - [#96532](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/96532)
16
+ [`d54c7df2e836`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/d54c7df2e836) -
17
+ Editing enforce-style-prop rule to use eslint utils functions
18
+
3
19
  ## 0.11.4
4
20
 
5
21
  ### Patch Changes
package/README.md CHANGED
@@ -1,10 +1,39 @@
1
- # Atlassian UI Styling Standard ESLint Plugin
1
+ # UI Styling Standard ESLint Plugin
2
2
 
3
- The UI Styling Standard plugin utilizes rules from across Atlassian, Open Source, and more, to define what the standard for writing styles at Atlassian should look like.
3
+ The UI Styling Standard is a set of principles to guide styling UI code across Atlassian's frontend
4
+ codebases and ecosystem.
5
+
6
+ These are the current ESLint rules that enforce and help comply with the UI Styling Standard today,
7
+ but more are planned to support the standard over time.
4
8
 
5
9
  ## Installation
6
10
 
7
- Not intended for use outside the Atlassian frontend repository.
11
+ You must use the recommended config to follow the styling standards at Atlassian, which will ensure
12
+ compatability and performance with the design system.
13
+
14
+ ```diff
15
+ module.exports = {
16
+ extends: [
17
+ + 'plugin:@atlaskit/ui-styling-standard/recommended',
18
+ ],
19
+ };
20
+ ```
21
+
22
+ We don't recommended maintaining your own configuration. If you do not use our config you will need
23
+ to specify individual rules and configuration. Add the plugin to your `.eslintrc.js` file and enable
24
+ individual rules as you're ready to adopt.
25
+
26
+ ```diff
27
+ module.exports = {
28
+ plugins: [
29
+ + '@atlaskit/ui-styling-standard',
30
+ ],
31
+ rules: [
32
+ + '@atlaskit/ui-styling-standard/convert-props-syntax': 'warn',
33
+ + '@atlaskit/design-system/local-cx-xcss': 'error',
34
+ ],
35
+ };
36
+ ```
8
37
 
9
38
  ## Rules
10
39
 
@@ -13,6 +42,7 @@ Not intended for use outside the Atlassian frontend repository.
13
42
 
14
43
  | Rule | Description | Recommended | Fixable | Suggestions |
15
44
  | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------- | ------- | ----------- |
45
+ | <a href="./src/rules/atlaskit-theme/README.md">atlaskit-theme</a> | Ban certain usages of `@atlaskit/theme` that `@compiled/react` does not understand | Yes | | |
16
46
  | <a href="./src/rules/convert-props-syntax/README.md">convert-props-syntax</a> | Convert props syntax that is unsupported by styled-components@<4 or @emotion/styled to props syntax that is supported. This is useful when used in conjunction with `no-styled-tagged-template-expression`, as output from the latter may use props syntax unsupported by those libraries. | Yes | Yes | |
17
47
  | <a href="./src/rules/enforce-style-prop/README.md">enforce-style-prop</a> | Disallows usage of static styles in the `style` attribute in components | Yes | | |
18
48
  | <a href="./src/rules/local-cx-xcss/README.md">local-cx-xcss</a> | Ensures the cx() function, which is part of the XCSS API, is only used within the xcss prop. This aids tracking what styles are applied to a jsx element. | Yes | | |
@@ -0,0 +1,113 @@
1
+ # atlaskit-theme
2
+
3
+ This rule bans certain usages of `@atlaskit/theme` that `@compiled/react` is unable to compile. This
4
+ includes `typography`, `elevation` and `skeletonShimmer`.
5
+
6
+ ## Examples
7
+
8
+ ### Typography
9
+
10
+ Use `<Heading>` instead of `typography`.
11
+
12
+ 👎 Example of **incorrect** code for this rule:
13
+
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
+ ```
22
+
23
+ ```tsx
24
+ import { styled } from '@compiled/react';
25
+ import { typography } from '@atlaskit/theme';
26
+
27
+ export const HeadingComponent = styled.h2(typography.h200());
28
+ ```
29
+
30
+ 👍 Example of **correct** code for this rule:
31
+
32
+ ```tsx
33
+ import { styled } from '@compiled/react';
34
+
35
+ const HeadingComponent = styled.h2({
36
+ fontSize: '20px',
37
+ });
38
+ ```
39
+
40
+ ```tsx
41
+ import Heading from '@atlaskit/heading';
42
+ import { token } from '@atlaskit/tokens';
43
+ import { styled } from '@compiled/react';
44
+
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>
53
+ );
54
+ ```
55
+
56
+ ### Elevation
57
+
58
+ We don’t support this mixin, please use tokens instead.
59
+
60
+ 👎 Example of **incorrect** code for this rule:
61
+
62
+ ```tsx
63
+ import { styled } from '@compiled/react';
64
+ import { elevation } from '@atlaskit/theme';
65
+
66
+ export const ElevationComponent = styled.div`
67
+ ${elevation.e100()};
68
+ `;
69
+ ```
70
+
71
+ 👍 Example of **correct** code for this rule:
72
+
73
+ ```tsx
74
+ import { styled } from '@compiled/react';
75
+ import { token } from '@atlaskit/tokens';
76
+
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
+ ),
82
+ });
83
+ ```
84
+
85
+ ### Skeleton Shimmer
86
+
87
+ You can preview our `@atlaskit/skeleton` (docs available to internal Atlassians only:
88
+ [link](https://staging.atlassian.design/components/skeleton/examples)).
89
+
90
+ Otherwise, please use an SVG skeleton or your own `@compiled/react` variant yourself.
91
+
92
+ 👎 Example of **incorrect** code for this rule:
93
+
94
+ ```tsx
95
+ import { styled } from '@compiled/react';
96
+ import { skeletonShimmer } from '@atlaskit/theme/constants';
97
+
98
+ export const SkeletonShimmerComponent = styled.div`
99
+ ${skeletonShimmer};
100
+ `;
101
+ ```
102
+
103
+ 👍 Example of **correct** code for this rule:
104
+
105
+ ```tsx
106
+ export const SkeletonShimmerComponent = () => {
107
+ return (
108
+ <Wrapper>
109
+ <object data="./skeleton.svg" type="image/svg+xml"></object>
110
+ </Wrapper>
111
+ );
112
+ };
113
+ ```
@@ -1,36 +1,44 @@
1
1
  # convert-props-syntax
2
2
 
3
- Convert props syntax that are unsupported by `styled-components@<4` and `@emotion/styled` to a props syntax that is supported. This is useful when used in conjunction with `no-styled-tagged-template-expression`, as output from the latter may use props syntax that results in a type error.
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.
4
7
 
5
8
  These libraries do not support having an arrow function inside a CSS value:
6
9
 
7
10
  ```js
8
11
  styled.div({
9
- color: ({ myColor }) => myColor,
10
- backgroundColor: (props) => props.someColor,
12
+ color: ({ myColor }) => myColor,
13
+ backgroundColor: (props) => props.someColor,
11
14
  });
12
15
  ```
13
16
 
14
- However, refactoring the arrow function so that it is the argument to `styled.div` will fix the issue:
17
+ However, refactoring the arrow function so that it is the argument to `styled.div` will fix the
18
+ issue:
15
19
 
16
20
  ```js
17
21
  styled.div((props) => ({
18
- color: props.myColor,
19
- backgroundColor: props.someColor,
22
+ color: props.myColor,
23
+ backgroundColor: props.someColor,
20
24
  }));
21
25
  ```
22
26
 
23
- This ESLint rule will only run on usages of the `styled` API when imported from libraries that are known to have this problem.
27
+ This ESLint rule will only run on usages of the `styled` API when imported from libraries that are
28
+ known to have this problem.
24
29
 
25
30
  ## About the autofixer
26
31
 
27
- This rule has an autofixer that will automatically perform the above arrow function refactoring for the majority of cases, including for nested selectors and any props used in template literal values.
32
+ This rule has an autofixer that will automatically perform the above arrow function refactoring for
33
+ the majority of cases, including for nested selectors and any props used in template literal values.
28
34
 
29
- However, there are a few situations where the autofixer will not be run. For these, you will need to manually fix the output, or migrate the code to `@compiled/react`.
35
+ However, there are a few situations where the autofixer will not be run. For these, you will need to
36
+ manually fix the output, or migrate the code to `@compiled/react`.
30
37
 
31
38
  ### Type annotations
32
39
 
33
- Type annotations in the arrow function are not supported; you will need to remediate the lint error manually. For example:
40
+ Type annotations in the arrow function are not supported; you will need to remediate the lint error
41
+ manually. For example:
34
42
 
35
43
  ```js
36
44
  type Props = {
@@ -60,12 +68,13 @@ styled.div((props: Props) => ({
60
68
 
61
69
  ### Special syntax in the arrow function parameter(s)
62
70
 
63
- Rest elements, default values, and so on in the parameter of an arrow function will need to be remediated manually. For example:
71
+ Rest elements, default values, and so on in the parameter of an arrow function will need to be
72
+ remediated manually. For example:
64
73
 
65
74
  ```js
66
75
  styled.div({
67
- color: ({ myColor = '#fff' }) => myColor,
68
- backgroundColor: ({ myColor = '#aaa' }) => myColor,
76
+ color: ({ myColor = '#fff' }) => myColor,
77
+ backgroundColor: ({ myColor = '#aaa' }) => myColor,
69
78
  });
70
79
  ```
71
80
 
@@ -73,8 +82,8 @@ could potentially be remediated with
73
82
 
74
83
  ```js
75
84
  styled.div((props) => ({
76
- color: myColor ?? '#fff',
77
- backgroundColor: myColor ?? '#aaa',
85
+ color: myColor ?? '#fff',
86
+ backgroundColor: myColor ?? '#aaa',
78
87
  }));
79
88
  ```
80
89
 
@@ -86,12 +95,12 @@ styled.div((props) => ({
86
95
  import styled from 'styled-components';
87
96
 
88
97
  styled.div({
89
- color: ({ myColor }) => myColor,
90
- backgroundColor: (props) => props.someColor,
98
+ color: ({ myColor }) => myColor,
99
+ backgroundColor: (props) => props.someColor,
91
100
  });
92
101
 
93
102
  styled.div({
94
- color: `url(/tmp/${({ coolProp }) => coolProp}.png)`,
103
+ color: `url(/tmp/${({ coolProp }) => coolProp}.png)`,
95
104
  });
96
105
  ```
97
106
 
@@ -101,15 +110,16 @@ styled.div({
101
110
  import styled from '@emotion/styled';
102
111
 
103
112
  styled.div((props) => ({
104
- color: props.myColor,
105
- backgroundColor: props.someColor,
113
+ color: props.myColor,
114
+ backgroundColor: props.someColor,
106
115
  }));
107
116
 
108
117
  styled.div((props) => ({
109
- color: url(`/tmp/${coolProp}.png`),
118
+ color: url(`/tmp/${coolProp}.png`),
110
119
  }));
111
120
  ```
112
121
 
113
122
  ## When not to use it
114
123
 
115
- You do not need this rule if you are not using a codebase that has a violating library as it will never do anything.
124
+ You do not need this rule if you are not using a codebase that has a violating library as it will
125
+ never do anything.
@@ -2,7 +2,10 @@
2
2
 
3
3
  This rule enforces passing dynamic CSS values to the `style` prop in JSX components.
4
4
 
5
- We only want `props.style` to be used for dynamic values that cannot be easily determined at build time, e.g. `<div style={{ width: props.width }}>`. No statics values such as numbers, strings or any other statically analysable values should be passed to the `style` attribute. Instead, static CSS values should be passed into the `css` prop in JSX components.
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
9
 
7
10
  ## Examples
8
11
 
@@ -10,14 +13,14 @@ We only want `props.style` to be used for dynamic values that cannot be easily d
10
13
 
11
14
  ```tsx
12
15
  function Component() {
13
- return (
14
- <div
15
- style={{
16
- margin: 0,
17
- color: 'red',
18
- }}
19
- />
20
- );
16
+ return (
17
+ <div
18
+ style={{
19
+ margin: 0,
20
+ color: 'red',
21
+ }}
22
+ />
23
+ );
21
24
  }
22
25
  ```
23
26
 
@@ -25,14 +28,14 @@ function Component() {
25
28
 
26
29
  ```tsx
27
30
  function Component(props) {
28
- return (
29
- <div
30
- style={{
31
- width: props.width,
32
- '--my-nested-width': props.width,
33
- }}
34
- css={css({ margin: 0, color: 'red' })}
35
- />
36
- );
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
+ );
37
40
  }
38
41
  ```
@@ -1,5 +1,5 @@
1
- The UI Styling Standard is a set of principles to guide styling UI code
2
- across Atlassian's frontend codebases and ecosystem.
1
+ The UI Styling Standard is a set of principles to guide styling UI code across Atlassian's frontend
2
+ codebases and ecosystem.
3
3
 
4
4
  These are the current ESLint rules that enforce and help comply with the UI Styling Standard today,
5
5
  but more are planned to support the standard over time.
@@ -11,6 +11,7 @@ but more are planned to support the standard over time.
11
11
 
12
12
  | Rule | Description | Recommended | Fixable | Suggestions |
13
13
  | --------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------- | ------- | ----------- |
14
+ | <a href="atlaskit-theme/usage">atlaskit-theme</a> | Ban certain usages of `@atlaskit/theme` that `@compiled/react` does not understand | Yes | | |
14
15
  | <a href="convert-props-syntax/usage">convert-props-syntax</a> | Convert props syntax that is unsupported by styled-components@<4 or @emotion/styled to props syntax that is supported. This is useful when used in conjunction with `no-styled-tagged-template-expression`, as output from the latter may use props syntax unsupported by those libraries. | Yes | Yes | |
15
16
  | <a href="enforce-style-prop/usage">enforce-style-prop</a> | Disallows usage of static styles in the `style` attribute in components | Yes | | |
16
17
  | <a href="local-cx-xcss/usage">local-cx-xcss</a> | Ensures the cx() function, which is part of the XCSS API, is only used within the xcss prop. This aids tracking what styles are applied to a jsx element. | Yes | | |
@@ -38,39 +39,46 @@ but more are planned to support the standard over time.
38
39
 
39
40
  ## Purpose of the UI Styling Standard
40
41
 
41
- For Atlassians, refer to the [internal UI Styling Standard policy](https://go.atlassian.com/ui-styling-standard-policy).
42
+ For Atlassians, refer to the
43
+ [internal UI Styling Standard policy](https://go.atlassian.com/ui-styling-standard-policy).
42
44
 
43
45
  To enforce scoped encapsulation, type safety, and deterministic behavior in styling code that is
44
46
  present in other programming languages. This is a stepping stone to large performance improvements,
45
- reduced visual regressions, and enables testing and maintainability at scale.
46
- This approach improves readability and developer productivity via automation with tooling, testing,
47
- code migrations, and future advancements like generative AI.
47
+ reduced visual regressions, and enables testing and maintainability at scale. This approach improves
48
+ readability and developer productivity via automation with tooling, testing, code migrations, and
49
+ future advancements like generative AI.
48
50
 
49
51
  ### Desired outcomes:
50
52
 
51
- - We can make large visual changes and migrations safely and in a fraction of the time.
52
- - To have the vast majority of styling code be deterministic, immutable, and bound to its scope, reducing unknown visual and UX regressions.
53
- - To enable teams to write tooling quicker that's better and more performant to lint, test, and migrate UI code to improve current and future developer productivity and satisfaction.
54
- - To enable large performance improvements for customers and developers with a zero-runtime styling solution.
55
- - To reduce the amount of overall custom styling code written while supporting customization without without the need for hacks and technical debt.
56
- - We aim to see a reduction of the “average styles per component”, reducing the effort to build and maintain UIs.
53
+ - We can make large visual changes and migrations safely and in a fraction of the time.
54
+ - To have the vast majority of styling code be deterministic, immutable, and bound to its scope,
55
+ reducing unknown visual and UX regressions.
56
+ - To enable teams to write tooling quicker that's better and more performant to lint, test, and
57
+ migrate UI code to improve current and future developer productivity and satisfaction.
58
+ - To enable large performance improvements for customers and developers with a zero-runtime
59
+ styling solution.
60
+ - To reduce the amount of overall custom styling code written while supporting customization
61
+ without without the need for hacks and technical debt.
62
+ - We aim to see a reduction of the “average styles per component”, reducing the effort to build
63
+ and maintain UIs.
57
64
 
58
65
  ## Basic principles
59
66
 
60
- We want the styling ecosystem (CSS, CSS-in-JS, and parts of JSX) at Atlassian and the wider ecosystem
61
- we support to be as mature as the other code we write, such as TypeScript/JavaScript, Java, Go, etc.
67
+ We want the styling ecosystem (CSS, CSS-in-JS, and parts of JSX) at Atlassian and the wider
68
+ ecosystem we support to be as mature as the other code we write, such as TypeScript/JavaScript,
69
+ Java, Go, etc.
62
70
 
63
71
  ### Like other languages, styling code must be:
64
72
 
65
- - type-safe
66
- - static and locally analyzable
67
- - reusable and composable
68
- - restricted to an encapsulated scope
69
- - deterministic—with styling known in isolation
70
- - discoverable and readable without deep knowledge of the CSS spec
73
+ - type-safe
74
+ - static and locally analyzable
75
+ - reusable and composable
76
+ - restricted to an encapsulated scope
77
+ - deterministic—with styling known in isolation
78
+ - discoverable and readable without deep knowledge of the CSS spec
71
79
 
72
- As the W3C CSS spec and wider industry grows, having our styling code meet these principles will mean we
73
- can programatically evolve that a better future state.
80
+ As the W3C CSS spec and wider industry grows, having our styling code meet these principles will
81
+ mean we can programatically evolve that a better future state.
74
82
 
75
83
  ## Examples
76
84
 
@@ -142,86 +150,93 @@ export const Component = ({
142
150
 
143
151
  ### Correct code
144
152
 
145
- Every element should be clear in isolation how it's styled, using locally and statically available context so both humans and tooling can read this component in a performant and deterministic manner.
153
+ Every element should be clear in isolation how it's styled, using locally and statically available
154
+ context so both humans and tooling can read this component in a performant and deterministic manner.
146
155
 
147
156
  1. Use `@compiled/…` wherever possible!
148
157
  2. Instead of dynamic styles:
149
- 1. Use static `css()` calls everywhere.
150
- 2. Compose styles together, turning styles on or off.
151
- 3. When absoluteuly necessary, use `props.style` for dynamic styles.
158
+ 1. Use static `css()` calls everywhere.
159
+ 2. Compose styles together, turning styles on or off.
160
+ 3. When absoluteuly necessary, use `props.style` for dynamic styles.
152
161
  3. Instead of nested selectors or global styles:
153
- 1. Style components directly.
154
- 2. Treat everything as local scope, parents shouldn't interact with children wherever feasible.
162
+ 1. Style components directly.
163
+ 2. Treat everything as local scope, parents shouldn't interact with children wherever feasible.
155
164
  4. Instead of passing raw styles around:
156
- 1. Write composable and reusable components which distribute styles with clear context.
157
- 2. Co-locate styles in the same file for human readability and far better tooling feasibility and performance.
158
- 5. Instead of `styled.…`, use `const styles = css({ … });` (hoisted and static) and `<div css={styles} />`.
159
- 1. There will be a safe way to make bounded customizations on components through the use of `<Component xcss={css({ … })}>` in the future.
160
- 6. Instead of `...props`, be explicit with the `aria-` or `data-` props you support, or have more complex spread handling. This is because `className`, `style`, and other things can be applied without any knowledge, resulting in regressions in the future.
161
- 7. Instead of `!important`, `&& { … }`, or other specificity hacks, ensure your styles are correctly scoped to the component.
165
+ 1. Write composable and reusable components which distribute styles with clear context.
166
+ 2. Co-locate styles in the same file for human readability and far better tooling feasibility
167
+ and performance.
168
+ 5. Instead of `styled.…`, use `const styles = css({ … });` (hoisted and static) and
169
+ `<div css={styles} />`.
170
+ 1. There will be a safe way to make bounded customizations on components through the use of
171
+ `<Component xcss={css({ … })}>` in the future.
172
+ 6. Instead of `...props`, be explicit with the `aria-` or `data-` props you support, or have more
173
+ complex spread handling. This is because `className`, `style`, and other things can be applied
174
+ without any knowledge, resulting in regressions in the future.
175
+ 7. Instead of `!important`, `&& { … }`, or other specificity hacks, ensure your styles are correctly
176
+ scoped to the component.
162
177
 
163
178
  ```tsx
164
179
  import { css } from '@compiled/react';
165
180
  import { token } from '@atlaskit/tokens';
166
181
 
167
182
  const wrapperStyles = css({
168
- padding: token('space.200'), // eg. from mixin
169
- font: token('font.body'), // eg. from mixin
170
- color: token('color.text'),
183
+ padding: token('space.200'), // eg. from mixin
184
+ font: token('font.body'), // eg. from mixin
185
+ color: token('color.text'),
171
186
  });
172
187
  const disabledWrapperStyles = css({
173
- color: token('color.text.disabled'),
188
+ color: token('color.text.disabled'),
174
189
  });
175
190
  const innerWrapperStyles = css({
176
- // eg. colocated `innerWrapperStyles` (alternatively could create a reusable `<InnerWrapper>`)
177
- display: 'flex',
178
- gap: token('space.100'),
179
- flexDirection: 'column',
191
+ // eg. colocated `innerWrapperStyles` (alternatively could create a reusable `<InnerWrapper>`)
192
+ display: 'flex',
193
+ gap: token('space.100'),
194
+ flexDirection: 'column',
180
195
  });
181
196
  const buttonStyles = css({
182
- appearance: 'none', // eg. from global styles
183
- padding: `${token('space.100')} ${token('space.200')}`, // eg. from global styles
184
- color: token('color.link'),
197
+ appearance: 'none', // eg. from global styles
198
+ padding: `${token('space.100')} ${token('space.200')}`, // eg. from global styles
199
+ color: token('color.link'),
185
200
  });
186
201
  const disabledButtonStyles = css({
187
- cursor: 'not-allowed', // eg. from disabledStyles
188
- color: token('color.text.disabled'),
189
- opacity: '70%',
202
+ cursor: 'not-allowed', // eg. from disabledStyles
203
+ color: token('color.text.disabled'),
204
+ opacity: '70%',
190
205
  });
191
206
  const buttonAppearanceStyles = cssMap({
192
- primary: { background: token('color.background.brand.subtlest') },
193
- secondary: { background: token('color.background.success') },
207
+ primary: { background: token('color.background.brand.subtlest') },
208
+ secondary: { background: token('color.background.success') },
194
209
  });
195
210
 
196
211
  export const Component = ({
197
- disabled = false,
198
- width = 100,
199
- appearance = 'primary',
200
- 'aria-label': ariaLabel,
212
+ disabled = false,
213
+ width = 100,
214
+ appearance = 'primary',
215
+ 'aria-label': ariaLabel,
201
216
  }: {
202
- disabled?: boolean;
203
- width?: number;
204
- appearance?: 'primary' | 'secondary';
205
- 'aria-label'?: string;
217
+ disabled?: boolean;
218
+ width?: number;
219
+ appearance?: 'primary' | 'secondary';
220
+ 'aria-label'?: string;
206
221
  }) => (
207
- <div
208
- css={[wrapperStyles, props.disabled && disabledWrapperStyles]}
209
- style={{ width: `${props.width}px` }}
210
- aria-label={ariaLabel}
211
- >
212
- <div css={innerWrapperStyles}>
213
- {/* Typically, this `<button>` should be an Atlassian Design System `<Button>` */}
214
- <button
215
- disabled={props.disabled}
216
- css={[
217
- buttonStyles,
218
- buttonAppearances[props.appearance],
219
- props.disabled && disabledButtonStyles,
220
- ]}
221
- >
222
- Click me
223
- </button>
222
+ <div
223
+ css={[wrapperStyles, props.disabled && disabledWrapperStyles]}
224
+ style={{ width: `${props.width}px` }}
225
+ aria-label={ariaLabel}
226
+ >
227
+ <div css={innerWrapperStyles}>
228
+ {/* Typically, this `<button>` should be an Atlassian Design System `<Button>` */}
229
+ <button
230
+ disabled={props.disabled}
231
+ css={[
232
+ buttonStyles,
233
+ buttonAppearances[props.appearance],
234
+ props.disabled && disabledButtonStyles,
235
+ ]}
236
+ >
237
+ Click me
238
+ </button>
239
+ </div>
224
240
  </div>
225
- </div>
226
241
  );
227
242
  ```
@@ -11,22 +11,15 @@ module.exports = {
11
11
 
12
12
  We don't recommended maintaining your own configuration.
13
13
  If you do not use our config you will need to specify individual rules and configuration.
14
- Add the plugin to your `.eslintrc.js` file.
14
+ Add the plugin to your `.eslintrc.js` file and enable individual rules as you're ready to adopt.
15
15
 
16
16
  ```diff
17
17
  module.exports = {
18
18
  plugins: [
19
19
  + '@atlaskit/ui-styling-standard',
20
20
  ],
21
- };
22
- ```
23
-
24
- Enable individual rules as that you're ready to adopt.
25
-
26
- ```diff
27
- module.exports = {
28
21
  rules: [
29
- + '@atlaskit/design-system/consistent-css-prop-usage': 'error',
22
+ + '@atlaskit/ui-styling-standard/convert-props-syntax': 'warn',
30
23
  + '@atlaskit/design-system/local-cx-xcss': 'error',
31
24
  ],
32
25
  };