forked from styled-components/styled-components-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLiveEdit.js
106 lines (92 loc) · 2.04 KB
/
LiveEdit.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import React from 'react';
import { LiveEditor, LiveError, LivePreview, LiveProvider } from 'react-live-runner';
import styled, { css } from 'styled-components';
import { darkGrey, red } from '../utils/colors';
import { headerFont, monospace } from '../utils/fonts';
import { phone } from '../utils/media';
import rem from '../utils/rem';
import baseScope from '../utils/scope';
const StyledProvider = styled(LiveProvider)`
box-shadow: ${rem(1)} ${rem(1)} ${rem(20)} rgba(20, 20, 20, 0.27);
overflow: hidden;
margin: ${rem(35)} 0;
text-align: left;
`;
const Row = styled.div`
display: flex;
flex-direction: row;
justify-content: stretch;
align-items: stretch;
${phone(css`
flex-direction: column;
`)};
`;
const columnMixin = css`
flex-basis: 50%;
width: 50%;
max-width: 50%;
${phone(css`
flex-basis: auto;
width: 100%;
max-width: 100%;
height: auto;
`)};
`;
const Code = styled.code`
${columnMixin};
`;
export const editorMixin = `
background: ${darkGrey};
font-size: 0.8rem;
font-family: ${monospace};
font-weight: 300;
min-height: ${rem(400)};
overflow-y: auto !important;
overflow-x: hidden;
cursor: text;
white-space: pre-wrap;
position: relative;
`;
const StyledEditor = styled(LiveEditor)`
${editorMixin};
`;
const StyledPreview = styled(LivePreview)`
position: relative;
padding: 0.5rem;
background: white;
color: black;
height: auto;
overflow: hidden;
white-space: normal;
${columnMixin};
`;
export const StyledError = styled(LiveError)`
display: block;
width: 100%;
padding: ${rem(8)};
background: ${red};
color: white;
font-size: 0.8rem;
font-family: ${headerFont};
white-space: pre;
`;
const LiveEdit = ({ code, scope = {} }) => {
return (
<StyledProvider
code={code}
scope={{
...baseScope,
...scope,
}}
>
<Row>
<Code>
<StyledEditor />
</Code>
<StyledPreview className="notranslate" />
</Row>
<StyledError />
</StyledProvider>
);
};
export default LiveEdit;