// @flow import React, { type Node, PureComponent } from 'react' import { css } from 'react-emotion' import { UnmountClosed } from 'react-collapse' import Box from '../../elements/Box' import FormHeading from '../../elements/FormHeading' import Grid from '../../elements/Grid' import Icons from '../../elements/Icons' type Props = { text: string, openByDefault?: boolean, render: () => Node, } type State = { showRenderProps: boolean, } class CollapsableFormHeading extends PureComponent { static defaultProps = { openByDefault: false, } state = { showRenderProps: false, } componentWillMount() { const { openByDefault } = this.props if (openByDefault === true) { this.setState(() => ({ showRenderProps: true })) } } toggleShowRenderProps = () => { this.setState(state => ({ showRenderProps: !state.showRenderProps })) } render() { const { showRenderProps } = this.state const { text, render } = this.props return ( {text} { render() } ) } } export default CollapsableFormHeading