Skip to content

Commit 0c0bcc0

Browse files
committed
docs: update
1 parent 63811eb commit 0c0bcc0

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed

website/content/docs/concepts/merging-styles.mdx

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ const className = css(style1, style2) // => 'bg_blue text_white'
2525
In some cases though, the style object might not be colocated in the same file as the component. In this case, you can
2626
use the `css.raw` function to preserve the original style object.
2727

28-
> All `.raw(...)` signatures are identity functions that return the same value as the input, but > serve as a hint to
29-
> the compiler that the value is a style object.
28+
> All `.raw(...)` signatures are identity functions that return the same value as the input, but serve as a hint to the
29+
> compiler that the value is a style object.
3030
3131
```js
3232
// style.js
@@ -48,6 +48,41 @@ const style2 = css.raw({
4848
const className = css(style1, style2) // => 'bg_blue text_white'
4949
```
5050

51+
## Spreading `css.raw` objects
52+
53+
> **Added in v1.6.1**
54+
55+
You can also spread `css.raw` objects within style declarations. This is particularly useful for reusing styles in
56+
nested selectors, conditions, and complex compositions:
57+
58+
### Child selectors
59+
60+
```js
61+
import { css } from 'styled-system/css'
62+
63+
const baseStyles = css.raw({ margin: 0, padding: 0 })
64+
65+
const component = css({
66+
'& p': { ...baseStyles, fontSize: '1rem' },
67+
'& h1': { ...baseStyles, fontSize: '2rem' }
68+
})
69+
```
70+
71+
### Nested conditions
72+
73+
```js
74+
import { css } from 'styled-system/css'
75+
76+
const interactive = css.raw({ cursor: 'pointer', transition: 'all 0.2s' })
77+
78+
const card = css({
79+
_hover: {
80+
...interactive,
81+
_dark: { ...interactive, color: 'white' }
82+
}
83+
})
84+
```
85+
5186
## Merging `cva` + `css` styles
5287

5388
The same technique can be used to merge an atomic `cva` recipe and a style object.

website/content/docs/guides/dynamic-styling.mdx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,30 @@ export const Funky: Story = {
226226
}
227227
```
228228

229+
### Enhanced `css.raw` spreading
230+
231+
> **Added in v1.6.1**
232+
233+
You can also spread `css.raw` objects within nested selectors and conditions for better style composition:
234+
235+
```tsx filename="App.tsx"
236+
import { css } from '../styled-system/css'
237+
238+
const baseStyles = css.raw({ margin: 0, padding: 0 })
239+
const interactive = css.raw({ cursor: 'pointer', transition: 'all 0.2s' })
240+
241+
const component = css({
242+
// Spreading in child selectors
243+
'& p': { ...baseStyles, fontSize: '1rem' },
244+
245+
// Spreading in nested conditions
246+
_hover: {
247+
...interactive,
248+
_dark: { ...interactive, color: 'white' }
249+
}
250+
})
251+
```
252+
229253
## Static expressions
230254

231255
Panda supports static expressions in your styles, as long as they are statically analyzable.

0 commit comments

Comments
 (0)