@itwin/components-react 5.19.0 → 5.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/lib/components-react/UiComponents.js +2 -1
- package/lib/components-react/UiComponents.js.map +1 -1
- package/lib/components-react/common/ImageRenderer.js +1 -1
- package/lib/components-react/common/ImageRenderer.js.map +1 -1
- package/lib/components-react/common/SubscriptionScheduler.js +1 -1
- package/lib/components-react/common/SubscriptionScheduler.js.map +1 -1
- package/lib/components-react/common/selection/SelectionHandler.js +20 -2
- package/lib/components-react/common/selection/SelectionHandler.js.map +1 -1
- package/lib/components-react/converters/BooleanTypeConverter.js +4 -4
- package/lib/components-react/converters/BooleanTypeConverter.js.map +1 -1
- package/lib/components-react/converters/PointTypeConverter.js +1 -0
- package/lib/components-react/converters/PointTypeConverter.js.map +1 -1
- package/lib/components-react/converters/TypeConverterManager.js +2 -1
- package/lib/components-react/converters/TypeConverterManager.js.map +1 -1
- package/lib/components-react/datepicker/IntlFormatter.js +1 -0
- package/lib/components-react/datepicker/IntlFormatter.js.map +1 -1
- package/lib/components-react/editors/BooleanEditor.js +23 -26
- package/lib/components-react/editors/BooleanEditor.js.map +1 -1
- package/lib/components-react/editors/CustomNumberEditor.js +92 -97
- package/lib/components-react/editors/CustomNumberEditor.js.map +1 -1
- package/lib/components-react/editors/DateTimeEditor.js +60 -63
- package/lib/components-react/editors/DateTimeEditor.js.map +1 -1
- package/lib/components-react/editors/EnumButtonGroupEditor.js +23 -26
- package/lib/components-react/editors/EnumButtonGroupEditor.js.map +1 -1
- package/lib/components-react/editors/EnumEditor.js +30 -33
- package/lib/components-react/editors/EnumEditor.js.map +1 -1
- package/lib/components-react/editors/IconEditor.js +16 -16
- package/lib/components-react/editors/IconEditor.js.map +1 -1
- package/lib/components-react/editors/ImageCheckBoxEditor.js +22 -25
- package/lib/components-react/editors/ImageCheckBoxEditor.js.map +1 -1
- package/lib/components-react/editors/NumericInputEditor.js +26 -29
- package/lib/components-react/editors/NumericInputEditor.js.map +1 -1
- package/lib/components-react/editors/PopupButton.js +26 -29
- package/lib/components-react/editors/PopupButton.js.map +1 -1
- package/lib/components-react/editors/PropertyEditorManager.js +2 -4
- package/lib/components-react/editors/PropertyEditorManager.js.map +1 -1
- package/lib/components-react/editors/SliderEditor.js +65 -68
- package/lib/components-react/editors/SliderEditor.js.map +1 -1
- package/lib/components-react/editors/TextEditor.js +22 -25
- package/lib/components-react/editors/TextEditor.js.map +1 -1
- package/lib/components-react/editors/TextareaEditor.js +29 -32
- package/lib/components-react/editors/TextareaEditor.js.map +1 -1
- package/lib/components-react/editors/ToggleEditor.js +26 -29
- package/lib/components-react/editors/ToggleEditor.js.map +1 -1
- package/lib/components-react/filter-builder/FilterBuilderState.js +1 -0
- package/lib/components-react/filter-builder/FilterBuilderState.js.map +1 -1
- package/lib/components-react/filtering/FilteringInput.js +36 -36
- package/lib/components-react/filtering/FilteringInput.js.map +1 -1
- package/lib/components-react/filtering/ResultSelector.js +50 -50
- package/lib/components-react/filtering/ResultSelector.js.map +1 -1
- package/lib/components-react/iconpicker/IconPickerButton.js +18 -18
- package/lib/components-react/iconpicker/IconPickerButton.js.map +1 -1
- package/lib/components-react/properties/ValueRendererManager.js +6 -7
- package/lib/components-react/properties/ValueRendererManager.js.map +1 -1
- package/lib/components-react/properties/renderers/NonPrimitivePropertyRenderer.js +17 -17
- package/lib/components-react/properties/renderers/NonPrimitivePropertyRenderer.js.map +1 -1
- package/lib/components-react/properties/renderers/PropertyGridColumns.js +4 -3
- package/lib/components-react/properties/renderers/PropertyGridColumns.js.map +1 -1
- package/lib/components-react/properties/renderers/PropertyView.js +23 -23
- package/lib/components-react/properties/renderers/PropertyView.js.map +1 -1
- package/lib/components-react/properties/renderers/label/NonPrimitivePropertyLabelRenderer.js +6 -9
- package/lib/components-react/properties/renderers/label/NonPrimitivePropertyLabelRenderer.js.map +1 -1
- package/lib/components-react/properties/renderers/value/table/NonPrimitiveValueRenderer.js +9 -12
- package/lib/components-react/properties/renderers/value/table/NonPrimitiveValueRenderer.js.map +1 -1
- package/lib/components-react/propertygrid/MergingPropertyDataProvider.js +2 -1
- package/lib/components-react/propertygrid/MergingPropertyDataProvider.js.map +1 -1
- package/lib/components-react/propertygrid/PropertyCategoryRendererManager.js +2 -4
- package/lib/components-react/propertygrid/PropertyCategoryRendererManager.js.map +1 -1
- package/lib/components-react/propertygrid/SimplePropertyDataProvider.js +6 -4
- package/lib/components-react/propertygrid/SimplePropertyDataProvider.js.map +1 -1
- package/lib/components-react/propertygrid/component/ColumnResizingPropertyListPropsSupplier.js +26 -29
- package/lib/components-react/propertygrid/component/ColumnResizingPropertyListPropsSupplier.js.map +1 -1
- package/lib/components-react/propertygrid/component/PropertyCategoryBlock.js +3 -3
- package/lib/components-react/propertygrid/component/PropertyCategoryBlock.js.map +1 -1
- package/lib/components-react/propertygrid/component/PropertyGridCommons.js +9 -9
- package/lib/components-react/propertygrid/component/PropertyGridCommons.js.map +1 -1
- package/lib/components-react/propertygrid/component/PropertyGridEventsRelatedPropsSupplier.js +22 -22
- package/lib/components-react/propertygrid/component/PropertyGridEventsRelatedPropsSupplier.js.map +1 -1
- package/lib/components-react/propertygrid/component/PropertyList.js +5 -5
- package/lib/components-react/propertygrid/component/PropertyList.js.map +1 -1
- package/lib/components-react/propertygrid/component/VirtualizedPropertyGrid.js +29 -29
- package/lib/components-react/propertygrid/component/VirtualizedPropertyGrid.js.map +1 -1
- package/lib/components-react/propertygrid/dataproviders/FilteringDataProvider.js +12 -14
- package/lib/components-react/propertygrid/dataproviders/FilteringDataProvider.js.map +1 -1
- package/lib/components-react/propertygrid/dataproviders/filterers/CompositePropertyDataFilterer.js +3 -0
- package/lib/components-react/propertygrid/dataproviders/filterers/CompositePropertyDataFilterer.js.map +1 -1
- package/lib/components-react/propertygrid/dataproviders/filterers/DisplayValuePropertyDataFilterer.js +1 -1
- package/lib/components-react/propertygrid/dataproviders/filterers/DisplayValuePropertyDataFilterer.js.map +1 -1
- package/lib/components-react/propertygrid/dataproviders/filterers/LabelPropertyDataFilterer.js +1 -1
- package/lib/components-react/propertygrid/dataproviders/filterers/LabelPropertyDataFilterer.js.map +1 -1
- package/lib/components-react/propertygrid/dataproviders/filterers/PropertyCategoryLabelFilterer.js +1 -1
- package/lib/components-react/propertygrid/dataproviders/filterers/PropertyCategoryLabelFilterer.js.map +1 -1
- package/lib/components-react/propertygrid/dataproviders/filterers/PropertyDataFiltererBase.js +1 -3
- package/lib/components-react/propertygrid/dataproviders/filterers/PropertyDataFiltererBase.js.map +1 -1
- package/lib/components-react/propertygrid/internal/PropertyGridEventHandler.js +11 -10
- package/lib/components-react/propertygrid/internal/PropertyGridEventHandler.js.map +1 -1
- package/lib/components-react/propertygrid/internal/PropertyGridModel.js +3 -3
- package/lib/components-react/propertygrid/internal/PropertyGridModel.js.map +1 -1
- package/lib/components-react/propertygrid/internal/PropertyGridModelSource.js +4 -2
- package/lib/components-react/propertygrid/internal/PropertyGridModelSource.js.map +1 -1
- package/lib/components-react/propertygrid/internal/flat-items/MutableCategorizedArrayProperty.js +2 -0
- package/lib/components-react/propertygrid/internal/flat-items/MutableCategorizedArrayProperty.js.map +1 -1
- package/lib/components-react/propertygrid/internal/flat-items/MutableCategorizedStructProperty.js +2 -0
- package/lib/components-react/propertygrid/internal/flat-items/MutableCategorizedStructProperty.js.map +1 -1
- package/lib/components-react/propertygrid/internal/flat-items/MutableCustomGridCategory.js +6 -1
- package/lib/components-react/propertygrid/internal/flat-items/MutableCustomGridCategory.js.map +1 -1
- package/lib/components-react/propertygrid/internal/flat-items/MutableFlatGridItem.js +10 -7
- package/lib/components-react/propertygrid/internal/flat-items/MutableFlatGridItem.js.map +1 -1
- package/lib/components-react/propertygrid/internal/flat-items/MutableGridCategory.js +3 -0
- package/lib/components-react/propertygrid/internal/flat-items/MutableGridCategory.js.map +1 -1
- package/lib/components-react/propertygrid/internal/flat-properties/FlatNonPrimitivePropertyRenderer.js +8 -8
- package/lib/components-react/propertygrid/internal/flat-properties/FlatNonPrimitivePropertyRenderer.js.map +1 -1
- package/lib/components-react/toolbar/InternalToolbarComponent.js +4 -4
- package/lib/components-react/toolbar/InternalToolbarComponent.js.map +1 -1
- package/lib/components-react/toolbar/utilities/Direction.js +12 -12
- package/lib/components-react/toolbar/utilities/Direction.js.map +1 -1
- package/lib/components-react/tree/HighlightingEngine.js +3 -1
- package/lib/components-react/tree/HighlightingEngine.js.map +1 -1
- package/lib/components-react/tree/SimpleTreeDataProvider.js +1 -0
- package/lib/components-react/tree/SimpleTreeDataProvider.js.map +1 -1
- package/lib/components-react/tree/controlled/TreeEventDispatcher.js +5 -1
- package/lib/components-react/tree/controlled/TreeEventDispatcher.js.map +1 -1
- package/lib/components-react/tree/controlled/TreeEventHandler.js +10 -14
- package/lib/components-react/tree/controlled/TreeEventHandler.js.map +1 -1
- package/lib/components-react/tree/controlled/TreeModel.js +7 -9
- package/lib/components-react/tree/controlled/TreeModel.js.map +1 -1
- package/lib/components-react/tree/controlled/TreeModelSource.js +3 -2
- package/lib/components-react/tree/controlled/TreeModelSource.js.map +1 -1
- package/lib/components-react/tree/controlled/TreeNodeLoader.js +11 -3
- package/lib/components-react/tree/controlled/TreeNodeLoader.js.map +1 -1
- package/lib/components-react/tree/controlled/component/TreeRenderer.js +1 -4
- package/lib/components-react/tree/controlled/component/TreeRenderer.js.map +1 -1
- package/lib/components-react/tree/controlled/internal/SparseTree.js +7 -5
- package/lib/components-react/tree/controlled/internal/SparseTree.js.map +1 -1
- package/lib/components-react/tree/controlled/internal/TreeModelMutator.js +3 -0
- package/lib/components-react/tree/controlled/internal/TreeModelMutator.js.map +1 -1
- package/lib/components-react/tree/controlled/internal/TreeSelectionManager.js +56 -51
- package/lib/components-react/tree/controlled/internal/TreeSelectionManager.js.map +1 -1
- package/package.json +5 -5
|
@@ -16,32 +16,13 @@ import { SvgPlaceholder } from "@itwin/itwinui-icons-react";
|
|
|
16
16
|
* @public
|
|
17
17
|
*/
|
|
18
18
|
export class EnumButtonGroupEditor extends React.Component {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
choices: [],
|
|
27
|
-
};
|
|
28
|
-
this._handleButtonClick = (index) => {
|
|
29
|
-
const propertyRecord = this.props.propertyRecord;
|
|
30
|
-
if (this.state.choices && this.state.choices.length > index) {
|
|
31
|
-
const selectValue = this.state.choices[index].value;
|
|
32
|
-
this.setState({
|
|
33
|
-
selectValue,
|
|
34
|
-
}, async () => {
|
|
35
|
-
if (propertyRecord && this.props.onCommit) {
|
|
36
|
-
const propertyValue = await this.getPropertyValue();
|
|
37
|
-
if (propertyValue !== undefined) {
|
|
38
|
-
this.props.onCommit({ propertyRecord, newValue: propertyValue });
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
}
|
|
19
|
+
_btnRefs = new Map();
|
|
20
|
+
_divElement = React.createRef();
|
|
21
|
+
state = {
|
|
22
|
+
selectValue: "",
|
|
23
|
+
enumIcons: [],
|
|
24
|
+
choices: [],
|
|
25
|
+
};
|
|
45
26
|
async getPropertyValue() {
|
|
46
27
|
const record = this.props.propertyRecord;
|
|
47
28
|
let propertyValue;
|
|
@@ -114,6 +95,22 @@ export class EnumButtonGroupEditor extends React.Component {
|
|
|
114
95
|
this.setState({ selectValue, enumIcons, choices });
|
|
115
96
|
}
|
|
116
97
|
}
|
|
98
|
+
_handleButtonClick = (index) => {
|
|
99
|
+
const propertyRecord = this.props.propertyRecord;
|
|
100
|
+
if (this.state.choices && this.state.choices.length > index) {
|
|
101
|
+
const selectValue = this.state.choices[index].value;
|
|
102
|
+
this.setState({
|
|
103
|
+
selectValue,
|
|
104
|
+
}, async () => {
|
|
105
|
+
if (propertyRecord && this.props.onCommit) {
|
|
106
|
+
const propertyValue = await this.getPropertyValue();
|
|
107
|
+
if (propertyValue !== undefined) {
|
|
108
|
+
this.props.onCommit({ propertyRecord, newValue: propertyValue });
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
};
|
|
117
114
|
getButton(choice, index, disabled) {
|
|
118
115
|
const choiceValue = this.state.choices
|
|
119
116
|
? this.state.choices[index].value
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EnumButtonGroupEditor.js","sourceRoot":"","sources":["../../../src/components-react/editors/EnumButtonGroupEditor.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,8BAA8B,CAAC;AACtC,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAS/B,OAAO,EACL,wBAAwB,EACxB,mBAAmB,GACpB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAS5D;;GAEG;AACH,MAAM,OAAO,qBACX,SAAQ,KAAK,CAAC,SAA0D;IAD1E;;QAIU,aAAQ,GAAG,IAAI,GAAG,EAAsC,CAAC;QACzD,gBAAW,GAAG,KAAK,CAAC,SAAS,EAAkB,CAAC;QAE/B,UAAK,GAAyC;YACrE,WAAW,EAAE,EAAE;YACf,SAAS,EAAE,EAAE;YACb,OAAO,EAAE,EAAE;SACZ,CAAC;QAiGM,uBAAkB,GAAG,CAAC,KAAa,EAAE,EAAE;YAC7C,MAAM,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,cAAgC,CAAC;YAEnE,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,GAAG,KAAK,EAAE,CAAC;gBAC5D,MAAM,WAAW,GAAG,IAAI,CAAC,KA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CAAC,MAAyB,EAAE,KAAa,EAAE,EAAE,CAClE,IAAI,CAAC,SAAS,CACZ,MAAM,EACN,KAAK,EACL,IAAI,CAAC,KAAK,CAAC,cAAc,EAAE,UAAU;gBACnC,IAAI,CAAC,KAAK,CAAC,cAAc,EAAE,UAAU,CACxC,CACF,CACC,CACP,CAAC;IACJ,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,6BAA8B,SAAQ,kBAAkB;IACnE,IAAW,SAAS;QAClB,OAAO,oBAAC,qBAAqB,OAAG,CAAC;IACnC,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module PropertyEditors\n */\n\nimport \"./EnumButtonGroupEditor.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport type {\n ButtonGroupEditorParams,\n EnumerationChoice,\n IconDefinition,\n PropertyEditorParams,\n PropertyRecord,\n PropertyValue,\n} from \"@itwin/appui-abstract\";\nimport {\n PropertyEditorParamTypes,\n PropertyValueFormat,\n} from \"@itwin/appui-abstract\";\nimport { Icon } from \"@itwin/core-react\";\nimport type { PropertyEditorProps, TypeEditor } from \"./EditorContainer.js\";\nimport { PropertyEditorBase } from \"./PropertyEditorManager.js\";\nimport { SvgPlaceholder } from \"@itwin/itwinui-icons-react\";\n\n/** @internal */\ninterface EnumButtonGroupEditorState {\n selectValue: string | number;\n enumIcons: IconDefinition[];\n choices: EnumerationChoice[];\n}\n\n/** EnumButtonGroupEditor React component that is a property editor with select input\n * @public\n */\nexport class EnumButtonGroupEditor\n extends React.Component<PropertyEditorProps, EnumButtonGroupEditorState>\n implements TypeEditor\n{\n private _btnRefs = new Map<string | number, HTMLButtonElement>();\n private _divElement = React.createRef<HTMLDivElement>();\n\n public override readonly state: Readonly<EnumButtonGroupEditorState> = {\n selectValue: \"\",\n enumIcons: [],\n choices: [],\n };\n\n public async getPropertyValue(): Promise<PropertyValue | undefined> {\n const record = this.props.propertyRecord;\n let propertyValue: PropertyValue | undefined;\n\n if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {\n propertyValue = {\n valueFormat: PropertyValueFormat.Primitive,\n value: this.state.selectValue,\n displayValue: \"\",\n };\n }\n\n return propertyValue;\n }\n\n public get htmlElement(): HTMLElement | null {\n return this._divElement.current;\n }\n\n public get hasFocus(): boolean {\n let containsFocus = false;\n if (this._divElement.current)\n containsFocus = this._divElement.current.contains(document.activeElement);\n return containsFocus;\n }\n\n public override componentDidMount() {\n void this.setStateFromProps();\n }\n\n /** @internal */\n public override componentDidUpdate(prevProps: PropertyEditorProps) {\n if (this.props.propertyRecord !== prevProps.propertyRecord) {\n void this.setStateFromProps();\n }\n }\n\n private async setStateFromProps() {\n const { propertyRecord } = this.props;\n\n if (\n propertyRecord &&\n propertyRecord.property.enum &&\n propertyRecord.value.valueFormat === PropertyValueFormat.Primitive\n ) {\n const primitiveValue = propertyRecord.value.value;\n let selectValue: string | number;\n\n if (typeof primitiveValue === \"string\") {\n selectValue = primitiveValue;\n } else {\n selectValue = primitiveValue as number;\n }\n\n let choices: EnumerationChoice[] = [];\n if (propertyRecord && propertyRecord.property.enum) {\n if (propertyRecord.property.enum.choices instanceof Promise) {\n choices = await propertyRecord.property.enum.choices;\n } else {\n choices = propertyRecord.property.enum.choices;\n }\n }\n\n const numChoices = choices.length;\n const enumIcons = new Array<IconDefinition>(numChoices);\n enumIcons.fill({ iconSpec: \"\" });\n\n if (\n propertyRecord.property.editor &&\n propertyRecord.property.editor.params\n ) {\n if (\n propertyRecord.property.editor &&\n propertyRecord.property.editor.params\n ) {\n const bgParams = propertyRecord.property.editor.params.find(\n (param: PropertyEditorParams) =>\n param.type === PropertyEditorParamTypes.ButtonGroupData.valueOf()\n ) as ButtonGroupEditorParams;\n if (bgParams) {\n bgParams.buttons.forEach(\n (iconDef: IconDefinition, index: number) => {\n if (index < numChoices) {\n enumIcons[index] = iconDef;\n }\n }\n );\n }\n }\n }\n\n this.setState({ selectValue, enumIcons, choices });\n }\n }\n\n private _handleButtonClick = (index: number) => {\n const propertyRecord = this.props.propertyRecord as PropertyRecord;\n\n if (this.state.choices && this.state.choices.length > index) {\n const selectValue = this.state.choices[index].value;\n\n this.setState(\n {\n selectValue,\n },\n async () => {\n if (propertyRecord && this.props.onCommit) {\n const propertyValue = await this.getPropertyValue();\n if (propertyValue !== undefined) {\n this.props.onCommit({ propertyRecord, newValue: propertyValue });\n }\n }\n }\n );\n }\n };\n\n private getButton(\n choice: EnumerationChoice,\n index: number,\n disabled?: boolean\n ) {\n const choiceValue = this.state.choices\n ? this.state.choices[index].value\n : 0;\n const isActive = choiceValue === this.state.selectValue ? true : false;\n let isDisabled = disabled;\n const isEnabledFunction = this.state.enumIcons[index].isEnabledFunction;\n if (isEnabledFunction && !isDisabled) {\n isDisabled = !isEnabledFunction();\n }\n\n const className = classnames(\n \"components-enumbuttongroup-button\",\n isDisabled && \"nz-is-disabled\",\n isActive && \"nz-is-active\"\n );\n\n return (\n <button\n ref={(btn) => {\n btn && this._btnRefs.set(choiceValue, btn);\n }}\n data-testid={choice.label}\n className={className}\n title={choice.label}\n key={choice.label}\n onClick={() => this._handleButtonClick(index)}\n >\n {/* eslint-disable-next-line @typescript-eslint/no-deprecated */}\n <Icon\n iconSpec={\n this.state.enumIcons[index].iconSpec === \"\" ? (\n <SvgPlaceholder />\n ) : (\n this.state.enumIcons[index].iconSpec\n )\n }\n />\n </button>\n );\n }\n\n public override render() {\n return (\n <div\n className={classnames(\n \"components-enumbuttongroup-editor\",\n this.props.className\n )}\n style={this.props.style}\n ref={this._divElement}\n >\n {this.state.choices &&\n this.state.enumIcons.length &&\n this.state.choices.map((choice: EnumerationChoice, index: number) =>\n this.getButton(\n choice,\n index,\n this.props.propertyRecord?.isDisabled ||\n this.props.propertyRecord?.isReadonly\n )\n )}\n </div>\n );\n }\n}\n\n/** Enum Property Button Group Editor registered for the \"enum\" type name and the \"enum-buttongroup\" editor name.\n * It uses the [[EnumButtonGroupEditor]] React component.\n * @public\n */\nexport class EnumPropertyButtonGroupEditor extends PropertyEditorBase {\n public get reactNode(): React.ReactNode {\n return <EnumButtonGroupEditor />;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"EnumButtonGroupEditor.js","sourceRoot":"","sources":["../../../src/components-react/editors/EnumButtonGroupEditor.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,8BAA8B,CAAC;AACtC,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAS/B,OAAO,EACL,wBAAwB,EACxB,mBAAmB,GACpB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAS5D;;GAEG;AACH,MAAM,OAAO,qBACX,SAAQ,KAAK,CAAC,SAA0D;IAGhE,QAAQ,GAAG,IAAI,GAAG,EAAsC,CAAC;IACzD,WAAW,GAAG,KAAK,CAAC,SAAS,EAAkB,CAAC;IAE/B,KAAK,GAAyC;QACrE,WAAW,EAAE,EAAE;QACf,SAAS,EAAE,EAAE;QACb,OAAO,EAAE,EAAE;KACZ,CAAC;IAEK,KAAK,CAAC,gBAAgB;QAC3B,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC;QACzC,IAAI,aAAwC,CAAC;QAE7C,IAAI,MAAM,IAAI,MAAM,CAAC,KAAK,CAAC,WAAW,KAAK,mBAAmB,CAAC,SAAS,EAAE,CAAC;YACzE,aAAa,GAAG;gBACd,WAAW,EAAE,mBAAmB,CAAC,SAAS;gBAC1C,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,WAAW;gBAC7B,YAAY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L,IAAI,CAAC,KAAK,CAAC,cAAc,EAAE,UAAU;gBACnC,IAAI,CAAC,KAAK,CAAC,cAAc,EAAE,UAAU,CACxC,CACF,CACC,CACP,CAAC;IACJ,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,6BAA8B,SAAQ,kBAAkB;IACnE,IAAW,SAAS;QAClB,OAAO,oBAAC,qBAAqB,OAAG,CAAC;IACnC,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module PropertyEditors\n */\n\nimport \"./EnumButtonGroupEditor.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport type {\n ButtonGroupEditorParams,\n EnumerationChoice,\n IconDefinition,\n PropertyEditorParams,\n PropertyRecord,\n PropertyValue,\n} from \"@itwin/appui-abstract\";\nimport {\n PropertyEditorParamTypes,\n PropertyValueFormat,\n} from \"@itwin/appui-abstract\";\nimport { Icon } from \"@itwin/core-react\";\nimport type { PropertyEditorProps, TypeEditor } from \"./EditorContainer.js\";\nimport { PropertyEditorBase } from \"./PropertyEditorManager.js\";\nimport { SvgPlaceholder } from \"@itwin/itwinui-icons-react\";\n\n/** @internal */\ninterface EnumButtonGroupEditorState {\n selectValue: string | number;\n enumIcons: IconDefinition[];\n choices: EnumerationChoice[];\n}\n\n/** EnumButtonGroupEditor React component that is a property editor with select input\n * @public\n */\nexport class EnumButtonGroupEditor\n extends React.Component<PropertyEditorProps, EnumButtonGroupEditorState>\n implements TypeEditor\n{\n private _btnRefs = new Map<string | number, HTMLButtonElement>();\n private _divElement = React.createRef<HTMLDivElement>();\n\n public override readonly state: Readonly<EnumButtonGroupEditorState> = {\n selectValue: \"\",\n enumIcons: [],\n choices: [],\n };\n\n public async getPropertyValue(): Promise<PropertyValue | undefined> {\n const record = this.props.propertyRecord;\n let propertyValue: PropertyValue | undefined;\n\n if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {\n propertyValue = {\n valueFormat: PropertyValueFormat.Primitive,\n value: this.state.selectValue,\n displayValue: \"\",\n };\n }\n\n return propertyValue;\n }\n\n public get htmlElement(): HTMLElement | null {\n return this._divElement.current;\n }\n\n public get hasFocus(): boolean {\n let containsFocus = false;\n if (this._divElement.current)\n containsFocus = this._divElement.current.contains(document.activeElement);\n return containsFocus;\n }\n\n public override componentDidMount() {\n void this.setStateFromProps();\n }\n\n /** @internal */\n public override componentDidUpdate(prevProps: PropertyEditorProps) {\n if (this.props.propertyRecord !== prevProps.propertyRecord) {\n void this.setStateFromProps();\n }\n }\n\n private async setStateFromProps() {\n const { propertyRecord } = this.props;\n\n if (\n propertyRecord &&\n propertyRecord.property.enum &&\n propertyRecord.value.valueFormat === PropertyValueFormat.Primitive\n ) {\n const primitiveValue = propertyRecord.value.value;\n let selectValue: string | number;\n\n if (typeof primitiveValue === \"string\") {\n selectValue = primitiveValue;\n } else {\n selectValue = primitiveValue as number;\n }\n\n let choices: EnumerationChoice[] = [];\n if (propertyRecord && propertyRecord.property.enum) {\n if (propertyRecord.property.enum.choices instanceof Promise) {\n choices = await propertyRecord.property.enum.choices;\n } else {\n choices = propertyRecord.property.enum.choices;\n }\n }\n\n const numChoices = choices.length;\n const enumIcons = new Array<IconDefinition>(numChoices);\n enumIcons.fill({ iconSpec: \"\" });\n\n if (\n propertyRecord.property.editor &&\n propertyRecord.property.editor.params\n ) {\n if (\n propertyRecord.property.editor &&\n propertyRecord.property.editor.params\n ) {\n const bgParams = propertyRecord.property.editor.params.find(\n (param: PropertyEditorParams) =>\n param.type === PropertyEditorParamTypes.ButtonGroupData.valueOf()\n ) as ButtonGroupEditorParams;\n if (bgParams) {\n bgParams.buttons.forEach(\n (iconDef: IconDefinition, index: number) => {\n if (index < numChoices) {\n enumIcons[index] = iconDef;\n }\n }\n );\n }\n }\n }\n\n this.setState({ selectValue, enumIcons, choices });\n }\n }\n\n private _handleButtonClick = (index: number) => {\n const propertyRecord = this.props.propertyRecord as PropertyRecord;\n\n if (this.state.choices && this.state.choices.length > index) {\n const selectValue = this.state.choices[index].value;\n\n this.setState(\n {\n selectValue,\n },\n async () => {\n if (propertyRecord && this.props.onCommit) {\n const propertyValue = await this.getPropertyValue();\n if (propertyValue !== undefined) {\n this.props.onCommit({ propertyRecord, newValue: propertyValue });\n }\n }\n }\n );\n }\n };\n\n private getButton(\n choice: EnumerationChoice,\n index: number,\n disabled?: boolean\n ) {\n const choiceValue = this.state.choices\n ? this.state.choices[index].value\n : 0;\n const isActive = choiceValue === this.state.selectValue ? true : false;\n let isDisabled = disabled;\n const isEnabledFunction = this.state.enumIcons[index].isEnabledFunction;\n if (isEnabledFunction && !isDisabled) {\n isDisabled = !isEnabledFunction();\n }\n\n const className = classnames(\n \"components-enumbuttongroup-button\",\n isDisabled && \"nz-is-disabled\",\n isActive && \"nz-is-active\"\n );\n\n return (\n <button\n ref={(btn) => {\n btn && this._btnRefs.set(choiceValue, btn);\n }}\n data-testid={choice.label}\n className={className}\n title={choice.label}\n key={choice.label}\n onClick={() => this._handleButtonClick(index)}\n >\n {/* eslint-disable-next-line @typescript-eslint/no-deprecated */}\n <Icon\n iconSpec={\n this.state.enumIcons[index].iconSpec === \"\" ? (\n <SvgPlaceholder />\n ) : (\n this.state.enumIcons[index].iconSpec\n )\n }\n />\n </button>\n );\n }\n\n public override render() {\n return (\n <div\n className={classnames(\n \"components-enumbuttongroup-editor\",\n this.props.className\n )}\n style={this.props.style}\n ref={this._divElement}\n >\n {this.state.choices &&\n this.state.enumIcons.length &&\n this.state.choices.map((choice: EnumerationChoice, index: number) =>\n this.getButton(\n choice,\n index,\n this.props.propertyRecord?.isDisabled ||\n this.props.propertyRecord?.isReadonly\n )\n )}\n </div>\n );\n }\n}\n\n/** Enum Property Button Group Editor registered for the \"enum\" type name and the \"enum-buttongroup\" editor name.\n * It uses the [[EnumButtonGroupEditor]] React component.\n * @public\n */\nexport class EnumPropertyButtonGroupEditor extends PropertyEditorBase {\n public get reactNode(): React.ReactNode {\n return <EnumButtonGroupEditor />;\n }\n}\n"]}
|
|
@@ -16,39 +16,14 @@ import { UiComponents } from "../UiComponents.js";
|
|
|
16
16
|
* @public
|
|
17
17
|
*/
|
|
18
18
|
export class EnumEditor extends React.PureComponent {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
parentDiv: null,
|
|
28
|
-
};
|
|
29
|
-
this._updateSelectValue = (newValue) => {
|
|
30
|
-
if (this._isMounted) {
|
|
31
|
-
let selectValue;
|
|
32
|
-
if (this.state.valueIsNumber)
|
|
33
|
-
selectValue = parseInt(newValue, 10);
|
|
34
|
-
else
|
|
35
|
-
selectValue = newValue;
|
|
36
|
-
this.setState({
|
|
37
|
-
selectValue,
|
|
38
|
-
}, async () => {
|
|
39
|
-
if (this.props.propertyRecord && this.props.onCommit) {
|
|
40
|
-
const propertyValue = await this.getPropertyValue();
|
|
41
|
-
if (propertyValue) {
|
|
42
|
-
this.props.onCommit({
|
|
43
|
-
propertyRecord: this.props.propertyRecord,
|
|
44
|
-
newValue: propertyValue,
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
}
|
|
19
|
+
_isMounted = false;
|
|
20
|
+
_divElement = React.createRef();
|
|
21
|
+
state = {
|
|
22
|
+
selectValue: "",
|
|
23
|
+
valueIsNumber: false,
|
|
24
|
+
options: [],
|
|
25
|
+
parentDiv: null,
|
|
26
|
+
};
|
|
52
27
|
async getPropertyValue() {
|
|
53
28
|
const record = this.props.propertyRecord;
|
|
54
29
|
let propertyValue;
|
|
@@ -70,6 +45,28 @@ export class EnumEditor extends React.PureComponent {
|
|
|
70
45
|
containsFocus = this._divElement.current.contains(document.activeElement);
|
|
71
46
|
return containsFocus;
|
|
72
47
|
}
|
|
48
|
+
_updateSelectValue = (newValue) => {
|
|
49
|
+
if (this._isMounted) {
|
|
50
|
+
let selectValue;
|
|
51
|
+
if (this.state.valueIsNumber)
|
|
52
|
+
selectValue = parseInt(newValue, 10);
|
|
53
|
+
else
|
|
54
|
+
selectValue = newValue;
|
|
55
|
+
this.setState({
|
|
56
|
+
selectValue,
|
|
57
|
+
}, async () => {
|
|
58
|
+
if (this.props.propertyRecord && this.props.onCommit) {
|
|
59
|
+
const propertyValue = await this.getPropertyValue();
|
|
60
|
+
if (propertyValue) {
|
|
61
|
+
this.props.onCommit({
|
|
62
|
+
propertyRecord: this.props.propertyRecord,
|
|
63
|
+
newValue: propertyValue,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
};
|
|
73
70
|
componentDidMount() {
|
|
74
71
|
this._isMounted = true;
|
|
75
72
|
void this.setStateFromProps();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EnumEditor.js","sourceRoot":"","sources":["../../../src/components-react/editors/EnumEditor.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,mBAAmB,CAAC;AAC3B,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAUlD;;GAEG;AACH,MAAM,OAAO,UACX,SAAQ,KAAK,CAAC,aAAmD;IADnE;;QAIU,eAAU,GAAG,KAAK,CAAC;QACnB,gBAAW,GAAG,KAAK,CAAC,SAAS,EAAkB,CAAC;QAE/B,UAAK,GAA8B;YAC1D,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QACpG,6BAA6B;QAC7B,OAAO,CACL,6BAAK,GAAG,EAAE,IAAI,CAAC,WAAW;YACxB,oBAAC,MAAM,IACL,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,aAAa,EAC1D,KAAK,EAAE,WAAW,EAClB,QAAQ,EAAE,IAAI,CAAC,kBAAkB,iBACrB,0BAA0B,EACtC,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,EAC3B,YAAY,EAAE;oBACZ,GAAG,EAAE,CAAC,EAAE,EAAE,EAAE;wBACV,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ;4BAAE,OAAO;wBACjC,EAAE,EAAE,KAAK,EAAE,CAAC;oBACd,CAAC;oBACD,SAAS,EAAE,mBAAmB;iBAC/B,gBACW,YAAY,CAAC,SAAS,CAAC,aAAa,CAAC,EACjD,IAAI,EAAC,OAAO,EACZ,QAAQ,EACN,IAAI,CAAC,KAAK,CAAC,cAAc,EAAE,UAAU;oBACrC,IAAI,CAAC,KAAK,CAAC,cAAc,EAAE,UAAU,GAEvC,CACE,CACP,CAAC;IACJ,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,kBAAmB,SAAQ,kBAAkB;IACxD,IAAoB,qBAAqB;QACvC,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAoB,gCAAgC;QAClD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAW,SAAS;QAClB,OAAO,oBAAC,UAAU,OAAG,CAAC;IACxB,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module PropertyEditors\n */\n\nimport \"./EnumEditor.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport type { EnumerationChoice, PropertyValue } from \"@itwin/appui-abstract\";\nimport { PropertyValueFormat } from \"@itwin/appui-abstract\";\nimport type { SelectOption } from \"@itwin/itwinui-react\";\nimport { Select } from \"@itwin/itwinui-react\";\nimport type { PropertyEditorProps, TypeEditor } from \"./EditorContainer.js\";\nimport { PropertyEditorBase } from \"./PropertyEditorManager.js\";\nimport { UiComponents } from \"../UiComponents.js\";\n\n/** @internal */\ninterface EnumEditorState {\n selectValue: string | number;\n valueIsNumber: boolean;\n options: SelectOption<string>[];\n parentDiv: HTMLDivElement | null;\n}\n\n/** EnumEditor React component that is a property editor with select input\n * @public\n */\nexport class EnumEditor\n extends React.PureComponent<PropertyEditorProps, EnumEditorState>\n implements TypeEditor\n{\n private _isMounted = false;\n private _divElement = React.createRef<HTMLDivElement>();\n\n public override readonly state: Readonly<EnumEditorState> = {\n selectValue: \"\",\n valueIsNumber: false,\n options: [],\n parentDiv: null,\n };\n\n public async getPropertyValue(): Promise<PropertyValue | undefined> {\n const record = this.props.propertyRecord;\n let propertyValue: PropertyValue | undefined;\n\n if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {\n propertyValue = {\n valueFormat: PropertyValueFormat.Primitive,\n value: this.state.selectValue,\n displayValue: \"\",\n };\n }\n\n return propertyValue;\n }\n\n public get htmlElement(): HTMLElement | null {\n return this._divElement.current;\n }\n\n public get hasFocus(): boolean {\n let containsFocus = false;\n if (this._divElement.current)\n containsFocus = this._divElement.current.contains(document.activeElement);\n return containsFocus;\n }\n\n private _updateSelectValue = (newValue: string) => {\n if (this._isMounted) {\n let selectValue: string | number;\n\n if (this.state.valueIsNumber) selectValue = parseInt(newValue, 10);\n else selectValue = newValue;\n\n this.setState(\n {\n selectValue,\n },\n async () => {\n if (this.props.propertyRecord && this.props.onCommit) {\n const propertyValue = await this.getPropertyValue();\n if (propertyValue) {\n this.props.onCommit({\n propertyRecord: this.props.propertyRecord,\n newValue: propertyValue,\n });\n }\n }\n }\n );\n }\n };\n\n public override componentDidMount() {\n this._isMounted = true;\n void this.setStateFromProps();\n }\n\n public override componentWillUnmount() {\n this._isMounted = false;\n }\n\n /** @internal */\n public override componentDidUpdate(prevProps: PropertyEditorProps) {\n if (this.props.propertyRecord !== prevProps.propertyRecord) {\n void this.setStateFromProps();\n }\n }\n\n private async setStateFromProps() {\n const { propertyRecord } = this.props;\n let initialValue: string | number = \"\";\n let valueIsNumber: boolean = false;\n\n if (\n propertyRecord &&\n propertyRecord.value.valueFormat === PropertyValueFormat.Primitive\n ) {\n const primitiveValue = propertyRecord.value.value;\n if (typeof primitiveValue === \"string\") {\n initialValue = primitiveValue;\n valueIsNumber = false;\n } else {\n initialValue = primitiveValue as number;\n valueIsNumber = true;\n }\n }\n\n let choices: EnumerationChoice[] | undefined;\n\n if (propertyRecord && propertyRecord.property.enum) {\n if (propertyRecord.property.enum.choices instanceof Promise) {\n choices = await propertyRecord.property.enum.choices;\n } else {\n choices = propertyRecord.property.enum.choices;\n }\n }\n\n const options: SelectOption<string>[] = [];\n if (choices) {\n choices.forEach((choice: EnumerationChoice) => {\n options.push({ value: choice.value.toString(), label: choice.label });\n });\n }\n\n if (this._isMounted)\n this.setState({\n selectValue: initialValue,\n valueIsNumber,\n options,\n parentDiv: this._divElement.current,\n });\n }\n\n public override render() {\n const className = classnames(\n \"components-cell-editor\",\n \"components-enum-editor\",\n this.props.className\n );\n const selectValue =\n this.state.selectValue !== undefined\n ? this.state.selectValue.toString()\n : undefined;\n\n // set min-width to show about 4 characters + down arrow\n const minWidthStyle: React.CSSProperties = {\n minWidth: `6em`,\n };\n\n // The iTwinUI-react Select onBlur still does not work properly, so it cannot be used yet. NEEDSWORK\n // onBlur={this.props.onBlur}\n return (\n <div ref={this._divElement}>\n <Select\n className={className}\n style={this.props.style ? this.props.style : minWidthStyle}\n value={selectValue}\n onChange={this._updateSelectValue}\n data-testid=\"components-select-editor\"\n options={this.state.options}\n triggerProps={{\n ref: (el) => {\n if (!this.props.setFocus) return;\n el?.focus();\n },\n className: \"components-button\",\n }}\n aria-label={UiComponents.translate(\"editor.enum\")}\n size=\"small\"\n disabled={\n this.props.propertyRecord?.isDisabled ||\n this.props.propertyRecord?.isReadonly\n }\n />\n </div>\n );\n }\n}\n\n/** Enum Property Button Group Editor registered for the \"enum\" type name.\n * It uses the [[EnumEditor]] React component.\n * @public\n */\nexport class EnumPropertyEditor extends PropertyEditorBase {\n public override get containerHandlesEnter(): boolean {\n return false;\n }\n public override get containerStopsKeydownPropagation(): boolean {\n return false;\n }\n\n public get reactNode(): React.ReactNode {\n return <EnumEditor />;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"EnumEditor.js","sourceRoot":"","sources":["../../../src/components-react/editors/EnumEditor.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,mBAAmB,CAAC;AAC3B,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAUlD;;GAEG;AACH,MAAM,OAAO,UACX,SAAQ,KAAK,CAAC,aAAmD;IAGzD,UAAU,GAAG,KAAK,CAAC;IACnB,WAAW,GAAG,KAAK,CAAC,SAAS,EAAkB,CAAC;IAE/B,KAAK,GAA8B;QAC1D,WAAW,EAAE,EAAE;QACf,aAAa,EAAE,KAAK;QACpB,OAAO,EAAE,EAAE;QACX,SAAS,EAAE,IAAI;KAChB,CAAC;IAEK,KAAK,CAAC,gBAAgB;QAC3B,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC;QACzC,IAAI,aAAwC,CAAC;QAE7C,IAAI,MAAM,IAAI,MAAM,C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EAAE,IAAI,CAAC,kBAAkB,iBACrB,0BAA0B,EACtC,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,EAC3B,YAAY,EAAE;oBACZ,GAAG,EAAE,CAAC,EAAE,EAAE,EAAE;wBACV,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ;4BAAE,OAAO;wBACjC,EAAE,EAAE,KAAK,EAAE,CAAC;oBACd,CAAC;oBACD,SAAS,EAAE,mBAAmB;iBAC/B,gBACW,YAAY,CAAC,SAAS,CAAC,aAAa,CAAC,EACjD,IAAI,EAAC,OAAO,EACZ,QAAQ,EACN,IAAI,CAAC,KAAK,CAAC,cAAc,EAAE,UAAU;oBACrC,IAAI,CAAC,KAAK,CAAC,cAAc,EAAE,UAAU,GAEvC,CACE,CACP,CAAC;IACJ,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,kBAAmB,SAAQ,kBAAkB;IACxD,IAAoB,qBAAqB;QACvC,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAoB,gCAAgC;QAClD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAW,SAAS;QAClB,OAAO,oBAAC,UAAU,OAAG,CAAC;IACxB,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module PropertyEditors\n */\n\nimport \"./EnumEditor.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport type { EnumerationChoice, PropertyValue } from \"@itwin/appui-abstract\";\nimport { PropertyValueFormat } from \"@itwin/appui-abstract\";\nimport type { SelectOption } from \"@itwin/itwinui-react\";\nimport { Select } from \"@itwin/itwinui-react\";\nimport type { PropertyEditorProps, TypeEditor } from \"./EditorContainer.js\";\nimport { PropertyEditorBase } from \"./PropertyEditorManager.js\";\nimport { UiComponents } from \"../UiComponents.js\";\n\n/** @internal */\ninterface EnumEditorState {\n selectValue: string | number;\n valueIsNumber: boolean;\n options: SelectOption<string>[];\n parentDiv: HTMLDivElement | null;\n}\n\n/** EnumEditor React component that is a property editor with select input\n * @public\n */\nexport class EnumEditor\n extends React.PureComponent<PropertyEditorProps, EnumEditorState>\n implements TypeEditor\n{\n private _isMounted = false;\n private _divElement = React.createRef<HTMLDivElement>();\n\n public override readonly state: Readonly<EnumEditorState> = {\n selectValue: \"\",\n valueIsNumber: false,\n options: [],\n parentDiv: null,\n };\n\n public async getPropertyValue(): Promise<PropertyValue | undefined> {\n const record = this.props.propertyRecord;\n let propertyValue: PropertyValue | undefined;\n\n if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {\n propertyValue = {\n valueFormat: PropertyValueFormat.Primitive,\n value: this.state.selectValue,\n displayValue: \"\",\n };\n }\n\n return propertyValue;\n }\n\n public get htmlElement(): HTMLElement | null {\n return this._divElement.current;\n }\n\n public get hasFocus(): boolean {\n let containsFocus = false;\n if (this._divElement.current)\n containsFocus = this._divElement.current.contains(document.activeElement);\n return containsFocus;\n }\n\n private _updateSelectValue = (newValue: string) => {\n if (this._isMounted) {\n let selectValue: string | number;\n\n if (this.state.valueIsNumber) selectValue = parseInt(newValue, 10);\n else selectValue = newValue;\n\n this.setState(\n {\n selectValue,\n },\n async () => {\n if (this.props.propertyRecord && this.props.onCommit) {\n const propertyValue = await this.getPropertyValue();\n if (propertyValue) {\n this.props.onCommit({\n propertyRecord: this.props.propertyRecord,\n newValue: propertyValue,\n });\n }\n }\n }\n );\n }\n };\n\n public override componentDidMount() {\n this._isMounted = true;\n void this.setStateFromProps();\n }\n\n public override componentWillUnmount() {\n this._isMounted = false;\n }\n\n /** @internal */\n public override componentDidUpdate(prevProps: PropertyEditorProps) {\n if (this.props.propertyRecord !== prevProps.propertyRecord) {\n void this.setStateFromProps();\n }\n }\n\n private async setStateFromProps() {\n const { propertyRecord } = this.props;\n let initialValue: string | number = \"\";\n let valueIsNumber: boolean = false;\n\n if (\n propertyRecord &&\n propertyRecord.value.valueFormat === PropertyValueFormat.Primitive\n ) {\n const primitiveValue = propertyRecord.value.value;\n if (typeof primitiveValue === \"string\") {\n initialValue = primitiveValue;\n valueIsNumber = false;\n } else {\n initialValue = primitiveValue as number;\n valueIsNumber = true;\n }\n }\n\n let choices: EnumerationChoice[] | undefined;\n\n if (propertyRecord && propertyRecord.property.enum) {\n if (propertyRecord.property.enum.choices instanceof Promise) {\n choices = await propertyRecord.property.enum.choices;\n } else {\n choices = propertyRecord.property.enum.choices;\n }\n }\n\n const options: SelectOption<string>[] = [];\n if (choices) {\n choices.forEach((choice: EnumerationChoice) => {\n options.push({ value: choice.value.toString(), label: choice.label });\n });\n }\n\n if (this._isMounted)\n this.setState({\n selectValue: initialValue,\n valueIsNumber,\n options,\n parentDiv: this._divElement.current,\n });\n }\n\n public override render() {\n const className = classnames(\n \"components-cell-editor\",\n \"components-enum-editor\",\n this.props.className\n );\n const selectValue =\n this.state.selectValue !== undefined\n ? this.state.selectValue.toString()\n : undefined;\n\n // set min-width to show about 4 characters + down arrow\n const minWidthStyle: React.CSSProperties = {\n minWidth: `6em`,\n };\n\n // The iTwinUI-react Select onBlur still does not work properly, so it cannot be used yet. NEEDSWORK\n // onBlur={this.props.onBlur}\n return (\n <div ref={this._divElement}>\n <Select\n className={className}\n style={this.props.style ? this.props.style : minWidthStyle}\n value={selectValue}\n onChange={this._updateSelectValue}\n data-testid=\"components-select-editor\"\n options={this.state.options}\n triggerProps={{\n ref: (el) => {\n if (!this.props.setFocus) return;\n el?.focus();\n },\n className: \"components-button\",\n }}\n aria-label={UiComponents.translate(\"editor.enum\")}\n size=\"small\"\n disabled={\n this.props.propertyRecord?.isDisabled ||\n this.props.propertyRecord?.isReadonly\n }\n />\n </div>\n );\n }\n}\n\n/** Enum Property Button Group Editor registered for the \"enum\" type name.\n * It uses the [[EnumEditor]] React component.\n * @public\n */\nexport class EnumPropertyEditor extends PropertyEditorBase {\n public override get containerHandlesEnter(): boolean {\n return false;\n }\n public override get containerStopsKeydownPropagation(): boolean {\n return false;\n }\n\n public get reactNode(): React.ReactNode {\n return <EnumEditor />;\n }\n}\n"]}
|
|
@@ -15,24 +15,11 @@ import { PropertyEditorBase } from "./PropertyEditorManager.js";
|
|
|
15
15
|
* @alpha
|
|
16
16
|
*/
|
|
17
17
|
export class IconEditor extends React.PureComponent {
|
|
18
|
+
_control = null;
|
|
19
|
+
_isMounted = false;
|
|
20
|
+
_divElement = React.createRef();
|
|
18
21
|
constructor(props) {
|
|
19
22
|
super(props);
|
|
20
|
-
this._control = null;
|
|
21
|
-
this._isMounted = false;
|
|
22
|
-
this._divElement = React.createRef();
|
|
23
|
-
this._onIconChange = (icon) => {
|
|
24
|
-
const propertyRecord = this.props.propertyRecord;
|
|
25
|
-
this.setState({
|
|
26
|
-
icon,
|
|
27
|
-
}, async () => {
|
|
28
|
-
if (propertyRecord && this.props.onCommit) {
|
|
29
|
-
const propertyValue = await this.getPropertyValue();
|
|
30
|
-
if (propertyValue) {
|
|
31
|
-
this.props.onCommit({ propertyRecord, newValue: propertyValue });
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
};
|
|
36
23
|
let icon = "";
|
|
37
24
|
let numColumns = 4;
|
|
38
25
|
const icons = [];
|
|
@@ -80,6 +67,19 @@ export class IconEditor extends React.PureComponent {
|
|
|
80
67
|
this._control.setFocus();
|
|
81
68
|
}
|
|
82
69
|
}
|
|
70
|
+
_onIconChange = (icon) => {
|
|
71
|
+
const propertyRecord = this.props.propertyRecord;
|
|
72
|
+
this.setState({
|
|
73
|
+
icon,
|
|
74
|
+
}, async () => {
|
|
75
|
+
if (propertyRecord && this.props.onCommit) {
|
|
76
|
+
const propertyValue = await this.getPropertyValue();
|
|
77
|
+
if (propertyValue) {
|
|
78
|
+
this.props.onCommit({ propertyRecord, newValue: propertyValue });
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
83
|
componentDidMount() {
|
|
84
84
|
this._isMounted = true;
|
|
85
85
|
void this.setStateFromProps();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IconEditor.js","sourceRoot":"","sources":["../../../src/components-react/editors/IconEditor.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,mBAAmB,CAAC;AAC3B,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAO/B,OAAO,EACL,wBAAwB,EACxB,mBAAmB,GACpB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAErE,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAShE;;GAEG;AACH,MAAM,OAAO,UACX,SAAQ,KAAK,CAAC,aAAmD;
|
|
1
|
+
{"version":3,"file":"IconEditor.js","sourceRoot":"","sources":["../../../src/components-react/editors/IconEditor.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,mBAAmB,CAAC;AAC3B,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAO/B,OAAO,EACL,wBAAwB,EACxB,mBAAmB,GACpB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAErE,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAShE;;GAEG;AACH,MAAM,OAAO,UACX,SAAQ,KAAK,CAAC,aAAmD;IAGzD,QAAQ,GAAQ,IAAI,CAAC;IACrB,UAAU,GAAG,KAAK,CAAC;IACnB,WAAW,GAAG,KAAK,CAAC,SAAS,EAAkB,CAAC;IAExD,YAAY,KAA0B;QACpC,KAAK,CAAC,KAAK,CAAC,CAAC;QAEb,IAAI,IAAI,GAAG,EAAE,CAAC;QACd,IAAI,UAAU,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,cAAc,EAAE,UAAU,EAC/C,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,cAAc,EAAE,UAAU,EAC/C,YAAY,EAAE,IAAI,CAAC,aAAa,iBACpB,wBAAwB,GACpC,CACE,CACP,CAAC;IACJ,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,kBAAmB,SAAQ,kBAAkB;IACxD,IAAW,SAAS;QAClB,OAAO,oBAAC,UAAU,OAAG,CAAC;IACxB,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module PropertyEditors\n */\n\nimport \"./IconEditor.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport type {\n IconListEditorParams,\n PropertyEditorParams,\n PropertyRecord,\n PropertyValue,\n} from \"@itwin/appui-abstract\";\nimport {\n PropertyEditorParamTypes,\n PropertyValueFormat,\n} from \"@itwin/appui-abstract\";\nimport { IconPickerButton } from \"../iconpicker/IconPickerButton.js\";\nimport type { PropertyEditorProps, TypeEditor } from \"./EditorContainer.js\";\nimport { PropertyEditorBase } from \"./PropertyEditorManager.js\";\n\n/** @internal */\ninterface IconEditorState {\n icon: string;\n icons: string[];\n numColumns: number;\n}\n\n/** IconEditor React component that is a property editor with button and popup\n * @alpha\n */\nexport class IconEditor\n extends React.PureComponent<PropertyEditorProps, IconEditorState>\n implements TypeEditor\n{\n private _control: any = null;\n private _isMounted = false;\n private _divElement = React.createRef<HTMLDivElement>();\n\n constructor(props: PropertyEditorProps) {\n super(props);\n\n let icon = \"\";\n let numColumns = 4;\n const icons: string[] = [];\n\n // TODO: add support for following if we need to specify set of weights to display\n const record = props.propertyRecord;\n if (\n record &&\n record.property &&\n record.property.editor &&\n record.property.editor.params\n ) {\n const iconParams = record.property.editor.params.find(\n (param: PropertyEditorParams) =>\n param.type === PropertyEditorParamTypes.IconListData.valueOf()\n ) as IconListEditorParams;\n if (iconParams) {\n if (iconParams.iconValue) icon = iconParams.iconValue;\n if (iconParams.numColumns) numColumns = iconParams.numColumns;\n if (iconParams.iconValues)\n iconParams.iconValues.forEach((i: string) => icons.push(i));\n }\n }\n\n this.state = { icon, icons, numColumns };\n }\n\n public async getPropertyValue(): Promise<PropertyValue | undefined> {\n const record = this.props.propertyRecord;\n let propertyValue: PropertyValue | undefined;\n\n if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {\n propertyValue = {\n valueFormat: PropertyValueFormat.Primitive,\n value: this.state.icon,\n displayValue: \"\",\n };\n }\n\n return propertyValue;\n }\n\n public get htmlElement(): HTMLElement | null {\n return this._divElement.current;\n }\n\n public get hasFocus(): boolean {\n let containsFocus = false;\n if (this._divElement.current)\n containsFocus = this._divElement.current.contains(document.activeElement);\n return containsFocus;\n }\n\n private setFocus(): void {\n if (this._control && !this.props.propertyRecord?.isDisabled) {\n this._control.setFocus();\n }\n }\n\n private _onIconChange = (icon: string) => {\n const propertyRecord = this.props.propertyRecord as PropertyRecord;\n\n this.setState(\n {\n icon,\n },\n async () => {\n if (propertyRecord && this.props.onCommit) {\n const propertyValue = await this.getPropertyValue();\n if (propertyValue) {\n this.props.onCommit({ propertyRecord, newValue: propertyValue });\n }\n }\n }\n );\n };\n\n public override componentDidMount() {\n this._isMounted = true;\n void this.setStateFromProps();\n }\n\n public override componentWillUnmount() {\n this._isMounted = false;\n }\n\n public override componentDidUpdate(prevProps: PropertyEditorProps) {\n if (this.props.propertyRecord !== prevProps.propertyRecord) {\n void this.setStateFromProps();\n }\n }\n\n private async setStateFromProps() {\n const record = this.props.propertyRecord;\n let initialValue = \"\";\n\n if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {\n initialValue = record.value.value as string;\n }\n\n if (this._isMounted)\n this.setState({ icon: initialValue }, () => {\n if (this.props.setFocus) {\n this.setFocus();\n }\n });\n }\n\n public override render() {\n const { icon, icons, numColumns } = this.state;\n return (\n <div\n className={classnames(\"components-icon-editor\", this.props.className)}\n style={this.props.style}\n ref={this._divElement}\n >\n <IconPickerButton\n ref={(control) => {\n this._control = control;\n }}\n icon={icon}\n icons={icons}\n numColumns={numColumns}\n disabled={this.props.propertyRecord?.isDisabled}\n readonly={this.props.propertyRecord?.isReadonly}\n onIconChange={this._onIconChange}\n data-testid=\"components-icon-editor\"\n />\n </div>\n );\n }\n}\n\n/** Icon Property Editor registered for the \"text\" and \"string\" type names and the \"icon-picker\" editor name.\n * It uses the [[IconEditor]] React component.\n * @alpha\n */\nexport class IconPropertyEditor extends PropertyEditorBase {\n public get reactNode(): React.ReactNode {\n return <IconEditor />;\n }\n}\n"]}
|
|
@@ -16,31 +16,13 @@ import { ImageCheckBox } from "@itwin/core-react";
|
|
|
16
16
|
* @public
|
|
17
17
|
*/
|
|
18
18
|
export class ImageCheckBoxEditor extends React.PureComponent {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
checkboxValue: false,
|
|
27
|
-
};
|
|
28
|
-
this._handleClick = (checked) => {
|
|
29
|
-
this.setState({
|
|
30
|
-
checkboxValue: checked,
|
|
31
|
-
}, async () => {
|
|
32
|
-
if (this.props.propertyRecord && this.props.onCommit) {
|
|
33
|
-
const propertyValue = await this.getPropertyValue();
|
|
34
|
-
if (this._isMounted && propertyValue !== undefined) {
|
|
35
|
-
this.props.onCommit({
|
|
36
|
-
propertyRecord: this.props.propertyRecord,
|
|
37
|
-
newValue: propertyValue,
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
};
|
|
43
|
-
}
|
|
19
|
+
_isMounted = false;
|
|
20
|
+
_inputElement = React.createRef();
|
|
21
|
+
state = {
|
|
22
|
+
imageOff: "",
|
|
23
|
+
imageOn: "",
|
|
24
|
+
checkboxValue: false,
|
|
25
|
+
};
|
|
44
26
|
async getPropertyValue() {
|
|
45
27
|
const record = this.props.propertyRecord;
|
|
46
28
|
let propertyValue;
|
|
@@ -94,6 +76,21 @@ export class ImageCheckBoxEditor extends React.PureComponent {
|
|
|
94
76
|
}
|
|
95
77
|
this.setState({ imageOn, imageOff, checkboxValue });
|
|
96
78
|
}
|
|
79
|
+
_handleClick = (checked) => {
|
|
80
|
+
this.setState({
|
|
81
|
+
checkboxValue: checked,
|
|
82
|
+
}, async () => {
|
|
83
|
+
if (this.props.propertyRecord && this.props.onCommit) {
|
|
84
|
+
const propertyValue = await this.getPropertyValue();
|
|
85
|
+
if (this._isMounted && propertyValue !== undefined) {
|
|
86
|
+
this.props.onCommit({
|
|
87
|
+
propertyRecord: this.props.propertyRecord,
|
|
88
|
+
newValue: propertyValue,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
};
|
|
97
94
|
render() {
|
|
98
95
|
const className = classnames("components-cell-editor", "components-imagecheckbox-editor", this.props.className);
|
|
99
96
|
const checked = this.state.checkboxValue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ImageCheckBoxEditor.js","sourceRoot":"","sources":["../../../src/components-react/editors/ImageCheckBoxEditor.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,4BAA4B,CAAC;AACpC,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAM/B,OAAO,EACL,wBAAwB,EACxB,mBAAmB,GACpB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAUlD;;;GAGG;AACH,MAAM,OAAO,mBACX,SAAQ,KAAK,CAAC,aAA4D;
|
|
1
|
+
{"version":3,"file":"ImageCheckBoxEditor.js","sourceRoot":"","sources":["../../../src/components-react/editors/ImageCheckBoxEdit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iBACd,iCAAiC,GAC7C,CACH,CAAC;IACJ,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,2BAA4B,SAAQ,kBAAkB;IACjE,IAAW,SAAS;QAClB,OAAO,oBAAC,mBAAmB,OAAG,CAAC;IACjC,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module PropertyEditors\n */\n\nimport \"./ImageCheckBoxEditor.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport type {\n ImageCheckBoxParams,\n PropertyEditorParams,\n PropertyValue,\n} from \"@itwin/appui-abstract\";\nimport {\n PropertyEditorParamTypes,\n PropertyValueFormat,\n} from \"@itwin/appui-abstract\";\nimport type { PropertyEditorProps, TypeEditor } from \"./EditorContainer.js\";\nimport { PropertyEditorBase } from \"./PropertyEditorManager.js\";\nimport { ImageCheckBox } from \"@itwin/core-react\";\n\n/** @internal */\ninterface ImageCheckBoxEditorState {\n /** Image for the \"checked\" state */\n imageOn: string;\n /** Image for the \"unchecked\" (default) state */\n imageOff: string;\n checkboxValue: boolean;\n}\n/** [[ImageCheckBoxEditor]]\n * Boolean editor that renders with an image instead of checkbox\n * @public\n */\nexport class ImageCheckBoxEditor\n extends React.PureComponent<PropertyEditorProps, ImageCheckBoxEditorState>\n implements TypeEditor\n{\n private _isMounted = false;\n private _inputElement: React.RefObject<HTMLInputElement | null> =\n React.createRef();\n\n public override readonly state: Readonly<ImageCheckBoxEditorState> = {\n imageOff: \"\",\n imageOn: \"\",\n checkboxValue: false,\n };\n\n public async getPropertyValue(): Promise<PropertyValue | undefined> {\n const record = this.props.propertyRecord;\n let propertyValue: PropertyValue | undefined;\n\n if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {\n propertyValue = {\n valueFormat: PropertyValueFormat.Primitive,\n value: this.state.checkboxValue,\n displayValue: \"\",\n };\n }\n\n return propertyValue;\n }\n\n public get htmlElement(): HTMLElement | null {\n return this._inputElement.current;\n }\n\n public get hasFocus(): boolean {\n return document.activeElement === this._inputElement.current;\n }\n\n public override componentDidMount() {\n this._isMounted = true;\n this.setStateFromProps();\n }\n\n public override componentWillUnmount() {\n this._isMounted = false;\n }\n\n /** @internal */\n public override componentDidUpdate(prevProps: PropertyEditorProps) {\n if (this.props.propertyRecord !== prevProps.propertyRecord) {\n this.setStateFromProps();\n }\n }\n\n private setStateFromProps() {\n const { propertyRecord } = this.props;\n let checkboxValue = false;\n let imageOn = \"\";\n let imageOff = \"\";\n\n if (\n propertyRecord &&\n propertyRecord.value.valueFormat === PropertyValueFormat.Primitive\n ) {\n const primitiveValue = propertyRecord.value.value;\n checkboxValue = primitiveValue as boolean;\n }\n\n if (\n propertyRecord &&\n propertyRecord.property &&\n propertyRecord.property.editor &&\n propertyRecord.property.editor.params\n ) {\n const imageCheckBoxParams = propertyRecord.property.editor.params.find(\n (param: PropertyEditorParams) =>\n param.type === PropertyEditorParamTypes.CheckBoxImages.valueOf()\n ) as ImageCheckBoxParams;\n if (imageCheckBoxParams) {\n imageOn = imageCheckBoxParams.imageOn;\n imageOff = imageCheckBoxParams.imageOff;\n }\n }\n this.setState({ imageOn, imageOff, checkboxValue });\n }\n\n private _handleClick = (checked: boolean) => {\n this.setState(\n {\n checkboxValue: checked,\n },\n async () => {\n if (this.props.propertyRecord && this.props.onCommit) {\n const propertyValue = await this.getPropertyValue();\n if (this._isMounted && propertyValue !== undefined) {\n this.props.onCommit({\n propertyRecord: this.props.propertyRecord,\n newValue: propertyValue,\n });\n }\n }\n }\n );\n };\n\n public override render() {\n const className = classnames(\n \"components-cell-editor\",\n \"components-imagecheckbox-editor\",\n this.props.className\n );\n const checked = this.state.checkboxValue;\n const isDisabled =\n this.props.propertyRecord?.isDisabled ||\n this.props.propertyRecord?.isReadonly;\n\n return (\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n <ImageCheckBox\n inputRef={this._inputElement}\n imageOff={this.state.imageOff}\n imageOn={this.state.imageOn}\n className={className}\n border={true}\n style={this.props.style}\n checked={checked}\n disabled={isDisabled}\n onClick={this._handleClick}\n data-testid=\"components-imagecheckbox-editor\"\n />\n );\n }\n}\n\n/** ImageCheckBox Property Editor registered for the \"bool\" and \"boolean\" type names.\n * It uses the [[ImageCheckBoxEditor]] React component.\n * @public\n */\nexport class ImageCheckBoxPropertyEditor extends PropertyEditorBase {\n public get reactNode(): React.ReactNode {\n return <ImageCheckBoxEditor />;\n }\n}\n"]}
|
|
@@ -16,35 +16,12 @@ import { InputWithDecorations } from "@itwin/itwinui-react";
|
|
|
16
16
|
* @public
|
|
17
17
|
*/
|
|
18
18
|
export class NumericInputEditor extends React.PureComponent {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
value: 0,
|
|
26
|
-
};
|
|
27
|
-
this._handleCommit = async () => {
|
|
28
|
-
if (this.props.propertyRecord && this.props.onCommit) {
|
|
29
|
-
const propertyValue = await this.getPropertyValue();
|
|
30
|
-
if (propertyValue !== undefined) {
|
|
31
|
-
this.props.onCommit({
|
|
32
|
-
propertyRecord: this.props.propertyRecord,
|
|
33
|
-
newValue: propertyValue,
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
this._updateValue = (value, _stringValue) => {
|
|
39
|
-
const newValue = value !== undefined ? value : 0;
|
|
40
|
-
if (this._isMounted)
|
|
41
|
-
this.setState({
|
|
42
|
-
value: newValue,
|
|
43
|
-
}, async () => {
|
|
44
|
-
await this._handleCommit();
|
|
45
|
-
});
|
|
46
|
-
};
|
|
47
|
-
}
|
|
19
|
+
_isMounted = false;
|
|
20
|
+
_inputElement = React.createRef();
|
|
21
|
+
hasFocus = false; // hot used since containerHandlesEnter is false
|
|
22
|
+
state = {
|
|
23
|
+
value: 0,
|
|
24
|
+
};
|
|
48
25
|
async getPropertyValue() {
|
|
49
26
|
const record = this.props.propertyRecord;
|
|
50
27
|
let propertyValue;
|
|
@@ -60,6 +37,26 @@ export class NumericInputEditor extends React.PureComponent {
|
|
|
60
37
|
get htmlElement() {
|
|
61
38
|
return this._inputElement.current;
|
|
62
39
|
}
|
|
40
|
+
_handleCommit = async () => {
|
|
41
|
+
if (this.props.propertyRecord && this.props.onCommit) {
|
|
42
|
+
const propertyValue = await this.getPropertyValue();
|
|
43
|
+
if (propertyValue !== undefined) {
|
|
44
|
+
this.props.onCommit({
|
|
45
|
+
propertyRecord: this.props.propertyRecord,
|
|
46
|
+
newValue: propertyValue,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
_updateValue = (value, _stringValue) => {
|
|
52
|
+
const newValue = value !== undefined ? value : 0;
|
|
53
|
+
if (this._isMounted)
|
|
54
|
+
this.setState({
|
|
55
|
+
value: newValue,
|
|
56
|
+
}, async () => {
|
|
57
|
+
await this._handleCommit();
|
|
58
|
+
});
|
|
59
|
+
};
|
|
63
60
|
componentDidMount() {
|
|
64
61
|
this._isMounted = true;
|
|
65
62
|
void this.setStateFromProps();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NumericInputEditor.js","sourceRoot":"","sources":["../../../src/components-react/editors/NumericInputEditor.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,2BAA2B,CAAC;AACnC,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAO/B,OAAO,EACL,wBAAwB,EACxB,mBAAmB,GACpB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAMhD,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAc5D;;G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K,CAAC;IACf,CAAC;CACF;AAUD,MAAM,aAAa,GAAG,KAAK,CAAC,UAAU,CACpC,SAAS,aAAa,CAAC,KAAK,EAAE,YAAY;IACxC,MAAM,EAAE,UAAU,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC;IACtC,IAAI,UAAU,EAAE,CAAC;QACf,OAAO,CACL,oBAAC,iBAAiB,OACZ,IAAI,EACR,GAAG,EAAE,YAAY,EACjB,UAAU,EAAE,UAAU,GACtB,CACH,CAAC;IACJ,CAAC;IAED,OAAO;IACL,4DAA4D;IAC5D,oBAAC,WAAW,IAAC,GAAG,EAAE,YAAY,KAAM,IAAI,GAAI,CAC7C,CAAC;AACJ,CAAC,CACF,CAAC;AAMF,MAAM,iBAAiB,GAAG,KAAK,CAAC,UAAU,CAGxC,SAAS,iBAAiB,CAAC,KAAK,EAAE,YAAY;IAC9C,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,YAAY,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC;IAEzE,MAAM,YAAY,GAAG,CAAC,KAA0C,EAAE,EAAE;QAClE,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC;QACjC,QAAQ,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC;IACnC,CAAC,CAAC;IACF,OAAO,CACL,oBAAC,oBAAoB,IAAC,IAAI,EAAC,OAAO;QAChC,oBAAC,oBAAoB,CAAC,KAAK,OACrB,IAAI,EACR,GAAG,EAAE,YAAY,EACjB,IAAI,EAAC,QAAQ,EACb,QAAQ,EAAE,YAAY,EACtB,IAAI,EAAC,OAAO,GACZ;QACD,UAAU,CACU,CACxB,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module PropertyEditors\n */\n\nimport \"./NumericInputEditor.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport type {\n InputEditorSizeParams,\n PropertyEditorParams,\n PropertyValue,\n RangeEditorParams,\n} from \"@itwin/appui-abstract\";\nimport {\n PropertyEditorParamTypes,\n PropertyValueFormat,\n} from \"@itwin/appui-abstract\";\nimport { NumberInput } from \"@itwin/core-react\";\nimport type {\n InternalInputEditorProps,\n PropertyEditorProps,\n TypeEditor,\n} from \"./EditorContainer.js\";\nimport { PropertyEditorBase } from \"./PropertyEditorManager.js\";\nimport { InputWithDecorations } from \"@itwin/itwinui-react\";\n\n/** @internal */\ninterface NumericInputEditorState {\n value: number;\n size?: number;\n maxLength?: number;\n\n min?: number;\n max?: number;\n step?: number;\n precision?: number;\n}\n\n/** NumericInputEditor React component that is a property editor with numeric input & up/down buttons\n * @public\n */\nexport class NumericInputEditor\n extends React.PureComponent<PropertyEditorProps, NumericInputEditorState>\n implements TypeEditor\n{\n private _isMounted = false;\n private _inputElement: React.RefObject<HTMLInputElement | null> =\n React.createRef();\n public hasFocus = false; // hot used since containerHandlesEnter is false\n\n public override readonly state: Readonly<NumericInputEditorState> = {\n value: 0,\n };\n\n public async getPropertyValue(): Promise<PropertyValue | undefined> {\n const record = this.props.propertyRecord;\n let propertyValue: PropertyValue | undefined;\n\n if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {\n propertyValue = {\n valueFormat: PropertyValueFormat.Primitive,\n value: this.state.value,\n displayValue: \"\",\n };\n }\n\n return propertyValue;\n }\n\n public get htmlElement(): HTMLElement | null {\n return this._inputElement.current;\n }\n\n private _handleCommit = async (): Promise<void> => {\n if (this.props.propertyRecord && this.props.onCommit) {\n const propertyValue = await this.getPropertyValue();\n if (propertyValue !== undefined) {\n this.props.onCommit({\n propertyRecord: this.props.propertyRecord,\n newValue: propertyValue,\n });\n }\n }\n };\n\n private _updateValue = (\n value: number | undefined,\n _stringValue: string\n ): void => {\n const newValue = value !== undefined ? value : 0;\n\n if (this._isMounted)\n this.setState(\n {\n value: newValue,\n },\n async () => {\n await this._handleCommit();\n }\n );\n };\n\n public override componentDidMount() {\n this._isMounted = true;\n void this.setStateFromProps();\n }\n\n public override componentWillUnmount() {\n this._isMounted = false;\n }\n\n /** @internal */\n public override componentDidUpdate(prevProps: PropertyEditorProps) {\n if (this.props.propertyRecord !== prevProps.propertyRecord) {\n void this.setStateFromProps();\n }\n }\n\n private async setStateFromProps() {\n const record = this.props.propertyRecord;\n let initialValue = 0;\n\n if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {\n initialValue = record.value.value as number;\n }\n\n let size: number | undefined;\n let maxLength: number | undefined;\n let min: number | undefined;\n let max: number | undefined;\n let step: number | undefined;\n let precision: number | undefined;\n\n if (\n record &&\n record.property &&\n record.property.editor &&\n record.property.editor.params\n ) {\n const editorSizeParams = record.property.editor.params.find(\n (param: PropertyEditorParams) =>\n param.type === PropertyEditorParamTypes.InputEditorSize.valueOf()\n ) as InputEditorSizeParams;\n if (editorSizeParams) {\n if (editorSizeParams.size) size = editorSizeParams.size;\n if (editorSizeParams.maxLength) maxLength = editorSizeParams.maxLength;\n }\n\n const rangeParams = record.property.editor.params.find(\n (param: PropertyEditorParams) =>\n param.type === PropertyEditorParamTypes.Range.valueOf()\n ) as RangeEditorParams;\n if (rangeParams) {\n min = rangeParams.minimum;\n max = rangeParams.maximum;\n step = rangeParams.step;\n precision = rangeParams.precision;\n }\n }\n\n if (this._isMounted)\n this.setState({\n value: initialValue,\n size,\n maxLength,\n min,\n max,\n step,\n precision,\n });\n }\n\n public override render(): React.ReactNode {\n const { decoration } = this.props as InternalInputEditorProps;\n const className = classnames(\n \"components-cell-editor\",\n \"components-numeric-input-editor\",\n this.props.className\n );\n const minSize = this.state.size ? this.state.size : 8;\n const style: React.CSSProperties = {\n ...this.props.style,\n minWidth: `${minSize * 0.75}em`,\n };\n\n return (\n <NumericEditor\n ref={this._inputElement}\n className={className}\n style={style}\n value={this.state.value}\n min={this.state.min}\n max={this.state.max}\n step={this.state.step}\n precision={this.state.precision}\n readOnly={this.props.propertyRecord?.isReadonly}\n disabled={this.props.propertyRecord?.isDisabled}\n maxLength={this.state.maxLength}\n onBlur={this.props.onBlur}\n onChange={this._updateValue}\n // eslint-disable-next-line jsx-a11y/no-autofocus\n autoFocus={\n this.props.setFocus && !this.props.propertyRecord?.isDisabled\n }\n isControlled={this.props.shouldCommitOnChange}\n decoration={decoration}\n />\n );\n }\n}\n\n/** Numeric Input Property Editor registered for the \"number\" type name and \"numeric-input\" editor name.\n * It uses the [[NumericInputEditor]] React component.\n * @public\n */\nexport class NumericInputPropertyEditor extends PropertyEditorBase {\n public get reactNode(): React.ReactNode {\n return <NumericInputEditor />;\n }\n public override get containerHandlesEnter(): boolean {\n // let input editor process enter key\n return false;\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-deprecated\ntype NumberInputProps = React.ComponentProps<typeof NumberInput>;\n\ninterface NumericEditorProps extends Omit<NumberInputProps, \"step\"> {\n decoration?: React.ReactNode;\n step?: number;\n}\n\nconst NumericEditor = React.forwardRef<HTMLInputElement, NumericEditorProps>(\n function NumericEditor(props, forwardedRef) {\n const { decoration, ...rest } = props;\n if (decoration) {\n return (\n <LockNumericEditor\n {...rest}\n ref={forwardedRef}\n decoration={decoration}\n />\n );\n }\n\n return (\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n <NumberInput ref={forwardedRef} {...rest} />\n );\n }\n);\n\ninterface LockNumericEditorProps extends NumericEditorProps {\n decoration: React.ReactNode;\n}\n\nconst LockNumericEditor = React.forwardRef<\n HTMLInputElement,\n LockNumericEditorProps\n>(function LockNumericEditor(props, forwardedRef) {\n const { decoration, precision, onChange, isControlled, ...rest } = props;\n\n const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {\n const value = event.target.value;\n onChange?.(Number(value), value);\n };\n return (\n <InputWithDecorations size=\"small\">\n <InputWithDecorations.Input\n {...rest}\n ref={forwardedRef}\n type=\"number\"\n onChange={handleChange}\n size=\"small\"\n />\n {decoration}\n </InputWithDecorations>\n );\n});\n"]}
|
|
1
|
+
{"version":3,"file":"NumericInputEditor.js","sourceRoot":"","sources":["../../../src/components-react/editors/NumericInputEditor.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,2BAA2B,CAAC;AACnC,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAO/B,OAAO,EACL,wBAAwB,EACxB,mBAAmB,GACpB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAMhD,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAc5D;;GAEG;AACH,MAAM,OAAO,kBACX,SAAQ,KAAK,CAAC,aAA2D;IAGjE,UAAU,GAAG,KAAK,CAAC;IACnB,aAAa,GACnB,KAAK,CAAC,SAAS,EAAE,CAAC;IACb,QAAQ,GAAG,KAAK,CAAC,CAAC,gDAAgD;IAEhD,KAAK,GAAsC;QAClE,KAAK,EAAE,CAAC;KACT,CAAC;IAEK,KAAK,CAAC,gBAAgB;QAC3B,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC;QACzC,IAAI,aAAwC,CAAC;QAE7C,IAAI,MAAM,IAAI,MAAM,CAAC,KAAK,CAAC,WAAW,KAAK,mBAAmB,CAAC,SAAS,EAAE,CAAC;YACzE,aAAa,GAAG;gBACd,WAAW,EAAE,mBAAmB,CAAC,SAAS;gBAC1C,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK;gBACvB,YAAY,EAAE,EAAE;aACjB,CAAC;QACJ,CAAC;QAED,OAAO,aAAa,CAAC;IACvB,CAAC;IAED,IAAW,WAAW;QACpB,OAAO,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC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,CAAC,KAAK,CAAC;QACjC,QAAQ,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC;IACnC,CAAC,CAAC;IACF,OAAO,CACL,oBAAC,oBAAoB,IAAC,IAAI,EAAC,OAAO;QAChC,oBAAC,oBAAoB,CAAC,KAAK,OACrB,IAAI,EACR,GAAG,EAAE,YAAY,EACjB,IAAI,EAAC,QAAQ,EACb,QAAQ,EAAE,YAAY,EACtB,IAAI,EAAC,OAAO,GACZ;QACD,UAAU,CACU,CACxB,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module PropertyEditors\n */\n\nimport \"./NumericInputEditor.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport type {\n InputEditorSizeParams,\n PropertyEditorParams,\n PropertyValue,\n RangeEditorParams,\n} from \"@itwin/appui-abstract\";\nimport {\n PropertyEditorParamTypes,\n PropertyValueFormat,\n} from \"@itwin/appui-abstract\";\nimport { NumberInput } from \"@itwin/core-react\";\nimport type {\n InternalInputEditorProps,\n PropertyEditorProps,\n TypeEditor,\n} from \"./EditorContainer.js\";\nimport { PropertyEditorBase } from \"./PropertyEditorManager.js\";\nimport { InputWithDecorations } from \"@itwin/itwinui-react\";\n\n/** @internal */\ninterface NumericInputEditorState {\n value: number;\n size?: number;\n maxLength?: number;\n\n min?: number;\n max?: number;\n step?: number;\n precision?: number;\n}\n\n/** NumericInputEditor React component that is a property editor with numeric input & up/down buttons\n * @public\n */\nexport class NumericInputEditor\n extends React.PureComponent<PropertyEditorProps, NumericInputEditorState>\n implements TypeEditor\n{\n private _isMounted = false;\n private _inputElement: React.RefObject<HTMLInputElement | null> =\n React.createRef();\n public hasFocus = false; // hot used since containerHandlesEnter is false\n\n public override readonly state: Readonly<NumericInputEditorState> = {\n value: 0,\n };\n\n public async getPropertyValue(): Promise<PropertyValue | undefined> {\n const record = this.props.propertyRecord;\n let propertyValue: PropertyValue | undefined;\n\n if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {\n propertyValue = {\n valueFormat: PropertyValueFormat.Primitive,\n value: this.state.value,\n displayValue: \"\",\n };\n }\n\n return propertyValue;\n }\n\n public get htmlElement(): HTMLElement | null {\n return this._inputElement.current;\n }\n\n private _handleCommit = async (): Promise<void> => {\n if (this.props.propertyRecord && this.props.onCommit) {\n const propertyValue = await this.getPropertyValue();\n if (propertyValue !== undefined) {\n this.props.onCommit({\n propertyRecord: this.props.propertyRecord,\n newValue: propertyValue,\n });\n }\n }\n };\n\n private _updateValue = (\n value: number | undefined,\n _stringValue: string\n ): void => {\n const newValue = value !== undefined ? value : 0;\n\n if (this._isMounted)\n this.setState(\n {\n value: newValue,\n },\n async () => {\n await this._handleCommit();\n }\n );\n };\n\n public override componentDidMount() {\n this._isMounted = true;\n void this.setStateFromProps();\n }\n\n public override componentWillUnmount() {\n this._isMounted = false;\n }\n\n /** @internal */\n public override componentDidUpdate(prevProps: PropertyEditorProps) {\n if (this.props.propertyRecord !== prevProps.propertyRecord) {\n void this.setStateFromProps();\n }\n }\n\n private async setStateFromProps() {\n const record = this.props.propertyRecord;\n let initialValue = 0;\n\n if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {\n initialValue = record.value.value as number;\n }\n\n let size: number | undefined;\n let maxLength: number | undefined;\n let min: number | undefined;\n let max: number | undefined;\n let step: number | undefined;\n let precision: number | undefined;\n\n if (\n record &&\n record.property &&\n record.property.editor &&\n record.property.editor.params\n ) {\n const editorSizeParams = record.property.editor.params.find(\n (param: PropertyEditorParams) =>\n param.type === PropertyEditorParamTypes.InputEditorSize.valueOf()\n ) as InputEditorSizeParams;\n if (editorSizeParams) {\n if (editorSizeParams.size) size = editorSizeParams.size;\n if (editorSizeParams.maxLength) maxLength = editorSizeParams.maxLength;\n }\n\n const rangeParams = record.property.editor.params.find(\n (param: PropertyEditorParams) =>\n param.type === PropertyEditorParamTypes.Range.valueOf()\n ) as RangeEditorParams;\n if (rangeParams) {\n min = rangeParams.minimum;\n max = rangeParams.maximum;\n step = rangeParams.step;\n precision = rangeParams.precision;\n }\n }\n\n if (this._isMounted)\n this.setState({\n value: initialValue,\n size,\n maxLength,\n min,\n max,\n step,\n precision,\n });\n }\n\n public override render(): React.ReactNode {\n const { decoration } = this.props as InternalInputEditorProps;\n const className = classnames(\n \"components-cell-editor\",\n \"components-numeric-input-editor\",\n this.props.className\n );\n const minSize = this.state.size ? this.state.size : 8;\n const style: React.CSSProperties = {\n ...this.props.style,\n minWidth: `${minSize * 0.75}em`,\n };\n\n return (\n <NumericEditor\n ref={this._inputElement}\n className={className}\n style={style}\n value={this.state.value}\n min={this.state.min}\n max={this.state.max}\n step={this.state.step}\n precision={this.state.precision}\n readOnly={this.props.propertyRecord?.isReadonly}\n disabled={this.props.propertyRecord?.isDisabled}\n maxLength={this.state.maxLength}\n onBlur={this.props.onBlur}\n onChange={this._updateValue}\n // eslint-disable-next-line jsx-a11y/no-autofocus\n autoFocus={\n this.props.setFocus && !this.props.propertyRecord?.isDisabled\n }\n isControlled={this.props.shouldCommitOnChange}\n decoration={decoration}\n />\n );\n }\n}\n\n/** Numeric Input Property Editor registered for the \"number\" type name and \"numeric-input\" editor name.\n * It uses the [[NumericInputEditor]] React component.\n * @public\n */\nexport class NumericInputPropertyEditor extends PropertyEditorBase {\n public get reactNode(): React.ReactNode {\n return <NumericInputEditor />;\n }\n public override get containerHandlesEnter(): boolean {\n // let input editor process enter key\n return false;\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-deprecated\ntype NumberInputProps = React.ComponentProps<typeof NumberInput>;\n\ninterface NumericEditorProps extends Omit<NumberInputProps, \"step\"> {\n decoration?: React.ReactNode;\n step?: number;\n}\n\nconst NumericEditor = React.forwardRef<HTMLInputElement, NumericEditorProps>(\n function NumericEditor(props, forwardedRef) {\n const { decoration, ...rest } = props;\n if (decoration) {\n return (\n <LockNumericEditor\n {...rest}\n ref={forwardedRef}\n decoration={decoration}\n />\n );\n }\n\n return (\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n <NumberInput ref={forwardedRef} {...rest} />\n );\n }\n);\n\ninterface LockNumericEditorProps extends NumericEditorProps {\n decoration: React.ReactNode;\n}\n\nconst LockNumericEditor = React.forwardRef<\n HTMLInputElement,\n LockNumericEditorProps\n>(function LockNumericEditor(props, forwardedRef) {\n const { decoration, precision, onChange, isControlled, ...rest } = props;\n\n const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {\n const value = event.target.value;\n onChange?.(Number(value), value);\n };\n return (\n <InputWithDecorations size=\"small\">\n <InputWithDecorations.Input\n {...rest}\n ref={forwardedRef}\n type=\"number\"\n onChange={handleChange}\n size=\"small\"\n />\n {decoration}\n </InputWithDecorations>\n );\n});\n"]}
|