Skip to content

Commit 9d85eb3

Browse files
author
Jonathan Avila
committed
Recursively flatten array of styles
1 parent 8f9a74a commit 9d85eb3

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

packages/core/src/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,15 @@ import './react-jsx'
1313

1414
export * from './types'
1515

16+
const flattenDeep = arr =>
17+
Array.isArray(arr)
18+
? arr.reduce((a, b) => a.concat(flattenDeep(b)), [])
19+
: [arr]
20+
1621
const getCSS = props => {
1722
if (!props.sx && !props.css) return undefined
1823
return theme => {
19-
const sx = Array.isArray(props.sx) ? props.sx : [props.sx]
24+
const sx = flattenDeep(props.sx)
2025
const styles = sx.map(s => css(s)(theme))
2126
const raw = typeof props.css === 'function' ? props.css(theme) : props.css
2227
return [...styles, raw]

0 commit comments

Comments
 (0)