-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFormInput.tsx
More file actions
50 lines (46 loc) · 929 Bytes
/
FormInput.tsx
File metadata and controls
50 lines (46 loc) · 929 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
38
39
40
41
42
43
44
45
46
47
48
49
50
import { Input, Tooltip } from '@heroui/react';
import { ReactNode, useCallback } from 'react';
export interface FormInputProps {
label: string;
type?: string;
tooltip?: string;
isInvalid?: boolean;
errorMessage?: ReactNode;
setValue?: (value: string) => void;
resetError?: () => void;
}
export function FormInput({
label,
type,
tooltip,
isInvalid,
errorMessage,
setValue,
resetError,
}: FormInputProps) {
const onValueChange = useCallback(
(value: string) => {
setValue?.(value);
resetError?.();
},
[setValue, resetError]
);
const input = (
<Input
size="sm"
label={label}
aria-label={label}
type={type}
isInvalid={isInvalid}
errorMessage={errorMessage}
onValueChange={onValueChange}
/>
);
return tooltip ? (
<Tooltip placement="right" content={tooltip}>
{input}
</Tooltip>
) : (
input
);
}