tasko/components/form/form-errors.tsx

29 lines
655 B
TypeScript
Raw Normal View History

2024-02-16 01:49:19 +00:00
import { XCircle } from 'lucide-react';
2024-02-15 02:30:10 +00:00
interface FormErrorsProps {
id: string;
errors?: Record<string, string[] | undefined>;
}
export const FormErrors = ({ id, errors }: FormErrorsProps) => {
if (!errors) return null;
return (
<div
id={`${id}-error`}
2024-02-16 01:49:19 +00:00
aria-live='polite'
className='mt-2 text-xs text-rose-500'
2024-02-15 02:30:10 +00:00
>
{errors?.[id]?.map((error: string) => (
<div
key={error}
2024-02-16 01:49:19 +00:00
className='flex items-center rounded-sm border border-rose-500 bg-rose-500/10 p-2 font-medium'
2024-02-15 02:30:10 +00:00
>
2024-02-16 01:49:19 +00:00
<XCircle className='mr-2 h-4 w-4' />
2024-02-15 02:30:10 +00:00
{error}
</div>
))}
</div>
);
};