Skip to content

Commit 011a083

Browse files
authored
Merge pull request #1098 from rvsia/addExpandButtonForOptions
Add button for expanding/hiding options in examples
2 parents cd83248 + f42b713 commit 011a083

File tree

1 file changed

+59
-21
lines changed

1 file changed

+59
-21
lines changed

packages/react-renderer-demo/src/components/component-example.js

Lines changed: 59 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ import Box from '@material-ui/core/Box';
1818
import LinkIcon from '@material-ui/icons/Link';
1919
import Button from '@material-ui/core/Button';
2020
import ButtonGroup from '@material-ui/core/ButtonGroup';
21+
import ExpandMoreIcon from '@material-ui/icons/ExpandMore';
22+
import CardHeader from '@material-ui/core/CardHeader';
23+
import IconButton from '@material-ui/core/IconButton';
2124

2225
import Link from 'next/link';
2326
import clsx from 'clsx';
@@ -133,6 +136,24 @@ const useStyles = makeStyles((theme) => ({
133136
hidden: {
134137
height: 0,
135138
minHeight: 0
139+
},
140+
expand: {
141+
transform: 'rotate(-90deg)'
142+
},
143+
hide: {
144+
transform: 'rotate(90deg)'
145+
},
146+
tableHeader: {
147+
paddingBottom: 0,
148+
[theme.breakpoints.down('sm')]: {
149+
display: 'none'
150+
}
151+
},
152+
tableBody: {
153+
paddingTop: 0
154+
},
155+
expandButton: {
156+
width: '100%'
136157
}
137158
}));
138159

@@ -144,6 +165,7 @@ const stringifyWithFunctions = (string) =>
144165

145166
const ComponentExample = ({ variants, schema, activeMapper, component, schemaVariants }) => {
146167
const [variant, setVariant] = useState('basic');
168+
const [expanded, setExpanded] = useState(true);
147169

148170
const { pathname, push } = useRouter();
149171
const classes = useStyles();
@@ -204,28 +226,39 @@ const ComponentExample = ({ variants, schema, activeMapper, component, schemaVar
204226
return (
205227
<React.Fragment>
206228
<Box display="flex" className={classes.box}>
207-
<Card style={{ minHeight: 500 }} square>
208-
<CardContent>
209-
<Table>
210-
<TableHead>
211-
<TableRow>
212-
<TableCell>Name</TableCell>
213-
<TableCell>Type</TableCell>
214-
<TableCell>Required</TableCell>
215-
</TableRow>
216-
</TableHead>
217-
<TableBody>
218-
{variants.map(({ name, type, required }) => (
219-
<TableRow key={name}>
220-
<TableCell>{name}</TableCell>
221-
<TableCell>{`${type}`}</TableCell>
222-
<TableCell>{required && <CheckIcon fontSize="small" />}</TableCell>
229+
{expanded && (
230+
<Card style={{ minHeight: 500 }} square>
231+
<CardHeader
232+
className={clsx(classes.tableHeader)}
233+
title={expanded ? 'Options' : ''}
234+
action={
235+
<IconButton aria-label="hide options" onClick={() => setExpanded(!expanded)}>
236+
<ExpandMoreIcon className={classes.hide} />
237+
</IconButton>
238+
}
239+
/>
240+
<CardContent className={classes.tableBody}>
241+
<Table>
242+
<TableHead>
243+
<TableRow>
244+
<TableCell>Name</TableCell>
245+
<TableCell>Type</TableCell>
246+
<TableCell>Required</TableCell>
223247
</TableRow>
224-
))}
225-
</TableBody>
226-
</Table>
227-
</CardContent>
228-
</Card>
248+
</TableHead>
249+
<TableBody>
250+
{variants.map(({ name, type, required }) => (
251+
<TableRow key={name}>
252+
<TableCell>{name}</TableCell>
253+
<TableCell>{`${type}`}</TableCell>
254+
<TableCell>{required && <CheckIcon fontSize="small" />}</TableCell>
255+
</TableRow>
256+
))}
257+
</TableBody>
258+
</Table>
259+
</CardContent>
260+
</Card>
261+
)}
229262
<Box display="flex" className={classes.editorContainer}>
230263
<div className={classes.smTabDown}>
231264
<Tabs
@@ -240,6 +273,11 @@ const ComponentExample = ({ variants, schema, activeMapper, component, schemaVar
240273
</Tabs>
241274
</div>
242275
<div className={classes.smTabUp}>
276+
{!expanded && (
277+
<IconButton className={classes.expandButton} aria-label="expand options" onClick={() => setExpanded(!expanded)}>
278+
<ExpandMoreIcon className={classes.expand} />
279+
</IconButton>
280+
)}
243281
<Tabs
244282
value={activeMapper}
245283
orientation="vertical"

0 commit comments

Comments
 (0)