import type { Ref } from "react"; import React, { forwardRef, JSX } from "react"; import clsx from "clsx"; import FieldLabel from "@/components/FieldLabel"; import Card from "@/components/Card"; import { cva } from "@/cva.config"; const sizes = { XS: "h-[26px] px-3 text-xs", SM: "h-[36px] px-3 text-[14px]", MD: "h-[40px] px-4 text-sm", LG: "h-[48px] py-4 px-5 text-base", }; const inputVariants = cva({ variants: { size: sizes }, }); type InputFieldProps = { size?: keyof typeof sizes; TrailingElm?: React.ReactNode; LeadingElm?: React.ReactNode; error?: string | null; } & Omit; type InputFieldWithLabelProps = InputFieldProps & { label: React.ReactNode; description?: string | null; }; const InputField = forwardRef(function InputField( { LeadingElm, TrailingElm, className, size = "MD", error, ...props }, ref, ) { const sizeClasses = inputVariants({ size }); return ( <> {LeadingElm && (
{LeadingElm}
)} {TrailingElm && (
{TrailingElm}
)}
{error && } ); }); InputField.displayName = "InputField"; const InputFieldWithLabel = forwardRef( function InputFieldWithLabel( { label, description, id, ...props }, ref: Ref, ) { return (
{(label || description) && ( )}
); }, ); InputFieldWithLabel.displayName = "InputFieldWithLabel"; export default InputField; export { InputFieldWithLabel }; export function FieldError({ error }: { error: string | React.ReactNode }) { return
{error}
; }