Skip to content

Commit 465df83

Browse files
committed
fix(emotion): fix ESM interop
Refer #338, #343
1 parent fa93d92 commit 465df83

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

packages/emotion/src/createStyled.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
import * as React from 'react'
2-
import emStyled, { CreateStyledComponent, CreateStyled } from '@emotion/styled'
2+
import { CreateStyledComponent, CreateStyled } from '@emotion/styled'
33
import { Theme } from '@emotion/react'
44
import { StyleGenerator, StyleGeneratorProps } from '@xstyled/system'
55
import { BoxElements } from '@xstyled/core'
66
import { createCssFunction, XCSSFunction } from './createCssFunction'
7-
8-
const emStyledInterop =
9-
// @ts-ignore
10-
typeof emStyled === 'function' ? emStyled : emStyled.default
7+
import { emStyled } from './emStyled'
118

129
const flattenArgs = (arg: any, props: any): any => {
1310
if (typeof arg === 'function') return flattenArgs(arg(props), props)
@@ -69,7 +66,7 @@ export const createBaseStyled = <TGen extends StyleGenerator>(
6966
: {}
7067
return ((component: any, options: any) =>
7168
getCreateStyle(
72-
emStyledInterop(component, { ...defaultOptions, ...options }),
69+
emStyled(component, { ...defaultOptions, ...options }),
7370
css,
7471
generator,
7572
)) as XStyled<TGen>
@@ -82,7 +79,7 @@ export const createStyled = <TGen extends StyleGenerator>(
8279
const styled = createBaseStyled(css)
8380
const xstyled = createBaseStyled(css, generator)
8481
styled.box = xstyled('div')
85-
Object.keys(emStyledInterop).forEach((key) => {
82+
Object.keys(emStyled).forEach((key) => {
8683
// @ts-ignore
8784
styled[key] = styled(key)
8885
// @ts-ignore

packages/emotion/src/createX.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import * as React from 'react'
22
import { Theme } from '@emotion/react'
3-
import emStyled, { StyledComponent } from '@emotion/styled'
3+
import { StyledComponent } from '@emotion/styled'
44
import { StyleGenerator, StyleGeneratorProps } from '@xstyled/system'
55
import { createBaseStyled } from './createStyled'
66
import { createCssFunction } from './createCssFunction'
7+
import { emStyled } from './emStyled'
78

89
type JSXElementKeys = keyof JSX.IntrinsicElements
910

packages/emotion/src/emStyled.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import styled from '@emotion/styled'
2+
3+
// Provide interop since `@emotion/styled` does not work out of the box with ESM
4+
export const emStyled =
5+
// @ts-ignore
6+
typeof styled === 'function' ? styled : styled.default

0 commit comments

Comments
 (0)