-
Notifications
You must be signed in to change notification settings - Fork 0
/
playground.jsx
115 lines (97 loc) · 2.41 KB
/
playground.jsx
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
107
108
109
110
111
112
113
114
115
/* eslint-disable react/prop-types */
import React, { Fragment } from "react";
import Playground from "component-playground";
import ReactDOM from "react-dom";
import styled, { createGlobalStyle } from "styled-components";
import { lighten, complement } from "polished";
import * as components from "./src";
const GlobalStyle = createGlobalStyle`
:root {
--primary: rgb(23, 121, 186);
--secondary: rgb(118, 118, 118);
--success: rgb(58, 219, 118);
--error: rgb(204, 75, 55);
--warning: rgb(255, 174, 0);
--primary-font_color: ${lighten(0.5, complement("rgb(23, 121, 186)"))};
--secondary-font_color: ${lighten(0.5, complement("rgb(118, 118, 118)"))};
--success-font_color: ${lighten(0.5, complement("rgb(58, 219, 118)"))};
--error-font_color: ${lighten(0.5, complement("rgb(204, 75, 55)"))};
--warning-font_color: ${lighten(0.5, complement("rgb(255, 174, 0)"))};
}
body, html {
width: 100%;
height: 100%;
}
#root {
padding: 40px 20px;
}
`;
const Wrapper = styled.div`
display: ${p => (p.flex ? "flex" : "initial")};
> * {
margin: 1rem;
}
`;
const scope = { React, ...components, Wrapper };
const examples = Object.entries(components)
.map(([name, module]) => {
let src;
try {
src = require(`./examples/${name}.sample`);
} catch (e) {
return;
}
return {
name,
docClass: module,
src,
scope,
};
})
.filter(Boolean);
class Index extends React.Component {
render() {
return (
<Fragment>
<components.Normalize />
<GlobalStyle />
{examples.map(makePlayground)}
</Fragment>
);
}
}
ReactDOM.render(<Index />, document.getElementById("root"));
if (import.meta.webpackHot) import.meta.webpackHot.accept();
function makePlayground({ src, scope, name }) {
const Wrapper = styled.div`
.playground {
display: flex;
flex-direction: row;
align-items: center;
justify-items: space-between;
margin: 10px auto;
overflow: hidden;
}
.CodeMirror {
padding: 10px;
}
.playgroundCode {
}
.playgroundPreview {
margin-left: auto;
margin-right: 1rem;
box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.25);
}
`;
return (
<Wrapper key={`${name}`}>
<h1>{name}</h1>
<Playground
codeText={src}
scope={scope}
// collapsableCode
/>
<hr />
</Wrapper>
);
}