/** @jsx jsx */ import { css, jsx } from '@emotion/core'; 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[]; css?: any; } class DropdownLightMolecule 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="relative" > {}} className={`${this.props.className} outline-0`} data-test={this.props['data-test']} css={this.props.css} > {label} {items.map((item: any, idx: any) => { if (item.component) { return (
{item.component()}
); } return (
{item.label}
); })}
); } } export { DropdownLightMolecule };