Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
cba1c06
Init Quantity Formatting React pkg
hl662 Aug 11, 2025
aacb885
changelog
hl662 Aug 12, 2025
f908df6
rename all files, bump eslint
hl662 Aug 12, 2025
b396687
wip fleshing out tests
hl662 Aug 12, 2025
5befe3c
fix all the tests
hl662 Aug 12, 2025
84a0f46
fix localization, improve UI
hl662 Aug 12, 2025
ca839f5
fix
hl662 Aug 12, 2025
23ceb9d
update codeowners
hl662 Aug 12, 2025
0ddb26b
add format selector
hl662 Aug 12, 2025
fb22420
Use FormatDefinition, update README
hl662 Aug 13, 2025
ce979f3
pnpm change
hl662 Aug 13, 2025
ea834a9
flesh out quantity format panel more
hl662 Aug 13, 2025
a71e058
Merge remote-tracking branch 'origin/master' into nam/qty-fmt-pkg
hl662 Aug 13, 2025
516a759
integrate format manager for use with format set
hl662 Aug 13, 2025
c8a0efe
address comments
hl662 Aug 13, 2025
671f52f
downgrade type devDeps
hl662 Aug 13, 2025
92d5ddd
Finish FormatManager
hl662 Aug 14, 2025
c594ef1
run prettier
hl662 Aug 14, 2025
5e5c29d
rename widget to button, Expose formatting button in status bar
hl662 Aug 14, 2025
d915841
revert changes to lockfile in nonrelevant repos, hide panel if no for…
hl662 Aug 14, 2025
265a34a
integrate api extractor
hl662 Aug 14, 2025
c14c8a2
add images to readme, format ecsql query
hl662 Aug 14, 2025
dc9e1ee
remove outdated comment
hl662 Aug 14, 2025
7fd520e
run update extraction
hl662 Aug 14, 2025
4c4b049
shrink images
hl662 Aug 14, 2025
0f4a6ce
add stationing primary children component
hl662 Aug 15, 2025
0ef32d0
Merge remote-tracking branch 'origin/master' into nam/qty-fmt-pkg
hl662 Aug 18, 2025
4e9c88f
address comments
hl662 Aug 19, 2025
5fa2913
remove usage of isMounted, avoiding race conditions
hl662 Aug 19, 2025
2261b99
update styling
hl662 Aug 19, 2025
a6c8bc0
miseed a few
hl662 Aug 19, 2025
fd0c44e
prettier
hl662 Aug 19, 2025
0bf05f0
change to 15 items
hl662 Aug 19, 2025
1b8a4e3
updated readme images
hl662 Aug 19, 2025
5ca021e
Update UnitDescr.tsx
hl662 Aug 20, 2025
0e7262b
Update UnitDescr.tsx
hl662 Aug 20, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,6 @@

/packages/itwin/map-layers @itwin/viewer-components-reviewers @mdastous-bentley @eringram
/change/@itwin-map-layers* @itwin/viewer-components-reviewers @mdastous-bentley @eringram

/packages/itwin/quantity-formatting @itwin/viewer-components-reviewers @itwin/itwinjs-core-presentation @hl662
/change/@itwin-quantity-formatting-react* @itwin/viewer-components-reviewers @itwin/itwinjs-core-presentation
1 change: 1 addition & 0 deletions apps/test-viewer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"@itwin/presentation-hierarchies-react": "^1.8.1",
"@itwin/presentation-shared": "^1.2.2",
"@itwin/property-grid-react": "workspace:*",
"@itwin/quantity-formatting-react": "workspace:*",
"@itwin/reports-config-widget-react": "workspace:*",
"@itwin/tree-widget-react": "workspace:*",
"@itwin/unified-selection": "^1.4.1",
Expand Down
41 changes: 34 additions & 7 deletions apps/test-viewer/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions apps/test-viewer/scripts/linkWorkspaceDeps.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ const packages = [
name: "@itwin/one-click-lca-react",
dir: "one-click-lca-widget",
},
{
name:"@itwin/quantity-formatting-react",
dir: "quantity-formatting"
}
];

linkPackages();
Expand Down
9 changes: 9 additions & 0 deletions apps/test-viewer/src/UiProvidersConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
TreeWidgetComponent,
} from "@itwin/tree-widget-react";
import { RepositoriesTreeComponent } from "./components/repositories-tree/RepositoriesTree";
import { QuantityFormatUiItemsProvider } from "./components/QuantityFormatUiItemsProvider";
import { useViewerOptionsContext } from "./components/ViewerOptions";
import { unifiedSelectionStorage } from "./SelectionStorage";

Expand All @@ -47,6 +48,7 @@ import type { ClientPrefix } from "@itwin/grouping-mapping-widget";
import type { SelectableTreeDefinition } from "@itwin/tree-widget-react";
import type { UiItemsProvider } from "@itwin/appui-react";
import type { ComponentPropsWithRef } from "react";
import { QuantityFormatting } from "@itwin/quantity-formatting-react";

export interface UiProvidersConfig {
initialize: () => Promise<void>;
Expand Down Expand Up @@ -324,6 +326,13 @@ const configuredUiItems = new Map<string, UiItem>([
createUiItemsProviders: () => [new OneClickLCAProvider()],
},
],
[
"quantity-formatting",
{
initialize: async () => QuantityFormatting.startup(),
createUiItemsProviders: () => [new QuantityFormatUiItemsProvider()],
},
],
]);

function ModelsTreeWithOption(props: ComponentPropsWithRef<typeof ModelsTreeComponent>) {
Expand Down
107 changes: 107 additions & 0 deletions apps/test-viewer/src/components/QuantityFormatUiItemsProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/

import React, { useCallback, useState } from "react";
import { StagePanelLocation, StagePanelSection } from "@itwin/appui-react";
import { QuantityFormatPanel } from "@itwin/quantity-formatting-react";
import { IModelApp } from "@itwin/core-frontend";
import type { FormatProps } from "@itwin/core-quantity";
import { Button, Modal, ModalButtonBar } from "@itwin/itwinui-react";

import type { UiItemsProvider, Widget } from "@itwin/appui-react";

/** Widget component that shows a button to open the Quantity Format Panel in a modal */
const QuantityFormatWidget: React.FC = () => {
// Initial format definition with basic decimal format
const [formatDefinition, setFormatDefinition] = useState<FormatProps>({
precision: 4,
type: "Decimal",
composite: {
units: [{ name: "Units.M", label: "m" }],
},
});

const [isModalOpen, setIsModalOpen] = useState(false);

const handleFormatChange = useCallback((newFormat: FormatProps) => {
setFormatDefinition(newFormat);
}, []);

const handleOpenModal = useCallback(() => {
setIsModalOpen(true);
}, []);

const handleCloseModal = useCallback(() => {
setIsModalOpen(false);
}, []);

const handleApply = useCallback(() => {
// Here you could apply the format changes to the active iModel
console.log("Applied format changes:", formatDefinition);
setIsModalOpen(false);
}, [formatDefinition]);

// Memoize the unitsProvider to prevent unnecessary re-renders
const memoizedUnitsProvider = React.useMemo(() => IModelApp.quantityFormatter.unitsProvider, []);

return (
<>
<div style={{ padding: "16px" }}>
<Button
onClick={handleOpenModal}
styleType="high-visibility"
size="large"
style={{ width: "100%" }}
>
Configure Quantity Format
</Button>
</div>

<Modal
isOpen={isModalOpen}
onClose={handleCloseModal}
title="Quantity Format Settings"
style={{ width: "600px", maxWidth: "90vw" }}
>
<div style={{ padding: "16px", height: "1200px", overflow: "auto" }}>
<QuantityFormatPanel
formatDefinition={formatDefinition}
unitsProvider={memoizedUnitsProvider}
onFormatChange={handleFormatChange}
/>
</div>

<ModalButtonBar>
<Button styleType="default" onClick={handleCloseModal}>
Cancel
</Button>
<Button styleType="high-visibility" onClick={handleApply}>
Apply
</Button>
</ModalButtonBar>
</Modal>
</>
);
};

/** UiItemsProvider that adds a quantity format widget to the side panel */
export class QuantityFormatUiItemsProvider implements UiItemsProvider {
public readonly id = "QuantityFormatUiItemsProvider";

public provideWidgets(_stageId: string, stageUsage: string, location: StagePanelLocation, section?: StagePanelSection): ReadonlyArray<Widget> {
const widgets: Widget[] = [];
if (location === StagePanelLocation.Right && section === StagePanelSection.End && stageUsage === "General") {
const quantityFormatWidget: Widget = {
id: "quantity-format",
label: "Quantity Format",
content: <QuantityFormatWidget />,
};

widgets.push(quantityFormatWidget);
}

return widgets;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "Add @itwin/quantity-formatting-react package",
"packageName": "@itwin/quantity-formatting-react",
"email": "50554904+hl662@users.noreply.github.com",
"dependentChangeType": "patch"
}
2 changes: 1 addition & 1 deletion packages/itwin/measure-tools/LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MIT License

Copyright © 2021-2024 Bentley Systems, Incorporated. All rights reserved.
Copyright © 2021-2025 Bentley Systems, Incorporated. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
11 changes: 11 additions & 0 deletions packages/itwin/quantity-formatting/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# start off ignoring everything, and then add back only the files we want
*
!lib/**/*.d.ts
!lib/**/*.js
!lib/**/*.js.map
!lib/**/*.*css
!lib/public/**/*
!CHANGELOG.md

# ignore some stuff again
lib/**/test/**
9 changes: 9 additions & 0 deletions packages/itwin/quantity-formatting/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# MIT License

Copyright (c) Bentley Systems, Incorporated. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
48 changes: 48 additions & 0 deletions packages/itwin/quantity-formatting/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# @itwin/quantity-formatting-react

React components for quantity formatting in iTwin.js applications.

## Description

This package provides React components for working with quantities and their formatting in iTwin.js applications. It includes components for input, display, and conversion of quantities with proper unit handling.

**Key Features:**
- **QuantityFormatPanelV2**: Modern quantity format panel with improved UX
- **FormatPanelV2**: Flexible format panel with primary/secondary option organization
- **FormatSampleV2**: Real-time preview of quantity formatting
- **Comprehensive Format Support**: Support for Decimal, Fractional, Scientific, Station, Azimuth, Bearing, and Ratio formats
- **Modular Architecture**: Organized into panels and internal components for reusability

## Main Components
- `QuantityFormatPanelV2` - Main panel for quantity format configuration
- `FormatPanelV2` - Core format panel with expandable advanced options
- `FormatSampleV2` - Live preview component for formatted values

## Installation

```bash
npm install @itwin/quantity-formatting-react
```

## Usage

```typescript
import {
QuantityFormatPanelV2,
FormatPanelV2,
FormatSampleV2
} from "@itwin/quantity-formatting-react";

// Use the QuantityFormatPanelV2 component
<QuantityFormatPanelV2
formatDefinition={formatProps}
unitsProvider={unitsProvider}
onFormatChange={(newFormat) => console.log(newFormat)}
showSample={true}
initialMagnitude={1234.56}
/>
```

## License

This project is licensed under the MIT License - see the [LICENSE.md](./LICENSE.md) file for details.
24 changes: 24 additions & 0 deletions packages/itwin/quantity-formatting/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import iTwinPlugin from "@itwin/eslint-plugin";

export default [
{
files: ["**/*.{ts,tsx}"],
...iTwinPlugin.configs.uiConfig,
rules: {
"@itwin/no-internal": [
"warn",
{
tag: [
"internal",
"alpha",
],
},
],
"@typescript-eslint/consistent-type-imports": "error",
},
},
];
Loading
Loading