-
Notifications
You must be signed in to change notification settings - Fork 222
/
Playground.js
81 lines (72 loc) · 1.89 KB
/
Playground.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/* eslint-disable import/no-extraneous-dependencies, import/no-unresolved */
import React, { useState, useReducer, useRef, useEffect } from 'react';
import PropTypes from 'prop-types';
import ReactDOM, { findDOMNode } from 'react-dom';
import Transition, {
ENTERED,
ENTERING,
} from 'react-transition-group/Transition';
import * as Babel from '@babel/standalone';
import { LiveProvider, LiveEditor, LiveError, LivePreview } from 'react-live';
import * as ReactOverlays from 'react-overlays';
import getOffset from 'dom-helpers/offset';
import { css as emotionCss } from '@emotion/core';
import emotionStyled from '@emotion/styled';
import injectCss from '../injectCss';
Babel.registerPreset('env', require('@babel/preset-env'));
Babel.registerPlugin(
'class-properties',
require('@babel/plugin-proposal-class-properties'),
);
const scope = {
useState,
useReducer,
useRef,
useEffect,
ReactDOM,
findDOMNode,
injectCss,
...ReactOverlays,
getOffset,
Transition,
ENTERED,
ENTERING,
css: emotionCss,
styled: emotionStyled,
};
export default class Playground extends React.Component {
static propTypes = {
codeText: PropTypes.string,
};
render() {
return (
<LiveProvider
scope={scope}
mountStylesheet={false}
code={this.props.codeText}
noInline={this.props.codeText.includes('render(')}
transformCode={code =>
Babel.transform(code, {
presets: [
[
'env',
{
loose: true,
targets: {
browsers: ['> 1%', 'not ie <= 8'],
},
},
],
'react',
],
plugins: [['class-properties', { loose: true }]],
}).code
}
>
<LivePreview />
<LiveError />
<LiveEditor />
</LiveProvider>
);
}
}