-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathDemo.js
145 lines (134 loc) · 3.71 KB
/
Demo.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import React, { useState } from "react";
import { JsonForms } from "@jsonforms/react";
import { createTheme, styled, ThemeProvider } from "@mui/material/styles";
import {
materialCells,
materialRenderers,
} from "@jsonforms/material-renderers";
import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";
import { Highlight, themes } from "prism-react-renderer";
import { usePrismTheme } from "@docusaurus/theme-common";
const theme = createTheme({
components: {
MuiFormControl: {
styleOverrides: {
root: {
margin: "0.8em 0",
},
},
defaultProps: {
variant: "standard",
},
},
MuiTextField: {
defaultProps: {
variant: "standard",
},
},
MuiSelect: {
defaultProps: {
variant: "standard",
},
},
},
});
const defaultTheme = createTheme();
const CodeBlockName = styled("div")({
backgroundColor: "#292d3e",
color: "#fff",
borderTopRightRadius: "var(--ifm-pre-border-radius)",
borderTopLeftRadius: "var(--ifm-pre-border-radius)",
borderBottom: "1px solid #eee",
fontSize: "var(--ifm-code-font-size)",
fontWeight: 500,
padding: ".75rem var(--ifm-pre-padding)",
});
const CodeBlock = styled("pre")({
borderTopRightRadius: 0,
borderTopLeftRadius: 0,
});
const TabsWrapper = styled("div")({
color: "#000",
marginBottom: 20,
margin: "auto",
overflow: "scroll",
});
const TabsContainer = styled(Tabs)({
"& li:first-child": {
marginRight: "auto",
},
});
const DemoTab = styled(TabItem)({
borderRadius: "var(--ifm-pre-border-radius)",
padding: "16px",
border: "1px solid #eee",
});
const Code = (props) => {
let content = props.children;
let codeBlockTitle = props.name;
if (content === undefined) {
content = {};
}
const code = JSON.stringify(content, null, 2).replace(/\n$/, "");
const prismTheme = usePrismTheme();
return (
<Highlight code={code} language="json" theme={prismTheme}>
{({ className, style, tokens, getLineProps, getTokenProps }) => (
<div>
{codeBlockTitle && <CodeBlockName>{codeBlockTitle}</CodeBlockName>}
<CodeBlock style={style}>
{tokens.map((line, i) => (
<div {...getLineProps({ line, key: i })}>
{line.map((token, key) => (
<span {...getTokenProps({ token, key })} />
))}
</div>
))}
</CodeBlock>
</div>
)}
</Highlight>
);
};
export const Demo = (props) => {
const { data: inputData, schema, uischema, id, i18n } = props;
const [data, setData] = useState(inputData);
return (
<ThemeProvider theme={defaultTheme}>
<TabsWrapper id={id}>
<TabsContainer
defaultValue="demo"
values={[
{ label: "Demo", value: "demo" },
{ label: "Schema", value: "schema" },
{ label: "UI Schema", value: "uischema" },
{ label: "Data", value: "data" },
]}
>
<DemoTab value="demo">
<ThemeProvider theme={theme}>
<JsonForms
renderers={materialRenderers}
cells={materialCells}
onChange={({ data }) => setData(data)}
i18n={i18n}
{...props}
/>
</ThemeProvider>
</DemoTab>
<TabItem value="schema">
<Code name="schema.json">{schema}</Code>
</TabItem>
<TabItem value="uischema">
<Code name="uischema.json">{uischema}</Code>
</TabItem>
<TabItem value="data">
<Code>{data}</Code>
</TabItem>
</TabsContainer>
</TabsWrapper>
</ThemeProvider>
);
};
export default Demo;