packageDocumentation module import * as React from "react" ; import { CommonProps } from "@itwin/core-react" ; import { Format , FormatProps , FormatType } from "@itwin/core-quantity" ; import { DecimalPrecisionSelector } from "./misc/DecimalPrecision" ; import { FractionPrecisionSelector } from "./misc/FractionPrecision" ; import { UiIModelComponents } from "../UiIModelComponents" ; alpha export interface FormatPrecisionProps extends CommonProps { formatProps : FormatProps ; onChange ? : ( format : FormatProps ) => void ; } alpha export function FormatPrecision ( props ) { const { formatProps , onChange } = props ; const handlePrecisionChange = React . useCallback ( ( precision ) => { const newFormatProps = { ... formatProps , precision } ; onChange && onChange ( newFormatProps ) ; } , [ formatProps , onChange ] ) ; const formatType = Format . parseFormatType ( formatProps . type , "format" ) ; const label = React . useRef ( UiIModelComponents . translate ( "QuantityFormat.labels.precision" ) ) ; return ( < > < span className = { "uicore-label" } > { label . current } < /span> { formatType === FormatType . Fractional ? < FractionPrecisionSelector data - testid = "fraction-precision-selector" precision = { formatProps . precision ?? 0 } onChange = { handlePrecisionChange } / > : < DecimalPrecisionSelector data - testid = "decimal-precision-selector" precision = { formatProps . precision ?? 0 } onChange = { handlePrecisionChange } / > } < />); }