Skip to content

Commit

Permalink
Cleanup after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
saskliutas committed Dec 20, 2024
1 parent 5fdebac commit 12c3105
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,9 @@ export namespace EditorInterop {
value: {
rawValue: primitiveValue.value as number,
displayValue:
primitiveValue.displayValue !== undefined &&
primitiveValue.displayValue !== ""
? `${parseFloat(primitiveValue.displayValue)}`
: `${(primitiveValue.value as number) ?? ""}`,
primitiveValue.value !== undefined
? `${primitiveValue.value as number}`
: primitiveValue.displayValue ?? "",
} satisfies NumericValue,
};
case "enum":
Expand Down
2 changes: 1 addition & 1 deletion ui/imodel-components-react/src/imodel-components-react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export {
export {
QuantityEditor,
QuantityEditorSpec,
} from "./imodel-components-react/inputs/QuantityEditor.js";
} from "./imodel-components-react/inputs/newEditors/QuantityEditor.js";

export {
LineWeightSwatch,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ import { type QuantityTypeArg } from "@itwin/core-frontend";
import { useQuantityInfo } from "./UseQuantityInfo.js";
import type { EditorProps, EditorSpec } from "@itwin/components-react";
import { useNumericEditorProps } from "@itwin/components-react";
import { QuantityFormattedInput } from "./QuantityFormattedInput.js";
import { QuantityInput } from "./QuantityInput.js";

/**
* Editor specification for quantity values based on `IModelApp.quantityFormatter`.
* @beta
*/
export const QuantityEditorSpec: EditorSpec = {
applies: (metadata) =>
metadata.type === "number" &&
Expand All @@ -17,10 +21,7 @@ export const QuantityEditorSpec: EditorSpec = {
Editor: QuantityEditor,
};

/**
*
*/
export function QuantityEditor(props: EditorProps) {
function QuantityEditor(props: EditorProps) {
const { onChange, value, onFinish, size } = useNumericEditorProps(props);
const quantityType =
"quantityType" in props.metadata
Expand All @@ -32,7 +33,7 @@ export function QuantityEditor(props: EditorProps) {
});

return (
<QuantityFormattedInput
<QuantityInput
value={value}
onChange={onChange}
onBlur={onFinish}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import * as React from "react";
import { FormattedNumericInput } from "./FormattedNumericInput.js";
import { FormattedNumericInput } from "@itwin/components-react";
import type { FormatterSpec, ParserSpec } from "@itwin/core-quantity";

type FormattedNumericInputProps = React.ComponentPropsWithoutRef<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ interface UseQuantityInfoProps {
}

/**
*
* Hook that finds the formatter and parser in `IModelApp.quantityFormatter` for a given quantity type.
* @internal
*/
export function useQuantityInfo({ type }: UseQuantityInfoProps) {
const [{ formatter, parser }, setState] = React.useState<{
Expand All @@ -24,11 +25,7 @@ export function useQuantityInfo({ type }: UseQuantityInfoProps) {
}));

React.useEffect(() => {
const defaultFormatterSpec =
type !== undefined
? IModelApp.quantityFormatter.findFormatterSpecByQuantityType(type)
: undefined;
if (defaultFormatterSpec === undefined) {
if (type === undefined) {
setState({
formatter: undefined,
parser: undefined,
Expand Down

0 comments on commit 12c3105

Please sign in to comment.