import { clx, Input, Text } from "@medusajs/ui" import { getNumberOfDecimalPlaces } from "../../../lib/number-helper" import { ComponentProps, ElementRef, forwardRef } from "react" import Primitive from "react-currency-input-field" const MIN_DECIMAL_SCALE = 2 function resolveDecimalScale( value: string | readonly string[] | number | undefined | null ): number | undefined { if (value == null || Array.isArray(value)) { return MIN_DECIMAL_SCALE } return Math.max( getNumberOfDecimalPlaces(parseFloat(value.toString())), MIN_DECIMAL_SCALE ) } export const DeprecatedPercentageInput = forwardRef< ElementRef, Omit, "type"> >(({ min = 0, max = 100, step = 0.0001, ...props }, ref) => { return (
%
) }) DeprecatedPercentageInput.displayName = "PercentageInput" export const PercentageInput = forwardRef< ElementRef<"input">, ComponentProps >( ( { min = 0, max = 100, decimalScale, decimalsLimit, value, className, ...props }, ref ) => { const resolvedDecimalScale = decimalScale ?? resolveDecimalScale(value) const resolvedDecimalsLimit = decimalsLimit ?? resolvedDecimalScale return (
%
) } ) PercentageInput.displayName = "PercentageInput"