import { css, cx } from "emotion"; import * as React from "react"; import { ButtonAtom, CardAtom, IconAtom, TextAtom, } from "../../atoms"; // @ts-ignore import COLORS from "../../constants/colors"; interface Iitem { label?: string; handleClick?: any; component?: any; } interface IProps { className?: any; "data-test"?: any; type?: string; children: any; label?: string; items?: Iitem[]; } class DropdownMenuMolecule extends React.PureComponent { public state = { isExpanded: false, }; public dropdownMenuWrapper: any; public componentWillMount() { document.addEventListener("mousedown", this.handlePageClick); } public componentWillUnmount() { document.removeEventListener("mousedown", this.handlePageClick); } public handlePageClick = (e: any) => { if (this.dropdownMenuWrapper) { if (this.dropdownMenuWrapper.contains(e.target)) { this.setState({ isExpanded: !this.state.isExpanded }); return; } this.setState({ isExpanded: false }); } } public render() { const { isExpanded } = this.state; const { items = [], label, } = this.props; return (
{ this.dropdownMenuWrapper = dropdownMenuWrapper; }} className={cx("relative dib", this.props.className)} > {}} className="outline-0" data-test={this.props["data-test"]} > {label} {items.map((item: any, idx: any) => { if (item.component) { return (
{item.component()}
); } return (
{item.label}
); })}
); } } export { DropdownMenuMolecule };