Skip to content

Commit d11bb8b

Browse files
committed
chore(website): support emotion imports
1 parent de96dac commit d11bb8b

3 files changed

Lines changed: 290 additions & 6 deletions

File tree

website/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
"deploy": "rm -rf node_modules/.cache build && PREFIX=true next build && next export -o build && touch build/.nojekyll && gh-pages -d build -t true"
1111
},
1212
"dependencies": {
13+
"@emotion/css": "^11.7.1",
14+
"@emotion/is-prop-valid": "^1.1.1",
15+
"@emotion/react": "^11.7.1",
16+
"@emotion/styled": "^11.6.0",
1317
"common-tags": "^1.8.2",
1418
"next": "12.0.7",
1519
"react": "17.0.2",

website/src/constants.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,43 @@ import React from 'react'
22
import { createRequire } from 'react-live-runner'
33
import styled, { css, keyframes, createGlobalStyle } from 'styled-components'
44
import * as Styled from 'styled-components'
5+
import * as EmotionCss from '@emotion/css'
6+
import * as EmotionReact from '@emotion/react'
7+
import * as EmotionSytled from '@emotion/styled'
8+
import * as EmotionIsPropValid from '@emotion/is-prop-valid'
59
import { codeBlock } from 'common-tags'
610
// @ts-ignore
711
import hn from '!!raw-loader!./pages/examples/hacker-news.tsx'
812

9-
const imports = { react: React, 'styled-components': Styled }
13+
let counter = 0
14+
const emotionStyled = EmotionSytled.default
15+
Object.getOwnPropertyNames(emotionStyled).forEach((tag) => {
16+
if (tag === 'length') return
17+
Object.defineProperty(emotionStyled, tag, {
18+
get() {
19+
return emotionStyled(tag as keyof JSX.IntrinsicElements, {
20+
target: `e${tag}-${counter++}`,
21+
})
22+
},
23+
})
24+
})
25+
26+
const imports = {
27+
react: React,
28+
'styled-components': Styled,
29+
'@emotion/css': EmotionCss,
30+
'@emotion/react': EmotionReact,
31+
'@emotion/styled': EmotionSytled,
32+
'@emotion/is-prop-valid': EmotionIsPropValid,
33+
}
1034
export const scope = {
1135
...React,
1236
styled,
1337
css,
1438
keyframes,
1539
createGlobalStyle,
1640
require: createRequire(imports),
41+
jsxPragma: EmotionReact.jsx,
1742
}
1843

1944
export const examples = [

0 commit comments

Comments
 (0)