You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
FreeBug/frontend/edu-connect/src/components/ui/input.tsx

48 lines
1.6 KiB

import * as React from "react";
import { cn } from "@/lib/utils";
interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {
error?: string[];
label?: string;
helperText?: string;
required?: boolean;
}
const Input = React.forwardRef<HTMLInputElement, InputProps>(
({ className, type, error, label, helperText, required = false, ...props }, ref) => {
return (
<div className="w-full space-y-2">
{label && (
<div className="flex text-sm font-medium text-gray-700">
{label}
{required && <span className="text-red-500 ml-1">*</span>}
</div>
)}
<input
type={type}
className={cn(
"flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
error && error.length > 0 && "border-red-500 focus-visible:ring-red-500",
className
)}
ref={ref}
{...props}
/>
{helperText && (
<p className="text-sm text-muted-foreground">
{helperText}
</p>
)}
{error && error.map((message, index) => (
<p key={index} className="text-sm font-medium text-red-500">
{message}
</p>
))}
</div>
)
}
)
Input.displayName = "Input"
export { Input }