import * as React from "react"; import { GlobalState } from '../globalState'; import { Utilities } from '../tools/utilities'; interface ICommandDropdownComponentProps { globalState: GlobalState; icon: string; tooltip: string; items: { label: string, onClick?: () => void, onCheck?: (value: boolean) => void, storeKey?: string, defaultValue?: boolean | string; subItems?: string[]; }[]; } export class CommandDropdownComponent extends React.Component { public constructor(props: ICommandDropdownComponentProps) { super(props); this.state = {isExpanded: false} } public render() { return ( <> { this.state.isExpanded &&
this.setState({isExpanded: false})}>
}
this.setState({isExpanded: !this.state.isExpanded})}>
{ this.state.isExpanded &&
{ this.props.items.map(m => { return (
{ if (! m.onClick) { let newValue = !Utilities.ReadBoolFromStore(m.storeKey!, (m.defaultValue as boolean) || false); Utilities.StoreBoolFromStore(m.storeKey!, newValue); this.forceUpdate(); m.onCheck!(newValue); return; } m.onClick(); this.setState({isExpanded: false}); }} title={m.label}>
{m.label}
{ m.onCheck && { Utilities.StoreBoolFromStore(m.storeKey!, evt.target.checked); this.forceUpdate(); m.onCheck!(evt.target.checked); }} checked={Utilities.ReadBoolFromStore(m.storeKey!, (m.defaultValue as boolean) || false)}/> } { m.subItems &&
{ m.subItems.map(s => { return (
{s}
) }) }
}
) }) }
}
); } }