-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddRecordTextArea.tsx
More file actions
64 lines (58 loc) ยท 1.93 KB
/
AddRecordTextArea.tsx
File metadata and controls
64 lines (58 loc) ยท 1.93 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import React, { Dispatch, SetStateAction, useEffect } from 'react'
import { CELEBRATION_ID, INPUT_DETAILS } from '@assets/constant/constant'
import { parentCategoryID } from 'types/category'
type userProps = {
recordContent: string
setRecordContent: Dispatch<SetStateAction<string>>
currentRecordType: parentCategoryID
setIsInputFocus: Dispatch<SetStateAction<boolean>>
modifyTitle: string
}
function AddRecordTextArea({
currentRecordType,
setIsInputFocus,
recordContent,
setRecordContent,
modifyTitle,
}: userProps) {
const PLACEHOLDER_MESSAGE = {
celebration: 'ex) ์ค๋์ ๋์ ์์ผ์ด์์! ๋ชจ๋ ์ถํํด์ฃผ์ธ์!',
consolation: 'ex) ์ค๋์ ๊ธฐ๋ถ์ด ์ฐ์ธํ๋ค์. ์ ๋ฅผ ์๋กํด์ฃผ์ธ์',
}
useEffect(() => {
setRecordContent(
modifyTitle
? recordContent.replaceAll(/(<br>|<br\/>|<br \/>)/g, '\r\n')
: ''
)
}, [currentRecordType])
const handleChangeTextArea = (
e: React.ChangeEvent<HTMLTextAreaElement>
): void => {
const inputValueLength = e.target.value.length
if (inputValueLength > INPUT_DETAILS.MAX_TEXTAREA_TYPING) {
return
}
setRecordContent(e.target.value)
}
return (
<div
className={`mb-10 rounded-lg bg-grey-2 px-4 pt-4 pb-2 text-sm font-medium text-grey-5`}
>
<textarea
onFocus={() => setIsInputFocus(true)}
onBlur={() => setIsInputFocus(false)}
className={`min-h-[130px] w-full resize-none bg-grey-2 placeholder:text-grey-5 focus:outline-none focus:placeholder:text-transparent`}
onChange={handleChangeTextArea}
placeholder={
currentRecordType === CELEBRATION_ID
? PLACEHOLDER_MESSAGE.celebration
: PLACEHOLDER_MESSAGE.consolation
}
value={recordContent}
/>
<div className="text-right text-xs">{`${recordContent.length}/${INPUT_DETAILS.MAX_TEXTAREA_TYPING}`}</div>
</div>
)
}
export default AddRecordTextArea