From 0e79c096915838305b30c7c6633d1a8a8ca634d1 Mon Sep 17 00:00:00 2001 From: MrKBear Date: Tue, 15 Mar 2022 15:53:28 +0800 Subject: [PATCH] Recode color input & combo input with text field component --- source/Component/ColorInput/ColorInput.scss | 99 +++++---------------- source/Component/ColorInput/ColorInput.tsx | 55 ++++-------- source/Component/ComboInput/ComboInput.scss | 97 +++++--------------- source/Component/ComboInput/ComboInput.tsx | 52 +++++------ 4 files changed, 81 insertions(+), 222 deletions(-) diff --git a/source/Component/ColorInput/ColorInput.scss b/source/Component/ColorInput/ColorInput.scss index 99193d3..b85eea1 100644 --- a/source/Component/ColorInput/ColorInput.scss +++ b/source/Component/ColorInput/ColorInput.scss @@ -1,89 +1,32 @@ -@import "../Theme/Theme.scss"; +$line-min-height: 24px; -$line-min-height: 26px; +div.color-input { -div.color-input-root { - width: 100%; - display: flex; - min-height: $line-min-height; - padding: 5px 0; - - div.input-intro { - width: 50%; - height: 100%; - max-width: 220px; - min-height: $line-min-height; - display: flex; - align-items: center; - padding-right: 5px; - box-sizing: border-box; - } - - div.root-content { - width: 50%; - height: 100%; - max-width: 180px; - min-height: $line-min-height; - border-radius: 3px; - overflow: hidden; + div.color-view { + width: $line-min-height; + max-width: $line-min-height; display: flex; + justify-content: center; + align-items: center; - div.color-view { - width: $line-min-height; - max-width: $line-min-height; - display: flex; - justify-content: center; - align-items: center; - - div.color-box { - width: 12px; - height: 12px; - border-radius: 3px; - } - } - - div.value-view { - width: 100%; - height: 100%; - min-height: $line-min-height; - display: flex; - align-items: center; - - div.text-box { - padding-left: 1px; - } - } - - div.error-box { - display: flex; - align-items: center; - padding-left: 8px; + div.color-box { + width: 12px; + height: 12px; + border-radius: 3px; } } -} -div.dark.color-input-root { + div.value-view { + width: 100%; + height: 100%; + min-height: $line-min-height; + display: flex; + align-items: center; - div.root-content { - background-color: $lt-bg-color-lvl3-dark; - color: $lt-font-color-normal-dark; - } - - div.root-content:hover { - background-color: $lt-bg-color-lvl2-dark; - } -} - -div.light.color-input-root { - - div.root-content { - background-color: $lt-bg-color-lvl3-light; - color: $lt-font-color-normal-light; - } - - div.root-content:hover { - background-color: $lt-bg-color-lvl2-light; - } + div.text-box { + padding-left: 1px; + } + } } div.color-picker-root { diff --git a/source/Component/ColorInput/ColorInput.tsx b/source/Component/ColorInput/ColorInput.tsx index febf0fb..8328d04 100644 --- a/source/Component/ColorInput/ColorInput.tsx +++ b/source/Component/ColorInput/ColorInput.tsx @@ -1,16 +1,11 @@ import { Component, createRef, ReactNode } from "react"; -import { FontLevel, Theme } from "@Component/Theme/Theme"; +import { TextField, ITextFieldProps } from "@Component/TextField/TextField"; import { Callout, ColorPicker, DirectionalHint } from "@fluentui/react"; -import { AllI18nKeys, Localization } from "@Component/Localization/Localization"; import "./ColorInput.scss"; -interface IColorInputProps { - keyI18n: AllI18nKeys; - infoI18n?: AllI18nKeys; +interface IColorInputProps extends ITextFieldProps { value?: number[]; normal?: boolean; - disable?: boolean; - disableI18n?: AllI18nKeys; valueChange?: (color: number[]) => any; } @@ -65,16 +60,6 @@ class ColorInput extends Component { } - private renderErrorInput() { - return
- { - this.props.disableI18n ? - : - {this.props.value} - } -
; - } - private renderColorInput() { return <>
@@ -104,29 +89,21 @@ class ColorInput extends Component { public render(): ReactNode { return <> - -
- -
-
{ - this.setState({ - isPickerVisible: !this.props.disable - }) - }} - > - { this.props.disable ? null : this.renderColorInput() } - { this.props.disable ? this.renderErrorInput() : null } -
-
- + { + this.setState({ + isPickerVisible: !this.props.disableI18n + }) + }} + > + { this.renderColorInput() } + {this.state.isPickerVisible ? this.renderPicker(): null} - + ; } } diff --git a/source/Component/ComboInput/ComboInput.scss b/source/Component/ComboInput/ComboInput.scss index a073e7e..0f3930a 100644 --- a/source/Component/ComboInput/ComboInput.scss +++ b/source/Component/ComboInput/ComboInput.scss @@ -1,87 +1,32 @@ @import "../Theme/Theme.scss"; -$line-min-height: 26px; +$line-min-height: 24px; -div.combo-input-root { - width: 100%; - display: flex; - min-height: $line-min-height; - padding: 5px 0; - - div.input-intro { - width: 50%; - height: 100%; - max-width: 220px; - min-height: $line-min-height; - display: flex; - align-items: center; - padding-right: 5px; - box-sizing: border-box; - } - - div.root-content { - width: 50%; +div.combo-input { + + div.value-view { + width: 100%; height: 100%; - max-width: 180px; min-height: $line-min-height; - border-radius: 3px; - overflow: hidden; display: flex; - cursor: pointer; + align-items: center; + padding-left: 8px; + white-space: nowrap; + word-break: keep-all; + text-overflow: ellipsis; + overflow: hidden; - div.value-view { - width: 100%; - height: 100%; - min-height: $line-min-height; - display: flex; - align-items: center; - padding-left: 8px; - white-space: nowrap; - word-break: keep-all; - text-overflow: ellipsis; - overflow: hidden; - - span { - display: block; - } - } - - div.list-button { - width: $line-min-height; - height: $line-min-height; - flex-shrink: 0; - display: flex; - justify-content: center; - align-items: center; + span { + display: block; } } -} -div.dark.combo-input-root { - - div.root-content { - background-color: $lt-bg-color-lvl3-dark; - color: $lt-font-color-normal-dark; - } - - div.root-content:hover { - background-color: $lt-bg-color-lvl2-dark; - } -} - -div.light.combo-input-root { - - div.root-content { - background-color: $lt-bg-color-lvl3-light; - color: $lt-font-color-normal-light; - } - - div.root-content:hover { - background-color: $lt-bg-color-lvl2-light; - } -} - -div.combo-picker-root { - width: 300px; - height: 340px; + div.list-button { + width: $line-min-height; + height: $line-min-height; + flex-shrink: 0; + display: flex; + justify-content: center; + align-items: center; + } } \ No newline at end of file diff --git a/source/Component/ComboInput/ComboInput.tsx b/source/Component/ComboInput/ComboInput.tsx index 55e2c27..baeb5e2 100644 --- a/source/Component/ComboInput/ComboInput.tsx +++ b/source/Component/ComboInput/ComboInput.tsx @@ -1,13 +1,10 @@ import { Component, createRef, ReactNode } from "react"; -import { FontLevel, Theme } from "@Component/Theme/Theme"; import { PickerList, IDisplayItem } from "../PickerList/PickerList"; -import { AllI18nKeys, Localization } from "@Component/Localization/Localization"; +import { TextField, ITextFieldProps } from "../TextField/TextField"; import { Icon } from "@fluentui/react"; +import { Localization } from "@Component/Localization/Localization"; import "./ComboInput.scss"; - -interface IComboInputProps { - keyI18n: AllI18nKeys; - infoI18n?: AllI18nKeys; +interface IComboInputProps extends ITextFieldProps { allOption?: IDisplayItem[]; value?: IDisplayItem; valueChange?: (value: IDisplayItem) => any; @@ -53,31 +50,28 @@ class ComboInput extends Component { public render(): ReactNode { return <> - -
- + { + this.setState({ + isPickerVisible: true + }) + }} + > +
+ { + this.props.value ? + : + null + }
-
{ - this.setState({ - isPickerVisible: true - }) - }} - > -
- { - this.props.value ? - : - null - } -
-
- -
+
+
- + {this.state.isPickerVisible ? this.renderPicker(): null}