1
- import React , { useEffect , useState , lazy , Suspense } from 'react' ;
1
+ import React from 'react' ;
2
2
import Grid from '@material-ui/core/Grid' ;
3
3
import { makeStyles } from '@material-ui/core/styles' ;
4
4
import Typography from '@material-ui/core/Typography' ;
5
5
import Link from '@material-ui/core/Link' ;
6
6
import Box from '@material-ui/core/Box' ;
7
-
7
+ import CodeIcon from '@material-ui/icons/Code' ;
8
+ import ExpansionPanel from '@material-ui/core/ExpansionPanel' ;
9
+ import ExpansionPanelSummary from '@material-ui/core/ExpansionPanelSummary' ;
8
10
import dynamic from 'next/dynamic' ;
9
11
import PropTypes from 'prop-types' ;
12
+ import ExpansionPanelDetails from '@material-ui/core/ExpansionPanelDetails' ;
13
+ import Paper from '@material-ui/core/Paper' ;
14
+ import clsx from 'clsx' ;
15
+ import grey from '@material-ui/core/colors/grey' ;
16
+
17
+ import GhIcon from './common/gh-svg-icon' ;
10
18
11
19
const CodeEditor = dynamic ( import ( './code-editor' ) , {
12
20
ssr : false
@@ -15,11 +23,33 @@ const CodeEditor = dynamic(import('./code-editor'), {
15
23
const reqSource = require . context ( '!raw-loader!@docs/examples' , true , / \. j s / ) ;
16
24
const req = require . context ( '@docs/examples' , true , / \. j s / ) ;
17
25
18
- const useStyles = makeStyles ( ( ) => ( {
26
+ const useStyles = makeStyles ( ( theme ) => ( {
19
27
codeWrapper : {
20
28
background : '#1D1F21' ,
21
29
paddingTop : 16 ,
22
- paddingBottom : 16
30
+ paddingBottom : 16 ,
31
+ borderRadius : 4
32
+ } ,
33
+ componentPanel : {
34
+ padding : 16
35
+ } ,
36
+ heading : {
37
+ fontSize : theme . typography . pxToRem ( 15 ) ,
38
+ fontWeight : theme . typography . fontWeightRegular ,
39
+ flexGrow : 1
40
+ } ,
41
+ secondaryHeading : {
42
+ fontSize : theme . typography . pxToRem ( 15 ) ,
43
+ color : theme . palette . text . secondary
44
+ } ,
45
+ expansionPanel : {
46
+ border : 'none' ,
47
+ boxShadow : 'none' ,
48
+ background : 'none' ,
49
+ padding : 0
50
+ } ,
51
+ expansionPanelSummary : {
52
+ padding : 0
23
53
}
24
54
} ) ) ;
25
55
@@ -29,6 +59,38 @@ const CodeExample = ({ source, mode }) => {
29
59
let Component ;
30
60
if ( mode === 'preview' ) {
31
61
Component = req ( `./${ source } .js` ) . default ;
62
+
63
+ return (
64
+ < Grid container spacing = { 0 } className = "DocRawComponent" >
65
+ < Grid item xs = { 12 } >
66
+ < ExpansionPanel className = { classes . expansionPanel } >
67
+ < ExpansionPanelSummary className = { classes . expansionPanelSummary } expandIcon = { < CodeIcon /> } >
68
+ { Component && < Typography className = { classes . heading } > { Component . name } </ Typography > }
69
+ < Box display = "flex" >
70
+ < Link
71
+ href = { `https://github.com/data-driven-forms/react-forms/tree/master/packages/react-renderer-demo/src/app/examples/${ source } .js` }
72
+ target = "_blank"
73
+ rel = "noopener noreferrer"
74
+ onClick = { ( event ) => event . stopPropagation ( ) }
75
+ >
76
+ < GhIcon style = { { color : grey [ 700 ] } } />
77
+ </ Link >
78
+ </ Box >
79
+ </ ExpansionPanelSummary >
80
+ < ExpansionPanelDetails className = { clsx ( classes . expansionPanelDetail , classes . codeWrapper ) } >
81
+ < CodeEditor value = { codeSource } />
82
+ </ ExpansionPanelDetails >
83
+ </ ExpansionPanel >
84
+ </ Grid >
85
+ { Component && (
86
+ < Grid className = { classes . formContainer } item xs = { 12 } >
87
+ < Paper className = { classes . componentPanel } >
88
+ < Component />
89
+ </ Paper >
90
+ </ Grid >
91
+ ) }
92
+ </ Grid >
93
+ ) ;
32
94
}
33
95
34
96
return (
@@ -49,11 +111,6 @@ const CodeExample = ({ source, mode }) => {
49
111
< Grid item xs = { 12 } className = { classes . codeWrapper } >
50
112
< CodeEditor value = { codeSource } />
51
113
</ Grid >
52
- { mode === 'preview' && Component && (
53
- < Suspense fallback = { < div > loading</ div > } >
54
- < Component />
55
- </ Suspense >
56
- ) }
57
114
</ Grid >
58
115
) ;
59
116
} ;
0 commit comments