-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTextarea.component.tsx
More file actions
49 lines (43 loc) · 1.4 KB
/
Textarea.component.tsx
File metadata and controls
49 lines (43 loc) · 1.4 KB
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
"use client";
import Txt from "@/components/common/Txt.component";
import {
ApplicationNode,
ApplicationTextarea,
} from "@/src/constants/application/type";
import { useLocalStorage } from "@/src/hooks/useLocalstorage.hook";
import { FormEvent } from "react";
interface ApplicationTextareaProps {
data: ApplicationNode;
}
const ApplicationTexarea = ({ data }: ApplicationTextareaProps) => {
const textData = data as ApplicationTextarea;
const maxLength = ['deep', 'failure', 'studyPlan'].includes(textData.name) ? 500 : 800;
const [value, setValue] = useLocalStorage(textData.name, "");
const onInput = (e: FormEvent<HTMLTextAreaElement>) => {
setValue(e.currentTarget.value.slice(0, maxLength));
};
return (
<>
{textData.title && (
<label>
<Txt typography="h6">{`${textData.title}${
textData.require ? "*" : ""
}`}</Txt>
{textData.subtitle && <Txt>{` ${textData.subtitle}`}</Txt>}
</label>
)}
<div className="relative">
<textarea
className="border rounded-lg px-4 py-6 w-full resize-none"
rows={20}
name={textData.name}
value={value}
maxLength={maxLength}
onInput={onInput}
/>
<div className="absolute bottom-3 right-4 bg-white text-sm">{`(${value.length}/${maxLength})`}</div>
</div>
</>
);
};
export default ApplicationTexarea;