From cb2501f1f087e876f0dc75b411b32afc70e8d011 Mon Sep 17 00:00:00 2001 From: MrKBear Date: Fri, 8 Apr 2022 20:40:07 +0800 Subject: [PATCH] Detach separates the combolist from the pickerlist --- .../Input/BehaviorPicker/BehaviorPicker.tsx | 4 +- source/Input/ComboInput/ComboInput.tsx | 16 ++--- source/Input/ComboList/ComboList.scss | 1 + source/Input/ComboList/ComboList.tsx | 71 +++++++++++++++++++ source/Input/LabelPicker/LabelPicker.tsx | 4 +- source/Input/ObjectPicker/ObjectPicker.tsx | 8 +-- source/Input/PickerList/PickerList.tsx | 54 +++----------- source/Panel/GroupDetails/GroupDetails.tsx | 6 +- 8 files changed, 99 insertions(+), 65 deletions(-) create mode 100644 source/Input/ComboList/ComboList.scss create mode 100644 source/Input/ComboList/ComboList.tsx diff --git a/source/Input/BehaviorPicker/BehaviorPicker.tsx b/source/Input/BehaviorPicker/BehaviorPicker.tsx index 7276dfd..cf89104 100644 --- a/source/Input/BehaviorPicker/BehaviorPicker.tsx +++ b/source/Input/BehaviorPicker/BehaviorPicker.tsx @@ -145,10 +145,10 @@ class BehaviorPicker extends Component { + click={((item) => { if (item instanceof Behavior && this.props.add) { this.props.add(item); } diff --git a/source/Input/ComboInput/ComboInput.tsx b/source/Input/ComboInput/ComboInput.tsx index 122cd78..761a51f 100644 --- a/source/Input/ComboInput/ComboInput.tsx +++ b/source/Input/ComboInput/ComboInput.tsx @@ -1,6 +1,6 @@ import { Component, createRef, ReactNode } from "react"; import { Icon } from "@fluentui/react"; -import { PickerList, IDisplayItem } from "@Input/PickerList/PickerList"; +import { ComboList, IDisplayItem } from "@Input/ComboList/ComboList"; import { TextField, ITextFieldProps } from "@Input/TextField/TextField"; import { Localization } from "@Component/Localization/Localization"; import "./ComboInput.scss"; @@ -26,13 +26,11 @@ class ComboInput extends Component { private pickerTarget = createRef(); private renderPicker() { - return { - return item.key === this.props.value?.key ? - {...item, mark: true} : item; - })} - clickDisplayItems={((item) => { + item={this.props.allOption ?? []} + focus={this.props.value} + click={((item) => { if (this.props.valueChange) { this.props.valueChange(item); } @@ -64,8 +62,8 @@ class ComboInput extends Component {
{ this.props.value ? - : - null + : + null }
diff --git a/source/Input/ComboList/ComboList.scss b/source/Input/ComboList/ComboList.scss new file mode 100644 index 0000000..b835123 --- /dev/null +++ b/source/Input/ComboList/ComboList.scss @@ -0,0 +1 @@ +@import "../PickerList/PickerList.scss"; \ No newline at end of file diff --git a/source/Input/ComboList/ComboList.tsx b/source/Input/ComboList/ComboList.tsx new file mode 100644 index 0000000..f58cb72 --- /dev/null +++ b/source/Input/ComboList/ComboList.tsx @@ -0,0 +1,71 @@ +import { AllI18nKeys, Localization } from "@Component/Localization/Localization"; +import { Callout, DirectionalHint, Icon } from "@fluentui/react"; +import { Component, ReactNode, RefObject } from "react"; +import "./ComboList.scss"; + +interface IDisplayItem { + i18nOption?: Record; + i18n: AllI18nKeys; + key: string; +} + +interface IComboListProps { + target?: RefObject; + item: IDisplayItem[]; + focus?: IDisplayItem; + noData?: AllI18nKeys; + dismiss?: () => any; + click?: (item: IDisplayItem) => any; +} + +class ComboList extends Component { + + private renderString(item: IDisplayItem) { + + const isFocus = item.key === this.props.focus?.key; + + return
{ + if (this.props.click) { + this.props.click(item) + } + }} + > +
+ +
+
+ +
+
; + } + + public render(): ReactNode { + return +
+ { this.props.item.map((item) => this.renderString(item)) } + { + this.props.item.length <= 0 ? + + : null + } +
+
+ } +} + +export { ComboList, IDisplayItem } \ No newline at end of file diff --git a/source/Input/LabelPicker/LabelPicker.tsx b/source/Input/LabelPicker/LabelPicker.tsx index 3ae8d11..6a9c22a 100644 --- a/source/Input/LabelPicker/LabelPicker.tsx +++ b/source/Input/LabelPicker/LabelPicker.tsx @@ -48,13 +48,13 @@ class LabelPicker extends Component { this.setState({ isPickerVisible: false }); }} - clickObjectItems={(label) => { + click={(label) => { if (label instanceof Label && this.props.labelAdd) { this.props.labelAdd(label) } diff --git a/source/Input/ObjectPicker/ObjectPicker.tsx b/source/Input/ObjectPicker/ObjectPicker.tsx index 4b7c49e..0fd0ff6 100644 --- a/source/Input/ObjectPicker/ObjectPicker.tsx +++ b/source/Input/ObjectPicker/ObjectPicker.tsx @@ -6,7 +6,7 @@ import { Range } from "@Model/Range"; import { CtrlObject } from "@Model/CtrlObject"; import { Behavior } from "@Model/Behavior"; import { TextField, ITextFieldProps } from "@Input/TextField/TextField"; -import { PickerList, IDisplayItem, getObjectDisplayInfo, IDisplayInfo } from "@Input/PickerList/PickerList"; +import { PickerList, getObjectDisplayInfo, IDisplayInfo } from "@Input/PickerList/PickerList"; import { Localization } from "@Component/Localization/Localization"; import { Icon } from "@fluentui/react"; import "./ObjectPicker.scss"; @@ -79,8 +79,8 @@ class ObjectPicker extends Component { + item={this.getAllOption()} + click={((item) => { if (item instanceof Behavior) return; if (this.props.valueChange) { this.props.valueChange(item); @@ -166,4 +166,4 @@ class ObjectPicker extends Component; noData?: AllI18nKeys; dismiss?: () => any; - clickObjectItems?: (item: IPickerListItem) => any; - clickDisplayItems?: (item: IDisplayItem) => any; + click?: (item: IPickerListItem) => any; } class PickerList extends Component { @@ -116,8 +108,8 @@ class PickerList extends Component { className="picker-list-item" key={item.id} onClick={() => { - if (this.props.clickObjectItems) { - this.props.clickObjectItems(item) + if (this.props.click) { + this.props.click(item) } }} > @@ -143,27 +135,6 @@ class PickerList extends Component {
; } - private renderString(item: IDisplayItem) { - return
{ - if (this.props.clickDisplayItems) { - this.props.clickDisplayItems(item) - } - }} - > -
- -
-
- -
-
; - } - public render(): ReactNode { return { directionalHint={DirectionalHint.topCenter} >
- {this.props.objectList ? this.props.objectList.map((item) => { - return this.renderItem(item); - }) : null} - {this.props.displayItems ? this.props.displayItems.map((item) => { - return this.renderString(item); - }) : null} { - !(this.props.objectList || this.props.displayItems) || - !( - this.props.objectList && this.props.objectList.length > 0 || - this.props.displayItems && this.props.displayItems.length > 0 - ) ? + this.props.item.map((item) => this.renderItem(item)) + } + { + this.props.item.length <= 0 ? { } } -export { PickerList, IDisplayItem, IDisplayInfo, getObjectDisplayInfo } \ No newline at end of file +export { PickerList, IDisplayInfo, getObjectDisplayInfo } \ No newline at end of file diff --git a/source/Panel/GroupDetails/GroupDetails.tsx b/source/Panel/GroupDetails/GroupDetails.tsx index 35d3ed5..51d94c2 100644 --- a/source/Panel/GroupDetails/GroupDetails.tsx +++ b/source/Panel/GroupDetails/GroupDetails.tsx @@ -22,8 +22,8 @@ mapGenModToI18nKey.set(GenMod.Point, "Common.Attr.Key.Generation.Mod.Point"); mapGenModToI18nKey.set(GenMod.Range, "Common.Attr.Key.Generation.Mod.Range"); const allOption: IDisplayItem[] = [ - {nameKey: "Common.Attr.Key.Generation.Mod.Point", key: GenMod.Point}, - {nameKey: "Common.Attr.Key.Generation.Mod.Range", key: GenMod.Range} + {i18n: "Common.Attr.Key.Generation.Mod.Point", key: GenMod.Point}, + {i18n: "Common.Attr.Key.Generation.Mod.Range", key: GenMod.Range} ]; @useSetting @@ -144,7 +144,7 @@ class GroupDetails extends Component