import { Component, RefObject } from "react"; import { Label } from "@Model/Label"; import { Icon } from "@fluentui/react"; import { useSetting, IMixinSettingProps, Themes } from "@Context/Setting"; import "./LabelList.scss"; interface ILabelListProps { minHeight?: number; maxWidth?: number; width?: number; labels: Label[]; addRef?: RefObject; focusLabel?: Label; clickLabel?: (label: Label) => any; deleteLabel?: (label: Label) => any; addLabel?: () => 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"); } if (this.props.maxWidth) { classList.push("one-line"); } const colorCss = `rgb(${label.color.join(",")})`; const isDelete = label.isDeleted(); return
{ if (this.props.clickLabel && !this.isDeleteClick) { this.props.clickLabel(label); } this.isDeleteClick = false; }} >
{label.name}
{ this.props.deleteLabel ?
{ this.isDeleteClick = true; if (this.props.deleteLabel) { this.props.deleteLabel(label); } }} >
: null }
} private renderAllLabels() { return this.props.labels.map((label) => { return this.renderLabel(label); }); } private renderAddButton() { const theme = this.props.setting?.themes ?? Themes.dark; const classList: string[] = ["label", "add-button"]; classList.push( theme === Themes.dark ? "dark" : "light" ); return
{ this.props.addLabel ? this.props.addLabel() : null }} >
; } public render() { return
{this.renderAllLabels()} {this.props.addLabel ? this.renderAddButton() : null}
; } } export { LabelList };