mirror of
https://github.com/ahmadk953/tasko.git
synced 2025-05-04 12:43:24 +00:00
Initial Commit
This commit is contained in:
commit
f3e2f01bd7
150 changed files with 13612 additions and 0 deletions
73
components/form/form-input.tsx
Normal file
73
components/form/form-input.tsx
Normal file
|
@ -0,0 +1,73 @@
|
|||
"use client";
|
||||
|
||||
import { forwardRef } from "react";
|
||||
import { useFormStatus } from "react-dom";
|
||||
|
||||
import { cn } from "@/lib/utils";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { FormErrors } from "./form-errors";
|
||||
|
||||
interface FormInputProps {
|
||||
id: string;
|
||||
label?: string;
|
||||
type?: string;
|
||||
placeholder?: string;
|
||||
required?: boolean;
|
||||
disabled?: boolean;
|
||||
errors?: Record<string, string[] | undefined>;
|
||||
className?: string;
|
||||
defaultValue?: string;
|
||||
onBlur?: () => void;
|
||||
}
|
||||
|
||||
export const FormInput = forwardRef<HTMLInputElement, FormInputProps>(
|
||||
(
|
||||
{
|
||||
id,
|
||||
label,
|
||||
type,
|
||||
placeholder,
|
||||
required,
|
||||
disabled,
|
||||
errors,
|
||||
className,
|
||||
defaultValue = "",
|
||||
onBlur,
|
||||
},
|
||||
ref
|
||||
) => {
|
||||
const { pending } = useFormStatus();
|
||||
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
<div className="space-y-1">
|
||||
{label ? (
|
||||
<Label
|
||||
htmlFor={id}
|
||||
className="text-xs font-semibold text-neutral-700"
|
||||
>
|
||||
{label}
|
||||
</Label>
|
||||
) : null}
|
||||
<Input
|
||||
onBlur={onBlur}
|
||||
defaultValue={defaultValue}
|
||||
ref={ref}
|
||||
required={required}
|
||||
name={id}
|
||||
id={id}
|
||||
placeholder={placeholder}
|
||||
type={type}
|
||||
disabled={pending ?? disabled}
|
||||
className={cn("text-sm px-2 py-1 h-7", className)}
|
||||
aria-describedby={`${id}-error`}
|
||||
/>
|
||||
</div>
|
||||
<FormErrors id={id} errors={errors} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
FormInput.displayName = "FormInput";
|
Loading…
Add table
Add a link
Reference in a new issue