UNPKG

@itwin/core-frontend

Version:
65 lines 2.51 kB
/*--------------------------------------------------------------------------------------------- * 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 */ import { Parser } from "@itwin/core-quantity"; import { BaseQuantityDescription } from "@itwin/appui-abstract"; import { IModelApp } from "../IModelApp"; /** * Base Quantity Property Description * @beta */ export class FormattedQuantityDescription extends BaseQuantityDescription { _formatterSpec; _parserSpec; constructor(argsOrName, displayLabel, iconSpec, kindOfQuantityName) { if (typeof argsOrName === "string") { super(argsOrName, displayLabel, iconSpec, kindOfQuantityName); } else { super(argsOrName.name, argsOrName.displayLabel, argsOrName.iconSpec, argsOrName.kindOfQuantityName); } } formatValue(numberValue) { if (this.formatterSpec) { return IModelApp.quantityFormatter.formatQuantity(numberValue, this.formatterSpec); } return numberValue.toFixed(2); } parseString(userInput) { if (this.parserSpec) { const parseResult = IModelApp.quantityFormatter.parseToQuantityValue(userInput, this.parserSpec); if (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.quantityFormatter.findFormatterSpecByQuantityType(this.formatterQuantityType); if (formatterSpec) { this._formatterSpec = formatterSpec; return formatterSpec; } return undefined; } get parserSpec() { if (this._parserSpec) return this._parserSpec; const parserSpec = IModelApp.quantityFormatter.findParserSpecByQuantityType(this.formatterQuantityType); if (parserSpec) { this._parserSpec = parserSpec; return parserSpec; } return undefined; } } //# sourceMappingURL=FormattedQuantityDescription.js.map