Skip to content
العربية
Forms

UnitInput

A number with its unit, for example a time or a size.

import { UnitInput } from "@percentsa/ui";

Examples

Code
export function UnitInputExample() {
  const t = useT();
  const [delay, setDelay] = useState<{ value: number | null; unit: string }>({ value: 30, unit: "s" });
  return (
    <Field label={t("Request timeout", "مهلة الطلب")} className="w-60">
      <UnitInput
        value={delay.value}
        unit={delay.unit}
        onValueChange={(value, unit) => setDelay({ value, unit })}
        min={0}
        units={[
          { value: "ms", label: t("milliseconds", "ملّي ثانية") },
          { value: "s", label: t("seconds", "ثوانٍ") },
          { value: "min", label: t("minutes", "دقائق") },
        ]}
        unitLabel={t("Unit", "الوحدة")}
      />
    </Field>
  );
}