From 338bec2d59241495ee3143b57e8f107e544e76ae Mon Sep 17 00:00:00 2001 From: Delucse <46593742+Delucse@users.noreply.github.com> Date: Fri, 24 Jul 2020 18:18:47 +0200 Subject: [PATCH] accordion to view code of different languages --- src/App.js | 3 ++ src/components/CodeViewer.js | 101 +++++++++++++++++++++++++++++++---- 2 files changed, 93 insertions(+), 11 deletions(-) diff --git a/src/App.js b/src/App.js index a1a4c84..67e20d0 100644 --- a/src/App.js +++ b/src/App.js @@ -17,6 +17,9 @@ const theme = createMuiTheme({ palette: { primary: { main: '#4EAF47', + }, + secondary: { + main: '#DDDDDD' } } }); diff --git a/src/components/CodeViewer.js b/src/components/CodeViewer.js index 2651f69..0a62b12 100644 --- a/src/components/CodeViewer.js +++ b/src/components/CodeViewer.js @@ -7,9 +7,56 @@ import "prismjs/themes/prism.css"; import "prismjs/plugins/line-numbers/prism-line-numbers"; import "prismjs/plugins/line-numbers/prism-line-numbers.css"; +import { withStyles } from '@material-ui/core/styles'; +import MuiAccordion from '@material-ui/core/Accordion'; +import MuiAccordionSummary from '@material-ui/core/AccordionSummary'; +import MuiAccordionDetails from '@material-ui/core/AccordionDetails'; + +const Accordion = withStyles((theme) => ({ + root: { + border: `1px solid ${theme.palette.secondary.main}`, + boxShadow: 'none', + '&:before': { + display: 'none', + }, + '&$expanded': { + margin: 'auto', + }, + }, + expanded: {}, +}))(MuiAccordion); + +const AccordionSummary = withStyles((theme) => ({ + root: { + backgroundColor: theme.palette.secondary.main, + borderBottom: `1px solid white`, + marginBottom: -1, + minHeight: 50, + '&$expanded': { + minHeight: 50, + }, + }, + content: { + '&$expanded': { + margin: '12px 0', + }, + }, + expanded: {}, +}))(MuiAccordionSummary); + +const AccordionDetails = withStyles((theme) => ({ + root: { + padding: theme.spacing(2), + }, +}))(MuiAccordionDetails); + class CodeViewer extends Component { + state = { + expanded: true + } + componentDidMount() { Prism.highlightAll(); } @@ -18,19 +65,51 @@ class CodeViewer extends Component { Prism.highlightAll(); } + onChange = () => { + this.setState({ expanded: !this.state.expanded }); + } + render() { + var curlyBrackets = '{ }'; + var unequal = '<>'; return ( -
-
- {this.props.arduino}
-
-
-
-
- {`${this.props.xml}`}
-
-
+
+
+ {this.props.arduino}
+
+
+
+
+ {`${this.props.xml}`}
+
+
+