|
1 | 1 | import React from 'react' |
2 | 2 | import { createRequire } from 'react-live-runner' |
3 | | -import styled, { css, keyframes, createGlobalStyle } from 'styled-components' |
4 | | -import * as Styled from 'styled-components' |
| 3 | +import * as EmotionCss from '@emotion/css' |
| 4 | +import * as EmotionReact from '@emotion/react' |
| 5 | +import * as EmotionSytled from '@emotion/styled' |
| 6 | +import * as EmotionIsPropValid from '@emotion/is-prop-valid' |
| 7 | +import hashString from '@emotion/hash' |
5 | 8 | import { codeBlock } from 'common-tags' |
6 | 9 | // @ts-ignore |
7 | 10 | import hn from '!!raw-loader!./pages/examples/hacker-news.tsx' |
8 | 11 |
|
9 | | -const imports = { react: React, 'styled-components': Styled } |
| 12 | +let counter = 0 |
| 13 | +const emotionStyled = EmotionSytled.default |
| 14 | +Object.getOwnPropertyNames(emotionStyled).forEach((tag) => { |
| 15 | + if (tag === 'length') return |
| 16 | + Object.defineProperty(emotionStyled, tag, { |
| 17 | + get() { |
| 18 | + return emotionStyled(tag as keyof JSX.IntrinsicElements, { |
| 19 | + target: `e${hashString('react-runner')}${counter++}`, |
| 20 | + }) |
| 21 | + }, |
| 22 | + }) |
| 23 | +}) |
| 24 | + |
| 25 | +const imports = { |
| 26 | + react: React, |
| 27 | + '@emotion/css': EmotionCss, |
| 28 | + '@emotion/react': EmotionReact, |
| 29 | + '@emotion/styled': EmotionSytled, |
| 30 | + '@emotion/is-prop-valid': EmotionIsPropValid, |
| 31 | +} |
10 | 32 | export const scope = { |
11 | 33 | ...React, |
12 | | - styled, |
13 | | - css, |
14 | | - keyframes, |
15 | | - createGlobalStyle, |
| 34 | + styled: EmotionSytled.default, |
| 35 | + css: EmotionReact.css, |
| 36 | + keyframes: EmotionReact.keyframes, |
| 37 | + Global: EmotionReact.Global, |
16 | 38 | require: createRequire(imports), |
| 39 | + jsxPragma: EmotionReact.jsx, |
17 | 40 | } |
18 | 41 |
|
19 | 42 | export const examples = [ |
|
0 commit comments