File tree Expand file tree Collapse file tree 3 files changed +55
-7
lines changed
Expand file tree Collapse file tree 3 files changed +55
-7
lines changed Original file line number Diff line number Diff line change 11import Profile from '../Profile/Profile' ;
2+ import { Dropdown } from './Dropdown' ;
23
34interface CommentProps {
45 nickname : string | null ;
@@ -8,13 +9,18 @@ interface CommentProps {
89const Comment = ( { nickname, comment } : CommentProps ) => {
910 return (
1011 < div className = "w-[300px] pt-[5px] pb-[5px] h-auto sm:w-[450px] flex flex-initial rounded-xl sm:rounded-2xl border-solid border-[1px] border-gray-100 items-center" >
11- < div className = "flex gap-[10px] pl-3 pr-3 items-center" >
12- < div className = "h-full flex items-start" >
13- < Profile nickname = { nickname } />
12+ < div className = "flex justify-between w-full" >
13+ < div className = "flex gap-[10px] pl-3 pr-3 items-center" >
14+ < div className = "h-full flex items-start" >
15+ < Profile nickname = { nickname } />
16+ </ div >
17+ < div className = "font-pm flex flex-col gap-[5px]" >
18+ < div className = "text-[8px] sm:text-[12px] text-gray-600 mt-[5px]" > { nickname } </ div >
19+ < div className = "text-[10px] sm:text-[15px] mb-[5px]" > { comment } </ div >
20+ </ div >
1421 </ div >
15- < div className = "font-pm flex flex-col gap-[5px]" >
16- < div className = "text-[8px] sm:text-[12px] text-gray-600 mt-[5px]" > { nickname } </ div >
17- < div className = "text-[10px] sm:text-[15px] mb-[5px]" > { comment } </ div >
22+ < div className = "pr-3 flex items-center" >
23+ < Dropdown data = { [ '수정' , '삭제' ] } />
1824 </ div >
1925 </ div >
2026 </ div >
Original file line number Diff line number Diff line change 1+ import { useEffect , useRef , useState } from 'react' ;
2+
3+ interface DropdownProps {
4+ data : string [ ] ;
5+ }
6+
7+ export const Dropdown = ( { data } : DropdownProps ) => {
8+ const [ showOptions , setShowOptions ] = useState ( false ) ;
9+ const selectRef = useRef < HTMLDivElement > ( null ) ;
10+
11+ useEffect ( ( ) => {
12+ const handleClickOutside = ( event : MouseEvent ) => {
13+ if ( selectRef . current && ! selectRef . current . contains ( event . target as Node ) ) {
14+ setShowOptions ( false ) ;
15+ }
16+ } ;
17+
18+ document . addEventListener ( 'mousedown' , handleClickOutside ) ;
19+ return ( ) => {
20+ document . removeEventListener ( 'mousedown' , handleClickOutside ) ;
21+ } ;
22+ } , [ ] ) ;
23+
24+ return (
25+ < div ref = { selectRef } >
26+ < div className = "items-center cursor-pointer" onClick = { ( ) => setShowOptions ( ( prev ) => ! prev ) } >
27+ < p className = "text-gray-500 text-lg" > …</ p >
28+ </ div >
29+ { showOptions && (
30+ < ul className = "absolute z-1 flex flex-col bg-white border border-gray-300 rounded-md" >
31+ { data . map ( ( item , index ) => (
32+ < li
33+ key = { index }
34+ className = "w-fit font-pm text-xs sm:text-sm pt-1.5 pb-1.5 pl-2 pr-2 text-center text-gray-600 hover:bg-blue-600 hover:text-white cursor-pointer rounded-md transition"
35+ >
36+ { item }
37+ </ li >
38+ ) ) }
39+ </ ul >
40+ ) }
41+ </ div >
42+ ) ;
43+ } ;
Original file line number Diff line number Diff line change 1- import React from 'react' ;
21import { WinnerProps } from './Winner.types' ;
32
43const Winner = ( { name, question } : WinnerProps ) => {
You can’t perform that action at this time.
0 commit comments