fleet/frontend/components/StackedWhiteBoxes/StackedWhiteBoxes.jsx
noahtalerman 49e71e4ed6
Add new icons for Hosts page. Fix hosts list width on wide screens. (#128)
- Add new PNG files for the new icons in the left side navigation and the right side labels on the Hosts page.
- Rename the old `<Icon />` component to `<KolideIcon />` and create a new `<Icon />` component. The ultimate goal is to get rid of the `<KolideIcon />` and `<PlatformIcon />` components and use the encompassing `<Icon />` component for all icons. The full transition will be made when we have icon assets to replace all the kolide icons and platform icons. Currently, we don't.
- Rename the `icon_name_for_label.js` utility to `icon_name.js` because the utility now includes `iconNameForLabel()` and `iconNameForPlatform()` functions.
- Fixes issue #127.
2020-12-14 18:24:16 -08:00

129 lines
2.6 KiB
JavaScript

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { Link } from 'react-router';
import classnames from 'classnames';
import KolideIcon from 'components/icons/KolideIcon';
const baseClass = 'stacked-white-boxes';
class StackedWhiteBoxes extends Component {
static propTypes = {
children: PropTypes.element,
headerText: PropTypes.string,
className: PropTypes.string,
leadText: PropTypes.string,
onLeave: PropTypes.func,
previousLocation: PropTypes.string,
};
constructor (props) {
super(props);
this.state = {
isLoading: false,
isLoaded: false,
isLeaving: false,
};
}
componentWillMount () {
this.setState({
isLoading: true,
});
}
componentDidMount () {
const { didLoad } = this;
didLoad();
return false;
}
didLoad = () => {
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); },
300,
);
}
return false;
}
renderBackButton = () => {
const { previousLocation } = this.props;
const { nowLeaving } = this;
if (!previousLocation) return false;
return (
<div className={`${baseClass}__back`}>
<Link to={previousLocation} className={`${baseClass}__back-link`} onClick={nowLeaving}>
<KolideIcon name="x" />
</Link>
</div>
);
}
renderHeader = () => {
const { headerText } = this.props;
return (
<div className={`${baseClass}__header`}>
<p className={`${baseClass}__header-text`}>{headerText}</p>
</div>
);
}
render () {
const { children, className, leadText } = this.props;
const {
isLoading,
isLoaded,
isLeaving,
} = this.state;
const { renderBackButton, renderHeader } = this;
const boxClass = classnames(
baseClass,
className,
{
[`${baseClass}--loading`]: isLoading,
[`${baseClass}--loaded`]: isLoaded,
[`${baseClass}--leaving`]: isLeaving,
},
);
return (
<div className={boxClass}>
<div className={`${baseClass}__box`}>
{renderBackButton()}
{renderHeader()}
<p className={`${baseClass}__box-text`}>{leadText}</p>
{children}
</div>
</div>
);
}
}
export default StackedWhiteBoxes;