2016-09-16 21:19:37 +00:00
|
|
|
|
import React, { Component, PropTypes } from 'react';
|
|
|
|
|
import { Link } from 'react-router';
|
2016-11-03 19:40:54 +00:00
|
|
|
|
import classnames from 'classnames';
|
2016-09-16 21:19:37 +00:00
|
|
|
|
|
2016-12-06 16:55:48 +00:00
|
|
|
|
const baseClass = 'stacked-white-boxes';
|
|
|
|
|
|
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,
|
|
|
|
|
};
|
|
|
|
|
|
2016-12-06 16:55:48 +00:00
|
|
|
|
constructor (props) {
|
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
|
isLoading: false,
|
|
|
|
|
isLoaded: false,
|
|
|
|
|
isLeaving: false,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentWillMount () {
|
|
|
|
|
this.setState({
|
|
|
|
|
isLoading: true,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* eslint-disable react/no-did-mount-set-state */
|
|
|
|
|
componentDidMount () {
|
|
|
|
|
this.setState({
|
|
|
|
|
isLoading: false,
|
|
|
|
|
isLoaded: true,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
/* eslint-enable react/no-did-mount-set-state */
|
|
|
|
|
|
|
|
|
|
nowLeaving = (evt) => {
|
|
|
|
|
const { window } = global;
|
|
|
|
|
const { onLeave, previousLocation } = this.props;
|
|
|
|
|
evt.preventDefault();
|
|
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
|
isLoading: false,
|
|
|
|
|
isLoaded: false,
|
|
|
|
|
isLeaving: true,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (previousLocation) {
|
|
|
|
|
window.setTimeout(
|
|
|
|
|
() => { onLeave(previousLocation); },
|
|
|
|
|
300
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
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`}>
|
|
|
|
|
<Link to={previousLocation} className={`${baseClass}__back-link`} onClick={nowLeaving}>╳</Link>
|
2016-09-16 21:19:37 +00:00
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render () {
|
2016-12-06 16:55:48 +00:00
|
|
|
|
const { children, className, leadText } = this.props;
|
|
|
|
|
const {
|
|
|
|
|
isLoading,
|
|
|
|
|
isLoaded,
|
|
|
|
|
isLeaving,
|
|
|
|
|
} = this.state;
|
2016-09-16 21:19:37 +00:00
|
|
|
|
const { renderBackButton, renderHeader } = this;
|
|
|
|
|
|
2016-12-06 16:55:48 +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;
|