2021-02-04 19:15:23 +01:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import ReactCSSTransitionGroup from 'react-transition-group/CSSTransitionGroup';
|
|
|
|
import CustomizeGas from '../gas-customization/gas-modal-page-container';
|
2021-06-10 21:27:03 +02:00
|
|
|
import { MILLISECOND } from '../../../../shared/constants/time';
|
2018-08-23 04:27:35 +02:00
|
|
|
|
|
|
|
export default class Sidebar extends Component {
|
|
|
|
static propTypes = {
|
|
|
|
sidebarOpen: PropTypes.bool,
|
|
|
|
hideSidebar: PropTypes.func,
|
2018-10-26 07:50:36 +02:00
|
|
|
sidebarShouldClose: PropTypes.bool,
|
2018-08-23 04:27:35 +02:00
|
|
|
transitionName: PropTypes.string,
|
|
|
|
type: PropTypes.string,
|
2018-10-26 07:50:36 +02:00
|
|
|
sidebarProps: PropTypes.object,
|
2019-03-05 16:45:01 +01:00
|
|
|
onOverlayClose: PropTypes.func,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-08-23 04:27:35 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderOverlay() {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { onOverlayClose } = this.props;
|
2019-03-05 16:45:01 +01:00
|
|
|
|
2019-12-03 17:35:44 +01:00
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className="sidebar-overlay"
|
|
|
|
onClick={() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
onOverlayClose?.();
|
|
|
|
this.props.hideSidebar();
|
2019-12-03 17:35:44 +01:00
|
|
|
}}
|
|
|
|
/>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-08-23 04:27:35 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderSidebarContent() {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { type, sidebarProps = {} } = this.props;
|
2021-05-18 18:36:05 +02:00
|
|
|
const { transaction = {}, onSubmit, hideBasic } = sidebarProps;
|
2018-08-23 04:27:35 +02:00
|
|
|
switch (type) {
|
2018-10-26 07:50:36 +02:00
|
|
|
case 'customize-gas':
|
2020-11-03 00:41:28 +01:00
|
|
|
return (
|
|
|
|
<div className="sidebar-left">
|
2021-05-18 18:36:05 +02:00
|
|
|
<CustomizeGas
|
|
|
|
transaction={transaction}
|
|
|
|
onSubmit={onSubmit}
|
|
|
|
hideBasic={hideBasic}
|
|
|
|
/>
|
2020-11-03 00:41:28 +01:00
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-08-23 04:27:35 +02:00
|
|
|
default:
|
2021-02-04 19:15:23 +01:00
|
|
|
return null;
|
2018-08-23 04:27:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
componentDidUpdate(prevProps) {
|
2018-10-26 07:50:36 +02:00
|
|
|
if (!prevProps.sidebarShouldClose && this.props.sidebarShouldClose) {
|
2021-02-04 19:15:23 +01:00
|
|
|
this.props.hideSidebar();
|
2018-10-26 07:50:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
render() {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { transitionName, sidebarOpen, sidebarShouldClose } = this.props;
|
2018-08-23 04:27:35 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<ReactCSSTransitionGroup
|
|
|
|
transitionName={transitionName}
|
2021-06-10 21:27:03 +02:00
|
|
|
transitionEnterTimeout={MILLISECOND * 300}
|
|
|
|
transitionLeaveTimeout={MILLISECOND * 200}
|
2018-08-23 04:27:35 +02:00
|
|
|
>
|
2020-11-03 00:41:28 +01:00
|
|
|
{sidebarOpen && !sidebarShouldClose
|
|
|
|
? this.renderSidebarContent()
|
|
|
|
: null}
|
2018-08-23 04:27:35 +02:00
|
|
|
</ReactCSSTransitionGroup>
|
2020-11-03 00:41:28 +01:00
|
|
|
{sidebarOpen && !sidebarShouldClose ? this.renderOverlay() : null}
|
2018-08-23 04:27:35 +02:00
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-08-23 04:27:35 +02:00
|
|
|
}
|
|
|
|
}
|