-
Notifications
You must be signed in to change notification settings - Fork 34
Introduce @itwin/quantity-formatting-react #1404
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
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 aacb885
changelog
hl662 f908df6
rename all files, bump eslint
hl662 b396687
wip fleshing out tests
hl662 5befe3c
fix all the tests
hl662 84a0f46
fix localization, improve UI
hl662 ca839f5
fix
hl662 23ceb9d
update codeowners
hl662 0ddb26b
add format selector
hl662 fb22420
Use FormatDefinition, update README
hl662 ce979f3
pnpm change
hl662 ea834a9
flesh out quantity format panel more
hl662 a71e058
Merge remote-tracking branch 'origin/master' into nam/qty-fmt-pkg
hl662 516a759
integrate format manager for use with format set
hl662 c8a0efe
address comments
hl662 671f52f
downgrade type devDeps
hl662 92d5ddd
Finish FormatManager
hl662 c594ef1
run prettier
hl662 5e5c29d
rename widget to button, Expose formatting button in status bar
hl662 d915841
revert changes to lockfile in nonrelevant repos, hide panel if no for…
hl662 265a34a
integrate api extractor
hl662 c14c8a2
add images to readme, format ecsql query
hl662 dc9e1ee
remove outdated comment
hl662 7fd520e
run update extraction
hl662 4c4b049
shrink images
hl662 0f4a6ce
add stationing primary children component
hl662 0ef32d0
Merge remote-tracking branch 'origin/master' into nam/qty-fmt-pkg
hl662 4e9c88f
address comments
hl662 5fa2913
remove usage of isMounted, avoiding race conditions
hl662 2261b99
update styling
hl662 a6c8bc0
miseed a few
hl662 fd0c44e
prettier
hl662 0bf05f0
change to 15 items
hl662 1b8a4e3
updated readme images
hl662 5ca021e
Update UnitDescr.tsx
hl662 0e7262b
Update UnitDescr.tsx
hl662 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
apps/test-viewer/src/components/QuantityFormatUiItemsProvider.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, []); | ||
grigasp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
change/@itwin-quantity-formatting-react-904f8951-1da2-4b9f-99bb-e0c3b0559228.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/** |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
grigasp marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
grigasp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- **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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
}, | ||
}, | ||
]; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.