-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormField.tsx
More file actions
37 lines (35 loc) · 934 Bytes
/
FormField.tsx
File metadata and controls
37 lines (35 loc) · 934 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { ReactNode } from "react";
interface FormFieldProps {
label: string;
error?: string;
touched?: boolean;
optional?: boolean;
helperText?: string;
/** Rendered next to the label (e.g. info icon with hover message) */
labelSupplement?: ReactNode;
children: ReactNode;
}
export const FormField = ({
label,
error,
touched = false,
optional = false,
helperText,
labelSupplement,
children,
}: FormFieldProps) => {
return (
<div>
<label className="mb-2 flex items-center gap-1.5 text-sm font-medium">
<span>
{label}
{optional && <span className="font-normal text-gray-400"> (optional)</span>}
</span>
{labelSupplement}
</label>
{children}
{helperText && !error && <p className="mt-1 text-xs text-gray-500">{helperText}</p>}
{error && touched && <p className="text-destructive mt-1 text-sm">{error}</p>}
</div>
);
};