@itwin/components-react 4.6.3 → 4.7.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 +17 -1
- package/lib/cjs/components-react/UiComponents.d.ts.map +1 -1
- package/lib/cjs/components-react/UiComponents.js +3 -2
- package/lib/cjs/components-react/UiComponents.js.map +1 -1
- package/lib/cjs/components-react/common/ImageRenderer.d.ts.map +1 -1
- package/lib/cjs/components-react/common/ImageRenderer.js +2 -3
- package/lib/cjs/components-react/common/ImageRenderer.js.map +1 -1
- package/lib/cjs/components-react/common/UseAsyncValue.d.ts.map +1 -1
- package/lib/cjs/components-react/common/UseAsyncValue.js +7 -17
- package/lib/cjs/components-react/common/UseAsyncValue.js.map +1 -1
- package/lib/cjs/components-react/common/UseContextWithMandatoryProvider.d.ts.map +1 -1
- package/lib/cjs/components-react/common/UseContextWithMandatoryProvider.js +2 -1
- package/lib/cjs/components-react/common/UseContextWithMandatoryProvider.js.map +1 -1
- package/lib/cjs/components-react/common/UseDebouncedAsyncValue.d.ts.map +1 -1
- package/lib/cjs/components-react/common/UseDebouncedAsyncValue.js +22 -16
- package/lib/cjs/components-react/common/UseDebouncedAsyncValue.js.map +1 -1
- package/lib/cjs/components-react/datepicker/DatePicker.d.ts.map +1 -1
- package/lib/cjs/components-react/datepicker/DatePicker.js +6 -6
- package/lib/cjs/components-react/datepicker/DatePicker.js.map +1 -1
- package/lib/cjs/components-react/datepicker/DatePickerPopupButton.js +1 -1
- package/lib/cjs/components-react/datepicker/DatePickerPopupButton.js.map +1 -1
- package/lib/cjs/components-react/datepicker/TimeField.d.ts.map +1 -1
- package/lib/cjs/components-react/datepicker/TimeField.js +19 -22
- package/lib/cjs/components-react/datepicker/TimeField.js.map +1 -1
- package/lib/cjs/components-react/editors/CustomNumberEditor.d.ts.map +1 -1
- package/lib/cjs/components-react/editors/CustomNumberEditor.js +3 -2
- package/lib/cjs/components-react/editors/CustomNumberEditor.js.map +1 -1
- package/lib/cjs/components-react/editors/EditorContainer.d.ts.map +1 -1
- package/lib/cjs/components-react/editors/EditorContainer.js +4 -3
- package/lib/cjs/components-react/editors/EditorContainer.js.map +1 -1
- package/lib/cjs/components-react/editors/EnumButtonGroupEditor.d.ts +0 -1
- package/lib/cjs/components-react/editors/EnumButtonGroupEditor.d.ts.map +1 -1
- package/lib/cjs/components-react/editors/EnumButtonGroupEditor.js +1 -2
- package/lib/cjs/components-react/editors/EnumButtonGroupEditor.js.map +1 -1
- package/lib/cjs/components-react/editors/PopupButton.d.ts.map +1 -1
- package/lib/cjs/components-react/editors/PopupButton.js +4 -3
- package/lib/cjs/components-react/editors/PopupButton.js.map +1 -1
- package/lib/cjs/components-react/filtering/FilteringInput.d.ts.map +1 -1
- package/lib/cjs/components-react/filtering/FilteringInput.js +2 -2
- package/lib/cjs/components-react/filtering/FilteringInput.js.map +1 -1
- package/lib/cjs/components-react/filtering/ResultSelector.js +2 -2
- package/lib/cjs/components-react/filtering/ResultSelector.js.map +1 -1
- package/lib/cjs/components-react/inputs/ParsedInput.d.ts.map +1 -1
- package/lib/cjs/components-react/inputs/ParsedInput.js +3 -3
- package/lib/cjs/components-react/inputs/ParsedInput.js.map +1 -1
- package/lib/cjs/components-react/properties/renderers/value/Common.d.ts +4 -0
- package/lib/cjs/components-react/properties/renderers/value/Common.d.ts.map +1 -0
- package/lib/cjs/components-react/properties/renderers/value/Common.js +12 -0
- package/lib/cjs/components-react/properties/renderers/value/Common.js.map +1 -0
- package/lib/cjs/components-react/properties/renderers/value/DoublePropertyValueRenderer.d.ts.map +1 -1
- package/lib/cjs/components-react/properties/renderers/value/DoublePropertyValueRenderer.js +2 -8
- package/lib/cjs/components-react/properties/renderers/value/DoublePropertyValueRenderer.js.map +1 -1
- package/lib/cjs/components-react/properties/renderers/value/MultilineTextPropertyValueRenderer.d.ts.map +1 -1
- package/lib/cjs/components-react/properties/renderers/value/MultilineTextPropertyValueRenderer.js +2 -5
- package/lib/cjs/components-react/properties/renderers/value/MultilineTextPropertyValueRenderer.js.map +1 -1
- package/lib/cjs/components-react/properties/renderers/value/NavigationPropertyValueRenderer.d.ts.map +1 -1
- package/lib/cjs/components-react/properties/renderers/value/NavigationPropertyValueRenderer.js +2 -8
- package/lib/cjs/components-react/properties/renderers/value/NavigationPropertyValueRenderer.js.map +1 -1
- package/lib/cjs/components-react/tree/controlled/TreeEventDispatcher.d.ts.map +1 -1
- package/lib/cjs/components-react/tree/controlled/TreeEventDispatcher.js +10 -2
- package/lib/cjs/components-react/tree/controlled/TreeEventDispatcher.js.map +1 -1
- package/lib/cjs/components-react/tree/controlled/TreeEventHandler.d.ts +2 -0
- package/lib/cjs/components-react/tree/controlled/TreeEventHandler.d.ts.map +1 -1
- package/lib/cjs/components-react/tree/controlled/TreeEventHandler.js +2 -0
- package/lib/cjs/components-react/tree/controlled/TreeEventHandler.js.map +1 -1
- package/lib/cjs/components-react/tree/controlled/TreeEvents.d.ts +2 -0
- package/lib/cjs/components-react/tree/controlled/TreeEvents.d.ts.map +1 -1
- package/lib/cjs/components-react/tree/controlled/TreeEvents.js.map +1 -1
- package/lib/esm/components-react/UiComponents.d.ts.map +1 -1
- package/lib/esm/components-react/UiComponents.js +3 -2
- package/lib/esm/components-react/UiComponents.js.map +1 -1
- package/lib/esm/components-react/common/ImageRenderer.d.ts.map +1 -1
- package/lib/esm/components-react/common/ImageRenderer.js +2 -3
- package/lib/esm/components-react/common/ImageRenderer.js.map +1 -1
- package/lib/esm/components-react/common/UseAsyncValue.d.ts.map +1 -1
- package/lib/esm/components-react/common/UseAsyncValue.js +9 -19
- package/lib/esm/components-react/common/UseAsyncValue.js.map +1 -1
- package/lib/esm/components-react/common/UseContextWithMandatoryProvider.d.ts.map +1 -1
- package/lib/esm/components-react/common/UseContextWithMandatoryProvider.js +3 -2
- package/lib/esm/components-react/common/UseContextWithMandatoryProvider.js.map +1 -1
- package/lib/esm/components-react/common/UseDebouncedAsyncValue.d.ts.map +1 -1
- package/lib/esm/components-react/common/UseDebouncedAsyncValue.js +23 -17
- package/lib/esm/components-react/common/UseDebouncedAsyncValue.js.map +1 -1
- package/lib/esm/components-react/datepicker/DatePicker.d.ts.map +1 -1
- package/lib/esm/components-react/datepicker/DatePicker.js +6 -6
- package/lib/esm/components-react/datepicker/DatePicker.js.map +1 -1
- package/lib/esm/components-react/datepicker/DatePickerPopupButton.js +2 -2
- package/lib/esm/components-react/datepicker/DatePickerPopupButton.js.map +1 -1
- package/lib/esm/components-react/datepicker/TimeField.d.ts.map +1 -1
- package/lib/esm/components-react/datepicker/TimeField.js +19 -22
- package/lib/esm/components-react/datepicker/TimeField.js.map +1 -1
- package/lib/esm/components-react/editors/CustomNumberEditor.d.ts.map +1 -1
- package/lib/esm/components-react/editors/CustomNumberEditor.js +4 -3
- package/lib/esm/components-react/editors/CustomNumberEditor.js.map +1 -1
- package/lib/esm/components-react/editors/EditorContainer.d.ts.map +1 -1
- package/lib/esm/components-react/editors/EditorContainer.js +5 -4
- package/lib/esm/components-react/editors/EditorContainer.js.map +1 -1
- package/lib/esm/components-react/editors/EnumButtonGroupEditor.d.ts +0 -1
- package/lib/esm/components-react/editors/EnumButtonGroupEditor.d.ts.map +1 -1
- package/lib/esm/components-react/editors/EnumButtonGroupEditor.js +2 -3
- package/lib/esm/components-react/editors/EnumButtonGroupEditor.js.map +1 -1
- package/lib/esm/components-react/editors/PopupButton.d.ts.map +1 -1
- package/lib/esm/components-react/editors/PopupButton.js +5 -4
- package/lib/esm/components-react/editors/PopupButton.js.map +1 -1
- package/lib/esm/components-react/filtering/FilteringInput.d.ts.map +1 -1
- package/lib/esm/components-react/filtering/FilteringInput.js +2 -2
- package/lib/esm/components-react/filtering/FilteringInput.js.map +1 -1
- package/lib/esm/components-react/filtering/ResultSelector.js +2 -2
- package/lib/esm/components-react/filtering/ResultSelector.js.map +1 -1
- package/lib/esm/components-react/inputs/ParsedInput.d.ts.map +1 -1
- package/lib/esm/components-react/inputs/ParsedInput.js +3 -3
- package/lib/esm/components-react/inputs/ParsedInput.js.map +1 -1
- package/lib/esm/components-react/properties/renderers/value/Common.d.ts +4 -0
- package/lib/esm/components-react/properties/renderers/value/Common.d.ts.map +1 -0
- package/lib/esm/components-react/properties/renderers/value/Common.js +8 -0
- package/lib/esm/components-react/properties/renderers/value/Common.js.map +1 -0
- package/lib/esm/components-react/properties/renderers/value/DoublePropertyValueRenderer.d.ts.map +1 -1
- package/lib/esm/components-react/properties/renderers/value/DoublePropertyValueRenderer.js +1 -7
- package/lib/esm/components-react/properties/renderers/value/DoublePropertyValueRenderer.js.map +1 -1
- package/lib/esm/components-react/properties/renderers/value/MultilineTextPropertyValueRenderer.d.ts.map +1 -1
- package/lib/esm/components-react/properties/renderers/value/MultilineTextPropertyValueRenderer.js +2 -5
- package/lib/esm/components-react/properties/renderers/value/MultilineTextPropertyValueRenderer.js.map +1 -1
- package/lib/esm/components-react/properties/renderers/value/NavigationPropertyValueRenderer.d.ts.map +1 -1
- package/lib/esm/components-react/properties/renderers/value/NavigationPropertyValueRenderer.js +1 -7
- package/lib/esm/components-react/properties/renderers/value/NavigationPropertyValueRenderer.js.map +1 -1
- package/lib/esm/components-react/tree/controlled/TreeEventDispatcher.d.ts.map +1 -1
- package/lib/esm/components-react/tree/controlled/TreeEventDispatcher.js +10 -2
- package/lib/esm/components-react/tree/controlled/TreeEventDispatcher.js.map +1 -1
- package/lib/esm/components-react/tree/controlled/TreeEventHandler.d.ts +2 -0
- package/lib/esm/components-react/tree/controlled/TreeEventHandler.d.ts.map +1 -1
- package/lib/esm/components-react/tree/controlled/TreeEventHandler.js +2 -0
- package/lib/esm/components-react/tree/controlled/TreeEventHandler.js.map +1 -1
- package/lib/esm/components-react/tree/controlled/TreeEvents.d.ts +2 -0
- package/lib/esm/components-react/tree/controlled/TreeEvents.d.ts.map +1 -1
- package/lib/esm/components-react/tree/controlled/TreeEvents.js.map +1 -1
- package/package.json +7 -6
|
@@ -9,8 +9,9 @@
|
|
|
9
9
|
import "./CustomNumberEditor.scss";
|
|
10
10
|
import classnames from "classnames";
|
|
11
11
|
import * as React from "react";
|
|
12
|
+
import { Key } from "ts-key-enum";
|
|
12
13
|
import { Logger } from "@itwin/core-bentley";
|
|
13
|
-
import { MessageSeverity, PropertyEditorParamTypes, PropertyValueFormat,
|
|
14
|
+
import { MessageSeverity, PropertyEditorParamTypes, PropertyValueFormat, StandardEditorNames, StandardTypeNames, UiAdmin, } from "@itwin/appui-abstract";
|
|
14
15
|
import { Icon, IconInput } from "@itwin/core-react";
|
|
15
16
|
import { Input } from "@itwin/itwinui-react";
|
|
16
17
|
import { UiComponents } from "../UiComponents";
|
|
@@ -32,7 +33,7 @@ export class CustomNumberEditor extends React.PureComponent {
|
|
|
32
33
|
};
|
|
33
34
|
this._onKeyPress = (e) => {
|
|
34
35
|
// istanbul ignore else
|
|
35
|
-
if (e.key ===
|
|
36
|
+
if (e.key === Key.Escape) {
|
|
36
37
|
const initialDisplayValue = (this._lastValidValue &&
|
|
37
38
|
this._lastValidValue.displayValue) ??
|
|
38
39
|
/* istanbul ignore next */ this._getInitialDisplayValue();
|
|
@@ -48,7 +49,7 @@ export class CustomNumberEditor extends React.PureComponent {
|
|
|
48
49
|
}
|
|
49
50
|
}
|
|
50
51
|
// istanbul ignore else
|
|
51
|
-
if (e.key !==
|
|
52
|
+
if (e.key !== Key.Enter) {
|
|
52
53
|
UiAdmin.messagePresenter.closeInputFieldMessage();
|
|
53
54
|
}
|
|
54
55
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CustomNumberEditor.js","sourceRoot":"","sources":["../../../../src/components-react/editors/CustomNumberEditor.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,oCAAoC;AAEpC,OAAO,2BAA2B,CAAC;AACnC,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;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AM;YACL,uFAAuF;YACvF,SAAS,GAAG,CACV,oBAAC,KAAK,OACA,UAAU,EACd,GAAG,EAAE,IAAI,CAAC,aAAa,iBACX,gCAAgC,EAC5C,IAAI,EAAC,OAAO,GACZ,CACH,CAAC;SACH;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,0BAA2B,SAAQ,kBAAkB;IAChE,IAAW,SAAS;QAClB,OAAO,oBAAC,kBAAkB,OAAG,CAAC;IAChC,CAAC;IACD,IAAoB,sBAAsB;QACxC,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AACD,qBAAqB,CAAC,cAAc,CAClC,iBAAiB,CAAC,MAAM,EACxB,0BAA0B,EAC1B,mBAAmB,CAAC,YAAY,CACjC,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\n// cSpell:ignore customnumber testid\n\nimport \"./CustomNumberEditor.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport { Logger } from \"@itwin/core-bentley\";\nimport type {\n CustomFormattedNumberParams,\n IconEditorParams,\n InputEditorSizeParams,\n PrimitiveValue,\n PropertyEditorParams,\n PropertyRecord,\n PropertyValue,\n} from \"@itwin/appui-abstract\";\nimport {\n MessageSeverity,\n PropertyEditorParamTypes,\n PropertyValueFormat,\n SpecialKey,\n StandardEditorNames,\n StandardTypeNames,\n UiAdmin,\n} from \"@itwin/appui-abstract\";\nimport { Icon, IconInput } from \"@itwin/core-react\";\nimport type { InputProps } from \"@itwin/itwinui-react\";\nimport { Input } from \"@itwin/itwinui-react\";\n\nimport { UiComponents } from \"../UiComponents\";\nimport type { PropertyEditorProps, TypeEditor } from \"./EditorContainer\";\nimport {\n PropertyEditorBase,\n PropertyEditorManager,\n} from \"./PropertyEditorManager\";\n\n/** @internal */\ninterface CustomNumberEditorState {\n inputValue: string;\n size?: number;\n maxLength?: number;\n iconSpec?: string;\n}\n\n/** CustomNumberEditor is a React component that is a property editor for numbers that specify custom formatting and parsing functions.\n * @alpha\n */\nexport class CustomNumberEditor\n extends React.PureComponent<PropertyEditorProps, CustomNumberEditorState>\n implements TypeEditor\n{\n private _isMounted = false;\n private _formatParams: CustomFormattedNumberParams | undefined;\n private _inputElement = React.createRef<HTMLInputElement>();\n private _lastValidValue: PropertyValue | undefined;\n\n /** @internal */\n public override readonly state: Readonly<CustomNumberEditorState> = {\n inputValue: \"\",\n };\n\n public async getPropertyValue(): Promise<PropertyValue | undefined> {\n const record = this.props.propertyRecord as PropertyRecord;\n let propertyValue: PropertyValue | undefined;\n\n if (record.isReadonly) {\n return {\n valueFormat: PropertyValueFormat.Primitive,\n value: (record.value as PrimitiveValue).value,\n displayValue: (record.value as PrimitiveValue).displayValue,\n };\n }\n\n // istanbul ignore else\n if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {\n const parseResults = (\n this._formatParams as CustomFormattedNumberParams\n ).parseFunction(this.state.inputValue);\n if (!parseResults.parseError && undefined !== parseResults.value) {\n const newDisplayValue = (\n this._formatParams as CustomFormattedNumberParams\n ).formatFunction(parseResults.value as number);\n propertyValue = {\n valueFormat: PropertyValueFormat.Primitive,\n value: parseResults.value,\n displayValue: newDisplayValue,\n };\n this._lastValidValue = { ...propertyValue };\n // make sure the text in the input item matches the latest formatted text... this could get out if the input string say 1.5 === the display string of 1'-6\"\n // istanbul ignore else\n if (newDisplayValue !== this.state.inputValue) {\n this.setState({ inputValue: newDisplayValue });\n }\n } else {\n // istanbul ignore else\n if (this.htmlElement) {\n UiAdmin.messagePresenter.displayInputFieldMessage(\n this.htmlElement,\n MessageSeverity.Error,\n parseResults.parseError\n ? parseResults.parseError\n : /* istanbul ignore next */ UiComponents.translate(\n \"errors.unable-to-parse-quantity\"\n )\n );\n this.htmlElement.focus();\n } else {\n UiAdmin.messagePresenter.displayMessage(\n MessageSeverity.Error,\n parseResults.parseError\n ? parseResults.parseError\n : /* istanbul ignore next */ UiComponents.translate(\n \"errors.unable-to-parse-quantity\"\n )\n );\n }\n\n const displayValue =\n record.value.displayValue && record.value.displayValue.length > 0\n ? record.value.displayValue\n : /* istanbul ignore next */ (\n this._formatParams as CustomFormattedNumberParams\n ).formatFunction(record.value.value as number);\n propertyValue = this._lastValidValue\n ? { ...this._lastValidValue }\n : /* istanbul ignore next */ {\n valueFormat: PropertyValueFormat.Primitive,\n value: record.value.value,\n displayValue,\n };\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 private shouldSetFocus(): boolean {\n if (!this.props.setFocus) return false;\n\n const record = this.props.propertyRecord as PropertyRecord;\n const disabled = record && !record.isDisabled ? false : true;\n const readonly = record && !record.isReadonly ? false : true;\n\n return !disabled && !readonly;\n }\n\n private _applyUpdatedValue(userInput: string) {\n const record = this.props.propertyRecord as PropertyRecord;\n const readonly = record && !record.isReadonly ? false : true;\n const disabled = record && !record.isDisabled ? false : true;\n\n if (readonly || disabled) return;\n\n // istanbul ignore else\n if (this._isMounted)\n this.setState({\n inputValue: userInput,\n });\n }\n\n private _updateInputValue = (e: React.ChangeEvent<HTMLInputElement>) => {\n this._applyUpdatedValue(e.target.value);\n };\n\n /** @internal */\n public override componentDidMount() {\n this._isMounted = true;\n void this.setStateFromProps();\n }\n\n /** @internal */\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 _getInitialDisplayValue(): string {\n const record = this.props.propertyRecord;\n let initialDisplayValue = \"\";\n let numberValue = 0;\n // istanbul ignore else\n if (record) {\n // istanbul ignore else\n if (record.value.valueFormat === PropertyValueFormat.Primitive) {\n const primitiveValue = record.value;\n numberValue =\n undefined !== primitiveValue.value\n ? (primitiveValue.value as number)\n : /* istanbul ignore next */ 0;\n // istanbul ignore else\n if (primitiveValue.displayValue)\n initialDisplayValue = primitiveValue.displayValue;\n else\n initialDisplayValue = (\n this._formatParams as CustomFormattedNumberParams\n ).formatFunction(numberValue);\n }\n }\n\n return initialDisplayValue;\n }\n\n private async setStateFromProps() {\n const record = this.props.propertyRecord;\n // istanbul ignore next\n if (!record || !record.property) {\n Logger.logError(\n UiComponents.loggerCategory(this),\n \"PropertyRecord must be defined to use CustomNumberPropertyEditor\"\n );\n return;\n }\n // istanbul ignore else\n if (\n record.property &&\n record.property.editor &&\n record.property.editor.params\n ) {\n this._formatParams = record.property.editor.params.find(\n (param: PropertyEditorParams) =>\n param.type === PropertyEditorParamTypes.CustomFormattedNumber\n ) as CustomFormattedNumberParams;\n }\n\n if (!this._formatParams) {\n Logger.logError(\n UiComponents.loggerCategory(this),\n `CustomFormattedNumberParams must be defined for property ${record.property.name}`\n );\n return;\n }\n\n const initialDisplayValue = this._getInitialDisplayValue();\n this._lastValidValue = {\n valueFormat: PropertyValueFormat.Primitive,\n value: (record.value as PrimitiveValue).value,\n displayValue: initialDisplayValue,\n };\n let size: number | undefined;\n let maxLength: number | undefined;\n let iconSpec: string | undefined;\n\n // istanbul ignore else\n if (\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\n ) as InputEditorSizeParams;\n // istanbul ignore else\n if (editorSizeParams) {\n // istanbul ignore else\n if (editorSizeParams.size) size = editorSizeParams.size;\n // istanbul ignore else\n if (editorSizeParams.maxLength) maxLength = editorSizeParams.maxLength;\n }\n\n const iconParams = record.property.editor.params.find(\n (param: PropertyEditorParams) =>\n param.type === PropertyEditorParamTypes.Icon\n ) as IconEditorParams;\n if (iconParams) {\n iconSpec = iconParams.definition.iconSpec;\n }\n }\n\n // istanbul ignore else\n if (this._isMounted)\n this.setState({\n inputValue: initialDisplayValue,\n size,\n maxLength,\n iconSpec,\n });\n }\n\n private _resetToLastValidDisplayValue() {\n const initialDisplayValue =\n (this._lastValidValue &&\n (this._lastValidValue as PrimitiveValue).displayValue) ??\n /* istanbul ignore next */ this._getInitialDisplayValue();\n this.setState({ inputValue: initialDisplayValue });\n }\n\n private _onKeyPress = (e: React.KeyboardEvent<HTMLInputElement>) => {\n // istanbul ignore else\n if (e.key === SpecialKey.Escape) {\n const initialDisplayValue =\n (this._lastValidValue &&\n (this._lastValidValue as PrimitiveValue).displayValue) ??\n /* istanbul ignore next */ this._getInitialDisplayValue();\n if (initialDisplayValue !== this.state.inputValue) {\n e.preventDefault();\n e.stopPropagation();\n this._resetToLastValidDisplayValue();\n } else {\n // istanbul ignore else\n if (this.props.onCancel) this.props.onCancel();\n }\n }\n\n // istanbul ignore else\n if (e.key !== SpecialKey.Enter) {\n UiAdmin.messagePresenter.closeInputFieldMessage();\n }\n };\n\n // istanbul ignore next\n private _onFocus = (e: React.FocusEvent<HTMLInputElement>) => {\n e.target.select();\n };\n\n /** @internal */\n public override render(): React.ReactNode {\n const minSize = this.state.size ? this.state.size : 8;\n const minWidthStyle: React.CSSProperties = {\n minWidth: `${minSize * 0.75}em`,\n };\n const record = this.props.propertyRecord as PropertyRecord;\n if (!record || !this._formatParams) return null;\n\n const readOnly = !record.isReadonly ? false : true;\n const disabled = !record.isDisabled ? false : true;\n\n const className = classnames(\n \"components-cell-editor\",\n \"components-customnumber-editor\",\n this.props.className\n );\n\n const inputProps: Omit<InputProps, \"size\"> = {\n className,\n style: this.props.style ? this.props.style : minWidthStyle,\n readOnly,\n disabled,\n maxLength: this.state.maxLength,\n value: this.state.inputValue,\n onChange: this._updateInputValue,\n onBlur: this.props.onBlur,\n onFocus: this._onFocus,\n setFocus: this.shouldSetFocus(),\n onKeyDown: this._onKeyPress,\n };\n\n let reactNode: React.ReactNode;\n if (this.state.iconSpec) {\n const icon = <Icon iconSpec={this.state.iconSpec} />;\n reactNode = (\n <IconInput\n {...inputProps}\n ref={this._inputElement}\n icon={icon}\n data-testid=\"components-customnumber-editor\"\n />\n );\n } else {\n // NEEDSWORK: still using core-react Input component because of `nativeKeyHandler` prop\n reactNode = (\n <Input\n {...inputProps}\n ref={this._inputElement}\n data-testid=\"components-customnumber-editor\"\n size=\"small\"\n />\n );\n }\n\n return reactNode;\n }\n}\n\n/** Custom Property Editor registered for the \"number\" type name and the \"number-custom\" editor name.\n * It uses the [[CustomNumberEditor]] React component.\n * @alpha\n */\nexport class CustomNumberPropertyEditor extends PropertyEditorBase {\n public get reactNode(): React.ReactNode {\n return <CustomNumberEditor />;\n }\n public override get containerHandlesEscape(): boolean {\n return false;\n }\n}\nPropertyEditorManager.registerEditor(\n StandardTypeNames.Number,\n CustomNumberPropertyEditor,\n StandardEditorNames.NumberCustom\n);\n"]}
|
|
1
|
+
{"version":3,"file":"CustomNumberEditor.js","sourceRoot":"","sources":["../../../../src/components-react/editors/CustomNumberEditor.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,oCAAoC;AAEpC,OAAO,2BAA2B,CAAC;AACnC,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAU7C,OAAO,EACL,eAAe,EACf,wBAAwB,EACxB,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,EACjB,OAAO,GACR,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAE7C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EACL,kBAAkB,EA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,IAAoB,sBAAsB;QACxC,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AACD,qBAAqB,CAAC,cAAc,CAClC,iBAAiB,CAAC,MAAM,EACxB,0BAA0B,EAC1B,mBAAmB,CAAC,YAAY,CACjC,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\n// cSpell:ignore customnumber testid\n\nimport \"./CustomNumberEditor.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport { Key } from \"ts-key-enum\";\nimport { Logger } from \"@itwin/core-bentley\";\nimport type {\n CustomFormattedNumberParams,\n IconEditorParams,\n InputEditorSizeParams,\n PrimitiveValue,\n PropertyEditorParams,\n PropertyRecord,\n PropertyValue,\n} from \"@itwin/appui-abstract\";\nimport {\n MessageSeverity,\n PropertyEditorParamTypes,\n PropertyValueFormat,\n StandardEditorNames,\n StandardTypeNames,\n UiAdmin,\n} from \"@itwin/appui-abstract\";\nimport { Icon, IconInput } from \"@itwin/core-react\";\nimport type { InputProps } from \"@itwin/itwinui-react\";\nimport { Input } from \"@itwin/itwinui-react\";\n\nimport { UiComponents } from \"../UiComponents\";\nimport type { PropertyEditorProps, TypeEditor } from \"./EditorContainer\";\nimport {\n PropertyEditorBase,\n PropertyEditorManager,\n} from \"./PropertyEditorManager\";\n\n/** @internal */\ninterface CustomNumberEditorState {\n inputValue: string;\n size?: number;\n maxLength?: number;\n iconSpec?: string;\n}\n\n/** CustomNumberEditor is a React component that is a property editor for numbers that specify custom formatting and parsing functions.\n * @alpha\n */\nexport class CustomNumberEditor\n extends React.PureComponent<PropertyEditorProps, CustomNumberEditorState>\n implements TypeEditor\n{\n private _isMounted = false;\n private _formatParams: CustomFormattedNumberParams | undefined;\n private _inputElement = React.createRef<HTMLInputElement>();\n private _lastValidValue: PropertyValue | undefined;\n\n /** @internal */\n public override readonly state: Readonly<CustomNumberEditorState> = {\n inputValue: \"\",\n };\n\n public async getPropertyValue(): Promise<PropertyValue | undefined> {\n const record = this.props.propertyRecord as PropertyRecord;\n let propertyValue: PropertyValue | undefined;\n\n if (record.isReadonly) {\n return {\n valueFormat: PropertyValueFormat.Primitive,\n value: (record.value as PrimitiveValue).value,\n displayValue: (record.value as PrimitiveValue).displayValue,\n };\n }\n\n // istanbul ignore else\n if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {\n const parseResults = (\n this._formatParams as CustomFormattedNumberParams\n ).parseFunction(this.state.inputValue);\n if (!parseResults.parseError && undefined !== parseResults.value) {\n const newDisplayValue = (\n this._formatParams as CustomFormattedNumberParams\n ).formatFunction(parseResults.value as number);\n propertyValue = {\n valueFormat: PropertyValueFormat.Primitive,\n value: parseResults.value,\n displayValue: newDisplayValue,\n };\n this._lastValidValue = { ...propertyValue };\n // make sure the text in the input item matches the latest formatted text... this could get out if the input string say 1.5 === the display string of 1'-6\"\n // istanbul ignore else\n if (newDisplayValue !== this.state.inputValue) {\n this.setState({ inputValue: newDisplayValue });\n }\n } else {\n // istanbul ignore else\n if (this.htmlElement) {\n UiAdmin.messagePresenter.displayInputFieldMessage(\n this.htmlElement,\n MessageSeverity.Error,\n parseResults.parseError\n ? parseResults.parseError\n : /* istanbul ignore next */ UiComponents.translate(\n \"errors.unable-to-parse-quantity\"\n )\n );\n this.htmlElement.focus();\n } else {\n UiAdmin.messagePresenter.displayMessage(\n MessageSeverity.Error,\n parseResults.parseError\n ? parseResults.parseError\n : /* istanbul ignore next */ UiComponents.translate(\n \"errors.unable-to-parse-quantity\"\n )\n );\n }\n\n const displayValue =\n record.value.displayValue && record.value.displayValue.length > 0\n ? record.value.displayValue\n : /* istanbul ignore next */ (\n this._formatParams as CustomFormattedNumberParams\n ).formatFunction(record.value.value as number);\n propertyValue = this._lastValidValue\n ? { ...this._lastValidValue }\n : /* istanbul ignore next */ {\n valueFormat: PropertyValueFormat.Primitive,\n value: record.value.value,\n displayValue,\n };\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 private shouldSetFocus(): boolean {\n if (!this.props.setFocus) return false;\n\n const record = this.props.propertyRecord as PropertyRecord;\n const disabled = record && !record.isDisabled ? false : true;\n const readonly = record && !record.isReadonly ? false : true;\n\n return !disabled && !readonly;\n }\n\n private _applyUpdatedValue(userInput: string) {\n const record = this.props.propertyRecord as PropertyRecord;\n const readonly = record && !record.isReadonly ? false : true;\n const disabled = record && !record.isDisabled ? false : true;\n\n if (readonly || disabled) return;\n\n // istanbul ignore else\n if (this._isMounted)\n this.setState({\n inputValue: userInput,\n });\n }\n\n private _updateInputValue = (e: React.ChangeEvent<HTMLInputElement>) => {\n this._applyUpdatedValue(e.target.value);\n };\n\n /** @internal */\n public override componentDidMount() {\n this._isMounted = true;\n void this.setStateFromProps();\n }\n\n /** @internal */\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 _getInitialDisplayValue(): string {\n const record = this.props.propertyRecord;\n let initialDisplayValue = \"\";\n let numberValue = 0;\n // istanbul ignore else\n if (record) {\n // istanbul ignore else\n if (record.value.valueFormat === PropertyValueFormat.Primitive) {\n const primitiveValue = record.value;\n numberValue =\n undefined !== primitiveValue.value\n ? (primitiveValue.value as number)\n : /* istanbul ignore next */ 0;\n // istanbul ignore else\n if (primitiveValue.displayValue)\n initialDisplayValue = primitiveValue.displayValue;\n else\n initialDisplayValue = (\n this._formatParams as CustomFormattedNumberParams\n ).formatFunction(numberValue);\n }\n }\n\n return initialDisplayValue;\n }\n\n private async setStateFromProps() {\n const record = this.props.propertyRecord;\n // istanbul ignore next\n if (!record || !record.property) {\n Logger.logError(\n UiComponents.loggerCategory(this),\n \"PropertyRecord must be defined to use CustomNumberPropertyEditor\"\n );\n return;\n }\n // istanbul ignore else\n if (\n record.property &&\n record.property.editor &&\n record.property.editor.params\n ) {\n this._formatParams = record.property.editor.params.find(\n (param: PropertyEditorParams) =>\n param.type === PropertyEditorParamTypes.CustomFormattedNumber\n ) as CustomFormattedNumberParams;\n }\n\n if (!this._formatParams) {\n Logger.logError(\n UiComponents.loggerCategory(this),\n `CustomFormattedNumberParams must be defined for property ${record.property.name}`\n );\n return;\n }\n\n const initialDisplayValue = this._getInitialDisplayValue();\n this._lastValidValue = {\n valueFormat: PropertyValueFormat.Primitive,\n value: (record.value as PrimitiveValue).value,\n displayValue: initialDisplayValue,\n };\n let size: number | undefined;\n let maxLength: number | undefined;\n let iconSpec: string | undefined;\n\n // istanbul ignore else\n if (\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\n ) as InputEditorSizeParams;\n // istanbul ignore else\n if (editorSizeParams) {\n // istanbul ignore else\n if (editorSizeParams.size) size = editorSizeParams.size;\n // istanbul ignore else\n if (editorSizeParams.maxLength) maxLength = editorSizeParams.maxLength;\n }\n\n const iconParams = record.property.editor.params.find(\n (param: PropertyEditorParams) =>\n param.type === PropertyEditorParamTypes.Icon\n ) as IconEditorParams;\n if (iconParams) {\n iconSpec = iconParams.definition.iconSpec;\n }\n }\n\n // istanbul ignore else\n if (this._isMounted)\n this.setState({\n inputValue: initialDisplayValue,\n size,\n maxLength,\n iconSpec,\n });\n }\n\n private _resetToLastValidDisplayValue() {\n const initialDisplayValue =\n (this._lastValidValue &&\n (this._lastValidValue as PrimitiveValue).displayValue) ??\n /* istanbul ignore next */ this._getInitialDisplayValue();\n this.setState({ inputValue: initialDisplayValue });\n }\n\n private _onKeyPress = (e: React.KeyboardEvent<HTMLInputElement>) => {\n // istanbul ignore else\n if (e.key === Key.Escape) {\n const initialDisplayValue =\n (this._lastValidValue &&\n (this._lastValidValue as PrimitiveValue).displayValue) ??\n /* istanbul ignore next */ this._getInitialDisplayValue();\n if (initialDisplayValue !== this.state.inputValue) {\n e.preventDefault();\n e.stopPropagation();\n this._resetToLastValidDisplayValue();\n } else {\n // istanbul ignore else\n if (this.props.onCancel) this.props.onCancel();\n }\n }\n\n // istanbul ignore else\n if (e.key !== Key.Enter) {\n UiAdmin.messagePresenter.closeInputFieldMessage();\n }\n };\n\n // istanbul ignore next\n private _onFocus = (e: React.FocusEvent<HTMLInputElement>) => {\n e.target.select();\n };\n\n /** @internal */\n public override render(): React.ReactNode {\n const minSize = this.state.size ? this.state.size : 8;\n const minWidthStyle: React.CSSProperties = {\n minWidth: `${minSize * 0.75}em`,\n };\n const record = this.props.propertyRecord as PropertyRecord;\n if (!record || !this._formatParams) return null;\n\n const readOnly = !record.isReadonly ? false : true;\n const disabled = !record.isDisabled ? false : true;\n\n const className = classnames(\n \"components-cell-editor\",\n \"components-customnumber-editor\",\n this.props.className\n );\n\n const inputProps: Omit<InputProps, \"size\"> = {\n className,\n style: this.props.style ? this.props.style : minWidthStyle,\n readOnly,\n disabled,\n maxLength: this.state.maxLength,\n value: this.state.inputValue,\n onChange: this._updateInputValue,\n onBlur: this.props.onBlur,\n onFocus: this._onFocus,\n setFocus: this.shouldSetFocus(),\n onKeyDown: this._onKeyPress,\n };\n\n let reactNode: React.ReactNode;\n if (this.state.iconSpec) {\n const icon = <Icon iconSpec={this.state.iconSpec} />;\n reactNode = (\n <IconInput\n {...inputProps}\n ref={this._inputElement}\n icon={icon}\n data-testid=\"components-customnumber-editor\"\n />\n );\n } else {\n // NEEDSWORK: still using core-react Input component because of `nativeKeyHandler` prop\n reactNode = (\n <Input\n {...inputProps}\n ref={this._inputElement}\n data-testid=\"components-customnumber-editor\"\n size=\"small\"\n />\n );\n }\n\n return reactNode;\n }\n}\n\n/** Custom Property Editor registered for the \"number\" type name and the \"number-custom\" editor name.\n * It uses the [[CustomNumberEditor]] React component.\n * @alpha\n */\nexport class CustomNumberPropertyEditor extends PropertyEditorBase {\n public get reactNode(): React.ReactNode {\n return <CustomNumberEditor />;\n }\n public override get containerHandlesEscape(): boolean {\n return false;\n }\n}\nPropertyEditorManager.registerEditor(\n StandardTypeNames.Number,\n CustomNumberPropertyEditor,\n StandardEditorNames.NumberCustom\n);\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditorContainer.d.ts","sourceRoot":"","sources":["../../../../src/components-react/editors/EditorContainer.tsx"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,wBAAwB,CAAC;AAChC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"EditorContainer.d.ts","sourceRoot":"","sources":["../../../../src/components-react/editors/EditorContainer.tsx"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,wBAAwB,CAAC;AAChC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAE3E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAOrD;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,kCAAkC;IAClC,cAAc,EAAE,cAAc,CAAC;IAC/B,sCAAsC;IACtC,QAAQ,EAAE,aAAa,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAoB,SAAQ,WAAW;IACtD,kCAAkC;IAClC,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,yBAAyB;IACzB,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,mBAAmB,KAAK,IAAI,CAAC;IAC/C,yBAAyB;IACzB,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IACtB,uBAAuB;IACvB,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,UAAU,KAAK,IAAI,CAAC;IAC3C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AC,sBAAsB,CAU5B;IAEF,OAAO,CAAC,OAAO,CAqBb;IAEF,OAAO,CAAC,mBAAmB,CAEzB;IAEF,OAAO,CAAC,aAAa,CAEnB;IAEF,gBAAgB;IACA,MAAM;CAgBvB"}
|
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import "./EditorContainer.scss";
|
|
9
9
|
import * as React from "react";
|
|
10
|
-
import {
|
|
10
|
+
import { Key } from "ts-key-enum";
|
|
11
|
+
import { UiAdmin } from "@itwin/appui-abstract";
|
|
11
12
|
import { PropertyEditorManager } from "./PropertyEditorManager";
|
|
12
13
|
/**
|
|
13
14
|
* EditorContainer React component used by the Tree and PropertyGrid for cell editing.
|
|
@@ -31,13 +32,13 @@ export class EditorContainer extends React.PureComponent {
|
|
|
31
32
|
};
|
|
32
33
|
this._handleKeyDown = (e) => {
|
|
33
34
|
switch (e.key) {
|
|
34
|
-
case
|
|
35
|
+
case Key.Escape:
|
|
35
36
|
this.onPressEscape(e);
|
|
36
37
|
break;
|
|
37
|
-
case
|
|
38
|
+
case Key.Enter:
|
|
38
39
|
this.onPressEnter(e);
|
|
39
40
|
break;
|
|
40
|
-
case
|
|
41
|
+
case Key.Tab:
|
|
41
42
|
this.onPressTab(e);
|
|
42
43
|
break;
|
|
43
44
|
default:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditorContainer.js","sourceRoot":"","sources":["../../../../src/components-react/editors/EditorContainer.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,wBAAwB,CAAC;AAChC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAM5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAuEhE;;;GAGG;AACH,MAAM,OAAO,eAAgB,SAAQ,KAAK,CAAC,aAAmC;IAA9E;;QAyCU,sBAAi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eAAe,IAAI,IAAI,CAAC,KAAK,CAAC,cAAc,EAAE;YACrD,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,aAAa,CAC7D,KAAK,EACL,IAAI,CAAC,KAAK,CAAC,cAAc,CAC1B,CAAC;YAEF,IAAI,cAAc,CAAC,gBAAgB,EAAE;gBACnC,IAAI,CAAC,oBAAoB,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC;gBACvD,OAAO,GAAG,KAAK,CAAC;aACjB;SACF;aAAM;YACL,OAAO,GAAG,KAAK,CAAC;SACjB;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;IAiDD,gBAAgB;IACA,MAAM;QACpB,OAAO,CACL,8BACE,SAAS,EAAC,6BAA6B,EACvC,MAAM,EAAE,IAAI,CAAC,oBAAoB,EACjC,SAAS,EAAE,IAAI,CAAC,cAAc,EAC9B,OAAO,EAAE,IAAI,CAAC,YAAY,EAC1B,aAAa,EAAE,IAAI,CAAC,iBAAiB,EACrC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,iBACX,kBAAkB,EAC9B,IAAI,EAAC,cAAc,IAElB,IAAI,CAAC,YAAY,EAAE,CACf,CACR,CAAC;IACJ,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 \"./EditorContainer.scss\";\nimport * as React from \"react\";\nimport type { PropertyRecord, PropertyValue } from \"@itwin/appui-abstract\";\nimport { SpecialKey, UiAdmin } from \"@itwin/appui-abstract\";\nimport type { CommonProps } from \"@itwin/core-react\";\nimport type {\n AsyncErrorMessage,\n PropertyEditorBase,\n} from \"./PropertyEditorManager\";\nimport { PropertyEditorManager } from \"./PropertyEditorManager\";\n\n/** Arguments for the Property Updated event callback\n * @public\n */\nexport interface PropertyUpdatedArgs {\n /** The property being updated. */\n propertyRecord: PropertyRecord;\n /** The new value for the property. */\n newValue: PropertyValue;\n}\n\n/** Properties for a property editor component\n * @public\n */\nexport interface PropertyEditorProps extends CommonProps {\n /** The property being updated. */\n propertyRecord?: PropertyRecord;\n /** Handler for commit */\n onCommit?: (args: PropertyUpdatedArgs) => void;\n /** Handler for cancel */\n onCancel?: () => void;\n /** Handler for blur */\n onBlur?: (event: React.FocusEvent) => void;\n /** Indicates whether the Property Editor should set focus */\n setFocus?: boolean;\n /**\n * Indicates whether value change should call onCommit().\n * @internal\n */\n shouldCommitOnChange?: boolean;\n}\n\n/** [[EditorContainer]] React component properties\n * @public\n */\nexport interface EditorContainerProps extends CommonProps {\n /** The property being updated. */\n propertyRecord: PropertyRecord;\n /** Tooltip text */\n title?: string;\n /** Handler for commit */\n onCommit: (args: PropertyUpdatedArgs) => void;\n /** Handler for cancel */\n onCancel: () => void;\n /** Indicates whether the Property Editor should set focus */\n setFocus?: boolean;\n\n /** @internal */\n ignoreEditorBlur?: boolean;\n /**\n * Indicates whether value change should call onCommit().\n * @internal\n */\n shouldCommitOnChange?: boolean;\n}\n\n/** @internal */\ninterface CloneProps extends PropertyEditorProps {\n ref: (ref: any) => void;\n}\n\n/** Interface implemented by React based type editors\n * @public\n */\nexport interface TypeEditor {\n getPropertyValue: () => Promise<PropertyValue | undefined>;\n htmlElement: HTMLElement | null;\n hasFocus: boolean;\n}\n\n/**\n * EditorContainer React component used by the Tree and PropertyGrid for cell editing.\n * @public\n */\nexport class EditorContainer extends React.PureComponent<EditorContainerProps> {\n private _editorRef: TypeEditor | undefined;\n private _propertyEditor: PropertyEditorBase | undefined;\n\n private createEditor(): React.ReactNode {\n const editorRef = (ref: TypeEditor | undefined) => (this._editorRef = ref);\n\n const editorProps: CloneProps = {\n ref: editorRef,\n onCommit: this._handleEditorCommit,\n onCancel: this._handleEditorCancel,\n onBlur: this._handleEditorBlur,\n propertyRecord: this.props.propertyRecord,\n setFocus: this.props.setFocus !== undefined ? this.props.setFocus : true,\n className: this.props.className,\n style: this.props.style,\n shouldCommitOnChange: this.props.shouldCommitOnChange,\n };\n\n const propDescription = this.props.propertyRecord.property;\n\n const editorName =\n propDescription.editor !== undefined\n ? propDescription.editor.name\n : undefined;\n this._propertyEditor = PropertyEditorManager.createEditor(\n propDescription.typename,\n editorName,\n propDescription.dataController\n );\n const editorNode: React.ReactNode = this._propertyEditor.reactNode;\n\n let clonedNode: React.ReactNode = null;\n // istanbul ignore else\n if (React.isValidElement(editorNode)) {\n clonedNode = React.cloneElement(editorNode, editorProps);\n }\n\n return clonedNode;\n }\n\n private _handleEditorBlur = (_e: React.FocusEvent) => {\n // istanbul ignore else\n if (\n !this.props.ignoreEditorBlur &&\n this._propertyEditor &&\n this._propertyEditor.containerHandlesBlur\n )\n void this._handleContainerCommit();\n };\n\n private _handleContainerBlur = (e: React.FocusEvent) => {\n e.stopPropagation();\n };\n\n private _handleClick = (e: React.MouseEvent) => {\n e.stopPropagation();\n };\n\n private _handleKeyDown = (e: React.KeyboardEvent) => {\n switch (e.key) {\n case SpecialKey.Escape:\n this.onPressEscape(e);\n break;\n case SpecialKey.Enter:\n this.onPressEnter(e);\n break;\n case SpecialKey.Tab:\n this.onPressTab(e);\n break;\n default:\n if (\n this._propertyEditor &&\n this._propertyEditor.containerStopsKeydownPropagation\n )\n e.stopPropagation();\n }\n };\n\n private _handleRightClick = (e: React.MouseEvent) => {\n e.stopPropagation();\n };\n\n private onPressEscape(_e: React.KeyboardEvent): void {\n // istanbul ignore else\n if (this._propertyEditor && this._propertyEditor.containerHandlesEscape) {\n this._commitCancel();\n }\n }\n\n private onPressEnter(e: React.KeyboardEvent): void {\n // istanbul ignore else\n if (this._propertyEditor && this._propertyEditor.containerHandlesEnter) {\n // istanbul ignore else\n if (this._editorRef && this._editorRef.hasFocus) e.stopPropagation();\n void this._handleContainerCommit();\n }\n }\n\n private onPressTab(e: React.KeyboardEvent): void {\n // istanbul ignore else\n if (this._propertyEditor && this._propertyEditor.containerHandlesTab) {\n e.stopPropagation();\n void this._handleContainerCommit();\n }\n }\n\n private displayOutputMessage(errorMessage: AsyncErrorMessage | undefined) {\n // istanbul ignore else\n if (errorMessage && this._editorRef) {\n const htmlElement = this._editorRef && this._editorRef.htmlElement;\n // istanbul ignore else\n if (htmlElement)\n UiAdmin.messagePresenter.displayInputFieldMessage(\n htmlElement,\n errorMessage.severity,\n errorMessage.briefMessage,\n errorMessage.detailedMessage\n );\n else\n UiAdmin.messagePresenter.displayMessage(\n errorMessage.severity,\n errorMessage.briefMessage,\n errorMessage.detailedMessage,\n errorMessage.messageType\n );\n }\n }\n\n private async isNewValueValid(value: PropertyValue): Promise<boolean> {\n let isValid = true;\n\n // istanbul ignore else\n if (this._propertyEditor && this.props.propertyRecord) {\n const validateResult = await this._propertyEditor.validateValue(\n value,\n this.props.propertyRecord\n );\n\n if (validateResult.encounteredError) {\n this.displayOutputMessage(validateResult.errorMessage);\n isValid = false;\n }\n } else {\n isValid = false;\n }\n\n return isValid;\n }\n\n private _handleEditorCommit = (args: PropertyUpdatedArgs): void => {\n void this._commit(args);\n };\n\n private _handleContainerCommit = async (): Promise<void> => {\n const newValue =\n this._editorRef && (await this._editorRef.getPropertyValue());\n // istanbul ignore else\n if (newValue !== undefined) {\n void this._commit({\n propertyRecord: this.props.propertyRecord,\n newValue,\n });\n }\n };\n\n private _commit = async (args: PropertyUpdatedArgs) => {\n const newValue = args.newValue;\n const isValid = await this.isNewValueValid(newValue);\n if (isValid) {\n let doCommit = true;\n // istanbul ignore else\n if (this._propertyEditor && args.propertyRecord) {\n const commitResult = await this._propertyEditor.commitValue(\n newValue,\n args.propertyRecord\n );\n if (commitResult.encounteredError) {\n this.displayOutputMessage(commitResult.errorMessage);\n doCommit = false;\n }\n }\n\n if (doCommit) {\n this.props.onCommit(args);\n }\n }\n };\n\n private _handleEditorCancel = () => {\n this._commitCancel();\n };\n\n private _commitCancel = () => {\n this.props.onCancel();\n };\n\n /** @internal */\n public override render() {\n return (\n <span\n className=\"components-editor-container\"\n onBlur={this._handleContainerBlur}\n onKeyDown={this._handleKeyDown}\n onClick={this._handleClick}\n onContextMenu={this._handleRightClick}\n title={this.props.title}\n data-testid=\"editor-container\"\n role=\"presentation\"\n >\n {this.createEditor()}\n </span>\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"EditorContainer.js","sourceRoot":"","sources":["../../../../src/components-react/editors/EditorContainer.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,wBAAwB,CAAC;AAChC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAElC,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAMhD,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAuEhE;;;GAGG;AACH,MAAM,OAAO,eAAgB,SAAQ,KAAK,CAAC,aAAmC;IAA9E;;QAyCU,sBAAiB,GAAG,CAAC,EAAoB,EAAE,EAAE;YACnD,uBAAuB;YACvB,IACE,CAAC,IAAI,CAAC,KAAK,CAAC,gBAAgB;gBAC5B,IAAI,CAAC,eAAe;gBACpB,IAAI,CAAC,eAAe,CAAC,oBAAoB;gBAEzC,KAAK,IAAI,CAAC,sBAAsB,EAAE,CAAC;QACvC,CAAC,CAAC;QAEM,yBAAoB,GAAG,CAAC,CAAmB,EAAE,EAAE;YACrD,CAAC,CAAC,eAAe,EAAE,CAAC;QACtB,CAAC,CAAC;QAEM,iBAAY,GAAG,CAAC,CAAmB,EAAE,EAAE;YAC7C,CAAC,CAAC,eAAe,EAAE,CAAC;QACtB,CAAC,CAAC;QAEM,mBAAc,GAAG,CAAC,CAAsB,EAAE,EAAE;YAClD,QAAQ,CAAC,CAAC,GAAG,EAAE;gBACb,KAAK,GAAG,CAAC,MAAM;oBACb,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;oBACtB,MAAM;gBACR,KAA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rC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,iBACX,kBAAkB,EAC9B,IAAI,EAAC,cAAc,IAElB,IAAI,CAAC,YAAY,EAAE,CACf,CACR,CAAC;IACJ,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 \"./EditorContainer.scss\";\nimport * as React from \"react\";\nimport { Key } from \"ts-key-enum\";\nimport type { PropertyRecord, PropertyValue } from \"@itwin/appui-abstract\";\nimport { UiAdmin } from \"@itwin/appui-abstract\";\nimport type { CommonProps } from \"@itwin/core-react\";\nimport type {\n AsyncErrorMessage,\n PropertyEditorBase,\n} from \"./PropertyEditorManager\";\nimport { PropertyEditorManager } from \"./PropertyEditorManager\";\n\n/** Arguments for the Property Updated event callback\n * @public\n */\nexport interface PropertyUpdatedArgs {\n /** The property being updated. */\n propertyRecord: PropertyRecord;\n /** The new value for the property. */\n newValue: PropertyValue;\n}\n\n/** Properties for a property editor component\n * @public\n */\nexport interface PropertyEditorProps extends CommonProps {\n /** The property being updated. */\n propertyRecord?: PropertyRecord;\n /** Handler for commit */\n onCommit?: (args: PropertyUpdatedArgs) => void;\n /** Handler for cancel */\n onCancel?: () => void;\n /** Handler for blur */\n onBlur?: (event: React.FocusEvent) => void;\n /** Indicates whether the Property Editor should set focus */\n setFocus?: boolean;\n /**\n * Indicates whether value change should call onCommit().\n * @internal\n */\n shouldCommitOnChange?: boolean;\n}\n\n/** [[EditorContainer]] React component properties\n * @public\n */\nexport interface EditorContainerProps extends CommonProps {\n /** The property being updated. */\n propertyRecord: PropertyRecord;\n /** Tooltip text */\n title?: string;\n /** Handler for commit */\n onCommit: (args: PropertyUpdatedArgs) => void;\n /** Handler for cancel */\n onCancel: () => void;\n /** Indicates whether the Property Editor should set focus */\n setFocus?: boolean;\n\n /** @internal */\n ignoreEditorBlur?: boolean;\n /**\n * Indicates whether value change should call onCommit().\n * @internal\n */\n shouldCommitOnChange?: boolean;\n}\n\n/** @internal */\ninterface CloneProps extends PropertyEditorProps {\n ref: (ref: any) => void;\n}\n\n/** Interface implemented by React based type editors\n * @public\n */\nexport interface TypeEditor {\n getPropertyValue: () => Promise<PropertyValue | undefined>;\n htmlElement: HTMLElement | null;\n hasFocus: boolean;\n}\n\n/**\n * EditorContainer React component used by the Tree and PropertyGrid for cell editing.\n * @public\n */\nexport class EditorContainer extends React.PureComponent<EditorContainerProps> {\n private _editorRef: TypeEditor | undefined;\n private _propertyEditor: PropertyEditorBase | undefined;\n\n private createEditor(): React.ReactNode {\n const editorRef = (ref: TypeEditor | undefined) => (this._editorRef = ref);\n\n const editorProps: CloneProps = {\n ref: editorRef,\n onCommit: this._handleEditorCommit,\n onCancel: this._handleEditorCancel,\n onBlur: this._handleEditorBlur,\n propertyRecord: this.props.propertyRecord,\n setFocus: this.props.setFocus !== undefined ? this.props.setFocus : true,\n className: this.props.className,\n style: this.props.style,\n shouldCommitOnChange: this.props.shouldCommitOnChange,\n };\n\n const propDescription = this.props.propertyRecord.property;\n\n const editorName =\n propDescription.editor !== undefined\n ? propDescription.editor.name\n : undefined;\n this._propertyEditor = PropertyEditorManager.createEditor(\n propDescription.typename,\n editorName,\n propDescription.dataController\n );\n const editorNode: React.ReactNode = this._propertyEditor.reactNode;\n\n let clonedNode: React.ReactNode = null;\n // istanbul ignore else\n if (React.isValidElement(editorNode)) {\n clonedNode = React.cloneElement(editorNode, editorProps);\n }\n\n return clonedNode;\n }\n\n private _handleEditorBlur = (_e: React.FocusEvent) => {\n // istanbul ignore else\n if (\n !this.props.ignoreEditorBlur &&\n this._propertyEditor &&\n this._propertyEditor.containerHandlesBlur\n )\n void this._handleContainerCommit();\n };\n\n private _handleContainerBlur = (e: React.FocusEvent) => {\n e.stopPropagation();\n };\n\n private _handleClick = (e: React.MouseEvent) => {\n e.stopPropagation();\n };\n\n private _handleKeyDown = (e: React.KeyboardEvent) => {\n switch (e.key) {\n case Key.Escape:\n this.onPressEscape(e);\n break;\n case Key.Enter:\n this.onPressEnter(e);\n break;\n case Key.Tab:\n this.onPressTab(e);\n break;\n default:\n if (\n this._propertyEditor &&\n this._propertyEditor.containerStopsKeydownPropagation\n )\n e.stopPropagation();\n }\n };\n\n private _handleRightClick = (e: React.MouseEvent) => {\n e.stopPropagation();\n };\n\n private onPressEscape(_e: React.KeyboardEvent): void {\n // istanbul ignore else\n if (this._propertyEditor && this._propertyEditor.containerHandlesEscape) {\n this._commitCancel();\n }\n }\n\n private onPressEnter(e: React.KeyboardEvent): void {\n // istanbul ignore else\n if (this._propertyEditor && this._propertyEditor.containerHandlesEnter) {\n // istanbul ignore else\n if (this._editorRef && this._editorRef.hasFocus) e.stopPropagation();\n void this._handleContainerCommit();\n }\n }\n\n private onPressTab(e: React.KeyboardEvent): void {\n // istanbul ignore else\n if (this._propertyEditor && this._propertyEditor.containerHandlesTab) {\n e.stopPropagation();\n void this._handleContainerCommit();\n }\n }\n\n private displayOutputMessage(errorMessage: AsyncErrorMessage | undefined) {\n // istanbul ignore else\n if (errorMessage && this._editorRef) {\n const htmlElement = this._editorRef && this._editorRef.htmlElement;\n // istanbul ignore else\n if (htmlElement)\n UiAdmin.messagePresenter.displayInputFieldMessage(\n htmlElement,\n errorMessage.severity,\n errorMessage.briefMessage,\n errorMessage.detailedMessage\n );\n else\n UiAdmin.messagePresenter.displayMessage(\n errorMessage.severity,\n errorMessage.briefMessage,\n errorMessage.detailedMessage,\n errorMessage.messageType\n );\n }\n }\n\n private async isNewValueValid(value: PropertyValue): Promise<boolean> {\n let isValid = true;\n\n // istanbul ignore else\n if (this._propertyEditor && this.props.propertyRecord) {\n const validateResult = await this._propertyEditor.validateValue(\n value,\n this.props.propertyRecord\n );\n\n if (validateResult.encounteredError) {\n this.displayOutputMessage(validateResult.errorMessage);\n isValid = false;\n }\n } else {\n isValid = false;\n }\n\n return isValid;\n }\n\n private _handleEditorCommit = (args: PropertyUpdatedArgs): void => {\n void this._commit(args);\n };\n\n private _handleContainerCommit = async (): Promise<void> => {\n const newValue =\n this._editorRef && (await this._editorRef.getPropertyValue());\n // istanbul ignore else\n if (newValue !== undefined) {\n void this._commit({\n propertyRecord: this.props.propertyRecord,\n newValue,\n });\n }\n };\n\n private _commit = async (args: PropertyUpdatedArgs) => {\n const newValue = args.newValue;\n const isValid = await this.isNewValueValid(newValue);\n if (isValid) {\n let doCommit = true;\n // istanbul ignore else\n if (this._propertyEditor && args.propertyRecord) {\n const commitResult = await this._propertyEditor.commitValue(\n newValue,\n args.propertyRecord\n );\n if (commitResult.encounteredError) {\n this.displayOutputMessage(commitResult.errorMessage);\n doCommit = false;\n }\n }\n\n if (doCommit) {\n this.props.onCommit(args);\n }\n }\n };\n\n private _handleEditorCancel = () => {\n this._commitCancel();\n };\n\n private _commitCancel = () => {\n this.props.onCancel();\n };\n\n /** @internal */\n public override render() {\n return (\n <span\n className=\"components-editor-container\"\n onBlur={this._handleContainerBlur}\n onKeyDown={this._handleKeyDown}\n onClick={this._handleClick}\n onContextMenu={this._handleRightClick}\n title={this.props.title}\n data-testid=\"editor-container\"\n role=\"presentation\"\n >\n {this.createEditor()}\n </span>\n );\n }\n}\n"]}
|
|
@@ -18,7 +18,6 @@ interface EnumButtonGroupEditorState {
|
|
|
18
18
|
export declare class EnumButtonGroupEditor extends React.Component<PropertyEditorProps, EnumButtonGroupEditorState> implements TypeEditor {
|
|
19
19
|
private _btnRefs;
|
|
20
20
|
private _divElement;
|
|
21
|
-
private _placeholderIconSpec;
|
|
22
21
|
/** @internal */
|
|
23
22
|
readonly state: Readonly<EnumButtonGroupEditorState>;
|
|
24
23
|
getPropertyValue(): Promise<PropertyValue | undefined>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EnumButtonGroupEditor.d.ts","sourceRoot":"","sources":["../../../../src/components-react/editors/EnumButtonGroupEditor.tsx"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,8BAA8B,CAAC;AAEtC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAEV,iBAAiB,EACjB,cAAc,EAGd,aAAa,EACd,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"EnumButtonGroupEditor.d.ts","sourceRoot":"","sources":["../../../../src/components-react/editors/EnumButtonGroupEditor.tsx"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,8BAA8B,CAAC;AAEtC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAEV,iBAAiB,EACjB,cAAc,EAGd,aAAa,EACd,MAAM,uBAAuB,CAAC;AAQ/B,OAAO,KAAK,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,EACL,kBAAkB,EAEnB,MAAM,yBAAyB,CAAC;AAKjC,gBAAgB;AAChB,UAAU,0BAA0B;IAClC,WAAW,EAAE,MAAM,GAAG,MAAM,CAAC;IAC7B,SAAS,EAAE,cAAc,EAAE,CAAC;IAC5B,OAAO,EAAE,iBAAiB,EAAE,CAAC;CAC9B;AAED;;GAEG;AACH,qBAAa,qBACX,SAAQ,KAAK,CAAC,SAAS,CAAC,mBAAmB,EAAE,0BAA0B,CACvE,YAAW,UAAU;IAErB,OAAO,CAAC,QAAQ,CAAiD;IACjE,OAAO,CAAC,WAAW,CAAqC;IAExD,gBAAgB;IAChB,SAAyB,KAAK,EAAE,QAAQ,CAAC,0BAA0B,CAAC,CAIlE;IAEW,gBAAgB,IAAI,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;IAgBnE,IAAW,WAAW,IAAI,WAAW,GAAG,IAAI,CAE3C;IAED,IAAW,QAAQ,IAAI,OAAO,CAM7B;IAED,gBAAgB;IACA,iBAAiB;IAIjC,gBAAgB;IACA,kBAAkB,CAAC,SAAS,EAAE,mBAAmB;YAMnD,iBAAiB;IAgE/B,OAAO,CAAC,kBAAkB,CAuBxB;IAEF,OAAO,CAAC,SAAS;IAkCjB,gBAAgB;IACA,MAAM;CAkBvB;AAED;;;GAGG;AACH,qBAAa,6BAA8B,SAAQ,kBAAkB;IAEnE,IAAW,SAAS,IAAI,KAAK,CAAC,SAAS,CAEtC;CACF"}
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import "./EnumButtonGroupEditor.scss";
|
|
9
9
|
import classnames from "classnames";
|
|
10
10
|
import * as React from "react";
|
|
11
|
-
import {
|
|
11
|
+
import { PropertyEditorParamTypes, PropertyValueFormat, StandardEditorNames, StandardTypeNames, } from "@itwin/appui-abstract";
|
|
12
12
|
import { Icon } from "@itwin/core-react";
|
|
13
13
|
import { PropertyEditorBase, PropertyEditorManager, } from "./PropertyEditorManager";
|
|
14
14
|
import svgPlaceholder from "@bentley/icons-generic/icons/placeholder.svg";
|
|
@@ -20,7 +20,6 @@ export class EnumButtonGroupEditor extends React.Component {
|
|
|
20
20
|
super(...arguments);
|
|
21
21
|
this._btnRefs = new Map();
|
|
22
22
|
this._divElement = React.createRef();
|
|
23
|
-
this._placeholderIconSpec = IconSpecUtilities.createWebComponentIconSpec(svgPlaceholder);
|
|
24
23
|
/** @internal */
|
|
25
24
|
this.state = {
|
|
26
25
|
selectValue: "",
|
|
@@ -106,7 +105,7 @@ export class EnumButtonGroupEditor extends React.Component {
|
|
|
106
105
|
}
|
|
107
106
|
const numChoices = choices.length;
|
|
108
107
|
const enumIcons = new Array(numChoices);
|
|
109
|
-
enumIcons.fill({ iconSpec:
|
|
108
|
+
enumIcons.fill({ iconSpec: svgPlaceholder });
|
|
110
109
|
// istanbul ignore else
|
|
111
110
|
if (propertyRecord.property.editor &&
|
|
112
111
|
propertyRecord.property.editor.params) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EnumButtonGroupEditor.js","sourceRoot":"","sources":["../../../../src/components-react/editors/EnumButtonGroupEditor.tsx"],"names":[],"mappings":"AA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/*---------------------------------------------------------------------------------------------\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 IconSpecUtilities,\n PropertyEditorParamTypes,\n PropertyValueFormat,\n StandardEditorNames,\n StandardTypeNames,\n} from \"@itwin/appui-abstract\";\nimport { Icon } from \"@itwin/core-react\";\nimport type { PropertyEditorProps, TypeEditor } from \"./EditorContainer\";\nimport {\n PropertyEditorBase,\n PropertyEditorManager,\n} from \"./PropertyEditorManager\";\nimport svgPlaceholder from \"@bentley/icons-generic/icons/placeholder.svg\";\n\n// cspell:ignore buttongroup enumbuttongroup\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 private _placeholderIconSpec =\n IconSpecUtilities.createWebComponentIconSpec(svgPlaceholder);\n\n /** @internal */\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 // istanbul ignore else\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 // istanbul ignore else\n if (this._divElement.current)\n containsFocus = this._divElement.current.contains(document.activeElement);\n return containsFocus;\n }\n\n /** @internal */\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 // istanbul ignore else\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 // istanbul ignore else\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: this._placeholderIconSpec });\n\n // istanbul ignore else\n if (\n propertyRecord.property.editor &&\n propertyRecord.property.editor.params\n ) {\n // istanbul ignore else\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\n ) as ButtonGroupEditorParams;\n // istanbul ignore else\n if (bgParams) {\n bgParams.buttons.forEach(\n (iconDef: IconDefinition, index: number) => {\n // istanbul ignore else\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 // istanbul ignore else\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 // istanbul ignore else\n if (propertyRecord && this.props.onCommit) {\n const propertyValue = await this.getPropertyValue();\n // istanbul ignore else\n if (propertyValue !== undefined) {\n this.props.onCommit({ propertyRecord, newValue: propertyValue });\n }\n }\n }\n );\n }\n };\n\n private getButton(choice: EnumerationChoice, index: number) {\n const choiceValue = this.state.choices\n ? this.state.choices[index].value\n : /* istanbul ignore next */ 0;\n const isActive = choiceValue === this.state.selectValue ? true : false;\n let isDisabled = false;\n const isEnabledFunction = this.state.enumIcons[index].isEnabledFunction;\n // istanbul ignore else\n if (isEnabledFunction) {\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={(ref: HTMLButtonElement | null) =>\n ref && this._btnRefs.set(choiceValue, ref)\n }\n data-testid={choice.label}\n className={className}\n title={choice.label}\n key={choice.label}\n onClick={() => this._handleButtonClick(index)}\n >\n <Icon iconSpec={this.state.enumIcons[index].iconSpec} />\n </button>\n );\n }\n\n /** @internal */\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(choice, index)\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 // istanbul ignore next\n public get reactNode(): React.ReactNode {\n return <EnumButtonGroupEditor />;\n }\n}\n\nPropertyEditorManager.registerEditor(\n StandardTypeNames.Enum,\n EnumPropertyButtonGroupEditor,\n StandardEditorNames.EnumButtonGroup\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,EACnB,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEzC,OAAO,EACL,kBAAkB,EAClB,qBAAqB,GACtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,cAAc,MAAM,8CAA8C,CAAC;AAW1E;;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;QAExD,gBAAgB;QACS,UAAK,GAAyC;YACrE,WAAW,EAAE,EAAE;YACf,SAAS,EAAE,EAAE;YACb,OAAO,EAAE,EAAE;SACZ,CAAC;QA0GM,uBAAkB,GAAG,CAAC,KAAa,EAAE,EAAE;YAC7C,MAAM,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,cAAgC,CAAC;YAEnE,uBAAuB;YACvB,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,GAAG,KAAK,EAAE;gBAC3D,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC;gBAEpD,IAAI,CAAC,QAAQ,CACX;oBACE,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,CAAC,cAAc,CAClC,iBAAiB,CAAC,IAAI,EACtB,6BAA6B,EAC7B,mBAAmB,CAAC,eAAe,CACpC,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 \"./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 StandardEditorNames,\n StandardTypeNames,\n} from \"@itwin/appui-abstract\";\nimport { Icon } from \"@itwin/core-react\";\nimport type { PropertyEditorProps, TypeEditor } from \"./EditorContainer\";\nimport {\n PropertyEditorBase,\n PropertyEditorManager,\n} from \"./PropertyEditorManager\";\nimport svgPlaceholder from \"@bentley/icons-generic/icons/placeholder.svg\";\n\n// cspell:ignore buttongroup enumbuttongroup\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 /** @internal */\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 // istanbul ignore else\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 // istanbul ignore else\n if (this._divElement.current)\n containsFocus = this._divElement.current.contains(document.activeElement);\n return containsFocus;\n }\n\n /** @internal */\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 // istanbul ignore else\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 // istanbul ignore else\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: svgPlaceholder });\n\n // istanbul ignore else\n if (\n propertyRecord.property.editor &&\n propertyRecord.property.editor.params\n ) {\n // istanbul ignore else\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\n ) as ButtonGroupEditorParams;\n // istanbul ignore else\n if (bgParams) {\n bgParams.buttons.forEach(\n (iconDef: IconDefinition, index: number) => {\n // istanbul ignore else\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 // istanbul ignore else\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 // istanbul ignore else\n if (propertyRecord && this.props.onCommit) {\n const propertyValue = await this.getPropertyValue();\n // istanbul ignore else\n if (propertyValue !== undefined) {\n this.props.onCommit({ propertyRecord, newValue: propertyValue });\n }\n }\n }\n );\n }\n };\n\n private getButton(choice: EnumerationChoice, index: number) {\n const choiceValue = this.state.choices\n ? this.state.choices[index].value\n : /* istanbul ignore next */ 0;\n const isActive = choiceValue === this.state.selectValue ? true : false;\n let isDisabled = false;\n const isEnabledFunction = this.state.enumIcons[index].isEnabledFunction;\n // istanbul ignore else\n if (isEnabledFunction) {\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={(ref: HTMLButtonElement | null) =>\n ref && this._btnRefs.set(choiceValue, ref)\n }\n data-testid={choice.label}\n className={className}\n title={choice.label}\n key={choice.label}\n onClick={() => this._handleButtonClick(index)}\n >\n <Icon iconSpec={this.state.enumIcons[index].iconSpec} />\n </button>\n );\n }\n\n /** @internal */\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(choice, index)\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 // istanbul ignore next\n public get reactNode(): React.ReactNode {\n return <EnumButtonGroupEditor />;\n }\n}\n\nPropertyEditorManager.registerEditor(\n StandardTypeNames.Enum,\n EnumPropertyButtonGroupEditor,\n StandardEditorNames.EnumButtonGroup\n);\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PopupButton.d.ts","sourceRoot":"","sources":["../../../../src/components-react/editors/PopupButton.tsx"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,oBAAoB,CAAC;AAE5B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"PopupButton.d.ts","sourceRoot":"","sources":["../../../../src/components-react/editors/PopupButton.tsx"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,oBAAoB,CAAC;AAE5B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AASrE;;GAEG;AACH,MAAM,WAAW,gBAAiB,SAAQ,WAAW;IACnD,sCAAsC;IACtC,KAAK,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC,SAAS,CAAC;IAEjC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4BAA4B;IAC5B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,mCAAmC;IACnC,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,mDAAmD;IACnD,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,wKAAwK;IACxK,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,GAAG,MAAM,CAAC;IAEpD,sDAAsD;IACtD,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,iDAAiD;IACjD,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,oFAAoF;IACpF,YAAY,CAAC,EAAE,OAAO,CAAC;IAEvB,8CAA8C;IAC9C,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,UAAU,KAAK,IAAI,CAAC;IAC5C,qCAAqC;IACrC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,qCAAqC;IACrC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB;AAED,gBAAgB;AAChB,UAAU,gBAAgB;IACxB,SAAS,EAAE,OAAO,CAAC;CACpB;AAED;;GAEG;AACH,qBAAa,WAAY,SAAQ,KAAK,CAAC,aAAa,CAClD,gBAAgB,EAChB,gBAAgB,CACjB;IACC,OAAO,CAAC,UAAU,CAAqC;IAEvD,gBAAgB;IAChB,SAAyB,KAAK,EAAE,QAAQ,CAAC,gBAAgB,CAAC,CAExD;IAEF,gBAAgB;IACA,iBAAiB;IAKjC,OAAO,CAAC,YAAY,CAKlB;IAEK,UAAU;IAIjB,OAAO,CAAC,WAAW,CAOjB;IAEF,OAAO,CAAC,cAAc,CAYpB;IAEF,gBAAgB;IACA,MAAM,IAAI,KAAK,CAAC,SAAS;CA6D1C;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,cAAc,eAEjD;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,UAAU,KAAK,IAAI,CAAC;IACxC,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,UAAU,KAAK,IAAI,CAAC;CAC7C;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,aAAa,eA4BxD"}
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
import "./PopupButton.scss";
|
|
9
9
|
import classnames from "classnames";
|
|
10
10
|
import * as React from "react";
|
|
11
|
-
import {
|
|
11
|
+
import { Key } from "ts-key-enum";
|
|
12
|
+
import { RelativePosition } from "@itwin/appui-abstract";
|
|
12
13
|
import { Div, Icon, Popup, UiCore } from "@itwin/core-react";
|
|
13
14
|
import { Button } from "@itwin/itwinui-react";
|
|
14
15
|
import { SvgCheckmark, SvgChevronDown, SvgRemove, } from "@itwin/itwinui-icons-react";
|
|
@@ -36,9 +37,9 @@ export class PopupButton extends React.PureComponent {
|
|
|
36
37
|
};
|
|
37
38
|
this._handleKeyDown = (event) => {
|
|
38
39
|
// istanbul ignore else
|
|
39
|
-
if ((event.key ===
|
|
40
|
-
event.key ===
|
|
41
|
-
event.key ===
|
|
40
|
+
if ((event.key === Key.ArrowDown ||
|
|
41
|
+
event.key === " " ||
|
|
42
|
+
event.key === Key.Enter) &&
|
|
42
43
|
!this.state.showPopup) {
|
|
43
44
|
event.preventDefault();
|
|
44
45
|
event.stopPropagation();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PopupButton.js","sourceRoot":"","sources":["../../../../src/components-react/editors/PopupButton.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,oBAAoB,CAAC;AAC5B,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAErE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EACL,YAAY,EACZ,cAAc,EACd,SAAS,GACV,MAAM,4BAA4B,CAAC;AA0CpC;;GAEG;AACH,MAAM,OAAO,WAAY,SAAQ,KAAK,CAAC,aAGtC;IAHD;;QAIU,eAAU,GAAG,KAAK,CAAC,SAAS,EAAkB,CAAC;QAEvD,gBAAgB;QACS,UAAK,GAA+B;YAC3D,SAAS,EAAE,KAAK;SACjB,CAAC;QAQM,iBAAY,GAAG,CAAC,KAAuB,EAAE,EAAE;YACjD,IAAI,CAAC,QAAQ,CACX,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,E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,CACL,CACP,CAAC;AACJ,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 \"./PopupButton.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport { RelativePosition, SpecialKey } from \"@itwin/appui-abstract\";\nimport type { CommonDivProps, CommonProps } from \"@itwin/core-react\";\nimport { Div, Icon, Popup, UiCore } from \"@itwin/core-react\";\nimport { Button } from \"@itwin/itwinui-react\";\nimport {\n SvgCheckmark,\n SvgChevronDown,\n SvgRemove,\n} from \"@itwin/itwinui-icons-react\";\n\n/** Properties for [[PopupButton]] component\n * @alpha\n */\nexport interface PopupButtonProps extends CommonProps {\n /** Label to display in click area. */\n label?: string | React.ReactNode;\n /* Placeholder text used when there is no label yet */\n placeholder?: string;\n /** Contents of the popup */\n children: React.ReactNode;\n /** Title to display as tooltip. */\n title?: string;\n\n /** Set focus to popup - default is to set focus */\n moveFocus?: boolean;\n /** Element to receive focus, specified by React.RefObject or CSS selector string. If undefined and moveFocus is true then focus is moved to first focusable element. */\n focusTarget?: React.RefObject<HTMLElement> | string;\n\n /** Show or hide the box shadow (defaults to false) */\n showShadow?: boolean;\n /** Show or hide the arrow (defaults to false) */\n showArrow?: boolean;\n /** Indicates whether to set focus to the input element */\n setFocus?: boolean;\n /** Indicates whether to close the popup when Enter is pressed (defaults to true) */\n closeOnEnter?: boolean;\n\n /** Listens for click events on button area */\n onClick?: (event: React.MouseEvent) => void;\n /** Listens for popup close events */\n onClose?: () => void;\n /** Listens for Enter key in popup */\n onEnter?: () => void;\n}\n\n/** @internal */\ninterface PopupButtonState {\n showPopup: boolean;\n}\n\n/** PopupButton React component that is a button and property editor popup host\n * @alpha\n */\nexport class PopupButton extends React.PureComponent<\n PopupButtonProps,\n PopupButtonState\n> {\n private _buttonRef = React.createRef<HTMLDivElement>();\n\n /** @internal */\n public override readonly state: Readonly<PopupButtonState> = {\n showPopup: false,\n };\n\n /** @internal */\n public override componentDidMount() {\n if (this.props.setFocus && this._buttonRef.current)\n this._buttonRef.current.focus();\n }\n\n private _togglePopup = (event: React.MouseEvent) => {\n this.setState(\n (prevState) => ({ showPopup: !prevState.showPopup }),\n () => this.props.onClick && this.props.onClick(event)\n );\n };\n\n public closePopup() {\n this._closePopup();\n }\n\n private _closePopup = () => {\n this.setState({ showPopup: false }, () => {\n this.props.onClose && this.props.onClose();\n\n // istanbul ignore else\n if (this._buttonRef.current) this._buttonRef.current.focus();\n });\n };\n\n private _handleKeyDown = (event: React.KeyboardEvent) => {\n // istanbul ignore else\n if (\n (event.key === SpecialKey.ArrowDown ||\n event.key === SpecialKey.Space ||\n event.key === SpecialKey.Enter) &&\n !this.state.showPopup\n ) {\n event.preventDefault();\n event.stopPropagation();\n this.setState({ showPopup: true });\n }\n };\n\n /** @internal */\n public override render(): React.ReactNode {\n const showArrow = this.props.showArrow ?? false;\n const showShadow = this.props.showShadow ?? false;\n const moveFocus = this.props.moveFocus ?? true;\n const showPlaceholder =\n this.props.label === undefined && this.props.placeholder !== undefined;\n\n const classNames = classnames(\n \"components-popup-button\",\n this.state.showPopup && \"components-popup-expanded\"\n );\n\n const valueClassNames = classnames(\n \"components-popup-button-value\",\n showPlaceholder && \"components-popup-button-placeholder\"\n );\n\n return (\n <div className={this.props.className}>\n <div\n className={classNames}\n onClick={this._togglePopup}\n onKeyDown={this._handleKeyDown}\n data-testid=\"components-popup-button\"\n tabIndex={0}\n ref={this._buttonRef}\n title={this.props.title}\n role=\"button\"\n >\n <div className={valueClassNames}>\n {this.props.label || this.props.placeholder}\n </div>\n <div className={\"components-popup-button-arrow\"}>\n <div\n className={classnames(\n \"components-popup-button-arrow-icon\",\n \"icon\"\n )}\n >\n <Icon iconSpec={<SvgChevronDown />} />\n </div>\n </div>\n </div>\n <Popup\n className=\"components-popup-button-popup\"\n isOpen={this.state.showPopup}\n position={RelativePosition.Bottom}\n onClose={this._closePopup}\n onEnter={this.props.onEnter}\n closeOnEnter={this.props.closeOnEnter}\n target={this._buttonRef.current}\n showArrow={showArrow}\n showShadow={showShadow}\n moveFocus={moveFocus}\n focusTarget={this.props.focusTarget}\n >\n {this.props.children}\n </Popup>\n </div>\n );\n }\n}\n\n/** Popup content with padding\n * @alpha\n */\nexport function PopupContent(props: CommonDivProps) {\n return <Div {...props} mainClassName=\"components-editor-popup-content\" />;\n}\n\n/** Properties for [[PopupOkCancelButtons]] component\n * @alpha\n */\nexport interface OkCancelProps {\n onOk: (event: React.MouseEvent) => void;\n onCancel: (event: React.MouseEvent) => void;\n}\n\n/** OK/Cancel Buttons\n * @alpha\n */\nexport function PopupOkCancelButtons(props: OkCancelProps) {\n return (\n <div className=\"components-popup-bottom-buttons\">\n <Button\n className={classnames(\n \"components-popup-large-button\",\n \"components-popup-ok-button\"\n )}\n data-testid=\"components-popup-ok-button\"\n styleType=\"cta\"\n title={UiCore.translate(\"dialog.ok\")}\n onClick={props.onOk}\n >\n <Icon iconSpec={<SvgCheckmark />} />\n </Button>\n <Button\n className={classnames(\n \"components-popup-large-button\",\n \"components-popup-cancel-button\"\n )}\n data-testid=\"components-popup-cancel-button\"\n title={UiCore.translate(\"dialog.cancel\")}\n onClick={props.onCancel}\n >\n <Icon iconSpec={<SvgRemove />} />\n </Button>\n </div>\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"PopupButton.js","sourceRoot":"","sources":["../../../../src/components-react/editors/PopupButton.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,oBAAoB,CAAC;AAC5B,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,OAAO,EA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nB,+BAA+B,EAC/B,4BAA4B,CAC7B,iBACW,4BAA4B,EACxC,SAAS,EAAC,KAAK,EACf,KAAK,EAAE,MAAM,CAAC,SAAS,CAAC,WAAW,CAAC,EACpC,OAAO,EAAE,KAAK,CAAC,IAAI;YAEnB,oBAAC,IAAI,IAAC,QAAQ,EAAE,oBAAC,YAAY,OAAG,GAAI,CAC7B;QACT,oBAAC,MAAM,IACL,SAAS,EAAE,UAAU,CACnB,+BAA+B,EAC/B,gCAAgC,CACjC,iBACW,gCAAgC,EAC5C,KAAK,EAAE,MAAM,CAAC,SAAS,CAAC,eAAe,CAAC,EACxC,OAAO,EAAE,KAAK,CAAC,QAAQ;YAEvB,oBAAC,IAAI,IAAC,QAAQ,EAAE,oBAAC,SAAS,OAAG,GAAI,CAC1B,CACL,CACP,CAAC;AACJ,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 \"./PopupButton.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport { Key } from \"ts-key-enum\";\nimport { RelativePosition } from \"@itwin/appui-abstract\";\nimport type { CommonDivProps, CommonProps } from \"@itwin/core-react\";\nimport { Div, Icon, Popup, UiCore } from \"@itwin/core-react\";\nimport { Button } from \"@itwin/itwinui-react\";\nimport {\n SvgCheckmark,\n SvgChevronDown,\n SvgRemove,\n} from \"@itwin/itwinui-icons-react\";\n\n/** Properties for [[PopupButton]] component\n * @alpha\n */\nexport interface PopupButtonProps extends CommonProps {\n /** Label to display in click area. */\n label?: string | React.ReactNode;\n /* Placeholder text used when there is no label yet */\n placeholder?: string;\n /** Contents of the popup */\n children: React.ReactNode;\n /** Title to display as tooltip. */\n title?: string;\n\n /** Set focus to popup - default is to set focus */\n moveFocus?: boolean;\n /** Element to receive focus, specified by React.RefObject or CSS selector string. If undefined and moveFocus is true then focus is moved to first focusable element. */\n focusTarget?: React.RefObject<HTMLElement> | string;\n\n /** Show or hide the box shadow (defaults to false) */\n showShadow?: boolean;\n /** Show or hide the arrow (defaults to false) */\n showArrow?: boolean;\n /** Indicates whether to set focus to the input element */\n setFocus?: boolean;\n /** Indicates whether to close the popup when Enter is pressed (defaults to true) */\n closeOnEnter?: boolean;\n\n /** Listens for click events on button area */\n onClick?: (event: React.MouseEvent) => void;\n /** Listens for popup close events */\n onClose?: () => void;\n /** Listens for Enter key in popup */\n onEnter?: () => void;\n}\n\n/** @internal */\ninterface PopupButtonState {\n showPopup: boolean;\n}\n\n/** PopupButton React component that is a button and property editor popup host\n * @alpha\n */\nexport class PopupButton extends React.PureComponent<\n PopupButtonProps,\n PopupButtonState\n> {\n private _buttonRef = React.createRef<HTMLDivElement>();\n\n /** @internal */\n public override readonly state: Readonly<PopupButtonState> = {\n showPopup: false,\n };\n\n /** @internal */\n public override componentDidMount() {\n if (this.props.setFocus && this._buttonRef.current)\n this._buttonRef.current.focus();\n }\n\n private _togglePopup = (event: React.MouseEvent) => {\n this.setState(\n (prevState) => ({ showPopup: !prevState.showPopup }),\n () => this.props.onClick && this.props.onClick(event)\n );\n };\n\n public closePopup() {\n this._closePopup();\n }\n\n private _closePopup = () => {\n this.setState({ showPopup: false }, () => {\n this.props.onClose && this.props.onClose();\n\n // istanbul ignore else\n if (this._buttonRef.current) this._buttonRef.current.focus();\n });\n };\n\n private _handleKeyDown = (event: React.KeyboardEvent) => {\n // istanbul ignore else\n if (\n (event.key === Key.ArrowDown ||\n event.key === \" \" ||\n event.key === Key.Enter) &&\n !this.state.showPopup\n ) {\n event.preventDefault();\n event.stopPropagation();\n this.setState({ showPopup: true });\n }\n };\n\n /** @internal */\n public override render(): React.ReactNode {\n const showArrow = this.props.showArrow ?? false;\n const showShadow = this.props.showShadow ?? false;\n const moveFocus = this.props.moveFocus ?? true;\n const showPlaceholder =\n this.props.label === undefined && this.props.placeholder !== undefined;\n\n const classNames = classnames(\n \"components-popup-button\",\n this.state.showPopup && \"components-popup-expanded\"\n );\n\n const valueClassNames = classnames(\n \"components-popup-button-value\",\n showPlaceholder && \"components-popup-button-placeholder\"\n );\n\n return (\n <div className={this.props.className}>\n <div\n className={classNames}\n onClick={this._togglePopup}\n onKeyDown={this._handleKeyDown}\n data-testid=\"components-popup-button\"\n tabIndex={0}\n ref={this._buttonRef}\n title={this.props.title}\n role=\"button\"\n >\n <div className={valueClassNames}>\n {this.props.label || this.props.placeholder}\n </div>\n <div className={\"components-popup-button-arrow\"}>\n <div\n className={classnames(\n \"components-popup-button-arrow-icon\",\n \"icon\"\n )}\n >\n <Icon iconSpec={<SvgChevronDown />} />\n </div>\n </div>\n </div>\n <Popup\n className=\"components-popup-button-popup\"\n isOpen={this.state.showPopup}\n position={RelativePosition.Bottom}\n onClose={this._closePopup}\n onEnter={this.props.onEnter}\n closeOnEnter={this.props.closeOnEnter}\n target={this._buttonRef.current}\n showArrow={showArrow}\n showShadow={showShadow}\n moveFocus={moveFocus}\n focusTarget={this.props.focusTarget}\n >\n {this.props.children}\n </Popup>\n </div>\n );\n }\n}\n\n/** Popup content with padding\n * @alpha\n */\nexport function PopupContent(props: CommonDivProps) {\n return <Div {...props} mainClassName=\"components-editor-popup-content\" />;\n}\n\n/** Properties for [[PopupOkCancelButtons]] component\n * @alpha\n */\nexport interface OkCancelProps {\n onOk: (event: React.MouseEvent) => void;\n onCancel: (event: React.MouseEvent) => void;\n}\n\n/** OK/Cancel Buttons\n * @alpha\n */\nexport function PopupOkCancelButtons(props: OkCancelProps) {\n return (\n <div className=\"components-popup-bottom-buttons\">\n <Button\n className={classnames(\n \"components-popup-large-button\",\n \"components-popup-ok-button\"\n )}\n data-testid=\"components-popup-ok-button\"\n styleType=\"cta\"\n title={UiCore.translate(\"dialog.ok\")}\n onClick={props.onOk}\n >\n <Icon iconSpec={<SvgCheckmark />} />\n </Button>\n <Button\n className={classnames(\n \"components-popup-large-button\",\n \"components-popup-cancel-button\"\n )}\n data-testid=\"components-popup-cancel-button\"\n title={UiCore.translate(\"dialog.cancel\")}\n onClick={props.onCancel}\n >\n <Icon iconSpec={<SvgRemove />} />\n </Button>\n </div>\n );\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FilteringInput.d.ts","sourceRoot":"","sources":["../../../../src/components-react/filtering/FilteringInput.tsx"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,uBAAuB,CAAC;AAE/B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"FilteringInput.d.ts","sourceRoot":"","sources":["../../../../src/components-react/filtering/FilteringInput.tsx"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,uBAAuB,CAAC;AAE/B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAIrD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAI5D;;GAEG;AACH,UAAU,mBAAmB;IAC3B,6CAA6C;IAC7C,UAAU,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,aAAa,EAAE,OAAO,CAAC;IAEvB,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAoB,SAAQ,WAAW;IACtD,6BAA6B;IAC7B,aAAa,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5C,oDAAoD;IACpD,cAAc,EAAE,MAAM,IAAI,CAAC;IAC3B,qDAAqD;IACrD,aAAa,EAAE,MAAM,IAAI,CAAC;IAC1B;;OAEG;IACH,MAAM,EAAE,oBAAoB,CAAC;IAC7B;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,mBAAmB,CAAC;IAC1C,sEAAsE;IACtE,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;;GAGG;AACH,oBAAY,oBAAoB;IAC9B,mCAAmC;IACnC,aAAa,IAAA;IACb,gDAAgD;IAChD,mBAAmB,IAAA;IACnB,gDAAgD;IAChD,iBAAiB,IAAA;CAClB;AAED;;GAEG;AACH,qBAAa,cAAe,SAAQ,KAAK,CAAC,aAAa,CACrD,mBAAmB,EACnB,mBAAmB,CACpB;IACC,OAAO,CAAC,aAAa,CAAuC;IAC5D,OAAO,CAAC,YAAY,CAAsC;IAC1D,OAAO,CAAC,YAAY,CAAqC;IACzD,OAAO,CAAC,WAAW,CAAsC;gBAE7C,KAAK,EAAE,mBAAmB;IAStC,OAAO,CAAC,KAAK;IAKb,OAAO,CAAC,oBAAoB,CAU1B;IAEF,OAAO,CAAC,oBAAoB,CAI1B;IAEF,OAAO,CAAC,mBAAmB,CAIzB;IAEF,OAAO,CAAC,gBAAgB,CAQtB;IAEF,OAAO,CAAC,eAAe,CAKrB;IAEF,gBAAgB;IACA,kBAAkB,CAAC,SAAS,EAAE,mBAAmB;IAQjD,MAAM;CA+EvB"}
|
|
@@ -8,11 +8,11 @@
|
|
|
8
8
|
import "./FilteringInput.scss";
|
|
9
9
|
import classnames from "classnames";
|
|
10
10
|
import * as React from "react";
|
|
11
|
+
import { Key } from "ts-key-enum";
|
|
11
12
|
import { Icon, UiCore } from "@itwin/core-react";
|
|
12
13
|
import { Input } from "@itwin/itwinui-react";
|
|
13
14
|
import { UiComponents } from "../UiComponents";
|
|
14
15
|
import { ResultSelector } from "./ResultSelector";
|
|
15
|
-
import { SpecialKey } from "@itwin/appui-abstract";
|
|
16
16
|
import { SvgClose, SvgSearch } from "@itwin/itwinui-icons-react";
|
|
17
17
|
/**
|
|
18
18
|
* Enumeration of possible component contexts
|
|
@@ -58,7 +58,7 @@ export class FilteringInput extends React.PureComponent {
|
|
|
58
58
|
this.focus();
|
|
59
59
|
};
|
|
60
60
|
this._onFilterKeyDown = (e) => {
|
|
61
|
-
if (e.key !==
|
|
61
|
+
if (e.key !== Key.Enter)
|
|
62
62
|
return;
|
|
63
63
|
if (!this.state.searchText)
|
|
64
64
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FilteringInput.js","sourceRoot":"","sources":["../../../../src/components-react/filtering/FilteringInput.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,uBAAuB,CAAC;AAC/B,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AA0CjE;;;GAGG;AACH,MAAM,CAAN,IAAY,oBAOX;AAPD,WAAY,oBAAoB;IAC9B,mCAAmC;IACnC,iFAAa,CAAA;IACb,gDAAgD;IAChD,6FAAmB,CAAA;IACnB,gDAAgD;IAChD,yFAAiB,CAAA;AACnB,CAAC,EAPW,oBAAoB,KAApB,oBAAoB,QAO/B;AAED;;GAEG;AACH,MAAM,OAAO,cAAe,SAAQ,KAAK,CAAC,aAGzC;IAMC,YAAY,KAA0B;QACpC,KAAK,CAAC,KAAK,CAAC,CAAC;QANP,kBAAa,GAAG,KAAK,CAAC,SAAS,EAAoB,CAAC;QACpD,iBAAY,GAAG,MAAM,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC;QAClD,iBAAY,GAAG,MAAM,CAAC,SAAS,CAAC,eAAe,CAAC,CAAC;QACjD,gBAAW,GAAG,MAAM,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC;QAgBjD,yBAAoB,GAAG,GAAG,EAAE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AE,IAAI,CAAC,YAAY;wBAExB,oBAAC,IAAI,IAAC,QAAQ,EAAE,oBAAC,QAAQ,OAAG,GAAI;wBAAC,GAAG,CAC/B,CACR,CAAC,CAAC,CAAC,SAAS;oBACZ,MAAM,KAAK,oBAAoB,CAAC,iBAAiB,CAAC,CAAC,CAAC;oBACnD,iEAAiE;oBACjE,8BACE,SAAS,EAAC,uCAAuC,EACjD,OAAO,EAAE,IAAI,CAAC,mBAAmB,iBACrB,oBAAoB,EAChC,IAAI,EAAC,QAAQ,EACb,QAAQ,EAAE,CAAC,CAAC,EACZ,KAAK,EAAE,IAAI,CAAC,WAAW;wBAEvB,oBAAC,IAAI,IAAC,QAAQ,EAAE,oBAAC,QAAQ,OAAG,GAAI;wBAAC,GAAG,CAC/B,CACR,CAAC,CAAC,CAAC,SAAS,CACR,CACF,CACH,CACP,CAAC;IACJ,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 Filtering\n */\n\nimport \"./FilteringInput.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport type { CommonProps } from \"@itwin/core-react\";\nimport { Icon, UiCore } from \"@itwin/core-react\";\nimport { Input } from \"@itwin/itwinui-react\";\nimport { UiComponents } from \"../UiComponents\";\nimport type { ResultSelectorProps } from \"./ResultSelector\";\nimport { ResultSelector } from \"./ResultSelector\";\nimport { SpecialKey } from \"@itwin/appui-abstract\";\nimport { SvgClose, SvgSearch } from \"@itwin/itwinui-icons-react\";\n\n/** [[FilteringInput]] React Component state\n * @internal\n */\ninterface FilteringInputState {\n /** A string which will be used for search */\n searchText: string;\n /**\n * Tells the component if the search was started.\n * Gets reset to false if search is canceled/cleared or searchText is changed.\n */\n searchStarted: boolean;\n /* Used for resetting the state of [[ResultSelector]] component */\n resultSelectorKey: number;\n}\n\n/**\n * [[FilteringInput]] React Component properties\n * @public\n */\nexport interface FilteringInputProps extends CommonProps {\n /** Filtering should start */\n onFilterStart: (searchText: string) => void;\n /** Filtering is canceled while still in progress */\n onFilterCancel: () => void;\n /** Filtering is cleared after everything's loaded */\n onFilterClear: () => void;\n /**\n * Tells the component what is the status of filtering.\n */\n status: FilteringInputStatus;\n /**\n * [[ResultSelector]] React Component properties.\n * Attribute should be memoized and updated when [[ResultSelector]] state needs to be reset.\n * This allows resetting the selected active match index back to 0.\n */\n resultSelectorProps?: ResultSelectorProps;\n /** Specify that the <input> element should automatically get focus */\n autoFocus?: boolean;\n}\n\n/**\n * Enumeration of possible component contexts\n * @public\n */\nexport enum FilteringInputStatus {\n /** Component is ready to filter */\n ReadyToFilter,\n /** Component's parent is currently filtering */\n FilteringInProgress,\n /** Component's parent has finished filtering */\n FilteringFinished,\n}\n\n/** A helper component for filtering trees and stepping through results\n * @public\n */\nexport class FilteringInput extends React.PureComponent<\n FilteringInputProps,\n FilteringInputState\n> {\n private _inputElement = React.createRef<HTMLInputElement>();\n private _searchLabel = UiCore.translate(\"general.search\");\n private _cancelLabel = UiCore.translate(\"dialog.cancel\");\n private _clearLabel = UiCore.translate(\"general.search\");\n\n constructor(props: FilteringInputProps) {\n super(props);\n this.state = {\n searchText: \"\",\n searchStarted: false,\n resultSelectorKey: 0,\n };\n }\n\n private focus() {\n // istanbul ignore next\n if (this._inputElement.current) this._inputElement.current.focus();\n }\n\n private _onSearchButtonClick = () => {\n if (!this.state.searchText) {\n // Empty search string is the same as clearing the search.\n this.setState({ searchStarted: false, searchText: \"\" });\n this.props.onFilterClear();\n return;\n }\n\n this.props.onFilterStart(this.state.searchText);\n this.setState({ searchStarted: true });\n };\n\n private _onCancelButtonClick = () => {\n this.setState({ searchStarted: false, searchText: \"\" });\n this.props.onFilterCancel();\n this.focus();\n };\n\n private _onClearButtonClick = () => {\n this.setState({ searchStarted: false, searchText: \"\" });\n this.props.onFilterClear();\n this.focus();\n };\n\n private _onFilterKeyDown = (e: React.KeyboardEvent<HTMLElement>): void => {\n if (e.key !== SpecialKey.Enter) return;\n\n if (!this.state.searchText) return;\n\n this.props.onFilterStart(this.state.searchText);\n this.setState({ searchStarted: true });\n e.stopPropagation();\n };\n\n private _onInputChanged = (e: React.ChangeEvent<HTMLInputElement>) => {\n if (this.state.searchStarted) {\n this.props.onFilterCancel();\n }\n this.setState({ searchText: e.target.value, searchStarted: false });\n };\n\n /** @internal */\n public override componentDidUpdate(prevProps: FilteringInputProps) {\n if (this.props.resultSelectorProps !== prevProps.resultSelectorProps) {\n this.setState((state) => ({\n resultSelectorKey: state.resultSelectorKey + 1,\n }));\n }\n }\n\n public override render() {\n const status = this.props.status;\n return (\n // TODO: What is filtering-input-preload-images?\n <div\n className={classnames(\n \"components-filtering-input\",\n \"filtering-input-preload-images\",\n this.props.className\n )}\n style={this.props.style}\n onKeyDown={this._onFilterKeyDown}\n role=\"presentation\"\n >\n <span className=\"components-filtering-input-input\">\n <Input\n type=\"text\"\n placeholder={UiComponents.translate(\"filteringInput.placeholder\")}\n // eslint-disable-next-line jsx-a11y/no-autofocus\n autoFocus={this.props.autoFocus}\n onKeyDown={this._onFilterKeyDown}\n value={this.state.searchText}\n onChange={this._onInputChanged}\n aria-label={UiCore.translate(\"general.search\")}\n size=\"small\"\n />\n\n <span className=\"components-filtering-input-input-components\">\n {status === FilteringInputStatus.FilteringFinished &&\n this.props.resultSelectorProps ? (\n <ResultSelector\n key={this.state.resultSelectorKey}\n {...this.props.resultSelectorProps}\n />\n ) : undefined}\n {status === FilteringInputStatus.ReadyToFilter ? (\n // eslint-disable-next-line jsx-a11y/click-events-have-key-events\n <span\n className=\"icon\"\n onClick={this._onSearchButtonClick}\n data-testid=\"filter-input-search\"\n role=\"button\"\n tabIndex={-1}\n title={this._searchLabel}\n >\n <Icon iconSpec={<SvgSearch />} />{\" \"}\n </span>\n ) : undefined}\n {status === FilteringInputStatus.FilteringInProgress ? (\n // eslint-disable-next-line jsx-a11y/click-events-have-key-events\n <span\n className=\"icon\"\n onClick={this._onCancelButtonClick}\n data-testid=\"filter-input-close\"\n role=\"button\"\n tabIndex={-1}\n title={this._cancelLabel}\n >\n <Icon iconSpec={<SvgClose />} />{\" \"}\n </span>\n ) : undefined}\n {status === FilteringInputStatus.FilteringFinished ? (\n // eslint-disable-next-line jsx-a11y/click-events-have-key-events\n <span\n className=\"components-filtering-input-clear icon\"\n onClick={this._onClearButtonClick}\n data-testid=\"filter-input-close\"\n role=\"button\"\n tabIndex={-1}\n title={this._clearLabel}\n >\n <Icon iconSpec={<SvgClose />} />{\" \"}\n </span>\n ) : undefined}\n </span>\n </span>\n </div>\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"FilteringInput.js","sourceRoot":"","sources":["../../../../src/components-react/filtering/FilteringInput.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,uBAAuB,CAAC;AAC/B,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAElC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AA0CjE;;;GAGG;AACH,MAAM,CAAN,IAAY,oBAOX;AAPD,WAAY,oBAAoB;IAC9B,mCAAmC;IACnC,iFAAa,CAAA;IACb,gDAAgD;IAChD,6FAAmB,CAAA;IACnB,gDAAgD;IAChD,yFAAiB,CAAA;AACnB,CAAC,EAPW,oBAAoB,KAApB,oBAAoB,QAO/B;AAED;;GAEG;AACH,MAAM,OAAO,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AI,CAAC,YAAY;wBAExB,oBAAC,IAAI,IAAC,QAAQ,EAAE,oBAAC,SAAS,OAAG,GAAI;wBAAC,GAAG,CAChC,CACR,CAAC,CAAC,CAAC,SAAS;oBACZ,MAAM,KAAK,oBAAoB,CAAC,mBAAmB,CAAC,CAAC,CAAC;oBACrD,iEAAiE;oBACjE,8BACE,SAAS,EAAC,MAAM,EAChB,OAAO,EAAE,IAAI,CAAC,oBAAoB,iBACtB,oBAAoB,EAChC,IAAI,EAAC,QAAQ,EACb,QAAQ,EAAE,CAAC,CAAC,EACZ,KAAK,EAAE,IAAI,CAAC,YAAY;wBAExB,oBAAC,IAAI,IAAC,QAAQ,EAAE,oBAAC,QAAQ,OAAG,GAAI;wBAAC,GAAG,CAC/B,CACR,CAAC,CAAC,CAAC,SAAS;oBACZ,MAAM,KAAK,oBAAoB,CAAC,iBAAiB,CAAC,CAAC,CAAC;oBACnD,iEAAiE;oBACjE,8BACE,SAAS,EAAC,uCAAuC,EACjD,OAAO,EAAE,IAAI,CAAC,mBAAmB,iBACrB,oBAAoB,EAChC,IAAI,EAAC,QAAQ,EACb,QAAQ,EAAE,CAAC,CAAC,EACZ,KAAK,EAAE,IAAI,CAAC,WAAW;wBAEvB,oBAAC,IAAI,IAAC,QAAQ,EAAE,oBAAC,QAAQ,OAAG,GAAI;wBAAC,GAAG,CAC/B,CACR,CAAC,CAAC,CAAC,SAAS,CACR,CACF,CACH,CACP,CAAC;IACJ,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 Filtering\n */\n\nimport \"./FilteringInput.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport { Key } from \"ts-key-enum\";\nimport type { CommonProps } from \"@itwin/core-react\";\nimport { Icon, UiCore } from \"@itwin/core-react\";\nimport { Input } from \"@itwin/itwinui-react\";\nimport { UiComponents } from \"../UiComponents\";\nimport type { ResultSelectorProps } from \"./ResultSelector\";\nimport { ResultSelector } from \"./ResultSelector\";\nimport { SvgClose, SvgSearch } from \"@itwin/itwinui-icons-react\";\n\n/** [[FilteringInput]] React Component state\n * @internal\n */\ninterface FilteringInputState {\n /** A string which will be used for search */\n searchText: string;\n /**\n * Tells the component if the search was started.\n * Gets reset to false if search is canceled/cleared or searchText is changed.\n */\n searchStarted: boolean;\n /* Used for resetting the state of [[ResultSelector]] component */\n resultSelectorKey: number;\n}\n\n/**\n * [[FilteringInput]] React Component properties\n * @public\n */\nexport interface FilteringInputProps extends CommonProps {\n /** Filtering should start */\n onFilterStart: (searchText: string) => void;\n /** Filtering is canceled while still in progress */\n onFilterCancel: () => void;\n /** Filtering is cleared after everything's loaded */\n onFilterClear: () => void;\n /**\n * Tells the component what is the status of filtering.\n */\n status: FilteringInputStatus;\n /**\n * [[ResultSelector]] React Component properties.\n * Attribute should be memoized and updated when [[ResultSelector]] state needs to be reset.\n * This allows resetting the selected active match index back to 0.\n */\n resultSelectorProps?: ResultSelectorProps;\n /** Specify that the <input> element should automatically get focus */\n autoFocus?: boolean;\n}\n\n/**\n * Enumeration of possible component contexts\n * @public\n */\nexport enum FilteringInputStatus {\n /** Component is ready to filter */\n ReadyToFilter,\n /** Component's parent is currently filtering */\n FilteringInProgress,\n /** Component's parent has finished filtering */\n FilteringFinished,\n}\n\n/** A helper component for filtering trees and stepping through results\n * @public\n */\nexport class FilteringInput extends React.PureComponent<\n FilteringInputProps,\n FilteringInputState\n> {\n private _inputElement = React.createRef<HTMLInputElement>();\n private _searchLabel = UiCore.translate(\"general.search\");\n private _cancelLabel = UiCore.translate(\"dialog.cancel\");\n private _clearLabel = UiCore.translate(\"general.search\");\n\n constructor(props: FilteringInputProps) {\n super(props);\n this.state = {\n searchText: \"\",\n searchStarted: false,\n resultSelectorKey: 0,\n };\n }\n\n private focus() {\n // istanbul ignore next\n if (this._inputElement.current) this._inputElement.current.focus();\n }\n\n private _onSearchButtonClick = () => {\n if (!this.state.searchText) {\n // Empty search string is the same as clearing the search.\n this.setState({ searchStarted: false, searchText: \"\" });\n this.props.onFilterClear();\n return;\n }\n\n this.props.onFilterStart(this.state.searchText);\n this.setState({ searchStarted: true });\n };\n\n private _onCancelButtonClick = () => {\n this.setState({ searchStarted: false, searchText: \"\" });\n this.props.onFilterCancel();\n this.focus();\n };\n\n private _onClearButtonClick = () => {\n this.setState({ searchStarted: false, searchText: \"\" });\n this.props.onFilterClear();\n this.focus();\n };\n\n private _onFilterKeyDown = (e: React.KeyboardEvent<HTMLElement>): void => {\n if (e.key !== Key.Enter) return;\n\n if (!this.state.searchText) return;\n\n this.props.onFilterStart(this.state.searchText);\n this.setState({ searchStarted: true });\n e.stopPropagation();\n };\n\n private _onInputChanged = (e: React.ChangeEvent<HTMLInputElement>) => {\n if (this.state.searchStarted) {\n this.props.onFilterCancel();\n }\n this.setState({ searchText: e.target.value, searchStarted: false });\n };\n\n /** @internal */\n public override componentDidUpdate(prevProps: FilteringInputProps) {\n if (this.props.resultSelectorProps !== prevProps.resultSelectorProps) {\n this.setState((state) => ({\n resultSelectorKey: state.resultSelectorKey + 1,\n }));\n }\n }\n\n public override render() {\n const status = this.props.status;\n return (\n // TODO: What is filtering-input-preload-images?\n <div\n className={classnames(\n \"components-filtering-input\",\n \"filtering-input-preload-images\",\n this.props.className\n )}\n style={this.props.style}\n onKeyDown={this._onFilterKeyDown}\n role=\"presentation\"\n >\n <span className=\"components-filtering-input-input\">\n <Input\n type=\"text\"\n placeholder={UiComponents.translate(\"filteringInput.placeholder\")}\n // eslint-disable-next-line jsx-a11y/no-autofocus\n autoFocus={this.props.autoFocus}\n onKeyDown={this._onFilterKeyDown}\n value={this.state.searchText}\n onChange={this._onInputChanged}\n aria-label={UiCore.translate(\"general.search\")}\n size=\"small\"\n />\n\n <span className=\"components-filtering-input-input-components\">\n {status === FilteringInputStatus.FilteringFinished &&\n this.props.resultSelectorProps ? (\n <ResultSelector\n key={this.state.resultSelectorKey}\n {...this.props.resultSelectorProps}\n />\n ) : undefined}\n {status === FilteringInputStatus.ReadyToFilter ? (\n // eslint-disable-next-line jsx-a11y/click-events-have-key-events\n <span\n className=\"icon\"\n onClick={this._onSearchButtonClick}\n data-testid=\"filter-input-search\"\n role=\"button\"\n tabIndex={-1}\n title={this._searchLabel}\n >\n <Icon iconSpec={<SvgSearch />} />{\" \"}\n </span>\n ) : undefined}\n {status === FilteringInputStatus.FilteringInProgress ? (\n // eslint-disable-next-line jsx-a11y/click-events-have-key-events\n <span\n className=\"icon\"\n onClick={this._onCancelButtonClick}\n data-testid=\"filter-input-close\"\n role=\"button\"\n tabIndex={-1}\n title={this._cancelLabel}\n >\n <Icon iconSpec={<SvgClose />} />{\" \"}\n </span>\n ) : undefined}\n {status === FilteringInputStatus.FilteringFinished ? (\n // eslint-disable-next-line jsx-a11y/click-events-have-key-events\n <span\n className=\"components-filtering-input-clear icon\"\n onClick={this._onClearButtonClick}\n data-testid=\"filter-input-close\"\n role=\"button\"\n tabIndex={-1}\n title={this._clearLabel}\n >\n <Icon iconSpec={<SvgClose />} />{\" \"}\n </span>\n ) : undefined}\n </span>\n </span>\n </div>\n );\n }\n}\n"]}
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import "./ResultSelector.scss";
|
|
9
9
|
import classnames from "classnames";
|
|
10
10
|
import * as React from "react";
|
|
11
|
-
import {
|
|
11
|
+
import { Key } from "ts-key-enum";
|
|
12
12
|
import { Icon } from "@itwin/core-react";
|
|
13
13
|
import { UiComponents } from "../UiComponents";
|
|
14
14
|
import { SvgChevronLeft, SvgChevronRight } from "@itwin/itwinui-icons-react";
|
|
@@ -67,7 +67,7 @@ export class ResultSelector extends React.PureComponent {
|
|
|
67
67
|
}));
|
|
68
68
|
};
|
|
69
69
|
this._onSelectedResultKeyDown = (event) => {
|
|
70
|
-
if (event.key ===
|
|
70
|
+
if (event.key === Key.Enter)
|
|
71
71
|
this._onSelectedResultConfirmed();
|
|
72
72
|
};
|
|
73
73
|
this.state = {
|