@@ -25,8 +25,8 @@ const className = css(style1, style2) // => 'bg_blue text_white'
2525In some cases though, the style object might not be colocated in the same file as the component. In this case, you can
2626use 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({
4848const 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
5388The same technique can be used to merge an atomic ` cva ` recipe and a style object.
0 commit comments