import { Component, ReactNode, createRef } from "react"; import { Label } from "@Model/Label"; import { PickerList } from "@Input/PickerList/PickerList"; import { TextField, ITextFieldProps } from "@Input/TextField/TextField"; import { useStatusWithEvent, IMixinStatusProps } from "@Context/Status"; import { LabelList } from "@Component/LabelList/LabelList"; import "./LabelPicker.scss" interface ILabelPickerProps extends ITextFieldProps { labels: Label[]; labelAdd?: (label: Label) => any; labelDelete?: (label: Label) => any; } interface ILabelPickerState { isPickerVisible: boolean; } @useStatusWithEvent("labelAttrChange", "labelChange") class LabelPicker extends Component { public constructor(props: ILabelPickerProps) { super(props); this.state = { isPickerVisible: false } } private addButtonRef = createRef(); private getOtherLabel() { let res: Label[] = []; let nowLabel: Label[] = this.props.labels ?? []; if (this.props.status) { this.props.status.model.labelPool.forEach((aLabel) => { let isHas = false; nowLabel.forEach((nLabel) => { if (aLabel.equal(nLabel)) isHas = true; }) if (!isHas) { res.push(aLabel); } }) } return res; } private renderPicker() { return { this.setState({ isPickerVisible: false }); }} click={(label) => { if (label instanceof Label && this.props.labelAdd) { this.props.labelAdd(label) } this.setState({ isPickerVisible: false }); }} target={this.addButtonRef} />; } public render(): ReactNode { return { this.props.labelDelete ? this.props.labelDelete(label) : 0; }} addLabel={() => { this.setState({ isPickerVisible: true }); }} /> {this.state.isPickerVisible ? this.renderPicker(): null} ; } } export { LabelPicker }