Skip to content

Commit ec798b4

Browse files
committed
fix(styled-components): support createGlobalStyle
1 parent 4b600a4 commit ec798b4

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { createGlobalStyle as scCreateGlobalStyle } from 'styled-components'
2+
import { css } from './css'
3+
4+
export const createGlobalStyle = (...args) => {
5+
return scCreateGlobalStyle(css(...args))
6+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React from 'react'
2+
import 'jest-dom/extend-expect'
3+
import { render } from '@testing-library/react'
4+
import { createGlobalStyle } from '.'
5+
6+
describe('#createGlobalStyle', () => {
7+
it('injects global styles', () => {
8+
const GlobalStyle = createGlobalStyle`
9+
.margin {
10+
margin: 2;
11+
}
12+
`
13+
const { container } = render(
14+
<>
15+
<GlobalStyle />
16+
<div className="margin" />
17+
</>,
18+
)
19+
expect(container.firstChild).toHaveStyle(`
20+
margin: 8px;
21+
`)
22+
})
23+
})

packages/styled-components/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export {
2-
createGlobalStyle,
32
isStyledComponent,
43
keyframes,
54
ServerStyleSheet,
@@ -14,5 +13,6 @@ export {
1413
} from 'styled-components'
1514

1615
export { css } from './css'
16+
export { createGlobalStyle } from './createGlobalStyle'
1717
export { Box } from './Box'
1818
export { styled as default } from './styled'

0 commit comments

Comments
 (0)