refactor: Update SidePanel.js to use a functional component (#2179)

This commit is contained in:
Nikola Mijajlović 2020-12-03 21:39:14 +01:00 committed by GitHub
parent 7323e63608
commit 45a07dfa19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,27 +1,16 @@
import './SidePanel.css'; import './SidePanel.css';
import React, { Component } from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import classNames from 'classnames'; import classNames from 'classnames';
class SidePanel extends Component { const SidePanel = ({ from, isOpen, children, width }) => {
static propTypes = { const fromSideClass = from === 'right' ? 'from-right' : 'from-left';
from: PropTypes.string.isRequired,
isOpen: PropTypes.bool.isRequired,
children: PropTypes.node,
width: PropTypes.string,
};
render() { const styles = width
const fromSideClass =
this.props.from === 'right' ? 'from-right' : 'from-left';
const styles = this.props.width
? { ? {
maxWidth: this.props.width, maxWidth: width,
marginRight: this.props.isOpen marginRight: isOpen ? '0' : Number.parseInt(width) * -1,
? '0'
: Number.parseInt(this.props.width) * -1,
} }
: {}; : {};
@ -29,13 +18,19 @@ class SidePanel extends Component {
<section <section
style={styles} style={styles}
className={classNames('sidepanel', fromSideClass, { className={classNames('sidepanel', fromSideClass, {
'is-open': this.props.isOpen, 'is-open': isOpen,
})} })}
> >
{this.props.children} {children}
</section> </section>
); );
} };
}
SidePanel.propTypes = {
from: PropTypes.string.isRequired,
isOpen: PropTypes.bool.isRequired,
children: PropTypes.node,
width: PropTypes.string,
};
export default SidePanel; export default SidePanel;