diff --git a/src/components/CodeViewer.js b/src/components/CodeViewer.js index 8477cc0..ac540f5 100644 --- a/src/components/CodeViewer.js +++ b/src/components/CodeViewer.js @@ -32,10 +32,10 @@ const AccordionSummary = withStyles((theme) => ({ root: { backgroundColor: theme.palette.secondary.main, borderBottom: `1px solid white`, - marginBottom: -1, - minHeight: 50, + marginBottom: '-1px', + minHeight: '50px', '&$expanded': { - minHeight: 50, + minHeight: '50px', }, }, content: { @@ -55,15 +55,24 @@ const AccordionDetails = withStyles((theme) => ({ class CodeViewer extends Component { - state = { - expanded: true + constructor(props){ + super(props); + this.state = { + expanded: true, + componentHeight: null + }; + this.myDiv = React.createRef(); } componentDidMount() { Prism.highlightAll(); + this.setState({componentHeight: this.myDiv.current.offsetHeight+'px'}); } - componentDidUpdate() { + componentDidUpdate(props, state) { + if(this.myDiv.current && this.myDiv.current.offsetHeight+'px' !== this.state.componentHeight){ + this.setState({componentHeight: this.myDiv.current.offsetHeight+'px'}); + } Prism.highlightAll(); } @@ -74,8 +83,9 @@ class CodeViewer extends Component { render() { var curlyBrackets = '{ }'; var unequal = '<>'; + console.log('render', this.myDiv); return ( - + {curlyBrackets}
Arduino Quellcode
- +
               
                 {this.props.arduino}
@@ -104,7 +114,7 @@ class CodeViewer extends Component {
             {unequal}
             
XML Blöcke
- +
               
                 {`${this.props.xml}`}