Skip to content

Commit 2e87beb

Browse files
authored
Update most of Compiled documentation to reflect current recommendations (#1688)
* Update 'Writing CSS' and 'Installation', move some sections into new 'Deprecated features' section * Update CSS prop page and deprecated syntax page: - move template literals to deprecated page - discourage dynamic styles - move outdated composition syntax to deprecated page * Fix order of pages in Guides and API sections * Fix typo in JSX pragma * Update documentation for Compiled APIs * Deprecate styled and ClassNames * Merge CSS page into CSS prop * Update cssMap to use flat `@media` query syntax, not the nested one that DST will remove support for * Move details about the `jsx-pragma` ESLint rule to the "JSX pragma" section of the Installation page * Make imports alphabetical
1 parent 2b3e2bd commit 2e87beb

14 files changed

+352
-251
lines changed

website/packages/docs/src/pages/api-class-names.mdx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
---
2-
section: 5-API
3-
order: 3
4-
name: Class Names
2+
section: 6-Deprecated API
3+
order: 11
4+
name: '[Deprecated] ClassNames'
55
---
66

77
import { ClassNamesObj, ClassNamesDynamic, ClassNamesComposition } from '../examples/class-names';
88

9-
# Class Names
9+
# \[Deprecated\] ClassNames
10+
11+
> **Deprecated**<br />
12+
> We do not recommend using `ClassNames` or the `className` prop in any code. Please use [`css`](/api-css-prop) or [`cssMap`](/api-cssmap) instead.
1013
1114
Use a component where styles are not necessarily used on a JSX element.
1215

Lines changed: 18 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,41 @@
11
---
22
section: 5-API
33
order: 1
4-
name: CSS Prop
4+
name: css prop
55
---
66

7-
import {
8-
CssPropObj,
9-
CssPropString,
10-
CssPropDynamic,
11-
CssPropCompositionCorrect,
12-
CssPropCompositionIncorrect,
13-
CssPropCompositionNoStyle,
14-
CssPropConditionalRules,
15-
} from '../examples/css-prop';
7+
import { CssPropConditionalRules, CssPropDynamic, CssPropObj } from '../examples/css-prop';
168

17-
# CSS Prop
9+
# css prop
1810

19-
Style a JSX element,
20-
enabled when a JSX pragma is defined and the JSX element also takes a `className` prop.
11+
Using a `css` function call on a `css` prop is the preferred way to apply styles to a JSX element. This is enabled when a JSX pragma is defined, and the JSX element takes a `className` prop.
2112

22-
<CssPropObj />
23-
24-
> **Don't worry about the pragma**<br />
25-
> For a streamlined developer experience install the `jsx-pragma` rule from the [ESLint plugin](/pkg-eslint-plugin) and never forget it again.
13+
We use a syntax similar to Emotion's `css` prop, but we wrap the style object in a `css` function call. Using the `css` function call allows us to apply type checking, and it makes it clear that the styles should be applied by Compiled (and not a different CSS-in-JS library).
2614

27-
## Template literal rules
15+
> **Only use `css` with Compiled APIs**<br />
16+
> The return value of the `css` function call at runtime is `null` and can only be passed to the `css` prop, or used with other Compiled APIs.
2817
29-
Write your styles as a template literal.
30-
Use the [`css`](/api-css) import for better syntax highlighting.
18+
<CssPropObj />
3119

32-
<CssPropString />
20+
## Using composition to combine styles
3321

34-
Although template literal is supported, we recommend using object style instead of template literal.
22+
Read [composition](/composition) for more information around composing styles together.
3523

3624
## Conditional rules
3725

38-
Conditionally apply [CSS rules](https://developer.mozilla.org/en-US/docs/Learn/CSS/First_steps/How_CSS_is_structured#Selectors).
26+
Conditionally apply [CSS rules](https://developer.mozilla.org/en-US/docs/Learn/CSS/First_steps/How_CSS_is_structured#Selectors) by passing an array to the `css` prop. The last styles applied in the array wins.
3927

4028
<CssPropConditionalRules />
4129

42-
## Dynamic declarations
43-
44-
Change a [CSS declaration](https://developer.mozilla.org/en-US/docs/Learn/CSS/First_steps/How_CSS_is_structured#Properties_and_values) at runtime,
45-
powered by [CSS variables](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties).
46-
47-
<CssPropDynamic />
48-
49-
## Composition gotchas
50-
51-
Compiled will try to generate the smallest amount of code possible.
52-
When composing styles ensure to explicitly define both a `className` and `style` prop.
30+
## Dynamic styling and props
5331

54-
Here the `className` and `style` props are both defined so styling works correctly.
32+
We no longer recommend passing dynamic styling or props to Compiled, as they can be tricky for other Atlassian tooling to statically analyse.
5533

56-
<CssPropCompositionCorrect />
34+
Instead, we recommend you:
5735

58-
The next few example show what happens if you don't do this.
36+
- First, determine whether you truly need the styles to be dynamic. Many cases of dynamic styling can be rewritten as conditional rules or [`cssMap` usages](/api-cssmap).
37+
- If you absolutely need to use dynamic styling, you can pass dynamic styling to the `style` prop. Check out the [UI Styling Standard](https://atlassian.design/components/eslint-plugin-ui-styling-standard/migration-guide) for more details.
5938

60-
### Spread pops
39+
In the past, this was how to write dynamic styles with Compiled:
6140

62-
The overflow `props` are spread onto the element so the composed styles are not applied.
63-
64-
Statically defining them fixes this.
65-
66-
<CssPropCompositionIncorrect />
67-
68-
### Missing style
69-
70-
The `style` prop is missing so the CSS variables used to power dynamic declarations aren't set.
71-
In this case instead it receives the `body` color value instead of pink.
72-
73-
Statically defining the style prop fixes this.
74-
75-
<CssPropCompositionNoStyle />
41+
<CssPropDynamic />
Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,9 @@
11
---
22
section: 5-API
3-
order: 99
4-
name: CSS
3+
order: 13
4+
name: '[Archived] CSS'
55
---
66

77
# CSS
88

9-
Define styles that can be statically typed and useable with other Compiled APIs.
10-
11-
> **Opaque styles**<br/>
12-
> The return value of `css` at runtime is `null` and can only be used with other Compiled APIs.
13-
14-
```jsx
15-
const redText = css({
16-
color: 'red',
17-
});
18-
19-
<div css={redText} />;
20-
```
21-
22-
Read [composition](/composition) for more information around composing styles together.
9+
The contents of this page have been merged into the [css prop](/api-css-prop) documentation. Check it out!

website/packages/docs/src/pages/api-cssmap.mdx

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
---
22
section: 5-API
3-
order: 99
4-
name: CSS Map
3+
order: 10
4+
name: cssMap
55
---
66

7-
# CSS Map
7+
# cssMap
88

99
Define a map consisting of named CSS rules that can be statically typed and useable with other Compiled APIs.
1010

11-
> **Can only be used with other Compiled APIs**<br />
12-
> The `cssMap` function returns an object at runtime, which contains classnames as its values and variant names as its keys. These can only be used in conjunction with other Compiled APIs.
11+
> **Only use `cssMap` with Compiled APIs**<br />
12+
> The `cssMap` function returns an object at runtime, which contains class names as its values and variant names as its keys. These can only be used in conjunction with other Compiled APIs.
1313
1414
```jsx
1515
import { cssMap } from '@compiled/react';
@@ -97,7 +97,7 @@ const borderStyleMap = cssMap({
9797

9898
### At-rules (`@media` queries, `@supports`, `@page`, etc.)
9999

100-
With `cssMap`, you can specify media queries by splitting the `@media` part and the rest of the media query into two, just like with the [`vanilla-extract`](https://vanilla-extract.style/documentation/styling/#media-queries) library. `@media` becomes the key, and the value is an object that contains the remainder of your media query. This allows you to more easily find your media queries in one place.
100+
With `cssMap`, you can also specify media queries and most other at-rules (`@supports`, `@page`, etc.) directly in the variant object. Media queries, and the styles inside them, will also be strongly typed.
101101

102102
See below for an example:
103103

@@ -106,28 +106,22 @@ const myMap = cssMap({
106106
danger: {
107107
color: 'red',
108108
// The generated CSS will be
109-
// @media (min-width: 500px) { ... }
110-
// @media (max-width: 800px) { ... }
111-
'@media': {
112-
'(min-width: 500px)': {
113-
fontSize: '1.5em',
114-
},
115-
'(max-width: 800px)': {
116-
fontSize: '1.8em',
117-
},
109+
'@media (min-width: 500px)': {
110+
fontSize: '1.5em',
111+
},
112+
'@media (max-width: 800px)': {
113+
fontSize: '1.8em',
118114
},
119115
},
120116
success: {
121117
color: 'green',
122-
'@media': {
123-
// You can specify different media queries
124-
// for another variant if you want.
125-
'(min-width: 400px)': {
126-
fontSize: '1.3em',
127-
},
128-
'(min-width: 900px)': {
129-
fontSize: '1.5em',
130-
},
118+
// You can specify different media queries
119+
// for another variant if you want.
120+
'@media (min-width: 400px)': {
121+
fontSize: '1.3em',
122+
},
123+
'@media (min-width: 900px)': {
124+
fontSize: '1.5em',
131125
},
132126
'&:hover': {
133127
color: '#8f8',
@@ -136,7 +130,7 @@ const myMap = cssMap({
136130
});
137131
```
138132

139-
This applies to other at-rules as well (CSS rules that start with an `@` sign), including `@support`, `@container`, and so on.
133+
Previously you would specify media queries by splitting the `@media` part and the rest of the media query into two, just like with the [`vanilla-extract`](https://vanilla-extract.style/documentation/styling/#media-queries) library. We no longer recommend this as it is inconsistent with other Compiled APIs, and our type checking now works without the need for splitting media queries into two.
140134

141135
### Nested selectors and advanced selectors
142136

@@ -149,10 +143,8 @@ However, if you really need to use nested selectors, this can be done through th
149143
const myMap = cssMap({
150144
danger: {
151145
color: 'red',
152-
'@media': {
153-
'(min-width: 100px)': {
154-
fontSize: '1.5em',
155-
},
146+
'@media (min-width: 100px)': {
147+
fontSize: '1.5em',
156148
},
157149
'&:hover': {
158150
color: 'pink',
@@ -169,10 +161,8 @@ const myMap = cssMap({
169161
},
170162
success: {
171163
color: 'green',
172-
'@media': {
173-
'(min-width: 100px)': {
174-
fontSize: '1.3em',
175-
},
164+
'@media (min-width: 100px)': {
165+
fontSize: '1.3em',
176166
},
177167
'&:hover': {
178168
color: '#8f8',
@@ -188,7 +178,7 @@ const myMap = cssMap({
188178

189179
## Composing styles
190180

191-
`cssMap` can be composed with other styles that are specified through the [css API](/api-css).
181+
`cssMap` can be composed with other styles that are specified through the [css API](/api-css-prop).
192182

193183
```jsx
194184
import { css, cssMap } from '@compiled/react';
Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
section: 5-API
3-
order: 99
4-
name: Keyframes
3+
order: 10
4+
name: keyframes
55
---
66

77
# Keyframes
@@ -21,15 +21,9 @@ const fadeOut = keyframes({
2121
},
2222
});
2323

24-
const fadeOut = keyframes`
25-
from {
26-
opacity: 1;
27-
}
28-
29-
to {
30-
opacity: 0;
31-
}
32-
`;
24+
const animationStyles = css({
25+
animation: `${fadeOut} 2s`,
26+
});
3327

34-
<div css={{ animation: `${fadeOut} 2s` }} />;
28+
const FadeOut = <div css={animationStyles}>I am fading out!</div>;
3529
```

website/packages/docs/src/pages/api-styled.mdx

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
section: 5-API
3-
order: 2
4-
name: Styled
2+
section: 6-Deprecated API
3+
order: 10
4+
name: '[Deprecated] styled'
55
---
66

77
import {
@@ -13,16 +13,20 @@ import {
1313
StyledComposition,
1414
} from '../examples/styled';
1515

16-
# Styled
16+
# \[Deprecated\] styled
17+
18+
> **Deprecated**<br />
19+
> We no longer recommend using `styled` prop in new code, and we support this only to make migration from `styled-components` possible. Please use [`css`](/api-css-prop) or [`cssMap`](/api-cssmap) instead.<br /><br />
20+
> If you use the recommended [UI Styling Standard ESLint plugin](https://atlassian.design/components/eslint-plugin-ui-styling-standard/no-styled/usage), this will be enforced for you.
1721
1822
Create a component that styles a JSX element which comes with built-in behavior such as `ref` and `as` prop support.
1923

2024
<StyledObj />
2125

22-
> **Tagged template expressions** <br /> Tagged template expressions are supported but call expression syntax is preferred.
26+
> **Tagged template expressions** <br /> Tagged template expressions are supported but using object styles is preferred.
2327
> See the
24-
> [no-styled-tagged-template-expression eslint rule](https://github.com/atlassian-labs/compiled/tree/master/packages/eslint-plugin/src/rules/no-styled-tagged-template-expression)
25-
> for more details.
28+
> [no-styled-tagged-template-expression ESLint rule](https://atlassian.design/components/eslint-plugin-design-system/no-styled-tagged-template-expression/usage) in the UI
29+
> Styling Standard for more details.
2630
2731
## Dynamic declarations
2832

@@ -49,7 +53,7 @@ but `$color` is not.
4953

5054
<StyledTransientProps />
5155

52-
## The as prop
56+
## The `as` prop
5357

5458
The `as` prop is useful when wanting to change the markup during runtime to something else,
5559
such as from a `<h1>` element to a `<span>`.
@@ -59,7 +63,7 @@ such as from a `<h1>` element to a `<span>`.
5963
## Composing components
6064

6165
Wrapping an already defined component enables you to pass styles to it.
62-
Here the `BlueText` styles take presedence over `RedText`.
66+
Here the `BlueText` styles take precedence over `RedText`.
6367

6468
<StyledComposition />
6569

@@ -68,8 +72,8 @@ Here the `BlueText` styles take presedence over `RedText`.
6872
6973
## TypeScript
7074

71-
Type support comes out of the box so you'll have a great time using Compiled with TypeScript,
72-
any interpolation will have access to the props defined in the tagged template generic.
75+
Type support comes out of the box, so you'll have a great time using Compiled with TypeScript.
76+
Any interpolation will have access to the props defined in the tagged template generic.
7377

7478
```jsx
7579
import { styled } from '@compiled/react';

website/packages/docs/src/pages/atomic-css.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
section: 50-Guides
33
name: Atomic CSS
4-
order: 99
4+
order: 20
55
---
66

77
# Atomic CSS

0 commit comments

Comments
 (0)