-
Notifications
You must be signed in to change notification settings - Fork 87
/
Copy pathInputField.tsx
40 lines (37 loc) · 1.38 KB
/
InputField.tsx
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
38
39
40
import classNames from "classnames";
import React, { memo, type PropsWithChildren, type ReactNode } from "react";
import { InputFieldHint } from "./InputFieldHint";
type Props = {
label?: ReactNode;
id?: string;
hint?: ReactNode;
error?: ReactNode;
topMargin?: boolean;
className?: string;
disabled?: boolean;
};
// eslint-disable-next-line react/display-name
export const InputField = memo(
({ label, id, hint, error, topMargin = true, className, children, disabled = false }: PropsWithChildren<Props>) => {
return (
<div className={classNames("flex flex-col space-y-2", { "mt-4": topMargin }, className)}>
{label && (
<label
className={classNames(
"text-sm font-semibold",
disabled ? "text-gray-400 dark:text-gray-400"
: error ? "text-red-600 dark:text-red-400"
: "text-gray-600 dark:text-gray-100",
)}
htmlFor={id}
>
{label}
</label>
)}
{children}
{error && <span className="text-red-500 text-sm">{error}</span>}
{hint && <InputFieldHint>{hint}</InputFieldHint>}
</div>
);
},
);