1- import React , { useEffect , useState , lazy , Suspense } from 'react' ;
1+ import React from 'react' ;
22import Grid from '@material-ui/core/Grid' ;
33import { makeStyles } from '@material-ui/core/styles' ;
44import Typography from '@material-ui/core/Typography' ;
55import Link from '@material-ui/core/Link' ;
66import 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' ;
810import dynamic from 'next/dynamic' ;
911import 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' ;
1018
1119const CodeEditor = dynamic ( import ( './code-editor' ) , {
1220 ssr : false
@@ -15,11 +23,33 @@ const CodeEditor = dynamic(import('./code-editor'), {
1523const reqSource = require . context ( '!raw-loader!@docs/examples' , true , / \. j s / ) ;
1624const req = require . context ( '@docs/examples' , true , / \. j s / ) ;
1725
18- const useStyles = makeStyles ( ( ) => ( {
26+ const useStyles = makeStyles ( ( theme ) => ( {
1927 codeWrapper : {
2028 background : '#1D1F21' ,
2129 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
2353 }
2454} ) ) ;
2555
@@ -29,6 +59,38 @@ const CodeExample = ({ source, mode }) => {
2959 let Component ;
3060 if ( mode === 'preview' ) {
3161 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+ ) ;
3294 }
3395
3496 return (
@@ -49,11 +111,6 @@ const CodeExample = ({ source, mode }) => {
49111 < Grid item xs = { 12 } className = { classes . codeWrapper } >
50112 < CodeEditor value = { codeSource } />
51113 </ Grid >
52- { mode === 'preview' && Component && (
53- < Suspense fallback = { < div > loading</ div > } >
54- < Component />
55- </ Suspense >
56- ) }
57114 </ Grid >
58115 ) ;
59116} ;
0 commit comments