2017-09-25 02:06:28 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { HeaderProps, ListProps, NodeProps, NodeState } from './types';
|
2017-09-04 00:04:27 +00:00
|
|
|
|
2017-12-18 23:29:26 +00:00
|
|
|
const InfoHeader = ({ children, onClickHandler }: HeaderProps) => (
|
2017-09-04 00:04:27 +00:00
|
|
|
<h6 onClick={onClickHandler}>
|
|
|
|
<span>+</span> {children}
|
2017-12-18 23:29:26 +00:00
|
|
|
</h6>
|
|
|
|
);
|
2017-09-04 00:04:27 +00:00
|
|
|
|
2017-12-18 23:29:26 +00:00
|
|
|
const InfoList = ({ children, isOpen }: ListProps) => (isOpen ? <ul>{children}</ul> : null);
|
2017-09-04 00:04:27 +00:00
|
|
|
|
2017-12-18 23:29:26 +00:00
|
|
|
export default class GeneralInfoNode extends React.Component<NodeProps, NodeState> {
|
2017-09-25 02:06:28 +00:00
|
|
|
public state = {
|
2017-09-04 00:04:27 +00:00
|
|
|
isOpen: false
|
|
|
|
};
|
|
|
|
|
2017-12-18 23:29:26 +00:00
|
|
|
public toggleVisibility = () => this.setState(prevState => ({ isOpen: !prevState.isOpen }));
|
2017-09-04 00:04:27 +00:00
|
|
|
|
2017-09-25 02:06:28 +00:00
|
|
|
public render() {
|
2017-12-18 23:29:26 +00:00
|
|
|
const { toggleVisibility, props: { innerList, headerContent }, state: { isOpen } } = this;
|
2017-09-04 00:04:27 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<section>
|
2017-12-18 23:29:26 +00:00
|
|
|
<InfoHeader onClickHandler={toggleVisibility}>{headerContent}</InfoHeader>
|
|
|
|
<InfoList isOpen={isOpen}>{innerList}</InfoList>
|
2017-09-04 00:04:27 +00:00
|
|
|
</section>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|