import { useId } from "react"; import type { InputHTMLAttributes, ReactNode } from "react"; import { cn } from "../lib/cn.js"; export interface InputProps extends Omit, "size"> { label?: ReactNode; hint?: ReactNode; error?: ReactNode; sizeVariant?: "sm" | "md" | "lg"; } const inputSize = { sm: "h-8 px-2.5 text-xs", md: "h-10 px-3 text-sm", lg: "h-12 px-4 text-base", } as const; export const Input = ({ label, hint, error, sizeVariant = "md", id, className, disabled, ...props }: InputProps) => { const generatedId = useId(); const inputId = id ?? generatedId; const messageId = `${inputId}-message`; const isInvalid = error !== undefined && error !== null && error !== ""; return (
{label ? ( ) : null} {isInvalid || hint ? (

{isInvalid ? error : hint}

) : null}
); };