@itwin/imodel-components-react 4.3.0-dev.1 → 4.3.1

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.
Files changed (54) hide show
  1. package/CHANGELOG.md +13 -1
  2. package/lib/cjs/imodel-components-react/UiIModelComponents.js +4 -2
  3. package/lib/cjs/imodel-components-react/UiIModelComponents.js.map +1 -1
  4. package/lib/cjs/imodel-components-react/color/ColorPickerButton.js +1 -1
  5. package/lib/cjs/imodel-components-react/color/ColorPickerButton.js.map +1 -1
  6. package/lib/cjs/imodel-components-react/inputs/QuantityNumberInput.js +1 -1
  7. package/lib/cjs/imodel-components-react/inputs/QuantityNumberInput.js.map +1 -1
  8. package/lib/cjs/imodel-components-react/navigationaids/CubeNavigationAid.js +10 -5
  9. package/lib/cjs/imodel-components-react/navigationaids/CubeNavigationAid.js.map +1 -1
  10. package/lib/cjs/imodel-components-react/quantityformat/FormatPanel.js +1 -1
  11. package/lib/cjs/imodel-components-react/quantityformat/FormatPanel.js.map +1 -1
  12. package/lib/cjs/imodel-components-react/quantityformat/FormatPrecision.js +2 -1
  13. package/lib/cjs/imodel-components-react/quantityformat/FormatPrecision.js.map +1 -1
  14. package/lib/cjs/imodel-components-react/quantityformat/FormatSample.js +2 -2
  15. package/lib/cjs/imodel-components-react/quantityformat/FormatSample.js.map +1 -1
  16. package/lib/cjs/imodel-components-react/quantityformat/FormatType.js +2 -3
  17. package/lib/cjs/imodel-components-react/quantityformat/FormatType.js.map +1 -1
  18. package/lib/cjs/imodel-components-react/quantityformat/FormatUnitLabel.js +2 -1
  19. package/lib/cjs/imodel-components-react/quantityformat/FormatUnitLabel.js.map +1 -1
  20. package/lib/cjs/imodel-components-react/quantityformat/FormatUnits.js +10 -6
  21. package/lib/cjs/imodel-components-react/quantityformat/FormatUnits.js.map +1 -1
  22. package/lib/cjs/imodel-components-react/quantityformat/MiscFormatOptions.js +7 -3
  23. package/lib/cjs/imodel-components-react/quantityformat/MiscFormatOptions.js.map +1 -1
  24. package/lib/cjs/imodel-components-react/quantityformat/misc/ThousandsSeparator.js +2 -1
  25. package/lib/cjs/imodel-components-react/quantityformat/misc/ThousandsSeparator.js.map +1 -1
  26. package/lib/cjs/imodel-components-react/viewport/ViewportComponent.js +9 -7
  27. package/lib/cjs/imodel-components-react/viewport/ViewportComponent.js.map +1 -1
  28. package/lib/esm/imodel-components-react/UiIModelComponents.js +4 -2
  29. package/lib/esm/imodel-components-react/UiIModelComponents.js.map +1 -1
  30. package/lib/esm/imodel-components-react/color/ColorPickerButton.js +1 -1
  31. package/lib/esm/imodel-components-react/color/ColorPickerButton.js.map +1 -1
  32. package/lib/esm/imodel-components-react/inputs/QuantityNumberInput.js +1 -1
  33. package/lib/esm/imodel-components-react/inputs/QuantityNumberInput.js.map +1 -1
  34. package/lib/esm/imodel-components-react/navigationaids/CubeNavigationAid.js +10 -5
  35. package/lib/esm/imodel-components-react/navigationaids/CubeNavigationAid.js.map +1 -1
  36. package/lib/esm/imodel-components-react/quantityformat/FormatPanel.js +1 -1
  37. package/lib/esm/imodel-components-react/quantityformat/FormatPanel.js.map +1 -1
  38. package/lib/esm/imodel-components-react/quantityformat/FormatPrecision.js +2 -1
  39. package/lib/esm/imodel-components-react/quantityformat/FormatPrecision.js.map +1 -1
  40. package/lib/esm/imodel-components-react/quantityformat/FormatSample.js +2 -2
  41. package/lib/esm/imodel-components-react/quantityformat/FormatSample.js.map +1 -1
  42. package/lib/esm/imodel-components-react/quantityformat/FormatType.js +2 -3
  43. package/lib/esm/imodel-components-react/quantityformat/FormatType.js.map +1 -1
  44. package/lib/esm/imodel-components-react/quantityformat/FormatUnitLabel.js +2 -1
  45. package/lib/esm/imodel-components-react/quantityformat/FormatUnitLabel.js.map +1 -1
  46. package/lib/esm/imodel-components-react/quantityformat/FormatUnits.js +10 -6
  47. package/lib/esm/imodel-components-react/quantityformat/FormatUnits.js.map +1 -1
  48. package/lib/esm/imodel-components-react/quantityformat/MiscFormatOptions.js +7 -3
  49. package/lib/esm/imodel-components-react/quantityformat/MiscFormatOptions.js.map +1 -1
  50. package/lib/esm/imodel-components-react/quantityformat/misc/ThousandsSeparator.js +2 -1
  51. package/lib/esm/imodel-components-react/quantityformat/misc/ThousandsSeparator.js.map +1 -1
  52. package/lib/esm/imodel-components-react/viewport/ViewportComponent.js +9 -7
  53. package/lib/esm/imodel-components-react/viewport/ViewportComponent.js.map +1 -1
  54. package/package.json +5 -5
@@ -1 +1 @@
1
- {"version":3,"file":"FormatPanel.js","sourceRoot":"","sources":["../../../../src/imodel-components-react/quantityformat/FormatPanel.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,oBAAoB,CAAC;AAC5B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAM/B,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE7D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AA6BxD,KAAK,UAAU,kBAAkB,CAC/B,WAAwB,EACxB,eAA0B,EAC1B,aAA4B;IAE5B,MAAM,YAAY,GAAG,MAAM,MAAM,CAAC,cAAc,CAC9C,QAAQ,EACR,aAAa,EACb,WAAW,CACZ,CAAC;IACF,OAAO,aAAa,CAAC,MAAM,CACzB,YAAY,CAAC,IAAI,EACjB,YAAY,EACZ,aAAa,EACb,eAAe,CAChB,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,KAAuB;IACjD,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAA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;QACD,KAAK,CAAC,sBAAsB;YAC3B,KAAK,CAAC,sBAAsB,CAAC,WAAW,EAAE,kBAAkB,CAAC;QAC/D,oBAAC,iBAAiB,IAChB,WAAW,EAAE,WAAW,EACxB,QAAQ,EAAE,kBAAkB,EAC5B,uBAAuB,EAAE,uBAAuB,EAChD,WAAW,EAAE,WAAW,EACxB,iBAAiB,EAAE,iBAAiB,IAEnC,KAAK,CAAC,wBAAwB;YAC7B,KAAK,CAAC,wBAAwB,CAAC,WAAW,EAAE,kBAAkB,CAAC,CAC/C,CAChB,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 QuantityFormat\n */\n\nimport \"./FormatPanel.scss\";\nimport * as React from \"react\";\nimport type {\n FormatProps,\n UnitProps,\n UnitsProvider,\n} from \"@itwin/core-quantity\";\nimport { Format, FormatterSpec } from \"@itwin/core-quantity\";\nimport type { CommonProps } from \"@itwin/core-react\";\nimport { FormatPrecision } from \"./FormatPrecision\";\nimport { FormatSample } from \"./FormatSample\";\nimport { FormatTypeOption } from \"./FormatType\";\nimport { FormatUnitLabel } from \"./FormatUnitLabel\";\nimport { FormatUnits } from \"./FormatUnits\";\nimport { MiscFormatOptions } from \"./MiscFormatOptions\";\n\n/** Properties of [[FormatPanel]] component.\n * @alpha\n */\nexport interface FormatPanelProps extends CommonProps {\n initialFormat: FormatProps;\n unitsProvider: UnitsProvider;\n persistenceUnit: Promise<UnitProps> | UnitProps;\n showSample?: boolean;\n initialMagnitude?: number;\n // if true a only primary format properties are initially displayed and a \"More/Less\" link is added.\n enableMinimumProperties?: boolean;\n onFormatChange?: (format: FormatProps) => void;\n provideFormatSpec?: (\n formatProps: FormatProps,\n persistenceUnit: UnitProps,\n unitsProvider: UnitsProvider\n ) => Promise<FormatterSpec>;\n providePrimaryChildren?: (\n formatProps: FormatProps,\n fireFormatChange: (newProps: FormatProps) => void\n ) => React.ReactNode;\n provideSecondaryChildren?: (\n formatProps: FormatProps,\n fireFormatChange: (newProps: FormatProps) => void\n ) => React.ReactNode;\n}\n\nasync function generateFormatSpec(\n formatProps: FormatProps,\n persistenceUnit: UnitProps,\n unitsProvider: UnitsProvider\n) {\n const actualFormat = await Format.createFromJSON(\n \"custom\",\n unitsProvider,\n formatProps\n );\n return FormatterSpec.create(\n actualFormat.name,\n actualFormat,\n unitsProvider,\n persistenceUnit\n );\n}\n\n/** Component to show/edit Quantity Format.\n * @alpha\n */\nexport function FormatPanel(props: FormatPanelProps) {\n const [formatSpec, setFormatSpec] = React.useState<FormatterSpec>();\n const {\n initialFormat,\n showSample,\n initialMagnitude,\n unitsProvider,\n persistenceUnit,\n onFormatChange,\n provideFormatSpec,\n enableMinimumProperties,\n } = props;\n const [formatProps, setFormatProps] = React.useState(initialFormat);\n const [showOptions, setShowOptions] = React.useState(false);\n\n React.useEffect(() => {\n setFormatProps(initialFormat);\n setFormatSpec(undefined); // this will trigger the new spec to be created in the useEffect hook\n }, [initialFormat]);\n\n const handleUserFormatChanges = React.useCallback(\n (newProps: FormatProps) => {\n setFormatProps(newProps);\n setFormatSpec(undefined); // this will trigger the new spec to be created in the useEffect hook\n onFormatChange && onFormatChange(newProps);\n },\n [onFormatChange]\n );\n\n const isMounted = React.useRef(false);\n\n // runs returned function only when component is unmounted.\n React.useEffect(() => {\n isMounted.current = true;\n return () => {\n isMounted.current = false;\n };\n }, []);\n\n React.useEffect(() => {\n async function fetchFormatSpec() {\n const pu = await persistenceUnit;\n let newFormatSpec: FormatterSpec;\n if (provideFormatSpec) {\n newFormatSpec = await provideFormatSpec(formatProps, pu, unitsProvider);\n } else {\n newFormatSpec = await generateFormatSpec(\n formatProps,\n pu,\n unitsProvider\n );\n }\n isMounted.current && setFormatSpec(newFormatSpec);\n }\n if (!formatSpec) void fetchFormatSpec();\n }, [\n formatProps,\n formatSpec,\n persistenceUnit,\n provideFormatSpec,\n unitsProvider,\n ]);\n\n const handleFormatChange = React.useCallback(\n (newFormatProps: FormatProps) => {\n handleUserFormatChanges(newFormatProps);\n },\n [handleUserFormatChanges]\n );\n\n const handleShowOptions = React.useCallback((show: boolean) => {\n setShowOptions(show);\n }, []);\n\n return (\n <div className=\"components-quantityFormat-panel\">\n {showSample && (\n <FormatSample\n formatSpec={formatSpec}\n initialMagnitude={initialMagnitude}\n />\n )}\n <FormatUnits\n unitsProvider={unitsProvider}\n persistenceUnit={formatSpec?.persistenceUnit}\n initialFormat={formatProps}\n onUnitsChange={handleFormatChange}\n />\n <FormatUnitLabel\n formatProps={formatProps}\n onUnitLabelChange={handleFormatChange}\n />\n <FormatTypeOption\n formatProps={formatProps}\n onChange={handleFormatChange}\n />\n <FormatPrecision\n formatProps={formatProps}\n onChange={handleFormatChange}\n />\n {props.providePrimaryChildren &&\n props.providePrimaryChildren(formatProps, handleFormatChange)}\n <MiscFormatOptions\n formatProps={formatProps}\n onChange={handleFormatChange}\n enableMinimumProperties={enableMinimumProperties}\n showOptions={showOptions}\n onShowHideOptions={handleShowOptions}\n >\n {props.provideSecondaryChildren &&\n props.provideSecondaryChildren(formatProps, handleFormatChange)}\n </MiscFormatOptions>\n </div>\n );\n}\n"]}
1
+ {"version":3,"file":"FormatPanel.js","sourceRoot":"","sources":["../../../../src/imodel-components-react/quantityformat/FormatPanel.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,oBAAoB,CAAC;AAC5B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAM/B,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE7D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EA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C;IAEP,OAAO,CACL,6BAAK,SAAS,EAAC,iCAAiC;QAC7C,UAAU,IAAI,CACb,oBAAC,YAAY,IACX,UAAU,EAAE,UAAU,EACtB,gBAAgB,EAAE,gBAAgB,GAClC,CACH;QACD,oBAAC,WAAW,IACV,aAAa,EAAE,aAAa,EAC5B,eAAe,EAAE,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,eAAe,EAC5C,aAAa,EAAE,WAAW,EAC1B,aAAa,EAAE,kBAAkB,GACjC;QACF,oBAAC,eAAe,IACd,WAAW,EAAE,WAAW,EACxB,iBAAiB,EAAE,kBAAkB,GACrC;QACF,oBAAC,gBAAgB,IACf,WAAW,EAAE,WAAW,EACxB,QAAQ,EAAE,kBAAkB,GAC5B;QACF,oBAAC,eAAe,IACd,WAAW,EAAE,WAAW,EACxB,QAAQ,EAAE,kBAAkB,GAC5B;QACD,KAAK,CAAC,sBAAsB;YAC3B,KAAK,CAAC,sBAAsB,CAAC,WAAW,EAAE,kBAAkB,CAAC;QAC/D,oBAAC,iBAAiB,IAChB,WAAW,EAAE,WAAW,EACxB,QAAQ,EAAE,kBAAkB,EAC5B,uBAAuB,EAAE,uBAAuB,EAChD,WAAW,EAAE,WAAW,EACxB,iBAAiB,EAAE,iBAAiB,IAEnC,KAAK,CAAC,wBAAwB;YAC7B,KAAK,CAAC,wBAAwB,CAAC,WAAW,EAAE,kBAAkB,CAAC,CAC/C,CAChB,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 QuantityFormat\n */\n\nimport \"./FormatPanel.scss\";\nimport * as React from \"react\";\nimport type {\n FormatProps,\n UnitProps,\n UnitsProvider,\n} from \"@itwin/core-quantity\";\nimport { Format, FormatterSpec } from \"@itwin/core-quantity\";\nimport type { CommonProps } from \"@itwin/core-react\";\nimport { FormatPrecision } from \"./FormatPrecision\";\nimport { FormatSample } from \"./FormatSample\";\nimport { FormatTypeOption } from \"./FormatType\";\nimport { FormatUnitLabel } from \"./FormatUnitLabel\";\nimport { FormatUnits } from \"./FormatUnits\";\nimport { MiscFormatOptions } from \"./MiscFormatOptions\";\n\n/** Properties of [[FormatPanel]] component.\n * @alpha\n */\nexport interface FormatPanelProps extends CommonProps {\n initialFormat: FormatProps;\n unitsProvider: UnitsProvider;\n persistenceUnit: Promise<UnitProps> | UnitProps;\n showSample?: boolean;\n initialMagnitude?: number;\n // if true a only primary format properties are initially displayed and a \"More/Less\" link is added.\n enableMinimumProperties?: boolean;\n onFormatChange?: (format: FormatProps) => void;\n provideFormatSpec?: (\n formatProps: FormatProps,\n persistenceUnit: UnitProps,\n unitsProvider: UnitsProvider\n ) => Promise<FormatterSpec>;\n providePrimaryChildren?: (\n formatProps: FormatProps,\n fireFormatChange: (newProps: FormatProps) => void\n ) => React.ReactNode;\n provideSecondaryChildren?: (\n formatProps: FormatProps,\n fireFormatChange: (newProps: FormatProps) => void\n ) => React.ReactNode;\n}\n\nasync function generateFormatSpec(\n formatProps: FormatProps,\n persistenceUnit: UnitProps,\n unitsProvider: UnitsProvider\n) {\n const actualFormat = await Format.createFromJSON(\n \"custom\",\n unitsProvider,\n formatProps\n );\n return FormatterSpec.create(\n actualFormat.name,\n actualFormat,\n unitsProvider,\n persistenceUnit\n );\n}\n\n/** Component to show/edit Quantity Format.\n * @alpha\n */\nexport function FormatPanel(props: FormatPanelProps) {\n const [formatSpec, setFormatSpec] = React.useState<FormatterSpec>();\n const {\n initialFormat,\n showSample,\n initialMagnitude,\n unitsProvider,\n persistenceUnit,\n onFormatChange,\n provideFormatSpec,\n enableMinimumProperties,\n } = props;\n const [formatProps, setFormatProps] = React.useState(initialFormat);\n const [showOptions, setShowOptions] = React.useState(false);\n\n React.useEffect(() => {\n setFormatProps(initialFormat);\n setFormatSpec(undefined); // this will trigger the new spec to be created in the useEffect hook\n }, [initialFormat]);\n\n const handleUserFormatChanges = React.useCallback(\n (newProps: FormatProps) => {\n setFormatProps(newProps);\n setFormatSpec(undefined); // this will trigger the new spec to be created in the useEffect hook\n onFormatChange && onFormatChange(newProps);\n },\n [onFormatChange]\n );\n\n const isMounted = React.useRef(false);\n\n // runs returned function only when component is unmounted.\n React.useEffect(() => {\n isMounted.current = true;\n return () => {\n isMounted.current = false;\n };\n }, []);\n\n React.useEffect(() => {\n async function fetchFormatSpec() {\n const pu = await persistenceUnit;\n let newFormatSpec: FormatterSpec;\n if (provideFormatSpec) {\n newFormatSpec = await provideFormatSpec(formatProps, pu, unitsProvider);\n } else {\n newFormatSpec = await generateFormatSpec(\n formatProps,\n pu,\n unitsProvider\n );\n }\n isMounted.current && setFormatSpec(newFormatSpec);\n }\n if (!formatSpec) void fetchFormatSpec();\n }, [\n formatProps,\n formatSpec,\n persistenceUnit,\n provideFormatSpec,\n unitsProvider,\n ]);\n\n const handleFormatChange = React.useCallback(\n (newFormatProps: FormatProps) => {\n handleUserFormatChanges(newFormatProps);\n },\n [handleUserFormatChanges]\n );\n\n const handleShowOptions = React.useCallback((show: boolean) => {\n setShowOptions(show);\n }, []);\n\n return (\n <div className=\"components-quantityFormat-panel\">\n {showSample && (\n <FormatSample\n formatSpec={formatSpec}\n initialMagnitude={initialMagnitude}\n />\n )}\n <FormatUnits\n unitsProvider={unitsProvider}\n persistenceUnit={formatSpec?.persistenceUnit}\n initialFormat={formatProps}\n onUnitsChange={handleFormatChange}\n />\n <FormatUnitLabel\n formatProps={formatProps}\n onUnitLabelChange={handleFormatChange}\n />\n <FormatTypeOption\n formatProps={formatProps}\n onChange={handleFormatChange}\n />\n <FormatPrecision\n formatProps={formatProps}\n onChange={handleFormatChange}\n />\n {props.providePrimaryChildren &&\n props.providePrimaryChildren(formatProps, handleFormatChange)}\n <MiscFormatOptions\n formatProps={formatProps}\n onChange={handleFormatChange}\n enableMinimumProperties={enableMinimumProperties}\n showOptions={showOptions}\n onShowHideOptions={handleShowOptions}\n >\n {props.provideSecondaryChildren &&\n props.provideSecondaryChildren(formatProps, handleFormatChange)}\n </MiscFormatOptions>\n </div>\n );\n}\n"]}
@@ -14,6 +14,7 @@ import { UiIModelComponents } from "../UiIModelComponents";
14
14
  * @alpha
15
15
  */
16
16
  export function FormatPrecision(props) {
17
+ var _a, _b;
17
18
  const { formatProps, onChange } = props;
18
19
  const handlePrecisionChange = React.useCallback((precision) => {
19
20
  const newFormatProps = { ...formatProps, precision };
@@ -23,6 +24,6 @@ export function FormatPrecision(props) {
23
24
  const label = React.useRef(UiIModelComponents.translate("QuantityFormat.labels.precision"));
24
25
  return (React.createElement(React.Fragment, null,
25
26
  React.createElement("span", { className: "uicore-label" }, label.current),
26
- formatType === FormatType.Fractional ? (React.createElement(FractionPrecisionSelector, { "data-testid": "fraction-precision-selector", precision: formatProps.precision ?? 0, onChange: handlePrecisionChange })) : (React.createElement(DecimalPrecisionSelector, { "data-testid": "decimal-precision-selector", precision: formatProps.precision ?? 0, onChange: handlePrecisionChange }))));
27
+ formatType === FormatType.Fractional ? (React.createElement(FractionPrecisionSelector, { "data-testid": "fraction-precision-selector", precision: (_a = formatProps.precision) !== null && _a !== void 0 ? _a : 0, onChange: handlePrecisionChange })) : (React.createElement(DecimalPrecisionSelector, { "data-testid": "decimal-precision-selector", precision: (_b = formatProps.precision) !== null && _b !== void 0 ? _b : 0, onChange: handlePrecisionChange }))));
27
28
  }
28
29
  //# sourceMappingURL=FormatPrecision.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"FormatPrecision.js","sourceRoot":"","sources":["../../../../src/imodel-components-react/quantityformat/FormatPrecision.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAU3D;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,KAA2B;IACzD,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IAExC,MAAM,qBAAqB,GAAG,KAAK,CAAC,WAAW,CAC7C,CAAC,SAAiB,EAAE,EAAE;QACpB,MAAM,cAAc,GAAG,EAAE,GAAG,WAAW,EAAE,SAAS,EAAE,CAAC;QACrD,QAAQ,IAAI,QAAQ,CAAC,cAAc,CAAC,CAAC;IACvC,CAAC,EACD,CAAC,WAAW,EAAE,QAAQ,CAAC,CACxB,CAAC;IAEF,MAAM,UAAU,GAAG,eAAe,CAAC,WAAW,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAE/D,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CACxB,kBAAkB,CAAC,SAAS,CAAC,iCAAiC,CAAC,CAChE,CAAC;IACF,OAAO,CACL;QACE,8BAAM,SAAS,EAAE,cAAc,IAAG,KAAK,CAAC,OAAO,CAAQ;QACtD,UAAU,KAAK,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,CACtC,oBAAC,yBAAyB,mBACZ,6BAA6B,EACzC,SAAS,EAAE,WAAW,CAAC,SAAS,IAAI,CAAC,EACrC,QAAQ,EAAE,qBAAqB,GAC/B,CACH,CAAC,CAAC,CAAC,CACF,oBAAC,wBAAwB,mBACX,4BAA4B,EACxC,SAAS,EAAE,WAAW,CAAC,SAAS,IAAI,CAAC,EACrC,QAAQ,EAAE,qBAAqB,GAC/B,CACH,CACA,CACJ,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 QuantityFormat\n */\n\nimport * as React from \"react\";\nimport type { CommonProps } from \"@itwin/core-react\";\nimport type { FormatProps } from \"@itwin/core-quantity\";\nimport { FormatType, parseFormatType } from \"@itwin/core-quantity\";\nimport { DecimalPrecisionSelector } from \"./misc/DecimalPrecision\";\nimport { FractionPrecisionSelector } from \"./misc/FractionPrecision\";\nimport { UiIModelComponents } from \"../UiIModelComponents\";\n\n/** Properties of [[FormatPrecision]] component.\n * @alpha\n */\nexport interface FormatPrecisionProps extends CommonProps {\n formatProps: FormatProps;\n onChange?: (format: FormatProps) => void;\n}\n\n/** Component to show/edit Quantity Format Precision.\n * @alpha\n */\nexport function FormatPrecision(props: FormatPrecisionProps) {\n const { formatProps, onChange } = props;\n\n const handlePrecisionChange = React.useCallback(\n (precision: number) => {\n const newFormatProps = { ...formatProps, precision };\n onChange && onChange(newFormatProps);\n },\n [formatProps, onChange]\n );\n\n const formatType = parseFormatType(formatProps.type, \"format\");\n\n const label = React.useRef(\n UiIModelComponents.translate(\"QuantityFormat.labels.precision\")\n );\n return (\n <>\n <span className={\"uicore-label\"}>{label.current}</span>\n {formatType === FormatType.Fractional ? (\n <FractionPrecisionSelector\n data-testid=\"fraction-precision-selector\"\n precision={formatProps.precision ?? 0}\n onChange={handlePrecisionChange}\n />\n ) : (\n <DecimalPrecisionSelector\n data-testid=\"decimal-precision-selector\"\n precision={formatProps.precision ?? 0}\n onChange={handlePrecisionChange}\n />\n )}\n </>\n );\n}\n"]}
1
+ {"version":3,"file":"FormatPrecision.js","sourceRoot":"","sources":["../../../../src/imodel-components-react/quantityformat/FormatPrecision.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAU3D;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,KAA2B;;IACzD,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IAExC,MAAM,qBAAqB,GAAG,KAAK,CAAC,WAAW,CAC7C,CAAC,SAAiB,EAAE,EAAE;QACpB,MAAM,cAAc,GAAG,EAAE,GAAG,WAAW,EAAE,SAAS,EAAE,CAAC;QACrD,QAAQ,IAAI,QAAQ,CAAC,cAAc,CAAC,CAAC;IACvC,CAAC,EACD,CAAC,WAAW,EAAE,QAAQ,CAAC,CACxB,CAAC;IAEF,MAAM,UAAU,GAAG,eAAe,CAAC,WAAW,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAE/D,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CACxB,kBAAkB,CAAC,SAAS,CAAC,iCAAiC,CAAC,CAChE,CAAC;IACF,OAAO,CACL;QACE,8BAAM,SAAS,EAAE,cAAc,IAAG,KAAK,CAAC,OAAO,CAAQ;QACtD,UAAU,KAAK,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,CACtC,oBAAC,yBAAyB,mBACZ,6BAA6B,EACzC,SAAS,EAAE,MAAA,WAAW,CAAC,SAAS,mCAAI,CAAC,EACrC,QAAQ,EAAE,qBAAqB,GAC/B,CACH,CAAC,CAAC,CAAC,CACF,oBAAC,wBAAwB,mBACX,4BAA4B,EACxC,SAAS,EAAE,MAAA,WAAW,CAAC,SAAS,mCAAI,CAAC,EACrC,QAAQ,EAAE,qBAAqB,GAC/B,CACH,CACA,CACJ,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 QuantityFormat\n */\n\nimport * as React from \"react\";\nimport type { CommonProps } from \"@itwin/core-react\";\nimport type { FormatProps } from \"@itwin/core-quantity\";\nimport { FormatType, parseFormatType } from \"@itwin/core-quantity\";\nimport { DecimalPrecisionSelector } from \"./misc/DecimalPrecision\";\nimport { FractionPrecisionSelector } from \"./misc/FractionPrecision\";\nimport { UiIModelComponents } from \"../UiIModelComponents\";\n\n/** Properties of [[FormatPrecision]] component.\n * @alpha\n */\nexport interface FormatPrecisionProps extends CommonProps {\n formatProps: FormatProps;\n onChange?: (format: FormatProps) => void;\n}\n\n/** Component to show/edit Quantity Format Precision.\n * @alpha\n */\nexport function FormatPrecision(props: FormatPrecisionProps) {\n const { formatProps, onChange } = props;\n\n const handlePrecisionChange = React.useCallback(\n (precision: number) => {\n const newFormatProps = { ...formatProps, precision };\n onChange && onChange(newFormatProps);\n },\n [formatProps, onChange]\n );\n\n const formatType = parseFormatType(formatProps.type, \"format\");\n\n const label = React.useRef(\n UiIModelComponents.translate(\"QuantityFormat.labels.precision\")\n );\n return (\n <>\n <span className={\"uicore-label\"}>{label.current}</span>\n {formatType === FormatType.Fractional ? (\n <FractionPrecisionSelector\n data-testid=\"fraction-precision-selector\"\n precision={formatProps.precision ?? 0}\n onChange={handlePrecisionChange}\n />\n ) : (\n <DecimalPrecisionSelector\n data-testid=\"decimal-precision-selector\"\n precision={formatProps.precision ?? 0}\n onChange={handlePrecisionChange}\n />\n )}\n </>\n );\n}\n"]}
@@ -16,11 +16,11 @@ import { SvgProgressForward } from "@itwin/itwinui-icons-react";
16
16
  */
17
17
  export function FormatSample(props) {
18
18
  const { initialMagnitude, formatSpec, hideLabels } = props;
19
- const initialValue = initialMagnitude ?? 0;
19
+ const initialValue = initialMagnitude !== null && initialMagnitude !== void 0 ? initialMagnitude : 0;
20
20
  const [magnitude, setMagnitude] = React.useState(initialValue);
21
21
  const [sampleValue, setSampleValue] = React.useState(initialValue.toString());
22
22
  React.useEffect(() => {
23
- const value = initialMagnitude ?? 0;
23
+ const value = initialMagnitude !== null && initialMagnitude !== void 0 ? initialMagnitude : 0;
24
24
  setMagnitude(value);
25
25
  setSampleValue(value.toString());
26
26
  }, [initialMagnitude]);
@@ -1 +1 @@
1
- {"version":3,"file":"FormatSample.js","sourceRoot":"","sources":["../../../../src/imodel-components-react/quantityformat/FormatSample.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAWhE;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,KAAwB;IACnD,MAAM,EAAE,gBAAgB,EAAE,UAAU,EAAE,UAAU,EAAE,GAAG,KAAK,CAAC;IAC3D,MAAM,YAAY,GAAG,gBAAgB,IAAI,CAAC,CAAC;IAC3C,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;IAC/D,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC,CAAC;IAE9E,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,MAAM,KAAK,GAAG,gBAAgB,IAAI,CAAC,CAAC;QACpC,YAAY,CAAC,KAAK,CAAC,CAAC;QACpB,cAAc,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;IACnC,CAAC,EAAE,CAAC,gBAAgB,CAAC,CAAC,CAAC;IAEvB,MAAM,iBAAiB,GAAG,KAAK,CAAC,WAAW,CAAC,GAAG,EAAE;QAC/C,IAAI,QAAQ,GAAG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AAC,CAC5D,CAAC;IACF,MAAM,cAAc,GAAG,KAAK,CAAC,MAAM,CACjC,kBAAkB,CAAC,SAAS,CAAC,iCAAiC,CAAC,CAChE,CAAC;IAEF,OAAO,CACL;QACG,CAAC,UAAU,IAAI,CACd,8BAAM,SAAS,EAAE,cAAc,IAAG,UAAU,CAAC,OAAO,CAAQ,CAC7D;QACD,8BAAM,SAAS,EAAC,mBAAmB;YACjC,oBAAC,KAAK,mBACQ,qBAAqB,EACjC,SAAS,EAAE,uCAAuC,EAClD,KAAK,EAAE,WAAW,EAClB,QAAQ,EAAE,mBAAmB,EAC7B,SAAS,EAAE,aAAa,EACxB,MAAM,EAAE,iBAAiB,EACzB,IAAI,EAAC,OAAO,GACZ;YACD,0BAA0B,CACtB;QACN,CAAC,UAAU,IAAI,CACd,8BAAM,SAAS,EAAE,cAAc,IAAG,cAAc,CAAC,OAAO,CAAQ,CACjE;QACD,6CAAkB,kBAAkB;YACjC,UAAU,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,IAAI,CAC1C,oBAAC,IAAI,IAAC,QAAQ,EAAE,oBAAC,kBAAkB,OAAG,GAAI,CAC3C;YACD,6CACc,yBAAyB,EACrC,SAAS,EAAE,mDAAmD,IAE7D,cAAc,CACV,CACF,CACN,CACJ,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 QuantityFormat\n */\n\nimport * as React from \"react\";\nimport type { FormatterSpec } from \"@itwin/core-quantity\";\nimport { SpecialKey } from \"@itwin/appui-abstract\";\nimport type { CommonProps } from \"@itwin/core-react\";\nimport { Icon } from \"@itwin/core-react\";\nimport { Input } from \"@itwin/itwinui-react\";\nimport { UiIModelComponents } from \"../UiIModelComponents\";\nimport { SvgProgressForward } from \"@itwin/itwinui-icons-react\";\n\n/** Properties of [[FormatSample]] component.\n * @alpha\n */\nexport interface FormatSampleProps extends CommonProps {\n formatSpec?: FormatterSpec;\n initialMagnitude?: number;\n hideLabels?: boolean;\n}\n\n/** Component to show the persistence value and formatted value given a FormatterSpec.\n * @alpha\n */\nexport function FormatSample(props: FormatSampleProps) {\n const { initialMagnitude, formatSpec, hideLabels } = props;\n const initialValue = initialMagnitude ?? 0;\n const [magnitude, setMagnitude] = React.useState(initialValue);\n const [sampleValue, setSampleValue] = React.useState(initialValue.toString());\n\n React.useEffect(() => {\n const value = initialMagnitude ?? 0;\n setMagnitude(value);\n setSampleValue(value.toString());\n }, [initialMagnitude]);\n\n const handleOnValueBlur = React.useCallback(() => {\n let newValue = Number.parseFloat(sampleValue);\n if (Number.isNaN(newValue)) newValue = 0;\n setMagnitude(newValue);\n setSampleValue(newValue.toString());\n }, [sampleValue]);\n\n const handleOnValueChange = React.useCallback(\n (event: React.ChangeEvent<HTMLInputElement>) => {\n setSampleValue(event.target.value);\n },\n []\n );\n\n const handleKeyDown = React.useCallback(\n (e: React.KeyboardEvent<HTMLInputElement>) => {\n // istanbul ignore else\n if (e.key === SpecialKey.Enter) {\n let newValue = Number.parseFloat(sampleValue);\n if (Number.isNaN(newValue)) newValue = 0;\n setMagnitude(newValue);\n setSampleValue(newValue.toString());\n e.preventDefault();\n }\n },\n [sampleValue]\n );\n\n const activePersistenceUnitLabel = formatSpec\n ? formatSpec.persistenceUnit.label\n : \"\";\n const formattedValue = formatSpec\n ? formatSpec.applyFormatting(magnitude)\n : \"\";\n\n const valueLabel = React.useRef(\n UiIModelComponents.translate(\"QuantityFormat.labels.value\")\n );\n const formattedLabel = React.useRef(\n UiIModelComponents.translate(\"QuantityFormat.labels.formatted\")\n );\n\n return (\n <>\n {!hideLabels && (\n <span className={\"uicore-label\"}>{valueLabel.current}</span>\n )}\n <span className=\"components-inline\">\n <Input\n data-testid=\"format-sample-input\"\n className={\"components-quantity-persistence-input\"}\n value={sampleValue}\n onChange={handleOnValueChange}\n onKeyDown={handleKeyDown}\n onBlur={handleOnValueBlur}\n size=\"small\"\n />\n {activePersistenceUnitLabel}\n </span>\n {!hideLabels && (\n <span className={\"uicore-label\"}>{formattedLabel.current}</span>\n )}\n <span data-testid=\"progress-forward\">\n {hideLabels && formattedValue.length > 0 && (\n <Icon iconSpec={<SvgProgressForward />} />\n )}\n <span\n data-testid=\"format-sample-formatted\"\n className={\"uicore-label components-quantity-formatted-sample\"}\n >\n {formattedValue}\n </span>\n </span>\n </>\n );\n}\n"]}
1
+ {"version":3,"file":"FormatSample.js","sourceRoot":"","sources":["../../../../src/imodel-components-react/quantityformat/FormatSample.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAWhE;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,KAAwB;IACnD,MAAM,EAAE,gBAAgB,EAAE,UAAU,EAAE,UAAU,EAAE,GAAG,KAAK,CAAC;IAC3D,MAAM,YAAY,GAAG,gBAAgB,aAAhB,gBAAgB,cAAhB,gBAAgB,GAAI,CAAC,CAAC;IAC3C,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;IAC/D,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC,CAAC;IAE9E,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,MAAM,KAAK,GAAG,gBAAgB,a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QAC3C,CAAC,CAAC,UAAU,CAAC,eAAe,CAAC,KAAK;QAClC,CAAC,CAAC,EAAE,CAAC;IACP,MAAM,cAAc,GAAG,UAAU;QAC/B,CAAC,CAAC,UAAU,CAAC,eAAe,CAAC,SAAS,CAAC;QACvC,CAAC,CAAC,EAAE,CAAC;IAEP,MAAM,UAAU,GAAG,KAAK,CAAC,MAAM,CAC7B,kBAAkB,CAAC,SAAS,CAAC,6BAA6B,CAAC,CAC5D,CAAC;IACF,MAAM,cAAc,GAAG,KAAK,CAAC,MAAM,CACjC,kBAAkB,CAAC,SAAS,CAAC,iCAAiC,CAAC,CAChE,CAAC;IAEF,OAAO,CACL;QACG,CAAC,UAAU,IAAI,CACd,8BAAM,SAAS,EAAE,cAAc,IAAG,UAAU,CAAC,OAAO,CAAQ,CAC7D;QACD,8BAAM,SAAS,EAAC,mBAAmB;YACjC,oBAAC,KAAK,mBACQ,qBAAqB,EACjC,SAAS,EAAE,uCAAuC,EAClD,KAAK,EAAE,WAAW,EAClB,QAAQ,EAAE,mBAAmB,EAC7B,SAAS,EAAE,aAAa,EACxB,MAAM,EAAE,iBAAiB,EACzB,IAAI,EAAC,OAAO,GACZ;YACD,0BAA0B,CACtB;QACN,CAAC,UAAU,IAAI,CACd,8BAAM,SAAS,EAAE,cAAc,IAAG,cAAc,CAAC,OAAO,CAAQ,CACjE;QACD,6CAAkB,kBAAkB;YACjC,UAAU,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,IAAI,CAC1C,oBAAC,IAAI,IAAC,QAAQ,EAAE,oBAAC,kBAAkB,OAAG,GAAI,CAC3C;YACD,6CACc,yBAAyB,EACrC,SAAS,EAAE,mDAAmD,IAE7D,cAAc,CACV,CACF,CACN,CACJ,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 QuantityFormat\n */\n\nimport * as React from \"react\";\nimport type { FormatterSpec } from \"@itwin/core-quantity\";\nimport { SpecialKey } from \"@itwin/appui-abstract\";\nimport type { CommonProps } from \"@itwin/core-react\";\nimport { Icon } from \"@itwin/core-react\";\nimport { Input } from \"@itwin/itwinui-react\";\nimport { UiIModelComponents } from \"../UiIModelComponents\";\nimport { SvgProgressForward } from \"@itwin/itwinui-icons-react\";\n\n/** Properties of [[FormatSample]] component.\n * @alpha\n */\nexport interface FormatSampleProps extends CommonProps {\n formatSpec?: FormatterSpec;\n initialMagnitude?: number;\n hideLabels?: boolean;\n}\n\n/** Component to show the persistence value and formatted value given a FormatterSpec.\n * @alpha\n */\nexport function FormatSample(props: FormatSampleProps) {\n const { initialMagnitude, formatSpec, hideLabels } = props;\n const initialValue = initialMagnitude ?? 0;\n const [magnitude, setMagnitude] = React.useState(initialValue);\n const [sampleValue, setSampleValue] = React.useState(initialValue.toString());\n\n React.useEffect(() => {\n const value = initialMagnitude ?? 0;\n setMagnitude(value);\n setSampleValue(value.toString());\n }, [initialMagnitude]);\n\n const handleOnValueBlur = React.useCallback(() => {\n let newValue = Number.parseFloat(sampleValue);\n if (Number.isNaN(newValue)) newValue = 0;\n setMagnitude(newValue);\n setSampleValue(newValue.toString());\n }, [sampleValue]);\n\n const handleOnValueChange = React.useCallback(\n (event: React.ChangeEvent<HTMLInputElement>) => {\n setSampleValue(event.target.value);\n },\n []\n );\n\n const handleKeyDown = React.useCallback(\n (e: React.KeyboardEvent<HTMLInputElement>) => {\n // istanbul ignore else\n if (e.key === SpecialKey.Enter) {\n let newValue = Number.parseFloat(sampleValue);\n if (Number.isNaN(newValue)) newValue = 0;\n setMagnitude(newValue);\n setSampleValue(newValue.toString());\n e.preventDefault();\n }\n },\n [sampleValue]\n );\n\n const activePersistenceUnitLabel = formatSpec\n ? formatSpec.persistenceUnit.label\n : \"\";\n const formattedValue = formatSpec\n ? formatSpec.applyFormatting(magnitude)\n : \"\";\n\n const valueLabel = React.useRef(\n UiIModelComponents.translate(\"QuantityFormat.labels.value\")\n );\n const formattedLabel = React.useRef(\n UiIModelComponents.translate(\"QuantityFormat.labels.formatted\")\n );\n\n return (\n <>\n {!hideLabels && (\n <span className={\"uicore-label\"}>{valueLabel.current}</span>\n )}\n <span className=\"components-inline\">\n <Input\n data-testid=\"format-sample-input\"\n className={\"components-quantity-persistence-input\"}\n value={sampleValue}\n onChange={handleOnValueChange}\n onKeyDown={handleKeyDown}\n onBlur={handleOnValueBlur}\n size=\"small\"\n />\n {activePersistenceUnitLabel}\n </span>\n {!hideLabels && (\n <span className={\"uicore-label\"}>{formattedLabel.current}</span>\n )}\n <span data-testid=\"progress-forward\">\n {hideLabels && formattedValue.length > 0 && (\n <Icon iconSpec={<SvgProgressForward />} />\n )}\n <span\n data-testid=\"format-sample-formatted\"\n className={\"uicore-label components-quantity-formatted-sample\"}\n >\n {formattedValue}\n </span>\n </span>\n </>\n );\n}\n"]}
@@ -43,6 +43,7 @@ function FormatTypeSelector(props) {
43
43
  export function FormatTypeOption(props) {
44
44
  const { formatProps, onChange } = props;
45
45
  const handleFormatTypeChange = React.useCallback((newType) => {
46
+ var _a;
46
47
  const type = formatTypeToString(newType);
47
48
  let precision;
48
49
  let stationOffsetSize;
@@ -58,9 +59,7 @@ export function FormatTypeOption(props) {
58
59
  break;
59
60
  case FormatType.Station:
60
61
  precision = DecimalPrecision.Two;
61
- stationOffsetSize = formatProps.composite?.units[0].name
62
- .toLocaleLowerCase()
63
- .endsWith("m")
62
+ stationOffsetSize = ((_a = formatProps.composite) === null || _a === void 0 ? void 0 : _a.units[0].name.toLocaleLowerCase().endsWith("m"))
64
63
  ? 3
65
64
  : 2;
66
65
  break;
@@ -1 +1 @@
1
- {"version":3,"file":"FormatType.js","sourceRoot":"","sources":["../../../../src/imodel-components-react/quantityformat/FormatType.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAA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;IAC/D,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CACxB,kBAAkB,CAAC,SAAS,CAAC,4BAA4B,CAAC,CAC3D,CAAC;IAEF,OAAO,CACL;QACE,8BAAM,SAAS,EAAE,sBAAsB,IAAG,KAAK,CAAC,OAAO,CAAQ;QAC/D,oBAAC,kBAAkB,mBACL,sBAAsB,EAClC,IAAI,EAAE,UAAU,EAChB,QAAQ,EAAE,sBAAsB,GAChC,CACD,CACJ,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 QuantityFormat\n */\n\nimport * as React from \"react\";\nimport type { CommonProps } from \"@itwin/core-react\";\nimport { UiIModelComponents } from \"../UiIModelComponents\";\nimport type { FormatProps } from \"@itwin/core-quantity\";\nimport {\n DecimalPrecision,\n FormatType,\n formatTypeToString,\n FractionalPrecision,\n parseFormatType,\n ScientificType,\n scientificTypeToString,\n} from \"@itwin/core-quantity\";\nimport type { SelectOption } from \"@itwin/itwinui-react\";\nimport { Select } from \"@itwin/itwinui-react\";\n\n/** Properties of [[FormatTypeSelector]] component.\n * @alpha\n */\ninterface FormatTypeSelectorProps extends CommonProps {\n type: FormatType;\n onChange: (value: FormatType) => void;\n}\n\n/** Component to select the format type.\n * @alpha\n */\nfunction FormatTypeSelector(props: FormatTypeSelectorProps) {\n const { type, onChange, ...otherProps } = props;\n const formatOptions = React.useRef<SelectOption<FormatType>[]>([\n {\n value: FormatType.Decimal,\n label: UiIModelComponents.translate(\"QuantityFormat.decimal\"),\n },\n {\n value: FormatType.Scientific,\n label: UiIModelComponents.translate(\"QuantityFormat.scientific\"),\n },\n {\n value: FormatType.Station,\n label: UiIModelComponents.translate(\"QuantityFormat.station\"),\n },\n {\n value: FormatType.Fractional,\n label: UiIModelComponents.translate(\"QuantityFormat.fractional\"),\n },\n ]);\n\n const handleOnChange = React.useCallback(\n (newValue: FormatType) => {\n onChange && onChange(newValue);\n },\n [onChange]\n );\n\n return (\n <Select\n options={formatOptions.current}\n value={type}\n onChange={handleOnChange}\n size=\"small\"\n {...otherProps}\n />\n );\n}\n\n/** Properties of [[FormatTypeOptionProps]] component.\n * @alpha\n */\nexport interface FormatTypeOptionProps extends CommonProps {\n formatProps: FormatProps;\n onChange?: (format: FormatProps) => void;\n}\n\n/** Component to set the Quantity Format type.\n * @alpha\n */\nexport function FormatTypeOption(props: FormatTypeOptionProps) {\n const { formatProps, onChange } = props;\n const handleFormatTypeChange = React.useCallback(\n (newType: FormatType) => {\n const type = formatTypeToString(newType);\n let precision: number | undefined;\n let stationOffsetSize: number | undefined;\n let scientificType: string | undefined;\n switch (\n newType // type must be decimal, fractional, scientific, or station\n ) {\n case FormatType.Scientific:\n precision = DecimalPrecision.Six;\n scientificType = scientificTypeToString(ScientificType.Normalized);\n break;\n case FormatType.Decimal:\n precision = DecimalPrecision.Four;\n break;\n case FormatType.Station:\n precision = DecimalPrecision.Two;\n stationOffsetSize = formatProps.composite?.units[0].name\n .toLocaleLowerCase()\n .endsWith(\"m\")\n ? 3\n : 2;\n break;\n case FormatType.Fractional:\n precision = FractionalPrecision.Eight;\n break;\n }\n const newFormatProps = {\n ...formatProps,\n type,\n precision,\n scientificType,\n stationOffsetSize,\n };\n onChange && onChange(newFormatProps);\n },\n [formatProps, onChange]\n );\n\n const formatType = parseFormatType(formatProps.type, \"format\");\n const label = React.useRef(\n UiIModelComponents.translate(\"QuantityFormat.labels.type\")\n );\n\n return (\n <>\n <span className={\"uicore-label.current\"}>{label.current}</span>\n <FormatTypeSelector\n data-testid=\"format-type-selector\"\n type={formatType}\n onChange={handleFormatTypeChange}\n />\n </>\n );\n}\n"]}
1
+ {"version":3,"file":"FormatType.js","sourceRoot":"","sources":["../../../../src/imodel-components-react/quantityformat/FormatType.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GA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,WAAW,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAC/D,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CACxB,kBAAkB,CAAC,SAAS,CAAC,4BAA4B,CAAC,CAC3D,CAAC;IAEF,OAAO,CACL;QACE,8BAAM,SAAS,EAAE,sBAAsB,IAAG,KAAK,CAAC,OAAO,CAAQ;QAC/D,oBAAC,kBAAkB,mBACL,sBAAsB,EAClC,IAAI,EAAE,UAAU,EAChB,QAAQ,EAAE,sBAAsB,GAChC,CACD,CACJ,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 QuantityFormat\n */\n\nimport * as React from \"react\";\nimport type { CommonProps } from \"@itwin/core-react\";\nimport { UiIModelComponents } from \"../UiIModelComponents\";\nimport type { FormatProps } from \"@itwin/core-quantity\";\nimport {\n DecimalPrecision,\n FormatType,\n formatTypeToString,\n FractionalPrecision,\n parseFormatType,\n ScientificType,\n scientificTypeToString,\n} from \"@itwin/core-quantity\";\nimport type { SelectOption } from \"@itwin/itwinui-react\";\nimport { Select } from \"@itwin/itwinui-react\";\n\n/** Properties of [[FormatTypeSelector]] component.\n * @alpha\n */\ninterface FormatTypeSelectorProps extends CommonProps {\n type: FormatType;\n onChange: (value: FormatType) => void;\n}\n\n/** Component to select the format type.\n * @alpha\n */\nfunction FormatTypeSelector(props: FormatTypeSelectorProps) {\n const { type, onChange, ...otherProps } = props;\n const formatOptions = React.useRef<SelectOption<FormatType>[]>([\n {\n value: FormatType.Decimal,\n label: UiIModelComponents.translate(\"QuantityFormat.decimal\"),\n },\n {\n value: FormatType.Scientific,\n label: UiIModelComponents.translate(\"QuantityFormat.scientific\"),\n },\n {\n value: FormatType.Station,\n label: UiIModelComponents.translate(\"QuantityFormat.station\"),\n },\n {\n value: FormatType.Fractional,\n label: UiIModelComponents.translate(\"QuantityFormat.fractional\"),\n },\n ]);\n\n const handleOnChange = React.useCallback(\n (newValue: FormatType) => {\n onChange && onChange(newValue);\n },\n [onChange]\n );\n\n return (\n <Select\n options={formatOptions.current}\n value={type}\n onChange={handleOnChange}\n size=\"small\"\n {...otherProps}\n />\n );\n}\n\n/** Properties of [[FormatTypeOptionProps]] component.\n * @alpha\n */\nexport interface FormatTypeOptionProps extends CommonProps {\n formatProps: FormatProps;\n onChange?: (format: FormatProps) => void;\n}\n\n/** Component to set the Quantity Format type.\n * @alpha\n */\nexport function FormatTypeOption(props: FormatTypeOptionProps) {\n const { formatProps, onChange } = props;\n const handleFormatTypeChange = React.useCallback(\n (newType: FormatType) => {\n const type = formatTypeToString(newType);\n let precision: number | undefined;\n let stationOffsetSize: number | undefined;\n let scientificType: string | undefined;\n switch (\n newType // type must be decimal, fractional, scientific, or station\n ) {\n case FormatType.Scientific:\n precision = DecimalPrecision.Six;\n scientificType = scientificTypeToString(ScientificType.Normalized);\n break;\n case FormatType.Decimal:\n precision = DecimalPrecision.Four;\n break;\n case FormatType.Station:\n precision = DecimalPrecision.Two;\n stationOffsetSize = formatProps.composite?.units[0].name\n .toLocaleLowerCase()\n .endsWith(\"m\")\n ? 3\n : 2;\n break;\n case FormatType.Fractional:\n precision = FractionalPrecision.Eight;\n break;\n }\n const newFormatProps = {\n ...formatProps,\n type,\n precision,\n scientificType,\n stationOffsetSize,\n };\n onChange && onChange(newFormatProps);\n },\n [formatProps, onChange]\n );\n\n const formatType = parseFormatType(formatProps.type, \"format\");\n const label = React.useRef(\n UiIModelComponents.translate(\"QuantityFormat.labels.type\")\n );\n\n return (\n <>\n <span className={\"uicore-label.current\"}>{label.current}</span>\n <FormatTypeSelector\n data-testid=\"format-type-selector\"\n type={formatType}\n onChange={handleFormatTypeChange}\n />\n </>\n );\n}\n"]}
@@ -36,6 +36,7 @@ function UomSeparatorSelector(props) {
36
36
  * @alpha
37
37
  */
38
38
  export function FormatUnitLabel(props) {
39
+ var _a;
39
40
  const { formatProps, onUnitLabelChange } = props;
40
41
  const handleSetFormatProps = React.useCallback((newProps) => {
41
42
  onUnitLabelChange && onUnitLabelChange(newProps);
@@ -85,6 +86,6 @@ export function FormatUnitLabel(props) {
85
86
  React.createElement("span", { className: "uicore-label" }, appendUnitLabel.current),
86
87
  React.createElement(Checkbox, { "data-testid": "show-unit-label-checkbox", checked: isFormatTraitSet(FormatTraits.ShowUnitLabel), onChange: handleShowUnitLabelChange }),
87
88
  React.createElement("span", { className: classnames("uicore-label", !isFormatTraitSet(FormatTraits.ShowUnitLabel) && "uicore-disabled") }, labelSeparator.current),
88
- React.createElement(UomSeparatorSelector, { "data-testid": "uom-separator-select", separator: formatProps.uomSeparator ?? "", onChange: handleUomSeparatorChange, disabled: !isFormatTraitSet(FormatTraits.ShowUnitLabel) })));
89
+ React.createElement(UomSeparatorSelector, { "data-testid": "uom-separator-select", separator: (_a = formatProps.uomSeparator) !== null && _a !== void 0 ? _a : "", onChange: handleUomSeparatorChange, disabled: !isFormatTraitSet(FormatTraits.ShowUnitLabel) })));
89
90
  }
90
91
  //# sourceMappingURL=FormatUnitLabel.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"FormatUnitLabel.js","sourceRoot":"","sources":["../../../../src/imodel-components-react/quantityformat/FormatUnitLabel.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE5E,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAQ3D,SAAS,oBAAoB,CAAC,KAAgC;IAC5D,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,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E,oBAAC,QAAQ,mBACK,0BAA0B,EACtC,OAAO,EAAE,gBAAgB,CAAC,YAAY,CAAC,aAAa,CAAC,EACrD,QAAQ,EAAE,yBAAyB,GACnC;QACF,8BACE,SAAS,EAAE,UAAU,CACnB,cAAc,EACd,CAAC,gBAAgB,CAAC,YAAY,CAAC,aAAa,CAAC,IAAI,iBAAiB,CACnE,IAEA,cAAc,CAAC,OAAO,CAClB;QACP,oBAAC,oBAAoB,mBACP,sBAAsB,EAClC,SAAS,EAAE,WAAW,CAAC,YAAY,IAAI,EAAE,EACzC,QAAQ,EAAE,wBAAwB,EAClC,QAAQ,EAAE,CAAC,gBAAgB,CAAC,YAAY,CAAC,aAAa,CAAC,GACvD,CACD,CACJ,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 QuantityFormat\n */\n\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport type { CommonProps } from \"@itwin/core-react\";\nimport type { FormatProps } from \"@itwin/core-quantity\";\nimport { Format, FormatTraits, getTraitString } from \"@itwin/core-quantity\";\nimport type { SelectOption } from \"@itwin/itwinui-react\";\nimport { Checkbox, Select } from \"@itwin/itwinui-react\";\nimport { UiIModelComponents } from \"../UiIModelComponents\";\n\ninterface UomSeparatorSelectorProps extends CommonProps {\n separator: string;\n disabled?: boolean;\n onChange: (value: string) => void;\n}\n\nfunction UomSeparatorSelector(props: UomSeparatorSelectorProps) {\n const { separator, onChange, ...otherProps } = props;\n const uomDefaultEntries = React.useRef<SelectOption<string>[]>([\n { value: \"\", label: UiIModelComponents.translate(\"QuantityFormat.none\") },\n { value: \" \", label: UiIModelComponents.translate(\"QuantityFormat.space\") },\n { value: \"-\", label: UiIModelComponents.translate(\"QuantityFormat.dash\") },\n ]);\n\n const handleOnChange = React.useCallback(\n (newValue: string) => {\n onChange && onChange(newValue);\n },\n [onChange]\n );\n\n const separatorOptions = React.useMemo(() => {\n const completeListOfEntries: SelectOption<string>[] = [];\n // istanbul ignore next (only used if format already has a character that does not match standard options)\n if (\n undefined ===\n uomDefaultEntries.current.find((option) => option.value === separator)\n ) {\n completeListOfEntries.push({ value: separator, label: separator });\n }\n completeListOfEntries.push(...uomDefaultEntries.current);\n return completeListOfEntries;\n }, [separator]);\n\n return (\n <Select\n options={separatorOptions}\n value={separator}\n onChange={handleOnChange}\n size=\"small\"\n {...otherProps}\n />\n );\n}\n\n/** Properties of [[FormatUnitLabel]] component.\n * @alpha\n */\nexport interface FormatUnitLabelProps extends CommonProps {\n formatProps: FormatProps;\n onUnitLabelChange?: (format: FormatProps) => void;\n}\n\n/** Component to set the label separator definition in a Quantity Format and if it the label is to be displayed.\n * @alpha\n */\nexport function FormatUnitLabel(props: FormatUnitLabelProps) {\n const { formatProps, onUnitLabelChange } = props;\n\n const handleSetFormatProps = React.useCallback(\n (newProps: FormatProps) => {\n onUnitLabelChange && onUnitLabelChange(newProps);\n },\n [onUnitLabelChange]\n );\n\n const isFormatTraitSet = React.useCallback(\n (trait: FormatTraits) => {\n return Format.isFormatTraitSetInProps(formatProps, trait);\n },\n [formatProps]\n );\n\n const setFormatTrait = React.useCallback(\n (trait: FormatTraits, setActive: boolean) => {\n const traitStr = getTraitString(trait);\n let formatTraits: string[] = [traitStr];\n if (setActive) {\n // setting trait\n // istanbul ignore else\n if (formatProps.formatTraits) {\n const traits = Array.isArray(formatProps.formatTraits)\n ? formatProps.formatTraits\n : /* istanbul ignore next */ formatProps.formatTraits.split(\n /,|;|\\|/\n );\n // istanbul ignore else\n if (!traits.find((traitEntry) => traitStr === traitEntry)) {\n formatTraits = [...traits, traitStr];\n }\n }\n } else {\n // clearing trait\n // istanbul ignore next\n if (!formatProps.formatTraits) return;\n const traits = Array.isArray(formatProps.formatTraits)\n ? formatProps.formatTraits\n : /* istanbul ignore next */ formatProps.formatTraits.split(/,|;|\\|/);\n formatTraits = traits.filter((traitEntry) => traitEntry !== traitStr);\n }\n const newFormatProps = { ...formatProps, formatTraits };\n handleSetFormatProps(newFormatProps);\n },\n [formatProps, handleSetFormatProps]\n );\n\n const handleUomSeparatorChange = React.useCallback(\n (newSeparator: string) => {\n const newFormatProps = { ...formatProps, uomSeparator: newSeparator };\n handleSetFormatProps(newFormatProps);\n },\n [formatProps, handleSetFormatProps]\n );\n\n const handleShowUnitLabelChange = React.useCallback(\n (e: React.ChangeEvent<HTMLInputElement>) => {\n setFormatTrait(FormatTraits.ShowUnitLabel, e.target.checked);\n },\n [setFormatTrait]\n );\n\n const appendUnitLabel = React.useRef(\n UiIModelComponents.translate(\"QuantityFormat.labels.appendUnitLabel\")\n );\n const labelSeparator = React.useRef(\n UiIModelComponents.translate(\"QuantityFormat.labels.labelSeparator\")\n );\n\n return (\n <>\n <span className={\"uicore-label\"}>{appendUnitLabel.current}</span>\n <Checkbox\n data-testid=\"show-unit-label-checkbox\"\n checked={isFormatTraitSet(FormatTraits.ShowUnitLabel)}\n onChange={handleShowUnitLabelChange}\n />\n <span\n className={classnames(\n \"uicore-label\",\n !isFormatTraitSet(FormatTraits.ShowUnitLabel) && \"uicore-disabled\"\n )}\n >\n {labelSeparator.current}\n </span>\n <UomSeparatorSelector\n data-testid=\"uom-separator-select\"\n separator={formatProps.uomSeparator ?? \"\"}\n onChange={handleUomSeparatorChange}\n disabled={!isFormatTraitSet(FormatTraits.ShowUnitLabel)}\n />\n </>\n );\n}\n"]}
1
+ {"version":3,"file":"FormatUnitLabel.js","sourceRoot":"","sources":["../../../../src/imodel-components-react/quantityformat/FormatUnitLabel.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE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C,CAAC,CACtE,CAAC;IACF,MAAM,cAAc,GAAG,KAAK,CAAC,MAAM,CACjC,kBAAkB,CAAC,SAAS,CAAC,sCAAsC,CAAC,CACrE,CAAC;IAEF,OAAO,CACL;QACE,8BAAM,SAAS,EAAE,cAAc,IAAG,eAAe,CAAC,OAAO,CAAQ;QACjE,oBAAC,QAAQ,mBACK,0BAA0B,EACtC,OAAO,EAAE,gBAAgB,CAAC,YAAY,CAAC,aAAa,CAAC,EACrD,QAAQ,EAAE,yBAAyB,GACnC;QACF,8BACE,SAAS,EAAE,UAAU,CACnB,cAAc,EACd,CAAC,gBAAgB,CAAC,YAAY,CAAC,aAAa,CAAC,IAAI,iBAAiB,CACnE,IAEA,cAAc,CAAC,OAAO,CAClB;QACP,oBAAC,oBAAoB,mBACP,sBAAsB,EAClC,SAAS,EAAE,MAAA,WAAW,CAAC,YAAY,mCAAI,EAAE,EACzC,QAAQ,EAAE,wBAAwB,EAClC,QAAQ,EAAE,CAAC,gBAAgB,CAAC,YAAY,CAAC,aAAa,CAAC,GACvD,CACD,CACJ,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 QuantityFormat\n */\n\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport type { CommonProps } from \"@itwin/core-react\";\nimport type { FormatProps } from \"@itwin/core-quantity\";\nimport { Format, FormatTraits, getTraitString } from \"@itwin/core-quantity\";\nimport type { SelectOption } from \"@itwin/itwinui-react\";\nimport { Checkbox, Select } from \"@itwin/itwinui-react\";\nimport { UiIModelComponents } from \"../UiIModelComponents\";\n\ninterface UomSeparatorSelectorProps extends CommonProps {\n separator: string;\n disabled?: boolean;\n onChange: (value: string) => void;\n}\n\nfunction UomSeparatorSelector(props: UomSeparatorSelectorProps) {\n const { separator, onChange, ...otherProps } = props;\n const uomDefaultEntries = React.useRef<SelectOption<string>[]>([\n { value: \"\", label: UiIModelComponents.translate(\"QuantityFormat.none\") },\n { value: \" \", label: UiIModelComponents.translate(\"QuantityFormat.space\") },\n { value: \"-\", label: UiIModelComponents.translate(\"QuantityFormat.dash\") },\n ]);\n\n const handleOnChange = React.useCallback(\n (newValue: string) => {\n onChange && onChange(newValue);\n },\n [onChange]\n );\n\n const separatorOptions = React.useMemo(() => {\n const completeListOfEntries: SelectOption<string>[] = [];\n // istanbul ignore next (only used if format already has a character that does not match standard options)\n if (\n undefined ===\n uomDefaultEntries.current.find((option) => option.value === separator)\n ) {\n completeListOfEntries.push({ value: separator, label: separator });\n }\n completeListOfEntries.push(...uomDefaultEntries.current);\n return completeListOfEntries;\n }, [separator]);\n\n return (\n <Select\n options={separatorOptions}\n value={separator}\n onChange={handleOnChange}\n size=\"small\"\n {...otherProps}\n />\n );\n}\n\n/** Properties of [[FormatUnitLabel]] component.\n * @alpha\n */\nexport interface FormatUnitLabelProps extends CommonProps {\n formatProps: FormatProps;\n onUnitLabelChange?: (format: FormatProps) => void;\n}\n\n/** Component to set the label separator definition in a Quantity Format and if it the label is to be displayed.\n * @alpha\n */\nexport function FormatUnitLabel(props: FormatUnitLabelProps) {\n const { formatProps, onUnitLabelChange } = props;\n\n const handleSetFormatProps = React.useCallback(\n (newProps: FormatProps) => {\n onUnitLabelChange && onUnitLabelChange(newProps);\n },\n [onUnitLabelChange]\n );\n\n const isFormatTraitSet = React.useCallback(\n (trait: FormatTraits) => {\n return Format.isFormatTraitSetInProps(formatProps, trait);\n },\n [formatProps]\n );\n\n const setFormatTrait = React.useCallback(\n (trait: FormatTraits, setActive: boolean) => {\n const traitStr = getTraitString(trait);\n let formatTraits: string[] = [traitStr];\n if (setActive) {\n // setting trait\n // istanbul ignore else\n if (formatProps.formatTraits) {\n const traits = Array.isArray(formatProps.formatTraits)\n ? formatProps.formatTraits\n : /* istanbul ignore next */ formatProps.formatTraits.split(\n /,|;|\\|/\n );\n // istanbul ignore else\n if (!traits.find((traitEntry) => traitStr === traitEntry)) {\n formatTraits = [...traits, traitStr];\n }\n }\n } else {\n // clearing trait\n // istanbul ignore next\n if (!formatProps.formatTraits) return;\n const traits = Array.isArray(formatProps.formatTraits)\n ? formatProps.formatTraits\n : /* istanbul ignore next */ formatProps.formatTraits.split(/,|;|\\|/);\n formatTraits = traits.filter((traitEntry) => traitEntry !== traitStr);\n }\n const newFormatProps = { ...formatProps, formatTraits };\n handleSetFormatProps(newFormatProps);\n },\n [formatProps, handleSetFormatProps]\n );\n\n const handleUomSeparatorChange = React.useCallback(\n (newSeparator: string) => {\n const newFormatProps = { ...formatProps, uomSeparator: newSeparator };\n handleSetFormatProps(newFormatProps);\n },\n [formatProps, handleSetFormatProps]\n );\n\n const handleShowUnitLabelChange = React.useCallback(\n (e: React.ChangeEvent<HTMLInputElement>) => {\n setFormatTrait(FormatTraits.ShowUnitLabel, e.target.checked);\n },\n [setFormatTrait]\n );\n\n const appendUnitLabel = React.useRef(\n UiIModelComponents.translate(\"QuantityFormat.labels.appendUnitLabel\")\n );\n const labelSeparator = React.useRef(\n UiIModelComponents.translate(\"QuantityFormat.labels.labelSeparator\")\n );\n\n return (\n <>\n <span className={\"uicore-label\"}>{appendUnitLabel.current}</span>\n <Checkbox\n data-testid=\"show-unit-label-checkbox\"\n checked={isFormatTraitSet(FormatTraits.ShowUnitLabel)}\n onChange={handleShowUnitLabelChange}\n />\n <span\n className={classnames(\n \"uicore-label\",\n !isFormatTraitSet(FormatTraits.ShowUnitLabel) && \"uicore-disabled\"\n )}\n >\n {labelSeparator.current}\n </span>\n <UomSeparatorSelector\n data-testid=\"uom-separator-select\"\n separator={formatProps.uomSeparator ?? \"\"}\n onChange={handleUomSeparatorChange}\n disabled={!isFormatTraitSet(FormatTraits.ShowUnitLabel)}\n />\n </>\n );\n}\n"]}
@@ -13,6 +13,7 @@ import { UiIModelComponents } from "../UiIModelComponents";
13
13
  * @alpha
14
14
  */
15
15
  export function FormatUnits(props) {
16
+ var _a, _b, _c;
16
17
  const { initialFormat, persistenceUnit, unitsProvider, onUnitsChange } = props;
17
18
  const initialFormatRef = React.useRef(initialFormat);
18
19
  const [formatProps, setFormatProps] = React.useState(initialFormat);
@@ -106,14 +107,17 @@ export function FormatUnits(props) {
106
107
  }, [formatProps, handleSetFormatProps]);
107
108
  const compositeSpacer = React.useRef(UiIModelComponents.translate("QuantityFormat.labels.compositeSpacer"));
108
109
  return (React.createElement(React.Fragment, null,
109
- formatProps.composite?.units
110
- ? formatProps.composite.units.map((value, index) => (React.createElement(UnitDescr, { key: value.name, name: value.name, label: value.label ?? "", parentUnitName: index > 0
111
- ? formatProps.composite.units[index - 1].name
112
- : undefined, unitsProvider: unitsProvider, index: index, onUnitChange: handleUnitChange, onLabelChange: handleUnitLabelChange, readonly: index < formatProps.composite.units.length - 1 })))
110
+ ((_a = formatProps.composite) === null || _a === void 0 ? void 0 : _a.units)
111
+ ? formatProps.composite.units.map((value, index) => {
112
+ var _a;
113
+ return (React.createElement(UnitDescr, { key: value.name, name: value.name, label: (_a = value.label) !== null && _a !== void 0 ? _a : "", parentUnitName: index > 0
114
+ ? formatProps.composite.units[index - 1].name
115
+ : undefined, unitsProvider: unitsProvider, index: index, onUnitChange: handleUnitChange, onLabelChange: handleUnitLabelChange, readonly: index < formatProps.composite.units.length - 1 }));
116
+ })
113
117
  : persistenceUnit && (React.createElement(UnitDescr, { key: persistenceUnit.name, name: persistenceUnit.name, label: persistenceUnit.label, unitsProvider: unitsProvider, index: 0, onUnitChange: handleUnitChange, onLabelChange: handleUnitLabelChange })),
114
- formatProps.composite?.units &&
118
+ ((_b = formatProps.composite) === null || _b === void 0 ? void 0 : _b.units) &&
115
119
  formatProps.composite.units.length > 1 && (React.createElement(React.Fragment, null,
116
120
  React.createElement("span", { key: "composite-spacer-label", className: "uicore-label" }, compositeSpacer.current),
117
- React.createElement(Input, { key: "composite-spacer", "data-testid": "composite-spacer", value: formatProps.composite.spacer ?? "", onChange: handleOnSpacerChange, size: "small" })))));
121
+ React.createElement(Input, { key: "composite-spacer", "data-testid": "composite-spacer", value: (_c = formatProps.composite.spacer) !== null && _c !== void 0 ? _c : "", onChange: handleOnSpacerChange, size: "small" })))));
118
122
  }
119
123
  //# sourceMappingURL=FormatUnits.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"FormatUnits.js","sourceRoot":"","sources":["../../../../src/imodel-components-react/quantityformat/FormatUnits.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAO/B,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAY3D;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,KAAuB;IACjD,MAAM,EAAE,aAAa,EAAE,eAAe,EAAE,aAAa,EAAE,aAAa,EAAE,GACpE,KAAK,CAAC;IACR,MAAM,gBAAgB,GAAG,KAAK,CAAC,MAAM,CAAc,aAAa,CAAC,CAAC;IAClE,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;IAEpE,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,IAAI,gBAAgB,CAAC,OAAO,KAAK,aAAa,EAAE;YAC9C,gBAAgB,CAAC,OAAO,GAAG,aAAa,CAAC;YACzC,cAAc,CAAC,aAAa,CAAC,CAAC;SAC/B;IACH,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC;IAEpB,MAAM,oBAAoB,GAAG,KAAK,CAAC,WAAW,CAC5C,CAAC,QAAqB,EAAE,EAAE;QACxB,cAAc,CAAC,QAAQ,CAAC,CAAC;QACzB,aAAa,IAAI,aAAa,CAAC,QAAQ,CAAC,CAAC;IAC3C,CAAC,EACD,CA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ACJ,GAAG,EAAE,kBAAkB,iBACX,kBAAkB,EAC9B,KAAK,EAAE,WAAW,CAAC,SAAS,CAAC,MAAM,IAAI,EAAE,EACzC,QAAQ,EAAE,oBAAoB,EAC9B,IAAI,EAAC,OAAO,GACZ,CACD,CACJ,CACF,CACJ,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 QuantityFormat\n */\n\nimport * as React from \"react\";\nimport type { CommonProps } from \"@itwin/core-react\";\nimport type {\n FormatProps,\n UnitProps,\n UnitsProvider,\n} from \"@itwin/core-quantity\";\nimport { Input } from \"@itwin/itwinui-react\";\nimport { UnitDescr } from \"./misc/UnitDescr\";\nimport { UiIModelComponents } from \"../UiIModelComponents\";\n\n/** Properties of [[FormatUnits]] component.\n * @alpha\n */\nexport interface FormatUnitsProps extends CommonProps {\n initialFormat: FormatProps;\n persistenceUnit?: UnitProps;\n unitsProvider: UnitsProvider;\n onUnitsChange?: (format: FormatProps) => void;\n}\n\n/** Component to show/edit Units used for Quantity Formatting.\n * @alpha\n */\nexport function FormatUnits(props: FormatUnitsProps) {\n const { initialFormat, persistenceUnit, unitsProvider, onUnitsChange } =\n props;\n const initialFormatRef = React.useRef<FormatProps>(initialFormat);\n const [formatProps, setFormatProps] = React.useState(initialFormat);\n\n React.useEffect(() => {\n if (initialFormatRef.current !== initialFormat) {\n initialFormatRef.current = initialFormat;\n setFormatProps(initialFormat);\n }\n }, [initialFormat]);\n\n const handleSetFormatProps = React.useCallback(\n (newProps: FormatProps) => {\n setFormatProps(newProps);\n onUnitsChange && onUnitsChange(newProps);\n },\n [onUnitsChange]\n );\n\n const handleUnitLabelChange = React.useCallback(\n (newLabel: string, index: number) => {\n // istanbul ignore else\n if (\n formatProps.composite &&\n formatProps.composite.units.length > index &&\n index >= 0\n ) {\n const units = formatProps.composite.units.map((entry, ndx) => {\n // istanbul ignore else\n if (index === ndx) return { name: entry.name, label: newLabel };\n else return entry;\n });\n\n const composite = { ...formatProps.composite, units };\n const newFormatProps = { ...formatProps, composite };\n handleSetFormatProps(newFormatProps);\n }\n },\n [formatProps, handleSetFormatProps]\n );\n\n const handleUnitChange = React.useCallback(\n (newUnit: string, index: number) => {\n const unitParts = newUnit.split(/:/);\n if (unitParts[0] === \"REMOVEUNIT\") {\n // istanbul ignore else\n if (formatProps.composite && formatProps.composite.units.length > 1) {\n const units = [...formatProps.composite.units];\n units.pop();\n const composite = { ...formatProps.composite, units };\n const newFormatProps = { ...formatProps, composite };\n handleSetFormatProps(newFormatProps);\n }\n } else if (unitParts[0] === \"ADDSUBUNIT\") {\n const units =\n formatProps.composite && formatProps.composite.units.length\n ? [\n ...formatProps.composite.units,\n { name: unitParts[1], label: unitParts[2] },\n ]\n : /* istanbul ignore next*/ [\n { name: unitParts[1], label: unitParts[2] },\n ];\n const composite = { ...formatProps.composite, units };\n const newFormatProps = { ...formatProps, composite };\n handleSetFormatProps(newFormatProps);\n } else {\n // istanbul ignore else\n if (\n formatProps.composite &&\n formatProps.composite.units.length > index &&\n index >= 0\n ) {\n const units = formatProps.composite.units.map((entry, ndx) => {\n // istanbul ignore else\n if (index === ndx)\n return { name: unitParts[0], label: unitParts[1] };\n else return entry;\n });\n const composite = { ...formatProps.composite, units };\n const newFormatProps = { ...formatProps, composite };\n handleSetFormatProps(newFormatProps);\n } else if (!formatProps.composite) {\n const composite = {\n units: [{ name: unitParts[0], label: unitParts[1] }],\n };\n const newFormatProps = { ...formatProps, composite };\n handleSetFormatProps(newFormatProps);\n }\n }\n },\n [formatProps, handleSetFormatProps]\n );\n\n const handleOnSpacerChange = React.useCallback(\n (e: React.ChangeEvent<HTMLInputElement>) => {\n // istanbul ignore else\n if (formatProps.composite) {\n const spacerValue = e.target.value.length\n ? e.target.value[0]\n : /* istanbul ignore next */ \"\"; // spacer can only be empty or a single character\n const composite = { ...formatProps.composite, spacer: spacerValue };\n const newFormatProps = { ...formatProps, composite };\n handleSetFormatProps(newFormatProps);\n }\n },\n [formatProps, handleSetFormatProps]\n );\n\n const compositeSpacer = React.useRef(\n UiIModelComponents.translate(\"QuantityFormat.labels.compositeSpacer\")\n );\n\n return (\n <>\n {formatProps.composite?.units\n ? formatProps.composite.units.map((value, index) => (\n <UnitDescr\n key={value.name}\n name={value.name}\n label={value.label ?? \"\"}\n parentUnitName={\n index > 0\n ? formatProps.composite!.units[index - 1].name\n : undefined\n }\n unitsProvider={unitsProvider}\n index={index}\n onUnitChange={handleUnitChange}\n onLabelChange={handleUnitLabelChange}\n readonly={index < formatProps.composite!.units.length - 1}\n />\n ))\n : persistenceUnit && (\n <UnitDescr\n key={persistenceUnit.name}\n name={persistenceUnit.name}\n label={persistenceUnit.label}\n unitsProvider={unitsProvider}\n index={0}\n onUnitChange={handleUnitChange}\n onLabelChange={handleUnitLabelChange}\n />\n )}\n\n {formatProps.composite?.units &&\n formatProps.composite.units.length > 1 && (\n <>\n <span key={\"composite-spacer-label\"} className={\"uicore-label\"}>\n {compositeSpacer.current}\n </span>\n <Input\n key={\"composite-spacer\"}\n data-testid=\"composite-spacer\"\n value={formatProps.composite.spacer ?? \"\"}\n onChange={handleOnSpacerChange}\n size=\"small\"\n />\n </>\n )}\n </>\n );\n}\n"]}
1
+ {"version":3,"file":"FormatUnits.js","sourceRoot":"","sources":["../../../../src/imodel-components-react/quantityformat/FormatUnits.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAO/B,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAY3D;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,KAAuB;;IACjD,MAAM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AAa,EAC5B,KAAK,EAAE,KAAK,EACZ,YAAY,EAAE,gBAAgB,EAC9B,aAAa,EAAE,qBAAqB,EACpC,QAAQ,EAAE,KAAK,GAAG,WAAW,CAAC,SAAU,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,GACzD,CACH,CAAA;aAAA,CAAC;YACJ,CAAC,CAAC,eAAe,IAAI,CACjB,oBAAC,SAAS,IACR,GAAG,EAAE,eAAe,CAAC,IAAI,EACzB,IAAI,EAAE,eAAe,CAAC,IAAI,EAC1B,KAAK,EAAE,eAAe,CAAC,KAAK,EAC5B,aAAa,EAAE,aAAa,EAC5B,KAAK,EAAE,CAAC,EACR,YAAY,EAAE,gBAAgB,EAC9B,aAAa,EAAE,qBAAqB,GACpC,CACH;QAEJ,CAAA,MAAA,WAAW,CAAC,SAAS,0CAAE,KAAK;YAC3B,WAAW,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,CACxC;YACE,8BAAM,GAAG,EAAE,wBAAwB,EAAE,SAAS,EAAE,cAAc,IAC3D,eAAe,CAAC,OAAO,CACnB;YACP,oBAAC,KAAK,IACJ,GAAG,EAAE,kBAAkB,iBACX,kBAAkB,EAC9B,KAAK,EAAE,MAAA,WAAW,CAAC,SAAS,CAAC,MAAM,mCAAI,EAAE,EACzC,QAAQ,EAAE,oBAAoB,EAC9B,IAAI,EAAC,OAAO,GACZ,CACD,CACJ,CACF,CACJ,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 QuantityFormat\n */\n\nimport * as React from \"react\";\nimport type { CommonProps } from \"@itwin/core-react\";\nimport type {\n FormatProps,\n UnitProps,\n UnitsProvider,\n} from \"@itwin/core-quantity\";\nimport { Input } from \"@itwin/itwinui-react\";\nimport { UnitDescr } from \"./misc/UnitDescr\";\nimport { UiIModelComponents } from \"../UiIModelComponents\";\n\n/** Properties of [[FormatUnits]] component.\n * @alpha\n */\nexport interface FormatUnitsProps extends CommonProps {\n initialFormat: FormatProps;\n persistenceUnit?: UnitProps;\n unitsProvider: UnitsProvider;\n onUnitsChange?: (format: FormatProps) => void;\n}\n\n/** Component to show/edit Units used for Quantity Formatting.\n * @alpha\n */\nexport function FormatUnits(props: FormatUnitsProps) {\n const { initialFormat, persistenceUnit, unitsProvider, onUnitsChange } =\n props;\n const initialFormatRef = React.useRef<FormatProps>(initialFormat);\n const [formatProps, setFormatProps] = React.useState(initialFormat);\n\n React.useEffect(() => {\n if (initialFormatRef.current !== initialFormat) {\n initialFormatRef.current = initialFormat;\n setFormatProps(initialFormat);\n }\n }, [initialFormat]);\n\n const handleSetFormatProps = React.useCallback(\n (newProps: FormatProps) => {\n setFormatProps(newProps);\n onUnitsChange && onUnitsChange(newProps);\n },\n [onUnitsChange]\n );\n\n const handleUnitLabelChange = React.useCallback(\n (newLabel: string, index: number) => {\n // istanbul ignore else\n if (\n formatProps.composite &&\n formatProps.composite.units.length > index &&\n index >= 0\n ) {\n const units = formatProps.composite.units.map((entry, ndx) => {\n // istanbul ignore else\n if (index === ndx) return { name: entry.name, label: newLabel };\n else return entry;\n });\n\n const composite = { ...formatProps.composite, units };\n const newFormatProps = { ...formatProps, composite };\n handleSetFormatProps(newFormatProps);\n }\n },\n [formatProps, handleSetFormatProps]\n );\n\n const handleUnitChange = React.useCallback(\n (newUnit: string, index: number) => {\n const unitParts = newUnit.split(/:/);\n if (unitParts[0] === \"REMOVEUNIT\") {\n // istanbul ignore else\n if (formatProps.composite && formatProps.composite.units.length > 1) {\n const units = [...formatProps.composite.units];\n units.pop();\n const composite = { ...formatProps.composite, units };\n const newFormatProps = { ...formatProps, composite };\n handleSetFormatProps(newFormatProps);\n }\n } else if (unitParts[0] === \"ADDSUBUNIT\") {\n const units =\n formatProps.composite && formatProps.composite.units.length\n ? [\n ...formatProps.composite.units,\n { name: unitParts[1], label: unitParts[2] },\n ]\n : /* istanbul ignore next*/ [\n { name: unitParts[1], label: unitParts[2] },\n ];\n const composite = { ...formatProps.composite, units };\n const newFormatProps = { ...formatProps, composite };\n handleSetFormatProps(newFormatProps);\n } else {\n // istanbul ignore else\n if (\n formatProps.composite &&\n formatProps.composite.units.length > index &&\n index >= 0\n ) {\n const units = formatProps.composite.units.map((entry, ndx) => {\n // istanbul ignore else\n if (index === ndx)\n return { name: unitParts[0], label: unitParts[1] };\n else return entry;\n });\n const composite = { ...formatProps.composite, units };\n const newFormatProps = { ...formatProps, composite };\n handleSetFormatProps(newFormatProps);\n } else if (!formatProps.composite) {\n const composite = {\n units: [{ name: unitParts[0], label: unitParts[1] }],\n };\n const newFormatProps = { ...formatProps, composite };\n handleSetFormatProps(newFormatProps);\n }\n }\n },\n [formatProps, handleSetFormatProps]\n );\n\n const handleOnSpacerChange = React.useCallback(\n (e: React.ChangeEvent<HTMLInputElement>) => {\n // istanbul ignore else\n if (formatProps.composite) {\n const spacerValue = e.target.value.length\n ? e.target.value[0]\n : /* istanbul ignore next */ \"\"; // spacer can only be empty or a single character\n const composite = { ...formatProps.composite, spacer: spacerValue };\n const newFormatProps = { ...formatProps, composite };\n handleSetFormatProps(newFormatProps);\n }\n },\n [formatProps, handleSetFormatProps]\n );\n\n const compositeSpacer = React.useRef(\n UiIModelComponents.translate(\"QuantityFormat.labels.compositeSpacer\")\n );\n\n return (\n <>\n {formatProps.composite?.units\n ? formatProps.composite.units.map((value, index) => (\n <UnitDescr\n key={value.name}\n name={value.name}\n label={value.label ?? \"\"}\n parentUnitName={\n index > 0\n ? formatProps.composite!.units[index - 1].name\n : undefined\n }\n unitsProvider={unitsProvider}\n index={index}\n onUnitChange={handleUnitChange}\n onLabelChange={handleUnitLabelChange}\n readonly={index < formatProps.composite!.units.length - 1}\n />\n ))\n : persistenceUnit && (\n <UnitDescr\n key={persistenceUnit.name}\n name={persistenceUnit.name}\n label={persistenceUnit.label}\n unitsProvider={unitsProvider}\n index={0}\n onUnitChange={handleUnitChange}\n onLabelChange={handleUnitLabelChange}\n />\n )}\n\n {formatProps.composite?.units &&\n formatProps.composite.units.length > 1 && (\n <>\n <span key={\"composite-spacer-label\"} className={\"uicore-label\"}>\n {compositeSpacer.current}\n </span>\n <Input\n key={\"composite-spacer\"}\n data-testid=\"composite-spacer\"\n value={formatProps.composite.spacer ?? \"\"}\n onChange={handleOnSpacerChange}\n size=\"small\"\n />\n </>\n )}\n </>\n );\n}\n"]}
@@ -21,6 +21,7 @@ import { UiIModelComponents } from "../UiIModelComponents";
21
21
  * @alpha
22
22
  */
23
23
  export function MiscFormatOptions(props) {
24
+ var _a, _b;
24
25
  const { formatProps, onChange, showOptions, onShowHideOptions, enableMinimumProperties, } = props;
25
26
  const handleSetFormatProps = React.useCallback((newFormatProps) => {
26
27
  onChange && onChange(newFormatProps);
@@ -112,7 +113,10 @@ export function MiscFormatOptions(props) {
112
113
  handleSetFormatProps(newFormatProps);
113
114
  }, [handleSetFormatProps]);
114
115
  const formatType = React.useMemo(() => parseFormatType(formatProps.type, "format"), [formatProps.type]);
115
- const showSignOption = React.useMemo(() => parseShowSignOption(formatProps.showSignOption ?? "onlyNegative", "format"), [formatProps.showSignOption]);
116
+ const showSignOption = React.useMemo(() => {
117
+ var _a;
118
+ return parseShowSignOption((_a = formatProps.showSignOption) !== null && _a !== void 0 ? _a : "onlyNegative", "format");
119
+ }, [formatProps.showSignOption]);
116
120
  const handleToggleButtonClick = React.useCallback(() => {
117
121
  onShowHideOptions(!showOptions);
118
122
  }, [onShowHideOptions, showOptions]);
@@ -149,14 +153,14 @@ export function MiscFormatOptions(props) {
149
153
  React.createElement("span", { className: "uicore-label" }, signOptionLabel.current),
150
154
  React.createElement(SignOptionSelector, { "data-testid": "sign-option-selector", signOption: showSignOption, onChange: handleShowSignChange }),
151
155
  React.createElement("span", { className: classnames("uicore-label", formatType !== FormatType.Station && "uicore-disabled") }, stationOffsetLabel.current),
152
- React.createElement(StationSizeSelector, { "data-testid": "station-size-selector", value: formatProps.stationOffsetSize ?? 2, disabled: formatType !== FormatType.Station, onChange: handleStationOffsetChange }),
156
+ React.createElement(StationSizeSelector, { "data-testid": "station-size-selector", value: (_a = formatProps.stationOffsetSize) !== null && _a !== void 0 ? _a : 2, disabled: formatType !== FormatType.Station, onChange: handleStationOffsetChange }),
153
157
  React.createElement("span", { className: classnames("uicore-label", formatType !== FormatType.Station && "uicore-disabled") }, stationSeparatorLabel.current),
154
158
  React.createElement(StationSeparatorSelector, { "data-testid": "station-separator-selector", separator: undefined !== formatProps.stationSeparator
155
159
  ? formatProps.stationSeparator
156
160
  : "+", disabled: formatType !== FormatType.Station, onChange: handleStationSeparatorChange }),
157
161
  React.createElement(ThousandsSeparator, { formatProps: formatProps, onChange: handleFormatChange }),
158
162
  React.createElement("span", { className: classnames("uicore-label", formatType === FormatType.Fractional && "uicore-disabled") }, decimalSeparatorLabel.current),
159
- React.createElement(DecimalSeparatorSelector, { "data-testid": "decimal-separator-selector", separator: formatProps.decimalSeparator ?? ".", onChange: handleDecimalSeparatorChange, disabled: formatType === FormatType.Fractional }),
163
+ React.createElement(DecimalSeparatorSelector, { "data-testid": "decimal-separator-selector", separator: (_b = formatProps.decimalSeparator) !== null && _b !== void 0 ? _b : ".", onChange: handleDecimalSeparatorChange, disabled: formatType === FormatType.Fractional }),
160
164
  React.createElement("span", { className: "uicore-label" }, showTrailZerosLabel.current),
161
165
  React.createElement(Checkbox, { "data-testid": "show-trail-zeros", checked: isFormatTraitSet(FormatTraits.TrailZeroes), onChange: handleShowTrailingZeroesChange }),
162
166
  React.createElement("span", { className: classnames("uicore-label", formatType === FormatType.Fractional && "uicore-disabled") }, keepDecimalPointLabel.current),
@@ -1 +1 @@
1
- {"version":3,"file":"MiscFormatOptions.js","sourceRoot":"","sources":["../../../../src/imodel-components-react/quantityformat/MiscFormatOptions.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO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AC1D,IAEA,iBAAiB,CAAC,OAAO,CACrB;YACP,oBAAC,QAAQ,mBACK,eAAe,EAC3B,OAAO,EAAE,gBAAgB,CAAC,YAAY,CAAC,YAAY,CAAC,EACpD,QAAQ,EAAE,2BAA2B,EACrC,QAAQ,EAAE,UAAU,KAAK,UAAU,CAAC,UAAU,GAC9C;YAEF,8BACE,SAAS,EAAE,UAAU,CACnB,cAAc,EACd,UAAU,KAAK,UAAU,CAAC,UAAU,IAAI,iBAAiB,CAC1D,IAEA,mBAAmB,CAAC,OAAO,CACvB;YACP,oBAAC,sBAAsB,mBACT,0BAA0B,EACtC,IAAI,EACF,WAAW,CAAC,cAAc;oBAC1B,WAAW,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC;oBACnC,CAAC,CAAC,mBAAmB,CAAC,WAAW,CAAC,cAAc,EAAE,QAAQ,CAAC;oBAC3D,CAAC,CAAC,cAAc,CAAC,UAAU,EAE/B,QAAQ,EAAE,UAAU,KAAK,UAAU,CAAC,UAAU,EAC9C,QAAQ,EAAE,0BAA0B,GACpC;YAED,KAAK,CAAC,QAAQ;YAEd,uBAAuB,IAAI,WAAW,IAAI,CACzC,2BACE,OAAO,EAAE,uBAAuB,EAChC,OAAO,EAAE,iBAAiB,EAC1B,SAAS,EAAE,qCAAqC,EAChD,IAAI,EAAC,MAAM,iBACC,qBAAqB,EACjC,QAAQ,EAAE,CAAC,IAEV,SAAS,CAAC,OAAO,CAChB,CACL,CACA,CACJ,CACA,CACJ,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 QuantityFormat\n */\n\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport { SpecialKey } from \"@itwin/appui-abstract\";\nimport type { CommonProps } from \"@itwin/core-react\";\nimport { Checkbox } from \"@itwin/itwinui-react\";\nimport type { FormatProps, ShowSignOption } from \"@itwin/core-quantity\";\nimport {\n Format,\n FormatTraits,\n FormatType,\n getTraitString,\n parseFormatType,\n parseScientificType,\n parseShowSignOption,\n ScientificType,\n scientificTypeToString,\n showSignOptionToString,\n} from \"@itwin/core-quantity\";\nimport { SignOptionSelector } from \"./misc/SignOption\";\nimport { ThousandsSeparator } from \"./misc/ThousandsSeparator\";\nimport { DecimalSeparatorSelector } from \"./misc/DecimalSeparator\";\nimport { ScientificTypeSelector } from \"./misc/ScientificType\";\nimport { StationSeparatorSelector } from \"./misc/StationSeparatorSelector\";\nimport { StationSizeSelector } from \"./misc/StationSizeSelector\";\nimport { UiIModelComponents } from \"../UiIModelComponents\";\n\n/** Properties of [[MiscFormatOptions]] component.\n * @alpha\n */\nexport interface MiscFormatOptionsProps extends CommonProps {\n formatProps: FormatProps;\n onChange?: (format: FormatProps) => void;\n enableMinimumProperties?: boolean;\n showOptions: boolean;\n onShowHideOptions: (show: boolean) => void;\n children?: React.ReactNode;\n}\n\n/** Component use to set miscellaneous properties is a Formatted Quantity.\n * @alpha\n */\nexport function MiscFormatOptions(props: MiscFormatOptionsProps) {\n const {\n formatProps,\n onChange,\n showOptions,\n onShowHideOptions,\n enableMinimumProperties,\n } = props;\n\n const handleSetFormatProps = React.useCallback(\n (newFormatProps: FormatProps) => {\n onChange && onChange(newFormatProps);\n },\n [onChange]\n );\n\n const isFormatTraitSet = React.useCallback(\n (trait: FormatTraits) => {\n return Format.isFormatTraitSetInProps(formatProps, trait);\n },\n [formatProps]\n );\n\n const handleShowSignChange = React.useCallback(\n (option: ShowSignOption) => {\n const newShowSignOption = showSignOptionToString(option);\n const newFormatProps = {\n ...formatProps,\n showSignOption: newShowSignOption,\n };\n handleSetFormatProps(newFormatProps);\n },\n [formatProps, handleSetFormatProps]\n );\n\n const setFormatTrait = React.useCallback(\n (trait: FormatTraits, setActive: boolean) => {\n const traitStr = getTraitString(trait);\n let formatTraits: string[] = [traitStr];\n if (setActive) {\n // setting trait\n // istanbul ignore else\n if (formatProps.formatTraits) {\n const traits = Array.isArray(formatProps.formatTraits)\n ? formatProps.formatTraits\n : /* istanbul ignore next */ formatProps.formatTraits.split(\n /,|;|\\|/\n );\n // istanbul ignore else\n if (!traits.find((traitEntry) => traitStr === traitEntry)) {\n formatTraits = [...traits, traitStr];\n }\n }\n } else {\n // clearing trait\n // istanbul ignore next\n if (!formatProps.formatTraits) return;\n const traits = Array.isArray(formatProps.formatTraits)\n ? formatProps.formatTraits\n : /* istanbul ignore next */ formatProps.formatTraits.split(/,|;|\\|/);\n formatTraits = traits.filter((traitEntry) => traitEntry !== traitStr);\n }\n const newFormatProps = { ...formatProps, formatTraits };\n handleSetFormatProps(newFormatProps);\n },\n [formatProps, handleSetFormatProps]\n );\n\n const handleShowTrailingZeroesChange = React.useCallback(\n (e: React.ChangeEvent<HTMLInputElement>) => {\n setFormatTrait(FormatTraits.TrailZeroes, e.target.checked);\n },\n [setFormatTrait]\n );\n\n const handleKeepDecimalPointChange = React.useCallback(\n (e: React.ChangeEvent<HTMLInputElement>) => {\n setFormatTrait(FormatTraits.KeepDecimalPoint, e.target.checked);\n },\n [setFormatTrait]\n );\n\n const handleKeepSingleZeroChange = React.useCallback(\n (e: React.ChangeEvent<HTMLInputElement>) => {\n setFormatTrait(FormatTraits.KeepSingleZero, e.target.checked);\n },\n [setFormatTrait]\n );\n\n const handleZeroEmptyChange = React.useCallback(\n (e: React.ChangeEvent<HTMLInputElement>) => {\n setFormatTrait(FormatTraits.ZeroEmpty, e.target.checked);\n },\n [setFormatTrait]\n );\n\n const handleUseFractionDashChange = React.useCallback(\n (e: React.ChangeEvent<HTMLInputElement>) => {\n setFormatTrait(FormatTraits.FractionDash, e.target.checked);\n },\n [setFormatTrait]\n );\n\n const handleDecimalSeparatorChange = React.useCallback(\n (decimalSeparator: string) => {\n let thousandSeparator = formatProps.thousandSeparator;\n // make sure 1000 and decimal separator do not match\n // istanbul ignore else\n if (isFormatTraitSet(FormatTraits.Use1000Separator)) {\n switch (decimalSeparator) {\n case \".\":\n thousandSeparator = \",\";\n break;\n case \",\":\n thousandSeparator = \".\";\n break;\n }\n }\n const newFormatProps = {\n ...formatProps,\n thousandSeparator,\n decimalSeparator,\n };\n handleSetFormatProps(newFormatProps);\n },\n [formatProps, isFormatTraitSet, handleSetFormatProps]\n );\n\n const handleScientificTypeChange = React.useCallback(\n (type: ScientificType) => {\n const newFormatProps = {\n ...formatProps,\n scientificType: scientificTypeToString(type),\n };\n handleSetFormatProps(newFormatProps);\n },\n [formatProps, handleSetFormatProps]\n );\n\n const handleFormatChange = React.useCallback(\n (newFormatProps: FormatProps) => {\n handleSetFormatProps(newFormatProps);\n },\n [handleSetFormatProps]\n );\n\n const formatType = React.useMemo(\n () => parseFormatType(formatProps.type, \"format\"),\n [formatProps.type]\n );\n const showSignOption = React.useMemo(\n () =>\n parseShowSignOption(\n formatProps.showSignOption ?? \"onlyNegative\",\n \"format\"\n ),\n [formatProps.showSignOption]\n );\n\n const handleToggleButtonClick = React.useCallback(() => {\n onShowHideOptions(!showOptions);\n }, [onShowHideOptions, showOptions]);\n\n const handleKeyUpOnLink = React.useCallback(\n (e: React.KeyboardEvent<HTMLAnchorElement>) => {\n // istanbul ignore else\n if (e.key === SpecialKey.Enter || e.key === SpecialKey.Space) {\n onShowHideOptions(!showOptions);\n e.preventDefault();\n }\n },\n [onShowHideOptions, showOptions]\n );\n\n const handleStationSeparatorChange = React.useCallback(\n (value: string) => {\n const newFormatProps = { ...formatProps, stationSeparator: value };\n handleSetFormatProps(newFormatProps);\n },\n [formatProps, handleSetFormatProps]\n );\n\n const handleStationOffsetChange = React.useCallback(\n (value: number) => {\n const newFormatProps = { ...formatProps, stationOffsetSize: value };\n handleSetFormatProps(newFormatProps);\n },\n [formatProps, handleSetFormatProps]\n );\n\n const signOptionLabel = React.useRef(\n UiIModelComponents.translate(\"QuantityFormat.labels.signOptionLabel\")\n );\n const stationOffsetLabel = React.useRef(\n UiIModelComponents.translate(\"QuantityFormat.labels.stationOffsetLabel\")\n );\n const stationSeparatorLabel = React.useRef(\n UiIModelComponents.translate(\"QuantityFormat.labels.stationSeparatorLabel\")\n );\n const decimalSeparatorLabel = React.useRef(\n UiIModelComponents.translate(\"QuantityFormat.labels.decimalSeparatorLabel\")\n );\n const showTrailZerosLabel = React.useRef(\n UiIModelComponents.translate(\"QuantityFormat.labels.showTrailZerosLabel\")\n );\n const keepSingleZeroLabel = React.useRef(\n UiIModelComponents.translate(\"QuantityFormat.labels.keepSingleZeroLabel\")\n );\n const zeroEmptyLabel = React.useRef(\n UiIModelComponents.translate(\"QuantityFormat.labels.zeroEmptyLabel\")\n );\n const moreLabel = React.useRef(\n UiIModelComponents.translate(\"QuantityFormat.labels.moreLabel\")\n );\n const lessLabel = React.useRef(\n UiIModelComponents.translate(\"QuantityFormat.labels.lessLabel\")\n );\n const keepDecimalPointLabel = React.useRef(\n UiIModelComponents.translate(\"QuantityFormat.labels.keepDecimalPointLabel\")\n );\n const fractionDashLabel = React.useRef(\n UiIModelComponents.translate(\"QuantityFormat.labels.fractionDashLabel\")\n );\n const scientificTypeLabel = React.useRef(\n UiIModelComponents.translate(\"QuantityFormat.labels.scientificTypeLabel\")\n );\n\n return (\n <>\n {enableMinimumProperties && !showOptions && (\n <a // eslint-disable-line jsx-a11y/anchor-is-valid\n onClick={handleToggleButtonClick}\n onKeyUp={handleKeyUpOnLink}\n className={\"components-quantityFormat-more-less\"}\n role=\"link\"\n data-testid=\"quantityFormat-more\"\n tabIndex={0}\n >\n {moreLabel.current}\n </a>\n )}\n {(!enableMinimumProperties || showOptions) && (\n <>\n <span className={\"uicore-label\"}>{signOptionLabel.current}</span>\n <SignOptionSelector\n data-testid=\"sign-option-selector\"\n signOption={showSignOption}\n onChange={handleShowSignChange}\n />\n\n <span\n className={classnames(\n \"uicore-label\",\n formatType !== FormatType.Station && \"uicore-disabled\"\n )}\n >\n {stationOffsetLabel.current}\n </span>\n <StationSizeSelector\n data-testid=\"station-size-selector\"\n value={formatProps.stationOffsetSize ?? 2}\n disabled={formatType !== FormatType.Station}\n onChange={handleStationOffsetChange}\n />\n\n <span\n className={classnames(\n \"uicore-label\",\n formatType !== FormatType.Station && \"uicore-disabled\"\n )}\n >\n {stationSeparatorLabel.current}\n </span>\n <StationSeparatorSelector\n data-testid=\"station-separator-selector\"\n separator={\n undefined !== formatProps.stationSeparator\n ? formatProps.stationSeparator\n : \"+\"\n }\n disabled={formatType !== FormatType.Station}\n onChange={handleStationSeparatorChange}\n />\n\n <ThousandsSeparator\n formatProps={formatProps}\n onChange={handleFormatChange}\n />\n\n <span\n className={classnames(\n \"uicore-label\",\n formatType === FormatType.Fractional && \"uicore-disabled\"\n )}\n >\n {decimalSeparatorLabel.current}\n </span>\n <DecimalSeparatorSelector\n data-testid=\"decimal-separator-selector\"\n separator={formatProps.decimalSeparator ?? \".\"}\n onChange={handleDecimalSeparatorChange}\n disabled={formatType === FormatType.Fractional}\n />\n\n <span className={\"uicore-label\"}>{showTrailZerosLabel.current}</span>\n <Checkbox\n data-testid=\"show-trail-zeros\"\n checked={isFormatTraitSet(FormatTraits.TrailZeroes)}\n onChange={handleShowTrailingZeroesChange}\n />\n\n <span\n className={classnames(\n \"uicore-label\",\n formatType === FormatType.Fractional && \"uicore-disabled\"\n )}\n >\n {keepDecimalPointLabel.current}\n </span>\n <Checkbox\n data-testid=\"keep-decimal-point\"\n checked={isFormatTraitSet(FormatTraits.KeepDecimalPoint)}\n onChange={handleKeepDecimalPointChange}\n />\n\n <span className={\"uicore-label\"}>{keepSingleZeroLabel.current}</span>\n <Checkbox\n data-testid=\"keep-single-zero\"\n checked={isFormatTraitSet(FormatTraits.KeepSingleZero)}\n onChange={handleKeepSingleZeroChange}\n />\n\n <span className={\"uicore-label\"}>{zeroEmptyLabel.current}</span>\n <Checkbox\n data-testid=\"zero-empty\"\n checked={isFormatTraitSet(FormatTraits.ZeroEmpty)}\n onChange={handleZeroEmptyChange}\n />\n\n <span\n className={classnames(\n \"uicore-label\",\n formatType !== FormatType.Fractional && \"uicore-disabled\"\n )}\n >\n {fractionDashLabel.current}\n </span>\n <Checkbox\n data-testid=\"fraction-dash\"\n checked={isFormatTraitSet(FormatTraits.FractionDash)}\n onChange={handleUseFractionDashChange}\n disabled={formatType !== FormatType.Fractional}\n />\n\n <span\n className={classnames(\n \"uicore-label\",\n formatType !== FormatType.Scientific && \"uicore-disabled\"\n )}\n >\n {scientificTypeLabel.current}\n </span>\n <ScientificTypeSelector\n data-testid=\"scientific-type-selector\"\n type={\n formatProps.scientificType &&\n formatProps.scientificType.length > 0\n ? parseScientificType(formatProps.scientificType, \"custom\")\n : ScientificType.Normalized\n }\n disabled={formatType !== FormatType.Scientific}\n onChange={handleScientificTypeChange}\n />\n\n {props.children}\n\n {enableMinimumProperties && showOptions && (\n <a // eslint-disable-line jsx-a11y/anchor-is-valid\n onClick={handleToggleButtonClick}\n onKeyUp={handleKeyUpOnLink}\n className={\"components-quantityFormat-more-less\"}\n role=\"link\"\n data-testid=\"quantityFormat-less\"\n tabIndex={0}\n >\n {lessLabel.current}\n </a>\n )}\n </>\n )}\n </>\n );\n}\n"]}
1
+ {"version":3,"file":"MiscFormatOptions.js","sourceRoot":"","sources":["../../../../src/imodel-components-react/quantityformat/MiscFormatOptions.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD,OAAO,EACL,MAAM,EACN,YAAY,EACZ,UAAU,EACV,cAAc,EACd,eAAe,EACf,mBAAmB,EACnB,mBAAmB,EACnB,cAAc,EACd,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB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vB;YACP,oBAAC,sBAAsB,mBACT,0BAA0B,EACtC,IAAI,EACF,WAAW,CAAC,cAAc;oBAC1B,WAAW,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC;oBACnC,CAAC,CAAC,mBAAmB,CAAC,WAAW,CAAC,cAAc,EAAE,QAAQ,CAAC;oBAC3D,CAAC,CAAC,cAAc,CAAC,UAAU,EAE/B,QAAQ,EAAE,UAAU,KAAK,UAAU,CAAC,UAAU,EAC9C,QAAQ,EAAE,0BAA0B,GACpC;YAED,KAAK,CAAC,QAAQ;YAEd,uBAAuB,IAAI,WAAW,IAAI,CACzC,2BACE,OAAO,EAAE,uBAAuB,EAChC,OAAO,EAAE,iBAAiB,EAC1B,SAAS,EAAE,qCAAqC,EAChD,IAAI,EAAC,MAAM,iBACC,qBAAqB,EACjC,QAAQ,EAAE,CAAC,IAEV,SAAS,CAAC,OAAO,CAChB,CACL,CACA,CACJ,CACA,CACJ,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 QuantityFormat\n */\n\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport { SpecialKey } from \"@itwin/appui-abstract\";\nimport type { CommonProps } from \"@itwin/core-react\";\nimport { Checkbox } from \"@itwin/itwinui-react\";\nimport type { FormatProps, ShowSignOption } from \"@itwin/core-quantity\";\nimport {\n Format,\n FormatTraits,\n FormatType,\n getTraitString,\n parseFormatType,\n parseScientificType,\n parseShowSignOption,\n ScientificType,\n scientificTypeToString,\n showSignOptionToString,\n} from \"@itwin/core-quantity\";\nimport { SignOptionSelector } from \"./misc/SignOption\";\nimport { ThousandsSeparator } from \"./misc/ThousandsSeparator\";\nimport { DecimalSeparatorSelector } from \"./misc/DecimalSeparator\";\nimport { ScientificTypeSelector } from \"./misc/ScientificType\";\nimport { StationSeparatorSelector } from \"./misc/StationSeparatorSelector\";\nimport { StationSizeSelector } from \"./misc/StationSizeSelector\";\nimport { UiIModelComponents } from \"../UiIModelComponents\";\n\n/** Properties of [[MiscFormatOptions]] component.\n * @alpha\n */\nexport interface MiscFormatOptionsProps extends CommonProps {\n formatProps: FormatProps;\n onChange?: (format: FormatProps) => void;\n enableMinimumProperties?: boolean;\n showOptions: boolean;\n onShowHideOptions: (show: boolean) => void;\n children?: React.ReactNode;\n}\n\n/** Component use to set miscellaneous properties is a Formatted Quantity.\n * @alpha\n */\nexport function MiscFormatOptions(props: MiscFormatOptionsProps) {\n const {\n formatProps,\n onChange,\n showOptions,\n onShowHideOptions,\n enableMinimumProperties,\n } = props;\n\n const handleSetFormatProps = React.useCallback(\n (newFormatProps: FormatProps) => {\n onChange && onChange(newFormatProps);\n },\n [onChange]\n );\n\n const isFormatTraitSet = React.useCallback(\n (trait: FormatTraits) => {\n return Format.isFormatTraitSetInProps(formatProps, trait);\n },\n [formatProps]\n );\n\n const handleShowSignChange = React.useCallback(\n (option: ShowSignOption) => {\n const newShowSignOption = showSignOptionToString(option);\n const newFormatProps = {\n ...formatProps,\n showSignOption: newShowSignOption,\n };\n handleSetFormatProps(newFormatProps);\n },\n [formatProps, handleSetFormatProps]\n );\n\n const setFormatTrait = React.useCallback(\n (trait: FormatTraits, setActive: boolean) => {\n const traitStr = getTraitString(trait);\n let formatTraits: string[] = [traitStr];\n if (setActive) {\n // setting trait\n // istanbul ignore else\n if (formatProps.formatTraits) {\n const traits = Array.isArray(formatProps.formatTraits)\n ? formatProps.formatTraits\n : /* istanbul ignore next */ formatProps.formatTraits.split(\n /,|;|\\|/\n );\n // istanbul ignore else\n if (!traits.find((traitEntry) => traitStr === traitEntry)) {\n formatTraits = [...traits, traitStr];\n }\n }\n } else {\n // clearing trait\n // istanbul ignore next\n if (!formatProps.formatTraits) return;\n const traits = Array.isArray(formatProps.formatTraits)\n ? formatProps.formatTraits\n : /* istanbul ignore next */ formatProps.formatTraits.split(/,|;|\\|/);\n formatTraits = traits.filter((traitEntry) => traitEntry !== traitStr);\n }\n const newFormatProps = { ...formatProps, formatTraits };\n handleSetFormatProps(newFormatProps);\n },\n [formatProps, handleSetFormatProps]\n );\n\n const handleShowTrailingZeroesChange = React.useCallback(\n (e: React.ChangeEvent<HTMLInputElement>) => {\n setFormatTrait(FormatTraits.TrailZeroes, e.target.checked);\n },\n [setFormatTrait]\n );\n\n const handleKeepDecimalPointChange = React.useCallback(\n (e: React.ChangeEvent<HTMLInputElement>) => {\n setFormatTrait(FormatTraits.KeepDecimalPoint, e.target.checked);\n },\n [setFormatTrait]\n );\n\n const handleKeepSingleZeroChange = React.useCallback(\n (e: React.ChangeEvent<HTMLInputElement>) => {\n setFormatTrait(FormatTraits.KeepSingleZero, e.target.checked);\n },\n [setFormatTrait]\n );\n\n const handleZeroEmptyChange = React.useCallback(\n (e: React.ChangeEvent<HTMLInputElement>) => {\n setFormatTrait(FormatTraits.ZeroEmpty, e.target.checked);\n },\n [setFormatTrait]\n );\n\n const handleUseFractionDashChange = React.useCallback(\n (e: React.ChangeEvent<HTMLInputElement>) => {\n setFormatTrait(FormatTraits.FractionDash, e.target.checked);\n },\n [setFormatTrait]\n );\n\n const handleDecimalSeparatorChange = React.useCallback(\n (decimalSeparator: string) => {\n let thousandSeparator = formatProps.thousandSeparator;\n // make sure 1000 and decimal separator do not match\n // istanbul ignore else\n if (isFormatTraitSet(FormatTraits.Use1000Separator)) {\n switch (decimalSeparator) {\n case \".\":\n thousandSeparator = \",\";\n break;\n case \",\":\n thousandSeparator = \".\";\n break;\n }\n }\n const newFormatProps = {\n ...formatProps,\n thousandSeparator,\n decimalSeparator,\n };\n handleSetFormatProps(newFormatProps);\n },\n [formatProps, isFormatTraitSet, handleSetFormatProps]\n );\n\n const handleScientificTypeChange = React.useCallback(\n (type: ScientificType) => {\n const newFormatProps = {\n ...formatProps,\n scientificType: scientificTypeToString(type),\n };\n handleSetFormatProps(newFormatProps);\n },\n [formatProps, handleSetFormatProps]\n );\n\n const handleFormatChange = React.useCallback(\n (newFormatProps: FormatProps) => {\n handleSetFormatProps(newFormatProps);\n },\n [handleSetFormatProps]\n );\n\n const formatType = React.useMemo(\n () => parseFormatType(formatProps.type, \"format\"),\n [formatProps.type]\n );\n const showSignOption = React.useMemo(\n () =>\n parseShowSignOption(\n formatProps.showSignOption ?? \"onlyNegative\",\n \"format\"\n ),\n [formatProps.showSignOption]\n );\n\n const handleToggleButtonClick = React.useCallback(() => {\n onShowHideOptions(!showOptions);\n }, [onShowHideOptions, showOptions]);\n\n const handleKeyUpOnLink = React.useCallback(\n (e: React.KeyboardEvent<HTMLAnchorElement>) => {\n // istanbul ignore else\n if (e.key === SpecialKey.Enter || e.key === SpecialKey.Space) {\n onShowHideOptions(!showOptions);\n e.preventDefault();\n }\n },\n [onShowHideOptions, showOptions]\n );\n\n const handleStationSeparatorChange = React.useCallback(\n (value: string) => {\n const newFormatProps = { ...formatProps, stationSeparator: value };\n handleSetFormatProps(newFormatProps);\n },\n [formatProps, handleSetFormatProps]\n );\n\n const handleStationOffsetChange = React.useCallback(\n (value: number) => {\n const newFormatProps = { ...formatProps, stationOffsetSize: value };\n handleSetFormatProps(newFormatProps);\n },\n [formatProps, handleSetFormatProps]\n );\n\n const signOptionLabel = React.useRef(\n UiIModelComponents.translate(\"QuantityFormat.labels.signOptionLabel\")\n );\n const stationOffsetLabel = React.useRef(\n UiIModelComponents.translate(\"QuantityFormat.labels.stationOffsetLabel\")\n );\n const stationSeparatorLabel = React.useRef(\n UiIModelComponents.translate(\"QuantityFormat.labels.stationSeparatorLabel\")\n );\n const decimalSeparatorLabel = React.useRef(\n UiIModelComponents.translate(\"QuantityFormat.labels.decimalSeparatorLabel\")\n );\n const showTrailZerosLabel = React.useRef(\n UiIModelComponents.translate(\"QuantityFormat.labels.showTrailZerosLabel\")\n );\n const keepSingleZeroLabel = React.useRef(\n UiIModelComponents.translate(\"QuantityFormat.labels.keepSingleZeroLabel\")\n );\n const zeroEmptyLabel = React.useRef(\n UiIModelComponents.translate(\"QuantityFormat.labels.zeroEmptyLabel\")\n );\n const moreLabel = React.useRef(\n UiIModelComponents.translate(\"QuantityFormat.labels.moreLabel\")\n );\n const lessLabel = React.useRef(\n UiIModelComponents.translate(\"QuantityFormat.labels.lessLabel\")\n );\n const keepDecimalPointLabel = React.useRef(\n UiIModelComponents.translate(\"QuantityFormat.labels.keepDecimalPointLabel\")\n );\n const fractionDashLabel = React.useRef(\n UiIModelComponents.translate(\"QuantityFormat.labels.fractionDashLabel\")\n );\n const scientificTypeLabel = React.useRef(\n UiIModelComponents.translate(\"QuantityFormat.labels.scientificTypeLabel\")\n );\n\n return (\n <>\n {enableMinimumProperties && !showOptions && (\n <a // eslint-disable-line jsx-a11y/anchor-is-valid\n onClick={handleToggleButtonClick}\n onKeyUp={handleKeyUpOnLink}\n className={\"components-quantityFormat-more-less\"}\n role=\"link\"\n data-testid=\"quantityFormat-more\"\n tabIndex={0}\n >\n {moreLabel.current}\n </a>\n )}\n {(!enableMinimumProperties || showOptions) && (\n <>\n <span className={\"uicore-label\"}>{signOptionLabel.current}</span>\n <SignOptionSelector\n data-testid=\"sign-option-selector\"\n signOption={showSignOption}\n onChange={handleShowSignChange}\n />\n\n <span\n className={classnames(\n \"uicore-label\",\n formatType !== FormatType.Station && \"uicore-disabled\"\n )}\n >\n {stationOffsetLabel.current}\n </span>\n <StationSizeSelector\n data-testid=\"station-size-selector\"\n value={formatProps.stationOffsetSize ?? 2}\n disabled={formatType !== FormatType.Station}\n onChange={handleStationOffsetChange}\n />\n\n <span\n className={classnames(\n \"uicore-label\",\n formatType !== FormatType.Station && \"uicore-disabled\"\n )}\n >\n {stationSeparatorLabel.current}\n </span>\n <StationSeparatorSelector\n data-testid=\"station-separator-selector\"\n separator={\n undefined !== formatProps.stationSeparator\n ? formatProps.stationSeparator\n : \"+\"\n }\n disabled={formatType !== FormatType.Station}\n onChange={handleStationSeparatorChange}\n />\n\n <ThousandsSeparator\n formatProps={formatProps}\n onChange={handleFormatChange}\n />\n\n <span\n className={classnames(\n \"uicore-label\",\n formatType === FormatType.Fractional && \"uicore-disabled\"\n )}\n >\n {decimalSeparatorLabel.current}\n </span>\n <DecimalSeparatorSelector\n data-testid=\"decimal-separator-selector\"\n separator={formatProps.decimalSeparator ?? \".\"}\n onChange={handleDecimalSeparatorChange}\n disabled={formatType === FormatType.Fractional}\n />\n\n <span className={\"uicore-label\"}>{showTrailZerosLabel.current}</span>\n <Checkbox\n data-testid=\"show-trail-zeros\"\n checked={isFormatTraitSet(FormatTraits.TrailZeroes)}\n onChange={handleShowTrailingZeroesChange}\n />\n\n <span\n className={classnames(\n \"uicore-label\",\n formatType === FormatType.Fractional && \"uicore-disabled\"\n )}\n >\n {keepDecimalPointLabel.current}\n </span>\n <Checkbox\n data-testid=\"keep-decimal-point\"\n checked={isFormatTraitSet(FormatTraits.KeepDecimalPoint)}\n onChange={handleKeepDecimalPointChange}\n />\n\n <span className={\"uicore-label\"}>{keepSingleZeroLabel.current}</span>\n <Checkbox\n data-testid=\"keep-single-zero\"\n checked={isFormatTraitSet(FormatTraits.KeepSingleZero)}\n onChange={handleKeepSingleZeroChange}\n />\n\n <span className={\"uicore-label\"}>{zeroEmptyLabel.current}</span>\n <Checkbox\n data-testid=\"zero-empty\"\n checked={isFormatTraitSet(FormatTraits.ZeroEmpty)}\n onChange={handleZeroEmptyChange}\n />\n\n <span\n className={classnames(\n \"uicore-label\",\n formatType !== FormatType.Fractional && \"uicore-disabled\"\n )}\n >\n {fractionDashLabel.current}\n </span>\n <Checkbox\n data-testid=\"fraction-dash\"\n checked={isFormatTraitSet(FormatTraits.FractionDash)}\n onChange={handleUseFractionDashChange}\n disabled={formatType !== FormatType.Fractional}\n />\n\n <span\n className={classnames(\n \"uicore-label\",\n formatType !== FormatType.Scientific && \"uicore-disabled\"\n )}\n >\n {scientificTypeLabel.current}\n </span>\n <ScientificTypeSelector\n data-testid=\"scientific-type-selector\"\n type={\n formatProps.scientificType &&\n formatProps.scientificType.length > 0\n ? parseScientificType(formatProps.scientificType, \"custom\")\n : ScientificType.Normalized\n }\n disabled={formatType !== FormatType.Scientific}\n onChange={handleScientificTypeChange}\n />\n\n {props.children}\n\n {enableMinimumProperties && showOptions && (\n <a // eslint-disable-line jsx-a11y/anchor-is-valid\n onClick={handleToggleButtonClick}\n onKeyUp={handleKeyUpOnLink}\n className={\"components-quantityFormat-more-less\"}\n role=\"link\"\n data-testid=\"quantityFormat-less\"\n tabIndex={0}\n >\n {lessLabel.current}\n </a>\n )}\n </>\n )}\n </>\n );\n}\n"]}
@@ -15,6 +15,7 @@ import { UiIModelComponents } from "../../UiIModelComponents";
15
15
  * @internal
16
16
  */
17
17
  export function ThousandsSeparator(props) {
18
+ var _a;
18
19
  const { formatProps, onChange } = props;
19
20
  const handleSetFormatProps = React.useCallback((newProps) => {
20
21
  onChange && onChange(newProps);
@@ -75,6 +76,6 @@ export function ThousandsSeparator(props) {
75
76
  React.createElement("span", { className: "uicore-label" }, useThousandSeparatorLabel.current),
76
77
  React.createElement(Checkbox, { "data-testid": "use-thousands-separator", checked: isFormatTraitSet(FormatTraits.Use1000Separator), onChange: handleUseThousandsSeparatorChange }),
77
78
  React.createElement("span", { className: classnames("uicore-label", !isFormatTraitSet(FormatTraits.Use1000Separator) && "uicore-disabled") }, thousandSeparatorLabel.current),
78
- React.createElement(ThousandsSelector, { "data-testid": "thousands-separator-selector", separator: formatProps.thousandSeparator ?? ",", disabled: !isFormatTraitSet(FormatTraits.Use1000Separator), onChange: handleThousandSeparatorChange })));
79
+ React.createElement(ThousandsSelector, { "data-testid": "thousands-separator-selector", separator: (_a = formatProps.thousandSeparator) !== null && _a !== void 0 ? _a : ",", disabled: !isFormatTraitSet(FormatTraits.Use1000Separator), onChange: handleThousandSeparatorChange })));
79
80
  }
80
81
  //# sourceMappingURL=ThousandsSeparator.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ThousandsSeparator.js","sourceRoot":"","sources":["../../../../../src/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AAG,CAAC;YACtD,4BAA4B;;gBACvB,gBAAgB,GAAG,GAAG,CAAC;SAC7B;QACD,MAAM,cAAc,GAAG;YACrB,GAAG,WAAW;YACd,iBAAiB;YACjB,gBAAgB;SACjB,CAAC;QACF,oBAAoB,CAAC,cAAc,CAAC,CAAC;IACvC,CAAC,EACD,CAAC,WAAW,EAAE,gBAAgB,EAAE,oBAAoB,CAAC,CACtD,CAAC;IAEF,MAAM,yBAAyB,GAAG,KAAK,CAAC,MAAM,CAC5C,kBAAkB,CAAC,SAAS,CAC1B,iDAAiD,CAClD,CACF,CAAC;IACF,MAAM,sBAAsB,GAAG,KAAK,CAAC,MAAM,CACzC,kBAAkB,CAAC,SAAS,CAAC,8CAA8C,CAAC,CAC7E,CAAC;IAEF,OAAO,CACL;QACE,8BAAM,SAAS,EAAE,cAAc,IAC5B,yBAAyB,CAAC,OAAO,CAC7B;QACP,oBAAC,QAAQ,mBACK,yBAAyB,EACrC,OAAO,EAAE,gBAAgB,CAAC,YAAY,CAAC,gBAAgB,CAAC,EACxD,QAAQ,EAAE,iCAAiC,GAC3C;QACF,8BACE,SAAS,EAAE,UAAU,CACnB,cAAc,EACd,CAAC,gBAAgB,CAAC,YAAY,CAAC,gBAAgB,CAAC,IAAI,iBAAiB,CACtE,IAEA,sBAAsB,CAAC,OAAO,CAC1B;QACP,oBAAC,iBAAiB,mBACJ,8BAA8B,EAC1C,SAAS,EAAE,WAAW,CAAC,iBAAiB,IAAI,GAAG,EAC/C,QAAQ,EAAE,CAAC,gBAAgB,CAAC,YAAY,CAAC,gBAAgB,CAAC,EAC1D,QAAQ,EAAE,6BAA6B,GACvC,CACD,CACJ,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 QuantityFormat\n */\n\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport type { CommonProps } from \"@itwin/core-react\";\nimport type { FormatProps } from \"@itwin/core-quantity\";\nimport { Format, FormatTraits, getTraitString } from \"@itwin/core-quantity\";\nimport { Checkbox } from \"@itwin/itwinui-react\";\nimport { ThousandsSelector } from \"./ThousandsSelector\";\nimport { UiIModelComponents } from \"../../UiIModelComponents\";\n\n/** Properties of [[ThousandsSeparator]] component.\n * @internal\n */\nexport interface ThousandsSeparatorProps extends CommonProps {\n formatProps: FormatProps;\n onChange?: (format: FormatProps) => void;\n}\n\n/** Component use to set Quantity Format thousand group separator.\n * @internal\n */\nexport function ThousandsSeparator(props: ThousandsSeparatorProps) {\n const { formatProps, onChange } = props;\n\n const handleSetFormatProps = React.useCallback(\n (newProps: FormatProps) => {\n onChange && onChange(newProps);\n },\n [onChange]\n );\n\n const setFormatTrait = React.useCallback(\n (trait: FormatTraits, setActive: boolean) => {\n const traitStr = getTraitString(trait);\n let formatTraits: string[] = [traitStr];\n if (setActive) {\n // setting trait\n // istanbul ignore else\n if (formatProps.formatTraits) {\n const traits = Array.isArray(formatProps.formatTraits)\n ? formatProps.formatTraits\n : /* istanbul ignore next */ formatProps.formatTraits.split(\n /,|;|\\|/\n );\n formatTraits = [...traits, traitStr];\n }\n } else {\n // clearing trait\n // istanbul ignore else\n if (formatProps.formatTraits) {\n const traits = Array.isArray(formatProps.formatTraits)\n ? formatProps.formatTraits\n : /* istanbul ignore next */ formatProps.formatTraits.split(\n /,|;|\\|/\n );\n formatTraits = traits.filter((traitEntry) => traitEntry !== traitStr);\n }\n }\n const newFormatProps = { ...formatProps, formatTraits };\n handleSetFormatProps(newFormatProps);\n },\n [formatProps, handleSetFormatProps]\n );\n\n const handleUseThousandsSeparatorChange = React.useCallback(\n (e: React.ChangeEvent<HTMLInputElement>) => {\n setFormatTrait(FormatTraits.Use1000Separator, e.target.checked);\n },\n [setFormatTrait]\n );\n\n const isFormatTraitSet = React.useCallback(\n (trait: FormatTraits) => {\n return Format.isFormatTraitSetInProps(formatProps, trait);\n },\n [formatProps]\n );\n\n const handleThousandSeparatorChange = React.useCallback(\n (thousandSeparator: string) => {\n let decimalSeparator = formatProps.decimalSeparator;\n // make sure 1000 and decimal separator do not match\n // istanbul ignore else\n if (isFormatTraitSet(FormatTraits.Use1000Separator)) {\n if (thousandSeparator === \".\") decimalSeparator = \",\";\n // thousandSeparator === \",\"\n else decimalSeparator = \".\";\n }\n const newFormatProps = {\n ...formatProps,\n thousandSeparator,\n decimalSeparator,\n };\n handleSetFormatProps(newFormatProps);\n },\n [formatProps, isFormatTraitSet, handleSetFormatProps]\n );\n\n const useThousandSeparatorLabel = React.useRef(\n UiIModelComponents.translate(\n \"QuantityFormat.labels.useThousandSeparatorLabel\"\n )\n );\n const thousandSeparatorLabel = React.useRef(\n UiIModelComponents.translate(\"QuantityFormat.labels.thousandSeparatorLabel\")\n );\n\n return (\n <>\n <span className={\"uicore-label\"}>\n {useThousandSeparatorLabel.current}\n </span>\n <Checkbox\n data-testid=\"use-thousands-separator\"\n checked={isFormatTraitSet(FormatTraits.Use1000Separator)}\n onChange={handleUseThousandsSeparatorChange}\n />\n <span\n className={classnames(\n \"uicore-label\",\n !isFormatTraitSet(FormatTraits.Use1000Separator) && \"uicore-disabled\"\n )}\n >\n {thousandSeparatorLabel.current}\n </span>\n <ThousandsSelector\n data-testid=\"thousands-separator-selector\"\n separator={formatProps.thousandSeparator ?? \",\"}\n disabled={!isFormatTraitSet(FormatTraits.Use1000Separator)}\n onChange={handleThousandSeparatorChange}\n />\n </>\n );\n}\n"]}
1
+ {"version":3,"file":"ThousandsSeparator.js","sourceRoot":"","sources":["../../../../../src/imodel-components-react/quantityformat/misc/ThousandsSeparator.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM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,gBAAgB,EAAE,oBAAoB,CAAC,CACtD,CAAC;IAEF,MAAM,yBAAyB,GAAG,KAAK,CAAC,MAAM,CAC5C,kBAAkB,CAAC,SAAS,CAC1B,iDAAiD,CAClD,CACF,CAAC;IACF,MAAM,sBAAsB,GAAG,KAAK,CAAC,MAAM,CACzC,kBAAkB,CAAC,SAAS,CAAC,8CAA8C,CAAC,CAC7E,CAAC;IAEF,OAAO,CACL;QACE,8BAAM,SAAS,EAAE,cAAc,IAC5B,yBAAyB,CAAC,OAAO,CAC7B;QACP,oBAAC,QAAQ,mBACK,yBAAyB,EACrC,OAAO,EAAE,gBAAgB,CAAC,YAAY,CAAC,gBAAgB,CAAC,EACxD,QAAQ,EAAE,iCAAiC,GAC3C;QACF,8BACE,SAAS,EAAE,UAAU,CACnB,cAAc,EACd,CAAC,gBAAgB,CAAC,YAAY,CAAC,gBAAgB,CAAC,IAAI,iBAAiB,CACtE,IAEA,sBAAsB,CAAC,OAAO,CAC1B;QACP,oBAAC,iBAAiB,mBACJ,8BAA8B,EAC1C,SAAS,EAAE,MAAA,WAAW,CAAC,iBAAiB,mCAAI,GAAG,EAC/C,QAAQ,EAAE,CAAC,gBAAgB,CAAC,YAAY,CAAC,gBAAgB,CAAC,EAC1D,QAAQ,EAAE,6BAA6B,GACvC,CACD,CACJ,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 QuantityFormat\n */\n\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport type { CommonProps } from \"@itwin/core-react\";\nimport type { FormatProps } from \"@itwin/core-quantity\";\nimport { Format, FormatTraits, getTraitString } from \"@itwin/core-quantity\";\nimport { Checkbox } from \"@itwin/itwinui-react\";\nimport { ThousandsSelector } from \"./ThousandsSelector\";\nimport { UiIModelComponents } from \"../../UiIModelComponents\";\n\n/** Properties of [[ThousandsSeparator]] component.\n * @internal\n */\nexport interface ThousandsSeparatorProps extends CommonProps {\n formatProps: FormatProps;\n onChange?: (format: FormatProps) => void;\n}\n\n/** Component use to set Quantity Format thousand group separator.\n * @internal\n */\nexport function ThousandsSeparator(props: ThousandsSeparatorProps) {\n const { formatProps, onChange } = props;\n\n const handleSetFormatProps = React.useCallback(\n (newProps: FormatProps) => {\n onChange && onChange(newProps);\n },\n [onChange]\n );\n\n const setFormatTrait = React.useCallback(\n (trait: FormatTraits, setActive: boolean) => {\n const traitStr = getTraitString(trait);\n let formatTraits: string[] = [traitStr];\n if (setActive) {\n // setting trait\n // istanbul ignore else\n if (formatProps.formatTraits) {\n const traits = Array.isArray(formatProps.formatTraits)\n ? formatProps.formatTraits\n : /* istanbul ignore next */ formatProps.formatTraits.split(\n /,|;|\\|/\n );\n formatTraits = [...traits, traitStr];\n }\n } else {\n // clearing trait\n // istanbul ignore else\n if (formatProps.formatTraits) {\n const traits = Array.isArray(formatProps.formatTraits)\n ? formatProps.formatTraits\n : /* istanbul ignore next */ formatProps.formatTraits.split(\n /,|;|\\|/\n );\n formatTraits = traits.filter((traitEntry) => traitEntry !== traitStr);\n }\n }\n const newFormatProps = { ...formatProps, formatTraits };\n handleSetFormatProps(newFormatProps);\n },\n [formatProps, handleSetFormatProps]\n );\n\n const handleUseThousandsSeparatorChange = React.useCallback(\n (e: React.ChangeEvent<HTMLInputElement>) => {\n setFormatTrait(FormatTraits.Use1000Separator, e.target.checked);\n },\n [setFormatTrait]\n );\n\n const isFormatTraitSet = React.useCallback(\n (trait: FormatTraits) => {\n return Format.isFormatTraitSetInProps(formatProps, trait);\n },\n [formatProps]\n );\n\n const handleThousandSeparatorChange = React.useCallback(\n (thousandSeparator: string) => {\n let decimalSeparator = formatProps.decimalSeparator;\n // make sure 1000 and decimal separator do not match\n // istanbul ignore else\n if (isFormatTraitSet(FormatTraits.Use1000Separator)) {\n if (thousandSeparator === \".\") decimalSeparator = \",\";\n // thousandSeparator === \",\"\n else decimalSeparator = \".\";\n }\n const newFormatProps = {\n ...formatProps,\n thousandSeparator,\n decimalSeparator,\n };\n handleSetFormatProps(newFormatProps);\n },\n [formatProps, isFormatTraitSet, handleSetFormatProps]\n );\n\n const useThousandSeparatorLabel = React.useRef(\n UiIModelComponents.translate(\n \"QuantityFormat.labels.useThousandSeparatorLabel\"\n )\n );\n const thousandSeparatorLabel = React.useRef(\n UiIModelComponents.translate(\"QuantityFormat.labels.thousandSeparatorLabel\")\n );\n\n return (\n <>\n <span className={\"uicore-label\"}>\n {useThousandSeparatorLabel.current}\n </span>\n <Checkbox\n data-testid=\"use-thousands-separator\"\n checked={isFormatTraitSet(FormatTraits.Use1000Separator)}\n onChange={handleUseThousandsSeparatorChange}\n />\n <span\n className={classnames(\n \"uicore-label\",\n !isFormatTraitSet(FormatTraits.Use1000Separator) && \"uicore-disabled\"\n )}\n >\n {thousandSeparatorLabel.current}\n </span>\n <ThousandsSelector\n data-testid=\"thousands-separator-selector\"\n separator={formatProps.thousandSeparator ?? \",\"}\n disabled={!isFormatTraitSet(FormatTraits.Use1000Separator)}\n onChange={handleThousandSeparatorChange}\n />\n </>\n );\n}\n"]}