2018-11-07 23:44:38 +01:00
|
|
|
// @flow
|
|
|
|
import React, { PureComponent, Node } from 'react';
|
|
|
|
import classnames from 'classnames';
|
|
|
|
import Button from 'component/button';
|
|
|
|
|
|
|
|
// Note:
|
|
|
|
// When we use this in other parts of the app, we will probably need to
|
|
|
|
// add props for collapsed height
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
children: Node | Array<Node>,
|
|
|
|
};
|
|
|
|
|
|
|
|
type State = {
|
|
|
|
expanded: boolean,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default class Expandable extends PureComponent<Props, State> {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
expanded: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
(this: any).handleClick = this.handleClick.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleClick() {
|
|
|
|
this.setState({
|
|
|
|
expanded: !this.state.expanded,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { children } = this.props;
|
|
|
|
const { expanded } = this.state;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="expandable">
|
|
|
|
<div
|
|
|
|
className={classnames({
|
|
|
|
'expandable--open': expanded,
|
|
|
|
'expandable--closed': !expanded,
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</div>
|
|
|
|
<Button
|
|
|
|
button="link"
|
2018-12-19 06:44:53 +01:00
|
|
|
className="expandable__button"
|
2018-11-07 23:44:38 +01:00
|
|
|
label={expanded ? __('Less') : __('More')}
|
|
|
|
onClick={this.handleClick}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|