|
1 | | -import { CloudIcon, ColorSirenIcon, SnowIcon, ThermostatIcon, WarmIcon } from '@/assets/icons'; |
2 | | -import { useState } from 'react'; |
| 1 | +import { useEffect, useRef, useState } from 'react'; |
3 | 2 | import { twMerge } from 'tailwind-merge'; |
4 | 3 |
|
| 4 | +import { CloudIcon, ColorSirenIcon, SnowIcon, ThermostatIcon, WarmIcon } from '@/assets/icons'; |
| 5 | + |
| 6 | +import ReportModal from './ReportModal'; |
| 7 | + |
5 | 8 | export default function LetterDetail({ title, text }: { title: string; text: string }) { |
6 | 9 | const FONT = ''; |
7 | | - const THEME = 'field'; |
| 10 | + const THEME = 'celebrate'; |
| 11 | + const DEGREES = [ |
| 12 | + { icon: WarmIcon, title: '따뜻해요' }, |
| 13 | + { icon: CloudIcon, title: '그럭저럭' }, |
| 14 | + { icon: SnowIcon, title: '앗! 차가워' }, |
| 15 | + ]; |
8 | 16 | const [degreeModalOpen, setDegreeModalOpen] = useState<boolean>(false); |
| 17 | + const [reportModalOpen, setReportModalOpen] = useState<boolean>(false); |
| 18 | + |
| 19 | + const degreeButtonRef = useRef<HTMLButtonElement>(null); |
| 20 | + const handleOutsideClick = (event: MouseEvent) => { |
| 21 | + const target = event.target as Node; |
| 22 | + if (!target || degreeButtonRef.current?.contains(target)) { |
| 23 | + return; |
| 24 | + } |
| 25 | + setDegreeModalOpen(false); |
| 26 | + }; |
| 27 | + useEffect(() => { |
| 28 | + document.body.addEventListener('click', handleOutsideClick); |
| 29 | + |
| 30 | + return () => { |
| 31 | + document.body.removeEventListener('click', handleOutsideClick); |
| 32 | + }; |
| 33 | + }, []); |
9 | 34 | return ( |
10 | | - <div className={twMerge(`flex grow flex-col gap-3 px-5 pb-7.5`, THEME)}> |
11 | | - <div className="absolute top-5 right-5 flex gap-3"> |
12 | | - <button |
13 | | - className="flex items-center justify-center gap-1" |
14 | | - onClick={() => { |
15 | | - setDegreeModalOpen(true); |
16 | | - }} |
17 | | - > |
18 | | - <img src={ThermostatIcon} alt="편지 온도 아이콘" /> |
19 | | - <span className="caption-b text-primary-1">편지 온도</span> |
20 | | - </button> |
21 | | - <button onClick={() => {}}> |
22 | | - <img src={ColorSirenIcon} alt="신고 아이콘" /> |
23 | | - </button> |
24 | | - {degreeModalOpen && ( |
25 | | - <div className="caption-b text-primary-1 bg-primary-5 absolute top-7 z-40 flex flex-col gap-1 p-2 shadow"> |
26 | | - <button |
27 | | - className="flex items-center justify-center gap-1" |
28 | | - onClick={() => { |
29 | | - setDegreeModalOpen(false); |
30 | | - }} |
31 | | - > |
32 | | - <img src={WarmIcon} alt="따뜻 아이콘" /> 따뜻해요 |
33 | | - </button> |
34 | | - <button |
35 | | - className="flex items-center justify-center gap-1" |
36 | | - onClick={() => { |
37 | | - setDegreeModalOpen(false); |
38 | | - }} |
39 | | - > |
40 | | - <img src={CloudIcon} alt="그럭저럭 아이콘" /> 그럭저럭 |
41 | | - </button> |
42 | | - <button |
43 | | - className="flex items-center justify-center gap-1" |
44 | | - onClick={() => { |
45 | | - setDegreeModalOpen(false); |
46 | | - }} |
47 | | - > |
48 | | - <img src={SnowIcon} alt="차가움 아이콘" /> 앗! 차가워 |
49 | | - </button> |
50 | | - </div> |
51 | | - )} |
52 | | - </div> |
53 | | - <div className="flex flex-col gap-3 px-5"> |
54 | | - <span className="body-b mt-[55px]">TO. 따숨이</span> |
55 | | - <span className="body-sb">{title}</span> |
| 35 | + <> |
| 36 | + {reportModalOpen && <ReportModal onClose={() => setReportModalOpen(false)} />} |
| 37 | + <div className={twMerge(`flex grow flex-col gap-3 px-5 pb-7.5`, THEME)}> |
| 38 | + <div className="absolute top-5 right-5 flex gap-3"> |
| 39 | + <button |
| 40 | + ref={degreeButtonRef} |
| 41 | + className="flex items-center justify-center gap-1" |
| 42 | + onClick={() => { |
| 43 | + setDegreeModalOpen((cur) => !cur); |
| 44 | + }} |
| 45 | + > |
| 46 | + <img src={ThermostatIcon} alt="편지 온도 아이콘" /> |
| 47 | + <span className="caption-b text-primary-1">편지 온도</span> |
| 48 | + </button> |
| 49 | + <button |
| 50 | + onClick={() => { |
| 51 | + setReportModalOpen(true); |
| 52 | + }} |
| 53 | + > |
| 54 | + <img src={ColorSirenIcon} alt="신고 아이콘" /> |
| 55 | + </button> |
| 56 | + {degreeModalOpen && ( |
| 57 | + <div className="caption-b text-primary-1 bg-primary-5 absolute top-7 z-40 flex flex-col gap-1 p-2 shadow"> |
| 58 | + {DEGREES.map((degree, idx) => { |
| 59 | + return ( |
| 60 | + <button |
| 61 | + key={idx} |
| 62 | + className="flex items-center justify-start gap-1" |
| 63 | + onClick={() => { |
| 64 | + console.log(idx); |
| 65 | + }} |
| 66 | + > |
| 67 | + <img src={degree.icon} alt={`${degree.title} 아이콘`} /> {degree.title} |
| 68 | + </button> |
| 69 | + ); |
| 70 | + })} |
| 71 | + </div> |
| 72 | + )} |
| 73 | + </div> |
| 74 | + <div className="flex flex-col gap-3 px-5"> |
| 75 | + <span className="body-b mt-[55px]">TO. 따숨이</span> |
| 76 | + <span className="body-sb">{title}</span> |
| 77 | + </div> |
| 78 | + <textarea |
| 79 | + readOnly |
| 80 | + value={text} |
| 81 | + className={twMerge( |
| 82 | + `body-r basic-theme min-h-full w-full grow px-6 focus:outline-none`, |
| 83 | + `${FONT}`, |
| 84 | + )} |
| 85 | + ></textarea> |
| 86 | + <span className="body-sb mt-10 flex justify-end">FROM. {'12E12'}</span> |
| 87 | + <button className="bg-primary-3 body-m mt-3 w-full rounded-lg py-2">편지 작성하기</button> |
56 | 88 | </div> |
57 | | - <textarea |
58 | | - readOnly |
59 | | - value={text} |
60 | | - className={twMerge( |
61 | | - `body-r basic-theme min-h-full w-full grow px-6 focus:outline-none`, |
62 | | - `${FONT}`, |
63 | | - )} |
64 | | - ></textarea> |
65 | | - <span className="body-sb mt-10 flex justify-end">FROM. {'12E12'}</span> |
66 | | - <button className="bg-primary-3 mt-3 w-full rounded-lg py-2">편지 작성하기</button> |
67 | | - </div> |
| 89 | + </> |
68 | 90 | ); |
69 | 91 | } |
0 commit comments