From 45a07dfa199a34bf15d253bb12d9680d8731043b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Mijajlovi=C4=87?= Date: Thu, 3 Dec 2020 21:39:14 +0100 Subject: [PATCH] refactor: Update SidePanel.js to use a functional component (#2179) --- platform/viewer/src/components/SidePanel.js | 57 ++++++++++----------- 1 file changed, 26 insertions(+), 31 deletions(-) diff --git a/platform/viewer/src/components/SidePanel.js b/platform/viewer/src/components/SidePanel.js index 5107f7629..4ee28ddb7 100644 --- a/platform/viewer/src/components/SidePanel.js +++ b/platform/viewer/src/components/SidePanel.js @@ -1,41 +1,36 @@ import './SidePanel.css'; -import React, { Component } from 'react'; +import React from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; -class SidePanel extends Component { - static propTypes = { - from: PropTypes.string.isRequired, - isOpen: PropTypes.bool.isRequired, - children: PropTypes.node, - width: PropTypes.string, - }; +const SidePanel = ({ from, isOpen, children, width }) => { + const fromSideClass = from === 'right' ? 'from-right' : 'from-left'; - render() { - const fromSideClass = - this.props.from === 'right' ? 'from-right' : 'from-left'; + const styles = width + ? { + maxWidth: width, + marginRight: isOpen ? '0' : Number.parseInt(width) * -1, + } + : {}; - const styles = this.props.width - ? { - maxWidth: this.props.width, - marginRight: this.props.isOpen - ? '0' - : Number.parseInt(this.props.width) * -1, - } - : {}; + return ( +
+ {children} +
+ ); +}; - return ( -
- {this.props.children} -
- ); - } -} +SidePanel.propTypes = { + from: PropTypes.string.isRequired, + isOpen: PropTypes.bool.isRequired, + children: PropTypes.node, + width: PropTypes.string, +}; export default SidePanel;