From c84c0b903bfbc373da8c79a72d58768cfa82fb47 Mon Sep 17 00:00:00 2001 From: MrKBear Date: Fri, 11 Mar 2022 22:10:19 +0800 Subject: [PATCH] Add add button on label list --- source/Component/LabelList/LabelList.scss | 27 ++++++++++++ source/Component/LabelList/LabelList.tsx | 50 +++++++++++++++++++---- source/Panel/LabelList/LabelList.scss | 2 +- source/Panel/LabelList/LabelList.tsx | 5 ++- 4 files changed, 75 insertions(+), 9 deletions(-) diff --git a/source/Component/LabelList/LabelList.scss b/source/Component/LabelList/LabelList.scss index a7adf0c..3a046a7 100644 --- a/source/Component/LabelList/LabelList.scss +++ b/source/Component/LabelList/LabelList.scss @@ -3,6 +3,8 @@ div.label { width: auto; height: auto; + min-height: 24px; + box-sizing: border-box; display: inline-flex; margin: 5px 5px; justify-content: center; @@ -23,11 +25,14 @@ div.label { div.label-name { padding: 2px 3px; + display: flex; + align-items: center; text-overflow: ellipsis; overflow: hidden; } div.delete-button { + flex-shrink: 0; padding: 2px 3px; border-radius: 3px; display: flex; @@ -37,6 +42,28 @@ div.label { } } +div.label.one-line div.label-name { + max-width: 100%; + word-break: keep-all; + white-space: nowrap; + text-overflow: ellipsis; + overflow: hidden; +} + +div.label.add-button { + width: 24px; + align-items: center; + justify-content: center; +} + +div.dark.label.add-button { + border: .5px dashed $lt-bg-color-lvl3-dark; +} + +div.light.label.add-button { + border: .5px dashed $lt-bg-color-lvl3-light; +} + div.dark.label { transition: none; background-color: $lt-bg-color-lvl3-dark; diff --git a/source/Component/LabelList/LabelList.tsx b/source/Component/LabelList/LabelList.tsx index a37f410..db90129 100644 --- a/source/Component/LabelList/LabelList.tsx +++ b/source/Component/LabelList/LabelList.tsx @@ -6,11 +6,14 @@ import { ErrorMessage } from "@Component/ErrorMessage/ErrorMessage"; import "./LabelList.scss"; interface ILabelListProps { + minHeight?: number; + maxWidth?: number; + width?: number; labels: Label[]; - canDelete?: boolean; focusLabel?: Label; clickLabel?: (label: Label) => any; deleteLabel?: (label: Label) => any; + addLabel?: () => any; } @useSetting @@ -21,15 +24,22 @@ class LabelList extends Component { private renderLabel(label: Label) { const theme = this.props.setting?.themes ?? Themes.dark; - const classList:string[] = ["label"]; + 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(",")})`; return
{ @@ -44,10 +54,10 @@ class LabelList extends Component { borderRadius: isFocus ? 0 : 3 }}/>
- {label.name} +
{label.name}
{ - this.props.canDelete ? + this.props.deleteLabel ?
{ @@ -63,17 +73,43 @@ class LabelList extends Component {
} - private renderAllLabels(labels: Label[]) { + private renderAllLabels() { return this.props.labels.map((label) => { return this.renderLabel(label); }); } + + private renderAddButton(isNoMargin: boolean = false) { + 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() { if (this.props.labels.length > 0) { - return this.renderAllLabels(this.props.labels); + return <> + {this.renderAllLabels()} + {this.props.addLabel ? this.renderAddButton() : null} + ; } else { - return + return <> + + {this.props.addLabel ? this.renderAddButton(true) : null} + ; } } } diff --git a/source/Panel/LabelList/LabelList.scss b/source/Panel/LabelList/LabelList.scss index b9eec31..b2233e1 100644 --- a/source/Panel/LabelList/LabelList.scss +++ b/source/Panel/LabelList/LabelList.scss @@ -2,7 +2,7 @@ div.label-list-panel-root { width: 100%; - height: 100%; + min-height: 100%; padding: 10px; box-sizing: border-box; } \ No newline at end of file diff --git a/source/Panel/LabelList/LabelList.tsx b/source/Panel/LabelList/LabelList.tsx index b6dd9a1..13c15b8 100644 --- a/source/Panel/LabelList/LabelList.tsx +++ b/source/Panel/LabelList/LabelList.tsx @@ -30,7 +30,6 @@ class LabelList extends Component { @@ -49,6 +48,10 @@ class LabelList extends Component { + this.props.status ? this.props.status.newLabel() : undefined; + }} />
; }