import { Component } from "react"; import { Label } from "@Model/Label"; import { Icon } from "@fluentui/react"; import { useSetting, IMixinSettingProps, Themes } from "@Context/Setting"; import { ErrorMessage } from "@Component/ErrorMessage/ErrorMessage"; import "./LabelList.scss"; interface ILabelListProps { labels: Label[]; canDelete?: boolean; focusLabel?: Label; clickLabel?: (label: Label) => any; deleteLabel?: (label: Label) => any; } @useSetting class LabelList extends Component { private isDeleteClick: boolean = false; private renderLabel(label: Label) { const theme = this.props.setting?.themes ?? Themes.dark; const classList:string[] = ["label"]; classList.push( theme === Themes.dark ? "dark" : "light" ); const isFocus = this.props.focusLabel && this.props.focusLabel.equal(label); if (isFocus) { classList.push("focus"); } const colorCss = `rgb(${label.color.join(",")})`; return
{ if (this.props.clickLabel && !this.isDeleteClick) { this.props.clickLabel(label); } this.isDeleteClick = false; }} style={{ borderColor: isFocus ? colorCss : undefined }} >
{label.name}
{ this.props.canDelete ?
{ this.isDeleteClick = true; if (this.props.deleteLabel) { this.props.deleteLabel(label); } }} >
: null }
} private renderAllLabels(labels: Label[]) { return this.props.labels.map((label) => { return this.renderLabel(label); }); } public render() { if (this.props.labels.length > 0) { return this.renderAllLabels(this.props.labels); } else { return } } } export { LabelList };