Skip to content

Commit 0c95c1a

Browse files
committed
Restyled expansion panned and added GH link.
1 parent 4e25ebe commit 0c95c1a

File tree

2 files changed

+69
-11
lines changed

2 files changed

+69
-11
lines changed

packages/react-renderer-demo/src/app/src/components/code-example.js

Lines changed: 66 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1-
import React, { useEffect, useState, lazy, Suspense } from 'react';
1+
import React from 'react';
22
import Grid from '@material-ui/core/Grid';
33
import { makeStyles } from '@material-ui/core/styles';
44
import Typography from '@material-ui/core/Typography';
55
import Link from '@material-ui/core/Link';
66
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';
810
import dynamic from 'next/dynamic';
911
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';
1018

1119
const CodeEditor = dynamic(import('./code-editor'), {
1220
ssr: false
@@ -15,11 +23,33 @@ const CodeEditor = dynamic(import('./code-editor'), {
1523
const reqSource = require.context('!raw-loader!@docs/examples', true, /\.js/);
1624
const req = require.context('@docs/examples', true, /\.js/);
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
};
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
/* eslint-disable max-len */
22
import React from 'react';
3+
import SvgIcon from '@material-ui/core/SvgIcon';
34

45
const GhIcon = (props) => (
5-
<svg {...props} viewBox="0 0 24 24" aria-hidden="true" role="presentation">
6+
<SvgIcon {...props} viewBox="0 0 24 24" role="presentation">
67
<path d="M12 .3a12 12 0 0 0-3.8 23.4c.6.1.8-.3.8-.6v-2c-3.3.7-4-1.6-4-1.6-.6-1.4-1.4-1.8-1.4-1.8-1-.7.1-.7.1-.7 1.2 0 1.9 1.2 1.9 1.2 1 1.8 2.8 1.3 3.5 1 0-.8.4-1.3.7-1.6-2.7-.3-5.5-1.3-5.5-6 0-1.2.5-2.3 1.3-3.1-.2-.4-.6-1.6 0-3.2 0 0 1-.3 3.4 1.2a11.5 11.5 0 0 1 6 0c2.3-1.5 3.3-1.2 3.3-1.2.6 1.6.2 2.8 0 3.2.9.8 1.3 1.9 1.3 3.2 0 4.6-2.8 5.6-5.5 5.9.5.4.9 1 .9 2.2v3.3c0 .3.1.7.8.6A12 12 0 0 0 12 .3"></path>
7-
</svg>
8+
</SvgIcon>
89
);
910

1011
export default GhIcon;

0 commit comments

Comments
 (0)