2019-01-07 01:25:33 +00:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2016-09-16 21:19:37 +00:00
|
|
|
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
|
|
|
|
2020-12-15 02:24:16 +00:00
|
|
|
import KolideIcon from 'components/icons/KolideIcon';
|
2017-01-13 23:32:21 +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,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
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); },
|
2020-07-07 02:31:48 +00:00
|
|
|
300,
|
2016-12-06 16:55:48 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
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`}>
|
2017-01-13 23:32:21 +00:00
|
|
|
<Link to={previousLocation} className={`${baseClass}__back-link`} onClick={nowLeaving}>
|
2020-12-15 02:24:16 +00:00
|
|
|
<KolideIcon name="x" />
|
2017-01-13 23:32:21 +00:00
|
|
|
</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,
|
2020-07-07 02:31:48 +00:00
|
|
|
},
|
2016-12-06 16:55:48 +00:00
|
|
|
);
|
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;
|