2021-04-12 13:32:25 +00:00
|
|
|
import React, { Component } from "react";
|
|
|
|
import PropTypes from "prop-types";
|
|
|
|
import { Link } from "react-router";
|
|
|
|
import classnames from "classnames";
|
2016-09-16 21:19:37 +00:00
|
|
|
|
2021-06-07 01:56:30 +00:00
|
|
|
import FleetIcon from "components/icons/FleetIcon";
|
2017-01-13 23:32:21 +00:00
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
const baseClass = "stacked-white-boxes";
|
2016-12-06 16:55:48 +00:00
|
|
|
|
2016-09-16 21:19:37 +00:00
|
|
|
class StackedWhiteBoxes extends Component {
|
|
|
|
static propTypes = {
|
|
|
|
children: PropTypes.element,
|
|
|
|
headerText: PropTypes.string,
|
2016-11-03 19:40:54 +00:00
|
|
|
className: PropTypes.string,
|
2016-09-16 21:19:37 +00:00
|
|
|
leadText: PropTypes.string,
|
2016-12-06 16:55:48 +00:00
|
|
|
onLeave: PropTypes.func,
|
2016-09-16 21:19:37 +00:00
|
|
|
previousLocation: PropTypes.string,
|
|
|
|
};
|
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
constructor(props) {
|
2016-12-06 16:55:48 +00:00
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
isLoading: false,
|
|
|
|
isLoaded: false,
|
|
|
|
isLeaving: false,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
componentWillMount() {
|
2016-12-06 16:55:48 +00:00
|
|
|
this.setState({
|
|
|
|
isLoading: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
componentDidMount() {
|
2016-12-07 20:19:13 +00:00
|
|
|
const { didLoad } = this;
|
|
|
|
didLoad();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
didLoad = () => {
|
2016-12-06 16:55:48 +00:00
|
|
|
this.setState({
|
|
|
|
isLoading: false,
|
|
|
|
isLoaded: true,
|
|
|
|
});
|
2021-04-12 13:32:25 +00:00
|
|
|
};
|
2016-12-06 16:55:48 +00:00
|
|
|
|
|
|
|
nowLeaving = (evt) => {
|
|
|
|
const { window } = global;
|
|
|
|
const { onLeave, previousLocation } = this.props;
|
|
|
|
evt.preventDefault();
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
isLoading: false,
|
|
|
|
isLoaded: false,
|
|
|
|
isLeaving: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
if (previousLocation) {
|
2021-04-12 13:32:25 +00:00
|
|
|
window.setTimeout(() => {
|
|
|
|
onLeave(previousLocation);
|
|
|
|
}, 300);
|
2016-12-06 16:55:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2021-04-12 13:32:25 +00:00
|
|
|
};
|
2016-12-06 16:55:48 +00:00
|
|
|
|
2016-09-16 21:19:37 +00:00
|
|
|
renderBackButton = () => {
|
|
|
|
const { previousLocation } = this.props;
|
2016-12-06 16:55:48 +00:00
|
|
|
const { nowLeaving } = this;
|
2016-09-16 21:19:37 +00:00
|
|
|
|
|
|
|
if (!previousLocation) return false;
|
|
|
|
|
|
|
|
return (
|
2016-12-06 16:55:48 +00:00
|
|
|
<div className={`${baseClass}__back`}>
|
2021-04-12 13:32:25 +00:00
|
|
|
<Link
|
|
|
|
to={previousLocation}
|
|
|
|
className={`${baseClass}__back-link`}
|
|
|
|
onClick={nowLeaving}
|
|
|
|
>
|
2021-06-07 01:56:30 +00:00
|
|
|
<FleetIcon name="x" />
|
2017-01-13 23:32:21 +00:00
|
|
|
</Link>
|
2016-09-16 21:19:37 +00:00
|
|
|
</div>
|
|
|
|
);
|
2021-04-12 13:32:25 +00:00
|
|
|
};
|
2016-09-16 21:19:37 +00:00
|
|
|
|
|
|
|
renderHeader = () => {
|
2016-12-06 16:55:48 +00:00
|
|
|
const { headerText } = this.props;
|
2016-09-16 21:19:37 +00:00
|
|
|
|
|
|
|
return (
|
2016-12-06 16:55:48 +00:00
|
|
|
<div className={`${baseClass}__header`}>
|
|
|
|
<p className={`${baseClass}__header-text`}>{headerText}</p>
|
2016-09-16 21:19:37 +00:00
|
|
|
</div>
|
|
|
|
);
|
2021-04-12 13:32:25 +00:00
|
|
|
};
|
2016-09-16 21:19:37 +00:00
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
render() {
|
2016-12-06 16:55:48 +00:00
|
|
|
const { children, className, leadText } = this.props;
|
2021-04-12 13:32:25 +00:00
|
|
|
const { isLoading, isLoaded, isLeaving } = this.state;
|
2016-09-16 21:19:37 +00:00
|
|
|
const { renderBackButton, renderHeader } = this;
|
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
const boxClass = classnames(baseClass, className, {
|
|
|
|
[`${baseClass}--loading`]: isLoading,
|
|
|
|
[`${baseClass}--loaded`]: isLoaded,
|
|
|
|
[`${baseClass}--leaving`]: isLeaving,
|
|
|
|
});
|
2016-11-03 19:40:54 +00:00
|
|
|
|
2016-09-16 21:19:37 +00:00
|
|
|
return (
|
2016-12-06 16:55:48 +00:00
|
|
|
<div className={boxClass}>
|
2016-11-03 19:40:54 +00:00
|
|
|
<div className={`${baseClass}__box`}>
|
2016-09-16 21:19:37 +00:00
|
|
|
{renderBackButton()}
|
|
|
|
{renderHeader()}
|
2016-12-06 16:55:48 +00:00
|
|
|
<p className={`${baseClass}__box-text`}>{leadText}</p>
|
2016-09-16 21:19:37 +00:00
|
|
|
{children}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-03 19:40:54 +00:00
|
|
|
export default StackedWhiteBoxes;
|