Skip to content

Commit

Permalink
fix(emotion): fix ESM interop
Browse files Browse the repository at this point in the history
Refer #338, #343
  • Loading branch information
gregberge committed Jan 10, 2022
1 parent fa93d92 commit 465df83
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
11 changes: 4 additions & 7 deletions packages/emotion/src/createStyled.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import * as React from 'react'
import emStyled, { CreateStyledComponent, CreateStyled } from '@emotion/styled'
import { CreateStyledComponent, CreateStyled } from '@emotion/styled'
import { Theme } from '@emotion/react'
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
import { emStyled } from './emStyled'

const flattenArgs = (arg: any, props: any): any => {
if (typeof arg === 'function') return flattenArgs(arg(props), props)
Expand Down Expand Up @@ -69,7 +66,7 @@ export const createBaseStyled = <TGen extends StyleGenerator>(
: {}
return ((component: any, options: any) =>
getCreateStyle(
emStyledInterop(component, { ...defaultOptions, ...options }),
emStyled(component, { ...defaultOptions, ...options }),
css,
generator,
)) as XStyled<TGen>
Expand All @@ -82,7 +79,7 @@ export const createStyled = <TGen extends StyleGenerator>(
const styled = createBaseStyled(css)
const xstyled = createBaseStyled(css, generator)
styled.box = xstyled('div')
Object.keys(emStyledInterop).forEach((key) => {
Object.keys(emStyled).forEach((key) => {
// @ts-ignore
styled[key] = styled(key)
// @ts-ignore
Expand Down
3 changes: 2 additions & 1 deletion packages/emotion/src/createX.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import * as React from 'react'
import { Theme } from '@emotion/react'
import emStyled, { StyledComponent } from '@emotion/styled'
import { StyledComponent } from '@emotion/styled'
import { StyleGenerator, StyleGeneratorProps } from '@xstyled/system'
import { createBaseStyled } from './createStyled'
import { createCssFunction } from './createCssFunction'
import { emStyled } from './emStyled'

type JSXElementKeys = keyof JSX.IntrinsicElements

Expand Down
6 changes: 6 additions & 0 deletions packages/emotion/src/emStyled.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import styled from '@emotion/styled'

// Provide interop since `@emotion/styled` does not work out of the box with ESM
export const emStyled =
// @ts-ignore
typeof styled === 'function' ? styled : styled.default

0 comments on commit 465df83

Please sign in to comment.