import type { HTMLAttributes, KeyboardEvent, ReactNode } from "react";
import { useContext, useId, useState } from "react";
import { cx } from "../../utils/cx.utils";
import { FormContext } from "../form/form.context";
import { Icon } from "../icons/icon";
import { Label } from "../label/label.component";
import "./number-input.component.css";
function roundStep(value: number, useFloat: boolean): number {
return useFloat ? Math.round(value * 100) / 100 : Math.round(value);
}
function clamp(value: number, min: number | undefined, max: number | undefined): number {
let result = value;
if (min !== undefined) result = Math.max(min, result);
if (max !== undefined) result = Math.min(max, result);
return result;
}
/**
* Formats a value the way {@link NumberInput} displays it: plain digits when
* `useFloat` is `false`, otherwise always two decimal places with a comma as
* the decimal separator (`5,00`, `5,01`) — except `0`, which is shown bare (`0`).
*/
function formatValue(value: number, useFloat: boolean): string {
if (!useFloat || value === 0) return String(value);
return value.toFixed(2).replace(".", ",");
}
/** Props accepted by {@link NumberInput}. */
export interface NumberInputProps extends Omit, "onChange"> {
/** Label rendered above the control, via {@link Label.Form}. */
label: ReactNode;
/**
* Field name to bind to the enclosing `