import React from 'react'; import { SessionIcon, SessionIconSize, SessionIconType } from './icon/'; import { SessionDropdownItem, SessionDropDownItemType, } from './SessionDropdownItem'; // THIS IS DROPDOWN ACCORDIAN STYLE OPTIONS SELECTOR ELEMENT, NOT A CONTEXTMENU interface State { expanded: boolean; } interface Props { label: string; onClick?: any; expanded?: boolean; options: Array<{ content: string; id?: string; icon?: SessionIconType | null; type?: SessionDropDownItemType; active?: boolean; onClick?: any; }>; } export class SessionDropdown extends React.Component { public static defaultProps = { expanded: false, }; constructor(props: any) { super(props); this.state = { expanded: !!this.props.expanded, }; this.toggleDropdown = this.toggleDropdown.bind(this); } public render() { const { label, options } = this.props; const { expanded } = this.state; const chevronOrientation = expanded ? 180 : 0; return (
{label}
{expanded && (
{options.map((item: any) => { return ( { this.handleItemClick(item.onClick); }} /> ); })}
)}
); } public toggleDropdown() { this.setState({ expanded: !this.state.expanded, }); } public handleItemClick(itemOnClickFn: any) { this.setState({ expanded: false }, itemOnClickFn()); } }