Skip to content

Commit fa93d92

Browse files
committed
fix(styled-components): fix ESM interop
Fixes #338
1 parent 5624604 commit fa93d92

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

packages/styled-components/src/createStyled.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,14 @@ import type { ElementType } from 'react'
33
import { BoxElements } from '@xstyled/core'
44
import { string } from '@xstyled/util'
55
import { StyleGenerator, StyleGeneratorProps, Theme } from '@xstyled/system'
6-
import scStyled, {
6+
import {
77
StyledConfig,
88
ThemedBaseStyledInterface,
99
ThemedStyledFunction,
1010
} from 'styled-components'
11+
import { scStyled } from './scStyled'
1112
import { createCssFunction, XCSSFunction } from './createCssFunction'
1213

13-
const scStyledInterop =
14-
// @ts-ignore
15-
typeof scStyled === 'function' ? scStyled : scStyled.default
16-
1714
const getCreateStyle = (
1815
baseCreateStyle: ThemedStyledFunction<any, any>,
1916
css: XCSSFunction,
@@ -80,7 +77,7 @@ export const createBaseStyled = <TGen extends StyleGenerator>(
8077
}
8178
: {}
8279
return ((component: Parameters<typeof scStyled>[0]) => {
83-
const baseStyled = scStyledInterop(component)
80+
const baseStyled = scStyled(component)
8481
return getCreateStyle(
8582
config ? baseStyled.withConfig(config) : baseStyled,
8683
css,
@@ -96,7 +93,7 @@ export const createStyled = <TGen extends StyleGenerator>(
9693
const styled = createBaseStyled(css)
9794
const xstyled = createBaseStyled(css, generator)
9895
styled.box = xstyled('div')
99-
Object.keys(scStyledInterop).forEach((key) => {
96+
Object.keys(scStyled).forEach((key) => {
10097
// @ts-ignore
10198
styled[key] = styled(key)
10299
// @ts-ignore

packages/styled-components/src/createX.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* eslint-disable no-continue, no-loop-func, no-cond-assign */
2-
import scStyled, { StyledComponent, DefaultTheme } from 'styled-components'
2+
import { StyledComponent, DefaultTheme } from 'styled-components'
3+
import { scStyled } from './scStyled'
34
import { StyleGenerator, StyleGeneratorProps } from '@xstyled/system'
45
import { createBaseStyled } from './createStyled'
56
import { createCssFunction } from './createCssFunction'

packages/styled-components/src/css.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import * as React from 'react'
22
import '@testing-library/jest-dom/extend-expect'
33
import { render, cleanup } from '@testing-library/react'
4-
import styled from 'styled-components'
54
import { css, ThemeProvider } from '.'
5+
import { scStyled as styled } from './scStyled'
66

77
afterEach(cleanup)
88

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

0 commit comments

Comments
 (0)