Skip to content

Commit

Permalink
feat(emotion): support ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
gregberge committed Dec 22, 2021
1 parent 31ca74b commit 292fe28
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/emotion/src/createStyled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import { StyleGenerator, StyleGeneratorProps } from '@xstyled/system'
import { BoxElements } from '@xstyled/core'
import { createCssFunction, XCSSFunction } from './createCssFunction'

const emStyledInterop =
// @ts-ignore
typeof emStyled === 'function' ? emStyled : emStyled.default

const flattenArgs = (arg: any, props: any): any => {
if (typeof arg === 'function') return flattenArgs(arg(props), props)
if (Array.isArray(arg)) return arg.map((arg) => flattenArgs(arg, props))
Expand Down Expand Up @@ -65,7 +69,7 @@ export const createBaseStyled = <TGen extends StyleGenerator>(
: {}
return ((component: any, options: any) =>
getCreateStyle(
emStyled(component, { ...defaultOptions, ...options }),
emStyledInterop(component, { ...defaultOptions, ...options }),
css,
generator,
)) as XStyled<TGen>
Expand All @@ -78,7 +82,7 @@ export const createStyled = <TGen extends StyleGenerator>(
const styled = createBaseStyled(css)
const xstyled = createBaseStyled(css, generator)
styled.box = xstyled('div')
Object.keys(emStyled).forEach((key) => {
Object.keys(emStyledInterop).forEach((key) => {
// @ts-ignore
styled[key] = styled(key)
// @ts-ignore
Expand Down

0 comments on commit 292fe28

Please sign in to comment.