UNPKG

@itwin/core-frontend

Version:
71 lines 2.93 kB
"use strict"; /*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ /** @packageDocumentation * @module Properties */ Object.defineProperty(exports, "__esModule", { value: true }); exports.FormattedQuantityDescription = void 0; const core_quantity_1 = require("@itwin/core-quantity"); const appui_abstract_1 = require("@itwin/appui-abstract"); const IModelApp_1 = require("../IModelApp"); /** * Base Quantity Property Description * @beta */ class FormattedQuantityDescription extends appui_abstract_1.BaseQuantityDescription { _formatterSpec; _parserSpec; constructor(argsOrName, displayLabel, iconSpec, kindOfQuantityName) { if (typeof argsOrName === "string") { // if argsOrName is a string, displayLabel must be defined. // eslint-disable-next-line @typescript-eslint/no-non-null-assertion super(argsOrName, displayLabel, iconSpec, kindOfQuantityName); } else { super(argsOrName.name, argsOrName.displayLabel, argsOrName.iconSpec, argsOrName.kindOfQuantityName); } } formatValue(numberValue) { if (this.formatterSpec) { return IModelApp_1.IModelApp.quantityFormatter.formatQuantity(numberValue, this.formatterSpec); } return numberValue.toFixed(2); } parseString(userInput) { if (this.parserSpec) { const parseResult = IModelApp_1.IModelApp.quantityFormatter.parseToQuantityValue(userInput, this.parserSpec); if (core_quantity_1.Parser.isParsedQuantity(parseResult)) { return { value: parseResult.value }; } else { return { parseError: this.parseError }; } } return { parseError: "no parser defined" }; } get formatterSpec() { if (this._formatterSpec) return this._formatterSpec; const formatterSpec = IModelApp_1.IModelApp.quantityFormatter.findFormatterSpecByQuantityType(this.formatterQuantityType); if (formatterSpec) { this._formatterSpec = formatterSpec; return formatterSpec; } return undefined; } get parserSpec() { if (this._parserSpec) return this._parserSpec; const parserSpec = IModelApp_1.IModelApp.quantityFormatter.findParserSpecByQuantityType(this.formatterQuantityType); if (parserSpec) { this._parserSpec = parserSpec; return parserSpec; } return undefined; } } exports.FormattedQuantityDescription = FormattedQuantityDescription; //# sourceMappingURL=FormattedQuantityDescription.js.map