Skip to content

Commit

Permalink
Recursively flatten array of styles
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Avila committed Mar 4, 2020
1 parent 8f9a74a commit 9d85eb3
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@ import './react-jsx'

export * from './types'

const flattenDeep = arr =>
Array.isArray(arr)
? arr.reduce((a, b) => a.concat(flattenDeep(b)), [])
: [arr]

const getCSS = props => {
if (!props.sx && !props.css) return undefined
return theme => {
const sx = Array.isArray(props.sx) ? props.sx : [props.sx]
const sx = flattenDeep(props.sx)
const styles = sx.map(s => css(s)(theme))
const raw = typeof props.css === 'function' ? props.css(theme) : props.css
return [...styles, raw]
Expand Down

0 comments on commit 9d85eb3

Please sign in to comment.