@itwin/presentation-components
Version:
React components based on iTwin.js Presentation library
59 lines • 3.41 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.QuantityPropertyEditorInput = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
const react_1 = require("react");
const appui_abstract_1 = require("@itwin/appui-abstract");
const itwinui_react_1 = require("@itwin/itwinui-react");
const SchemaMetadataContext_js_1 = require("../../common/SchemaMetadataContext.js");
const NumericPropertyInput_js_1 = require("./NumericPropertyInput.js");
const UseQuantityValueInput_js_1 = require("./UseQuantityValueInput.js");
/** @internal */
exports.QuantityPropertyEditorInput = (0, react_1.forwardRef)((props, ref) => {
const schemaMetadataContext = (0, SchemaMetadataContext_js_1.useSchemaMetadataContext)();
if (!props.propertyRecord.property.quantityType || !schemaMetadataContext) {
return (0, jsx_runtime_1.jsx)(NumericPropertyInput_js_1.NumericPropertyInput, { ...props, ref: ref });
}
const initialValue = props.propertyRecord.value?.value;
return ((0, jsx_runtime_1.jsx)(QuantityPropertyValueInput, { ...props, ref: ref, koqName: props.propertyRecord.property.quantityType, schemaContext: schemaMetadataContext.schemaContext, initialRawValue: initialValue }));
});
exports.QuantityPropertyEditorInput.displayName = "QuantityPropertyEditorInput";
const QuantityPropertyValueInput = (0, react_1.forwardRef)(({ propertyRecord, onCommit, koqName, schemaContext, initialRawValue, setFocus }, ref) => {
const { quantityValue, inputProps } = (0, UseQuantityValueInput_js_1.useQuantityValueInput)({ koqName, schemaContext, initialRawValue });
const inputRef = (0, react_1.useRef)(null);
(0, react_1.useImperativeHandle)(ref, () => ({
getValue: () => ({
valueFormat: appui_abstract_1.PropertyValueFormat.Primitive,
value: quantityValue.rawValue,
displayValue: quantityValue.formattedValue,
roundingError: quantityValue.roundingError,
}),
htmlElement: inputRef.current,
}), [quantityValue]);
const onBlur = () => {
onCommit &&
onCommit({
propertyRecord,
newValue: {
valueFormat: appui_abstract_1.PropertyValueFormat.Primitive,
value: quantityValue.rawValue,
displayValue: quantityValue.formattedValue,
roundingError: quantityValue.roundingError,
},
});
};
(0, react_1.useEffect)(() => {
if (setFocus && !inputProps.disabled) {
inputRef.current && inputRef.current.focus();
}
}, [inputProps.disabled, setFocus]);
return ((0, jsx_runtime_1.jsx)(itwinui_react_1.Input, { size: "small", ...inputProps, disabled: propertyRecord.isReadonly || inputProps.disabled, ref: inputRef, onBlur: onBlur, onFocus: () => {
inputRef.current?.setSelectionRange(0, 9999);
} }));
});
QuantityPropertyValueInput.displayName = "QuantityPropertyValueInput";
//# sourceMappingURL=QuantityPropertyEditorInput.js.map