import { AllI18nKeys, Localization } from "@Component/Localization/Localization"; import { PickerList } from "../PickerList/PickerList"; import { Label } from "@Model/Label"; import { useStatusWithEvent, IMixinStatusProps } from "@Context/Status"; import { Component, ReactNode, createRef } from "react"; import { LabelList } from "../LabelList/LabelList"; import "./LabelPicker.scss" interface ILabelPickerProps { keyI18n: AllI18nKeys; infoI18n?: AllI18nKeys; 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; } public render(): ReactNode { return
{ this.props.labelDelete ? this.props.labelDelete(label) : 0; }} addLabel={() => { this.setState({ isPickerVisible: true }); }} /> {this.state.isPickerVisible ? { this.setState({ isPickerVisible: false }); }} clickObjectItems={(label) => { if (label instanceof Label && this.props.labelAdd) { this.props.labelAdd(label) } this.setState({ isPickerVisible: false }); }} target={this.addButtonRef} /> : null}
} } export { LabelPicker }