@itwin/imodel-components-react 5.11.2 → 5.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/lib/imodel-components-react/UiIModelComponents.json +32 -1
- package/lib/imodel-components-react/quantityformat/FormatPanel.d.ts +3 -1
- package/lib/imodel-components-react/quantityformat/FormatPanel.d.ts.map +1 -1
- package/lib/imodel-components-react/quantityformat/FormatPanel.js +2 -1
- package/lib/imodel-components-react/quantityformat/FormatPanel.js.map +1 -1
- package/lib/imodel-components-react/quantityformat/FormatPrecision.d.ts.map +1 -1
- package/lib/imodel-components-react/quantityformat/FormatPrecision.js +4 -2
- package/lib/imodel-components-react/quantityformat/FormatPrecision.js.map +1 -1
- package/lib/imodel-components-react/quantityformat/FormatType.d.ts.map +1 -1
- package/lib/imodel-components-react/quantityformat/FormatType.js +60 -17
- package/lib/imodel-components-react/quantityformat/FormatType.js.map +1 -1
- package/lib/imodel-components-react/quantityformat/FormatUnitLabel.d.ts.map +1 -1
- package/lib/imodel-components-react/quantityformat/FormatUnitLabel.js +6 -5
- package/lib/imodel-components-react/quantityformat/FormatUnitLabel.js.map +1 -1
- package/lib/imodel-components-react/quantityformat/MiscFormatOptions.d.ts.map +1 -1
- package/lib/imodel-components-react/quantityformat/MiscFormatOptions.js +54 -27
- package/lib/imodel-components-react/quantityformat/MiscFormatOptions.js.map +1 -1
- package/lib/imodel-components-react/quantityformat/QuantityFormatPanel.d.ts.map +1 -1
- package/lib/imodel-components-react/quantityformat/QuantityFormatPanel.js +2 -2
- package/lib/imodel-components-react/quantityformat/QuantityFormatPanel.js.map +1 -1
- package/lib/imodel-components-react/quantityformat/misc/AzimuthOptions.d.ts +15 -0
- package/lib/imodel-components-react/quantityformat/misc/AzimuthOptions.d.ts.map +1 -0
- package/lib/imodel-components-react/quantityformat/misc/AzimuthOptions.js +53 -0
- package/lib/imodel-components-react/quantityformat/misc/AzimuthOptions.js.map +1 -0
- package/lib/imodel-components-react/quantityformat/misc/DecimalPrecision.js +2 -2
- package/lib/imodel-components-react/quantityformat/misc/DecimalPrecision.js.map +1 -1
- package/lib/imodel-components-react/quantityformat/misc/DecimalSeparator.js +2 -2
- package/lib/imodel-components-react/quantityformat/misc/DecimalSeparator.js.map +1 -1
- package/lib/imodel-components-react/quantityformat/misc/FractionPrecision.js +2 -2
- package/lib/imodel-components-react/quantityformat/misc/FractionPrecision.js.map +1 -1
- package/lib/imodel-components-react/quantityformat/misc/RatioType.d.ts +15 -0
- package/lib/imodel-components-react/quantityformat/misc/RatioType.d.ts.map +1 -0
- package/lib/imodel-components-react/quantityformat/misc/RatioType.js +45 -0
- package/lib/imodel-components-react/quantityformat/misc/RatioType.js.map +1 -0
- package/lib/imodel-components-react/quantityformat/misc/ScientificType.d.ts.map +1 -1
- package/lib/imodel-components-react/quantityformat/misc/ScientificType.js +2 -2
- package/lib/imodel-components-react/quantityformat/misc/ScientificType.js.map +1 -1
- package/lib/imodel-components-react/quantityformat/misc/SignOption.js +2 -2
- package/lib/imodel-components-react/quantityformat/misc/SignOption.js.map +1 -1
- package/lib/imodel-components-react/quantityformat/misc/StationSeparatorSelector.js +2 -2
- package/lib/imodel-components-react/quantityformat/misc/StationSeparatorSelector.js.map +1 -1
- package/lib/imodel-components-react/quantityformat/misc/StationSizeSelector.js +2 -2
- package/lib/imodel-components-react/quantityformat/misc/StationSizeSelector.js.map +1 -1
- package/lib/imodel-components-react/quantityformat/misc/ThousandsSelector.d.ts.map +1 -1
- package/lib/imodel-components-react/quantityformat/misc/ThousandsSelector.js +2 -2
- package/lib/imodel-components-react/quantityformat/misc/ThousandsSelector.js.map +1 -1
- package/lib/imodel-components-react/quantityformat/misc/ThousandsSeparator.d.ts.map +1 -1
- package/lib/imodel-components-react/quantityformat/misc/ThousandsSeparator.js +7 -5
- package/lib/imodel-components-react/quantityformat/misc/ThousandsSeparator.js.map +1 -1
- package/lib/public/locales/en/UiIModelComponents.json +32 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Change Log - @itwin/imodel-components-react
|
|
2
2
|
|
|
3
|
+
## 5.12.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- d4db451: Add support for Bearing, Ratio, Azimuth format types for FormatsPanel, including their properties. Drop use of deprecated APIs in quantity formatting related components.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- @itwin/components-react@5.12.0
|
|
12
|
+
- @itwin/core-react@5.12.0
|
|
13
|
+
|
|
3
14
|
## 5.11.2
|
|
4
15
|
|
|
5
16
|
### Patch Changes
|
|
@@ -54,6 +54,9 @@
|
|
|
54
54
|
"scientific": "Scientific",
|
|
55
55
|
"station": "Station",
|
|
56
56
|
"fractional": "Fractional",
|
|
57
|
+
"bearing": "Bearing",
|
|
58
|
+
"azimuth": "Azimuth",
|
|
59
|
+
"ratio": "Ratio",
|
|
57
60
|
"labels": {
|
|
58
61
|
"compositeSpacer": "Composite Spacer",
|
|
59
62
|
"formatted": "Formatted",
|
|
@@ -75,7 +78,10 @@
|
|
|
75
78
|
"scientificTypeLabel": "Scientific Type",
|
|
76
79
|
"useThousandSeparatorLabel": "Use Thousand Separator",
|
|
77
80
|
"thousandSeparatorLabel": "Thousand Separator",
|
|
78
|
-
"value": "Value"
|
|
81
|
+
"value": "Value",
|
|
82
|
+
"ratioTypeLabel": "Ratio Type",
|
|
83
|
+
"azimuthBase": "Azimuth Base",
|
|
84
|
+
"azimuthCounterClockwise": "Enable Azimuth Counter-Clockwise"
|
|
79
85
|
},
|
|
80
86
|
"fraction_precision": {
|
|
81
87
|
"whole": "Whole",
|
|
@@ -133,6 +139,31 @@
|
|
|
133
139
|
},
|
|
134
140
|
"popupButton": {
|
|
135
141
|
"setFormat": "Set Format"
|
|
142
|
+
},
|
|
143
|
+
"ratio-type": {
|
|
144
|
+
"n-to-one": {
|
|
145
|
+
"label": "N:1",
|
|
146
|
+
"description": "N to 1 ratio (e.g. N:1)"
|
|
147
|
+
},
|
|
148
|
+
"one-to-n": {
|
|
149
|
+
"label": "1:N",
|
|
150
|
+
"description": "1 to N ratio (e.g. 1:N)"
|
|
151
|
+
},
|
|
152
|
+
"use-greatest-common-divisor": {
|
|
153
|
+
"label": "GCD",
|
|
154
|
+
"description": "Simplifies ratio using GCD (e.g. 0.3 → 3:10)"
|
|
155
|
+
},
|
|
156
|
+
"value-based": {
|
|
157
|
+
"label": "Value Based",
|
|
158
|
+
"description": "Scales the smaller value to 1 (e.g. 0.5 → 2:1, 2 → 1:2)"
|
|
159
|
+
},
|
|
160
|
+
"default": {
|
|
161
|
+
"description": "How properties are shown as a ratio."
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
"azimuthType": {
|
|
165
|
+
"baseTooltip": "The starting direction (base) from which azimuth angles are measured.",
|
|
166
|
+
"ccwFlagTooltip": "If checked, azimuth angles are measured in a counter-clockwise direction from the base."
|
|
136
167
|
}
|
|
137
168
|
},
|
|
138
169
|
"BearingQuantityType": {
|
|
@@ -22,8 +22,10 @@ export interface FormatPanelProps extends CommonProps {
|
|
|
22
22
|
providePrimaryChildren?: (formatProps: FormatProps, fireFormatChange: (newProps: FormatProps) => void) => React.ReactNode;
|
|
23
23
|
provideSecondaryChildren?: (formatProps: FormatProps, fireFormatChange: (newProps: FormatProps) => void) => React.ReactNode;
|
|
24
24
|
}
|
|
25
|
+
type FormatPanelPropsWithoutPersistenceUnit = Omit<FormatPanelProps, "persistenceUnit"> & Partial<Pick<FormatPanelProps, "persistenceUnit">>;
|
|
25
26
|
/** Component to show/edit Quantity Format.
|
|
26
27
|
* @alpha
|
|
27
28
|
*/
|
|
28
|
-
export declare function FormatPanel(props:
|
|
29
|
+
export declare function FormatPanel(props: FormatPanelPropsWithoutPersistenceUnit): React.JSX.Element;
|
|
30
|
+
export {};
|
|
29
31
|
//# sourceMappingURL=FormatPanel.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormatPanel.d.ts","sourceRoot":"","sources":["../../../src/imodel-components-react/quantityformat/FormatPanel.tsx"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,oBAAoB,CAAC;AAC5B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EACV,WAAW,EACX,SAAS,EACT,aAAa,EACd,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAU,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAQrD;;;GAGG;AAEH,MAAM,WAAW,gBAAiB,SAAQ,WAAW;IACnD,aAAa,EAAE,WAAW,CAAC;IAC3B,aAAa,EAAE,aAAa,CAAC;IAC7B,eAAe,EAAE,OAAO,CAAC,SAAS,CAAC,GAAG,SAAS,CAAC;IAChD,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,IAAI,CAAC;IAC/C,iBAAiB,CAAC,EAAE,CAClB,WAAW,EAAE,WAAW,EACxB,eAAe,EAAE,SAAS,EAC1B,aAAa,EAAE,aAAa,KACzB,OAAO,CAAC,aAAa,CAAC,CAAC;IAC5B,sBAAsB,CAAC,EAAE,CACvB,WAAW,EAAE,WAAW,EACxB,gBAAgB,EAAE,CAAC,QAAQ,EAAE,WAAW,KAAK,IAAI,KAC9C,KAAK,CAAC,SAAS,CAAC;IACrB,wBAAwB,CAAC,EAAE,CACzB,WAAW,EAAE,WAAW,EACxB,gBAAgB,EAAE,CAAC,QAAQ,EAAE,WAAW,KAAK,IAAI,KAC9C,KAAK,CAAC,SAAS,CAAC;CACtB;AAoBD;;GAEG;
|
|
1
|
+
{"version":3,"file":"FormatPanel.d.ts","sour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AAiB,CAAC,CAAC,CAAC;AACrD;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,sCAAsC,qBAoHxE"}
|
|
@@ -21,7 +21,6 @@ async function generateFormatSpec(formatProps, persistenceUnit, unitsProvider) {
|
|
|
21
21
|
/** Component to show/edit Quantity Format.
|
|
22
22
|
* @alpha
|
|
23
23
|
*/
|
|
24
|
-
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
25
24
|
export function FormatPanel(props) {
|
|
26
25
|
const [formatSpec, setFormatSpec] = React.useState();
|
|
27
26
|
const { initialFormat, showSample, initialMagnitude, unitsProvider, persistenceUnit, onFormatChange, provideFormatSpec, enableMinimumProperties, } = props;
|
|
@@ -46,6 +45,8 @@ export function FormatPanel(props) {
|
|
|
46
45
|
}, []);
|
|
47
46
|
React.useEffect(() => {
|
|
48
47
|
async function fetchFormatSpec() {
|
|
48
|
+
if (!persistenceUnit)
|
|
49
|
+
return;
|
|
49
50
|
const pu = await persistenceUnit;
|
|
50
51
|
let newFormatSpec;
|
|
51
52
|
if (provideFormatSpec) {
|
|
@@ -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,sBAAsB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AA+B3D,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;
|
|
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,sBAAsB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AA+B3D,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;AASD;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,KAA6C;IACvE,MAAM,C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,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.js\";\nimport { FormatSample } from \"./FormatSample.js\";\nimport { FormatTypeOption } from \"./FormatType.js\";\nimport { FormatUnitLabel } from \"./FormatUnitLabel.js\";\nimport { FormatUnits } from \"./FormatUnits.js\";\nimport { MiscFormatOptions } from \"./MiscFormatOptions.js\";\n\n/** Properties of [[FormatPanel]] component.\n * @alpha\n * @deprecated in 4.17.0. Use `React.ComponentProps<typeof FormatPanel>`\n */\n// eslint-disable-next-line @typescript-eslint/no-deprecated\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\ntype FormatPanelPropsWithoutPersistenceUnit = Omit<\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n FormatPanelProps,\n \"persistenceUnit\"\n> &\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n Partial<Pick<FormatPanelProps, \"persistenceUnit\">>;\n/** Component to show/edit Quantity Format.\n * @alpha\n */\nexport function FormatPanel(props: FormatPanelPropsWithoutPersistenceUnit) {\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 if (!persistenceUnit) return;\n\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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormatPrecision.d.ts","sourceRoot":"","sources":["../../../src/imodel-components-react/quantityformat/FormatPrecision.tsx"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"FormatPrecision.d.ts","sourceRoot":"","sources":["../../../src/imodel-components-react/quantityformat/FormatPrecision.tsx"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAOxD;;;GAGG;AAEH,MAAM,WAAW,oBAAqB,SAAQ,WAAW;IACvD,WAAW,EAAE,WAAW,CAAC;IACzB,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,IAAI,CAAC;CAC1C;AAED;;GAEG;AAEH,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,qBAuC1D"}
|
|
@@ -10,6 +10,7 @@ import { FormatType, parseFormatType } from "@itwin/core-quantity";
|
|
|
10
10
|
import { DecimalPrecisionSelector } from "./misc/DecimalPrecision.js";
|
|
11
11
|
import { FractionPrecisionSelector } from "./misc/FractionPrecision.js";
|
|
12
12
|
import { useTranslation } from "../useTranslation.js";
|
|
13
|
+
import { Label } from "@itwin/itwinui-react";
|
|
13
14
|
/** Component to show/edit Quantity Format Precision.
|
|
14
15
|
* @alpha
|
|
15
16
|
*/
|
|
@@ -17,13 +18,14 @@ import { useTranslation } from "../useTranslation.js";
|
|
|
17
18
|
export function FormatPrecision(props) {
|
|
18
19
|
const { formatProps, onChange } = props;
|
|
19
20
|
const { translate } = useTranslation();
|
|
21
|
+
const precisionSelectorId = React.useId();
|
|
20
22
|
const handlePrecisionChange = React.useCallback((precision) => {
|
|
21
23
|
const newFormatProps = { ...formatProps, precision };
|
|
22
24
|
onChange && onChange(newFormatProps);
|
|
23
25
|
}, [formatProps, onChange]);
|
|
24
26
|
const formatType = parseFormatType(formatProps.type, "format");
|
|
25
27
|
return (React.createElement(React.Fragment, null,
|
|
26
|
-
React.createElement(
|
|
27
|
-
formatType === FormatType.Fractional ? (React.createElement(FractionPrecisionSelector, { "
|
|
28
|
+
React.createElement(Label, { className: "uicore-label", as: "div", displayStyle: "inline", id: precisionSelectorId }, translate("QuantityFormat.labels.precision")),
|
|
29
|
+
formatType === FormatType.Fractional ? (React.createElement(FractionPrecisionSelector, { "aria-labelledby": precisionSelectorId, precision: formatProps.precision ?? 0, onChange: handlePrecisionChange })) : (React.createElement(DecimalPrecisionSelector, { "aria-labelledby": precisionSelectorId, precision: formatProps.precision ?? 0, onChange: handlePrecisionChange }))));
|
|
28
30
|
}
|
|
29
31
|
//# 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,4BAA4B,CAAC;AACtE,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"FormatPrecision.js","sourceRoot":"","sources":["../../../src/imodel-components-react/quantityformat/FormatPrecision.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,KAAK,KAA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,CACF,oBAAC,wBAAwB,uBACN,mBAAmB,EACpC,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.js\";\nimport { FractionPrecisionSelector } from \"./misc/FractionPrecision.js\";\nimport { useTranslation } from \"../useTranslation.js\";\nimport { Label } from \"@itwin/itwinui-react\";\n\n/** Properties of [[FormatPrecision]] component.\n * @alpha\n * @deprecated in 4.17.0. Use `React.ComponentProps<typeof FormatPrecision>`\n */\n// eslint-disable-next-line @typescript-eslint/no-deprecated\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 */\n// eslint-disable-next-line @typescript-eslint/no-deprecated\nexport function FormatPrecision(props: FormatPrecisionProps) {\n const { formatProps, onChange } = props;\n const { translate } = useTranslation();\n const precisionSelectorId = React.useId();\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 return (\n <>\n <Label\n className={\"uicore-label\"}\n as=\"div\"\n displayStyle=\"inline\"\n id={precisionSelectorId}\n >\n {translate(\"QuantityFormat.labels.precision\")}\n </Label>\n {formatType === FormatType.Fractional ? (\n <FractionPrecisionSelector\n aria-labelledby={precisionSelectorId}\n precision={formatProps.precision ?? 0}\n onChange={handlePrecisionChange}\n />\n ) : (\n <DecimalPrecisionSelector\n aria-labelledby={precisionSelectorId}\n precision={formatProps.precision ?? 0}\n onChange={handlePrecisionChange}\n />\n )}\n </>\n );\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormatType.d.ts","sourceRoot":"","sources":["../../../src/imodel-components-react/quantityformat/FormatType.tsx"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"FormatType.d.ts","sourceRoot":"","sources":["../../../src/imodel-components-react/quantityformat/FormatType.tsx"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AA4GxD;;;GAGG;AAEH,MAAM,WAAW,qBAAsB,SAAQ,WAAW;IACxD,WAAW,EAAE,WAAW,CAAC;IACzB,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,IAAI,CAAC;CAC1C;AAED;;GAEG;AAEH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,qBA8E5D"}
|
|
@@ -6,16 +6,17 @@
|
|
|
6
6
|
* @module QuantityFormat
|
|
7
7
|
*/
|
|
8
8
|
import * as React from "react";
|
|
9
|
-
import { DecimalPrecision, FormatType,
|
|
10
|
-
import { Select } from "@itwin/itwinui-react";
|
|
9
|
+
import { DecimalPrecision, FormatType, FractionalPrecision, parseFormatType, RatioType, ScientificType, } from "@itwin/core-quantity";
|
|
10
|
+
import { Label, Select } from "@itwin/itwinui-react";
|
|
11
11
|
import { useTranslation } from "../useTranslation.js";
|
|
12
12
|
/** Component to select the format type.
|
|
13
13
|
* @alpha
|
|
14
14
|
*/
|
|
15
15
|
function FormatTypeSelector(props) {
|
|
16
|
-
const { type, onChange, ...
|
|
16
|
+
const { type, onChange, ...rest } = props;
|
|
17
17
|
const { translate } = useTranslation();
|
|
18
|
-
const
|
|
18
|
+
const formatTypeSelectorId = React.useId();
|
|
19
|
+
const formatOptions = React.useMemo(() => [
|
|
19
20
|
{
|
|
20
21
|
value: FormatType.Decimal,
|
|
21
22
|
label: translate("QuantityFormat.decimal"),
|
|
@@ -32,31 +33,53 @@ function FormatTypeSelector(props) {
|
|
|
32
33
|
value: FormatType.Fractional,
|
|
33
34
|
label: translate("QuantityFormat.fractional"),
|
|
34
35
|
},
|
|
35
|
-
|
|
36
|
+
{
|
|
37
|
+
value: FormatType.Bearing,
|
|
38
|
+
label: translate("QuantityFormat.bearing"),
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
value: FormatType.Azimuth,
|
|
42
|
+
label: translate("QuantityFormat.azimuth"),
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
value: FormatType.Ratio,
|
|
46
|
+
label: translate("QuantityFormat.ratio"),
|
|
47
|
+
},
|
|
48
|
+
], [translate]);
|
|
36
49
|
const handleOnChange = React.useCallback((newValue) => {
|
|
37
50
|
onChange && onChange(newValue);
|
|
38
51
|
}, [onChange]);
|
|
39
|
-
return (React.createElement(
|
|
52
|
+
return (React.createElement(React.Fragment, null,
|
|
53
|
+
React.createElement(Label, { className: "uicore-label", as: "div", displayStyle: "inline", id: formatTypeSelectorId }, translate("QuantityFormat.labels.type")),
|
|
54
|
+
React.createElement(Select, { options: formatOptions, value: type, "aria-labelledby": formatTypeSelectorId, onChange: handleOnChange, size: "small", ...rest })));
|
|
40
55
|
}
|
|
56
|
+
const handleUnitsWhenFormatTypeChange = (units, type) => {
|
|
57
|
+
if (type === FormatType.Ratio) {
|
|
58
|
+
// Only one display unit is allowed for Ratio format.
|
|
59
|
+
if (units.length > 1) {
|
|
60
|
+
return [units[0]];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return units;
|
|
64
|
+
};
|
|
41
65
|
/** Component to set the Quantity Format type.
|
|
42
66
|
* @alpha
|
|
43
67
|
*/
|
|
44
68
|
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
45
69
|
export function FormatTypeOption(props) {
|
|
46
|
-
const { formatProps, onChange } = props;
|
|
47
|
-
const
|
|
48
|
-
const handleFormatTypeChange = React.useCallback((newType) => {
|
|
49
|
-
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
50
|
-
const type = formatTypeToString(newType);
|
|
70
|
+
const { formatProps, onChange, ...rest } = props;
|
|
71
|
+
const handleFormatTypeChange = React.useCallback((type) => {
|
|
51
72
|
let precision;
|
|
52
73
|
let stationOffsetSize;
|
|
53
74
|
let scientificType;
|
|
54
|
-
|
|
55
|
-
|
|
75
|
+
let azimuthBaseUnit;
|
|
76
|
+
let azimuthBase;
|
|
77
|
+
let revolutionUnit;
|
|
78
|
+
let ratioType;
|
|
79
|
+
switch (type) {
|
|
56
80
|
case FormatType.Scientific:
|
|
57
81
|
precision = DecimalPrecision.Six;
|
|
58
|
-
|
|
59
|
-
scientificType = scientificTypeToString(ScientificType.Normalized);
|
|
82
|
+
scientificType = ScientificType.Normalized;
|
|
60
83
|
break;
|
|
61
84
|
case FormatType.Decimal:
|
|
62
85
|
precision = DecimalPrecision.Four;
|
|
@@ -72,19 +95,39 @@ export function FormatTypeOption(props) {
|
|
|
72
95
|
case FormatType.Fractional:
|
|
73
96
|
precision = FractionalPrecision.Eight;
|
|
74
97
|
break;
|
|
98
|
+
case FormatType.Bearing:
|
|
99
|
+
revolutionUnit = "Units.REVOLUTION"; // Warning: By default, BasicUnitsProvider does not contain this unit.
|
|
100
|
+
break;
|
|
101
|
+
case FormatType.Azimuth:
|
|
102
|
+
revolutionUnit = "Units.REVOLUTION"; // Warning: By default, BasicUnitsProvider does not contain this unit.
|
|
103
|
+
azimuthBaseUnit = "Units.ARC_DEG";
|
|
104
|
+
azimuthBase = 0.0;
|
|
105
|
+
break;
|
|
106
|
+
case FormatType.Ratio:
|
|
107
|
+
ratioType = RatioType.NToOne; // Default to N:1 ratio
|
|
108
|
+
break;
|
|
75
109
|
}
|
|
76
110
|
const newFormatProps = {
|
|
77
111
|
...formatProps,
|
|
112
|
+
composite: formatProps.composite
|
|
113
|
+
? {
|
|
114
|
+
...formatProps.composite,
|
|
115
|
+
units: handleUnitsWhenFormatTypeChange(formatProps.composite.units, type),
|
|
116
|
+
}
|
|
117
|
+
: undefined,
|
|
78
118
|
type,
|
|
79
119
|
precision,
|
|
80
120
|
scientificType,
|
|
81
121
|
stationOffsetSize,
|
|
122
|
+
revolutionUnit,
|
|
123
|
+
azimuthBaseUnit,
|
|
124
|
+
azimuthBase,
|
|
125
|
+
ratioType,
|
|
82
126
|
};
|
|
83
127
|
onChange && onChange(newFormatProps);
|
|
84
128
|
}, [formatProps, onChange]);
|
|
85
129
|
const formatType = parseFormatType(formatProps.type, "format");
|
|
86
130
|
return (React.createElement(React.Fragment, null,
|
|
87
|
-
React.createElement(
|
|
88
|
-
React.createElement(FormatTypeSelector, { "data-testid": "format-type-selector", type: formatType, onChange: handleFormatTypeChange })));
|
|
131
|
+
React.createElement(FormatTypeSelector, { ...rest, type: formatType, onChange: handleFormatTypeChange })));
|
|
89
132
|
}
|
|
90
133
|
//# sourceMappingURL=FormatType.js.map
|
|
@@ -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,CAAC;AAG/B,OAAO,EACL,gBAAgB,EAChB,UAAU,EACV,kBAAkB,EAClB,mBAAmB,EACnB,eAAe,EACf,cA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AAE,QAAQ,CAAC,CAAC;IAC/D,OAAO,CACL;QACE,8BAAM,SAAS,EAAE,sBAAsB,IACpC,SAAS,CAAC,4BAA4B,CAAC,CACnC;QACP,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 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\";\nimport { useTranslation } from \"../useTranslation.js\";\n\n/** Properties of [[FormatTypeSelector]] component.\n * @alpha\n */\n// eslint-disable-next-line @typescript-eslint/no-deprecated\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 { translate } = useTranslation();\n const formatOptions = React.useRef<SelectOption<FormatType>[]>([\n {\n value: FormatType.Decimal,\n label: translate(\"QuantityFormat.decimal\"),\n },\n {\n value: FormatType.Scientific,\n label: translate(\"QuantityFormat.scientific\"),\n },\n {\n value: FormatType.Station,\n label: translate(\"QuantityFormat.station\"),\n },\n {\n value: FormatType.Fractional,\n label: 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 [[FormatTypeOption]] component.\n * @alpha\n * @deprecated in 4.17.0. Use `React.ComponentProps<typeof FormatTypeOption>`\n */\n// eslint-disable-next-line @typescript-eslint/no-deprecated\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 */\n// eslint-disable-next-line @typescript-eslint/no-deprecated\nexport function FormatTypeOption(props: FormatTypeOptionProps) {\n const { formatProps, onChange } = props;\n const { translate } = useTranslation();\n const handleFormatTypeChange = React.useCallback(\n (newType: FormatType) => {\n // eslint-disable-next-line @typescript-eslint/no-deprecated\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 // eslint-disable-next-line @typescript-eslint/no-deprecated\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 return (\n <>\n <span className={\"uicore-label.current\"}>\n {translate(\"QuantityFormat.labels.type\")}\n </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;;GAEG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,EACL,gBAAgB,EAChB,UAAU,EACV,mBAAmB,EACnB,eAAe,EACf,SAAS,EACT,cAAc,GACf,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAWtD;;GAEG;AACH,SAAS,kBAAkB,CAAC,KAA8B;IACxD,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC;IAC1C,MAAM,EAAE,SAAS,EAAE,GAAG,cAAc,EAAE,CAAC;IACvC,MAAM,oBAAoB,GAAG,KAAK,CAAC,KAAK,EAAE,CAAC;IAC3C,MAAM,aAAa,GAAG,KAAK,CAAC,OAAO,CACjC,GAAG,EAAE,CAAC;QACJ;YACE,KAAK,EAAE,UAAU,CAAC,OAAO;YACzB,KAAK,EAAE,SAAS,CAAC,wBAAwB,CAAC;SAC3C;QACD;YACE,KAAK,EAAE,UAAU,CAAC,UAAU;YAC5B,KAAK,EAAE,SAAS,CAAC,2BAA2B,CAAC;SAC9C;QACD;YACE,KAAK,EAAE,UAAU,CAAC,OAAO;YACzB,KAAK,EAAE,SAAS,CAAC,wBAAwB,CAAC;SAC3C;QACD;YACE,KAAK,EAAE,UAAU,CAAC,UAAU;YAC5B,KAAK,EAAE,SAAS,CAAC,2BAA2B,CAAC;SAC9C;QACD;YACE,KAAK,EAAE,UAAU,CAAC,OAAO;YACzB,KAAK,EAAE,SAAS,CAAC,wBAAwB,CAAC;SAC3C;QACD;YACE,KAAK,EAAE,UAAU,CAAC,OAAO;YACzB,KAAK,EAAE,SAAS,CAAC,wBAAwB,CAAC;SAC3C;QACD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EAAE,+BAA+B,CACpC,WAAW,CAAC,SAAS,CAAC,KAAK,EAC3B,IAAI,CACL;iBACF;gBACH,CAAC,CAAC,SAAS;YACb,IAAI;YACJ,SAAS;YACT,cAAc;YACd,iBAAiB;YACjB,cAAc;YACd,eAAe;YACf,WAAW;YACX,SAAS;SACV,CAAC;QACF,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;IAC/D,OAAO,CACL;QACE,oBAAC,kBAAkB,OACb,IAAI,EACR,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 type { FormatProps } from \"@itwin/core-quantity\";\nimport {\n DecimalPrecision,\n FormatType,\n FractionalPrecision,\n parseFormatType,\n RatioType,\n ScientificType,\n} from \"@itwin/core-quantity\";\nimport type { SelectOption } from \"@itwin/itwinui-react\";\nimport { Label, Select } from \"@itwin/itwinui-react\";\nimport { useTranslation } from \"../useTranslation.js\";\n\n/** Properties of [[FormatTypeSelector]] component.\n * @alpha\n */\n// eslint-disable-next-line @typescript-eslint/no-deprecated\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, ...rest } = props;\n const { translate } = useTranslation();\n const formatTypeSelectorId = React.useId();\n const formatOptions = React.useMemo<SelectOption<FormatType>[]>(\n () => [\n {\n value: FormatType.Decimal,\n label: translate(\"QuantityFormat.decimal\"),\n },\n {\n value: FormatType.Scientific,\n label: translate(\"QuantityFormat.scientific\"),\n },\n {\n value: FormatType.Station,\n label: translate(\"QuantityFormat.station\"),\n },\n {\n value: FormatType.Fractional,\n label: translate(\"QuantityFormat.fractional\"),\n },\n {\n value: FormatType.Bearing,\n label: translate(\"QuantityFormat.bearing\"),\n },\n {\n value: FormatType.Azimuth,\n label: translate(\"QuantityFormat.azimuth\"),\n },\n {\n value: FormatType.Ratio,\n label: translate(\"QuantityFormat.ratio\"),\n },\n ],\n [translate]\n );\n\n const handleOnChange = React.useCallback(\n (newValue: FormatType) => {\n onChange && onChange(newValue);\n },\n [onChange]\n );\n\n return (\n <>\n <Label\n className=\"uicore-label\"\n as=\"div\"\n displayStyle=\"inline\"\n id={formatTypeSelectorId}\n >\n {translate(\"QuantityFormat.labels.type\")}\n </Label>\n <Select\n options={formatOptions}\n value={type}\n aria-labelledby={formatTypeSelectorId}\n onChange={handleOnChange}\n size=\"small\"\n {...rest}\n />\n </>\n );\n}\n\nconst handleUnitsWhenFormatTypeChange = (\n units: Array<{\n readonly name: string;\n readonly label?: string;\n }>,\n type: FormatType\n) => {\n if (type === FormatType.Ratio) {\n // Only one display unit is allowed for Ratio format.\n if (units.length > 1) {\n return [units[0]];\n }\n }\n return units;\n};\n\n/** Properties of [[FormatTypeOption]] component.\n * @alpha\n * @deprecated in 4.17.0. Use `React.ComponentProps<typeof FormatTypeOption>`\n */\n// eslint-disable-next-line @typescript-eslint/no-deprecated\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 */\n// eslint-disable-next-line @typescript-eslint/no-deprecated\nexport function FormatTypeOption(props: FormatTypeOptionProps) {\n const { formatProps, onChange, ...rest } = props;\n\n const handleFormatTypeChange = React.useCallback(\n (type: FormatType) => {\n let precision: number | undefined;\n let stationOffsetSize: number | undefined;\n let scientificType: string | undefined;\n let azimuthBaseUnit: string | undefined;\n let azimuthBase: number | undefined;\n let revolutionUnit: string | undefined;\n let ratioType: string | undefined;\n switch (type) {\n case FormatType.Scientific:\n precision = DecimalPrecision.Six;\n scientificType = 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 case FormatType.Bearing:\n revolutionUnit = \"Units.REVOLUTION\"; // Warning: By default, BasicUnitsProvider does not contain this unit.\n break;\n case FormatType.Azimuth:\n revolutionUnit = \"Units.REVOLUTION\"; // Warning: By default, BasicUnitsProvider does not contain this unit.\n azimuthBaseUnit = \"Units.ARC_DEG\";\n azimuthBase = 0.0;\n break;\n case FormatType.Ratio:\n ratioType = RatioType.NToOne; // Default to N:1 ratio\n break;\n }\n const newFormatProps: FormatProps = {\n ...formatProps,\n composite: formatProps.composite\n ? {\n ...formatProps.composite,\n units: handleUnitsWhenFormatTypeChange(\n formatProps.composite.units,\n type\n ),\n }\n : undefined,\n type,\n precision,\n scientificType,\n stationOffsetSize,\n revolutionUnit,\n azimuthBaseUnit,\n azimuthBase,\n ratioType,\n };\n onChange && onChange(newFormatProps);\n },\n [formatProps, onChange]\n );\n\n const formatType = parseFormatType(formatProps.type, \"format\");\n return (\n <>\n <FormatTypeSelector\n {...rest}\n type={formatType}\n onChange={handleFormatTypeChange}\n />\n </>\n );\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormatUnitLabel.d.ts","sourceRoot":"","sources":["../../../src/imodel-components-react/quantityformat/FormatUnitLabel.tsx"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"FormatUnitLabel.d.ts","sourceRoot":"","sources":["../../../src/imodel-components-react/quantityformat/FormatUnitLabel.tsx"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAsDxD;;;GAGG;AAEH,MAAM,WAAW,oBAAqB,SAAQ,WAAW;IACvD,WAAW,EAAE,WAAW,CAAC;IACzB,iBAAiB,CAAC,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,IAAI,CAAC;CACnD;AAED;;GAEG;AAEH,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,qBA2F1D"}
|
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
import classnames from "classnames";
|
|
9
9
|
import * as React from "react";
|
|
10
10
|
import { Format, FormatTraits, getTraitString } from "@itwin/core-quantity";
|
|
11
|
-
import { Checkbox, Select } from "@itwin/itwinui-react";
|
|
11
|
+
import { Checkbox, Label, Select } from "@itwin/itwinui-react";
|
|
12
12
|
import { useTranslation } from "../useTranslation.js";
|
|
13
13
|
function UomSeparatorSelector(props) {
|
|
14
|
-
const { separator, onChange, ...
|
|
14
|
+
const { separator, onChange, disabled, ...rest } = props;
|
|
15
15
|
const { translate } = useTranslation();
|
|
16
16
|
const handleOnChange = React.useCallback((newValue) => {
|
|
17
17
|
onChange && onChange(newValue);
|
|
@@ -30,7 +30,7 @@ function UomSeparatorSelector(props) {
|
|
|
30
30
|
completeListOfEntries.push(...uomDefaultEntries);
|
|
31
31
|
return completeListOfEntries;
|
|
32
32
|
}, [separator, translate]);
|
|
33
|
-
return (React.createElement(Select, { options: separatorOptions, value: separator, onChange: handleOnChange, size: "small", ...
|
|
33
|
+
return (React.createElement(Select, { options: separatorOptions, value: separator, onChange: handleOnChange, size: "small", disabled: disabled, ...rest }));
|
|
34
34
|
}
|
|
35
35
|
/** Component to set the label separator definition in a Quantity Format and if it the label is to be displayed.
|
|
36
36
|
* @alpha
|
|
@@ -39,6 +39,7 @@ function UomSeparatorSelector(props) {
|
|
|
39
39
|
export function FormatUnitLabel(props) {
|
|
40
40
|
const { formatProps, onUnitLabelChange } = props;
|
|
41
41
|
const { translate } = useTranslation();
|
|
42
|
+
const uomSeparatorSelectorId = React.useId();
|
|
42
43
|
const handleSetFormatProps = React.useCallback((newProps) => {
|
|
43
44
|
onUnitLabelChange && onUnitLabelChange(newProps);
|
|
44
45
|
}, [onUnitLabelChange]);
|
|
@@ -81,7 +82,7 @@ export function FormatUnitLabel(props) {
|
|
|
81
82
|
return (React.createElement(React.Fragment, null,
|
|
82
83
|
React.createElement("span", { className: "uicore-label" }, translate("QuantityFormat.labels.appendUnitLabel")),
|
|
83
84
|
React.createElement(Checkbox, { "data-testid": "show-unit-label-checkbox", checked: isFormatTraitSet(FormatTraits.ShowUnitLabel), onChange: handleShowUnitLabelChange }),
|
|
84
|
-
React.createElement("
|
|
85
|
-
React.createElement(UomSeparatorSelector, { "
|
|
85
|
+
React.createElement(Label, { as: "div", displayStyle: "inline", id: uomSeparatorSelectorId, className: classnames("uicore-label", !isFormatTraitSet(FormatTraits.ShowUnitLabel) && "uicore-disabled") }, translate("QuantityFormat.labels.labelSeparator")),
|
|
86
|
+
React.createElement(UomSeparatorSelector, { "aria-labelledby": uomSeparatorSelectorId, separator: formatProps.uomSeparator ?? "", onChange: handleUomSeparatorChange, disabled: !isFormatTraitSet(FormatTraits.ShowUnitLabel) })));
|
|
86
87
|
}
|
|
87
88
|
//# sourceMappingURL=FormatUnitLabel.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormatUnitLabel.js","sour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,KAAK,CAAC,WAAW,CACjD,CAAC,CAAsC,EAAE,EAAE;QACzC,cAAc,CAAC,YAAY,CAAC,aAAa,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC/D,CAAC,EACD,CAAC,cAAc,CAAC,CACjB,CAAC;IAEF,OAAO,CACL;QACE,8BAAM,SAAS,EAAE,cAAc,IAC5B,SAAS,CAAC,uCAAuC,CAAC,CAC9C;QACP,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,SAAS,CAAC,sCAAsC,CAAC,CAC7C;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 { useTranslation } from \"../useTranslation.js\";\n\n// eslint-disable-next-line @typescript-eslint/no-deprecated\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 { translate } = useTranslation();\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 uomDefaultEntries: SelectOption<string>[] = [\n { value: \"\", label: translate(\"QuantityFormat.none\") },\n { value: \" \", label: translate(\"QuantityFormat.space\") },\n { value: \"-\", label: translate(\"QuantityFormat.dash\") },\n ];\n const completeListOfEntries: SelectOption<string>[] = [];\n\n if (\n undefined ===\n uomDefaultEntries.find((option) => option.value === separator)\n ) {\n completeListOfEntries.push({ value: separator, label: separator });\n }\n completeListOfEntries.push(...uomDefaultEntries);\n return completeListOfEntries;\n }, [separator, translate]);\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 * @deprecated in 4.17.0. Use `React.ComponentProps<typeof FormatUnitLabel>`\n */\n// eslint-disable-next-line @typescript-eslint/no-deprecated\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 */\n// eslint-disable-next-line @typescript-eslint/no-deprecated\nexport function FormatUnitLabel(props: FormatUnitLabelProps) {\n const { formatProps, onUnitLabelChange } = props;\n const { translate } = useTranslation();\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 if (formatProps.formatTraits) {\n const traits = Array.isArray(formatProps.formatTraits)\n ? formatProps.formatTraits\n : formatProps.formatTraits.split(/,|;|\\|/);\n if (!traits.find((traitEntry) => traitStr === traitEntry)) {\n formatTraits = [...traits, traitStr];\n }\n }\n } else {\n // clearing trait\n if (!formatProps.formatTraits) return;\n const traits = Array.isArray(formatProps.formatTraits)\n ? formatProps.formatTraits\n : 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 return (\n <>\n <span className={\"uicore-label\"}>\n {translate(\"QuantityFormat.labels.appendUnitLabel\")}\n </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 {translate(\"QuantityFormat.labels.labelSeparator\")}\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-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vC,CAAC,EACD,CAAC,WAAW,EAAE,oBAAoB,CAAC,CACpC,CAAC;IAEF,MAAM,yBAAyB,GAAG,KAAK,CAAC,WAAW,CACjD,CAAC,CAAsC,EAAE,EAAE;QACzC,cAAc,CAAC,YAAY,CAAC,aAAa,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC/D,CAAC,EACD,CAAC,cAAc,CAAC,CACjB,CAAC;IAEF,OAAO,CACL;QACE,8BAAM,SAAS,EAAE,cAAc,IAC5B,SAAS,CAAC,uCAAuC,CAAC,CAC9C;QACP,oBAAC,QAAQ,mBACK,0BAA0B,EACtC,OAAO,EAAE,gBAAgB,CAAC,YAAY,CAAC,aAAa,CAAC,EACrD,QAAQ,EAAE,yBAAyB,GACnC;QACF,oBAAC,KAAK,IACJ,EAAE,EAAC,KAAK,EACR,YAAY,EAAC,QAAQ,EACrB,EAAE,EAAE,sBAAsB,EAC1B,SAAS,EAAE,UAAU,CACnB,cAAc,EACd,CAAC,gBAAgB,CAAC,YAAY,CAAC,aAAa,CAAC,IAAI,iBAAiB,CACnE,IAEA,SAAS,CAAC,sCAAsC,CAAC,CAC5C;QACR,oBAAC,oBAAoB,uBACF,sBAAsB,EACvC,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, Label, Select } from \"@itwin/itwinui-react\";\nimport { useTranslation } from \"../useTranslation.js\";\n\n// eslint-disable-next-line @typescript-eslint/no-deprecated\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, disabled, ...rest } = props;\n const { translate } = useTranslation();\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 uomDefaultEntries: SelectOption<string>[] = [\n { value: \"\", label: translate(\"QuantityFormat.none\") },\n { value: \" \", label: translate(\"QuantityFormat.space\") },\n { value: \"-\", label: translate(\"QuantityFormat.dash\") },\n ];\n const completeListOfEntries: SelectOption<string>[] = [];\n\n if (\n undefined ===\n uomDefaultEntries.find((option) => option.value === separator)\n ) {\n completeListOfEntries.push({ value: separator, label: separator });\n }\n completeListOfEntries.push(...uomDefaultEntries);\n return completeListOfEntries;\n }, [separator, translate]);\n\n return (\n <Select\n options={separatorOptions}\n value={separator}\n onChange={handleOnChange}\n size=\"small\"\n disabled={disabled}\n {...rest}\n />\n );\n}\n\n/** Properties of [[FormatUnitLabel]] component.\n * @alpha\n * @deprecated in 4.17.0. Use `React.ComponentProps<typeof FormatUnitLabel>`\n */\n// eslint-disable-next-line @typescript-eslint/no-deprecated\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 */\n// eslint-disable-next-line @typescript-eslint/no-deprecated\nexport function FormatUnitLabel(props: FormatUnitLabelProps) {\n const { formatProps, onUnitLabelChange } = props;\n const { translate } = useTranslation();\n\n const uomSeparatorSelectorId = React.useId();\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 if (formatProps.formatTraits) {\n const traits = Array.isArray(formatProps.formatTraits)\n ? formatProps.formatTraits\n : formatProps.formatTraits.split(/,|;|\\|/);\n if (!traits.find((traitEntry) => traitStr === traitEntry)) {\n formatTraits = [...traits, traitStr];\n }\n }\n } else {\n // clearing trait\n if (!formatProps.formatTraits) return;\n const traits = Array.isArray(formatProps.formatTraits)\n ? formatProps.formatTraits\n : 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 return (\n <>\n <span className={\"uicore-label\"}>\n {translate(\"QuantityFormat.labels.appendUnitLabel\")}\n </span>\n <Checkbox\n data-testid=\"show-unit-label-checkbox\"\n checked={isFormatTraitSet(FormatTraits.ShowUnitLabel)}\n onChange={handleShowUnitLabelChange}\n />\n <Label\n as=\"div\"\n displayStyle=\"inline\"\n id={uomSeparatorSelectorId}\n className={classnames(\n \"uicore-label\",\n !isFormatTraitSet(FormatTraits.ShowUnitLabel) && \"uicore-disabled\"\n )}\n >\n {translate(\"QuantityFormat.labels.labelSeparator\")}\n </Label>\n <UomSeparatorSelector\n aria-labelledby={uomSeparatorSelectorId}\n separator={formatProps.uomSeparator ?? \"\"}\n onChange={handleUomSeparatorChange}\n disabled={!isFormatTraitSet(FormatTraits.ShowUnitLabel)}\n />\n </>\n );\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MiscFormatOptions.d.ts","sourceRoot":"","sources":["../../../src/imodel-components-react/quantityformat/MiscFormatOptions.tsx"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,OAAO,KAAK,EAAE,WAAW,EAAkB,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"MiscFormatOptions.d.ts","sourceRoot":"","sources":["../../../src/imodel-components-react/quantityformat/MiscFormatOptions.tsx"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,OAAO,KAAK,EAAE,WAAW,EAAkB,MAAM,sBAAsB,CAAC;AAwBxE;;;GAGG;AAEH,MAAM,WAAW,sBAAuB,SAAQ,WAAW;IACzD,WAAW,EAAE,WAAW,CAAC;IACzB,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,IAAI,CAAC;IACzC,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,WAAW,EAAE,OAAO,CAAC;IACrB,iBAAiB,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IAC3C,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAED;;GAEG;AAEH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,qBAic9D"}
|