diff --git a/src/app/mobile/page.tsx b/src/app/mobile/page.tsx index 8c6e7b9..e3ae6eb 100644 --- a/src/app/mobile/page.tsx +++ b/src/app/mobile/page.tsx @@ -1,14 +1,32 @@ +'use client'; + import MobileLayout from '@/components/mobile/layout'; -import Header from '@/components/mobile/Header'; +import Dropdown from '@/components/mobile/Dropdown'; +import useDropdown from '@/hooks/useDropdown'; export default function Mobile() { + const dropdownActions = [ + { title: '전체', func: () => console.log('전체') }, + { title: '대여 신청', func: () => console.log('대여 신청') }, + { title: '반납 신청', func: () => console.log('반납 신청') }, + ]; + + const { showDropdown, hideDropdown, isDropdownVisible } = useDropdown(); + return ( - {/*
-

국민대학교 소프트웨어융합대학

-

복지물품 대여 시스템

-
*/} -
+ + + ); } diff --git a/src/components/mobile/Dropdown/index.tsx b/src/components/mobile/Dropdown/index.tsx new file mode 100644 index 0000000..3bca3f1 --- /dev/null +++ b/src/components/mobile/Dropdown/index.tsx @@ -0,0 +1,61 @@ +import { useEffect, useRef } from 'react'; +import { cn } from '@/lib/utils'; + +interface DropdownProps { + actions: { title: string; func: () => void }[]; + isVisible: boolean; + hideDropdown: () => void; + positionClasses?: string; +} + +export default function Dropdown({ + actions, + isVisible, + hideDropdown, + positionClasses = 'top-0 right-0', +}: DropdownProps) { + const dropdownRef = useRef(null); + + useEffect(() => { + const handleClickOutside = (event: MouseEvent) => { + if ( + dropdownRef.current && + !dropdownRef.current.contains(event.target as Node) + ) { + hideDropdown(); + } + }; + + document.addEventListener('mousedown', handleClickOutside); + + return () => { + document.removeEventListener('mousedown', handleClickOutside); + }; + }, [hideDropdown]); + + return ( +
    + {actions.map((action) => ( +
  • + +
  • + ))} +
+ ); +} diff --git a/src/hooks/useDropdown.ts b/src/hooks/useDropdown.ts new file mode 100644 index 0000000..c135bb8 --- /dev/null +++ b/src/hooks/useDropdown.ts @@ -0,0 +1,14 @@ +'use client'; + +import { useState } from 'react'; + +const useDropdown = () => { + const [isDropdownVisible, setIsDropdownVisible] = useState(false); + + const showDropdown = () => setIsDropdownVisible(true); + const hideDropdown = () => setIsDropdownVisible(false); + + return { showDropdown, hideDropdown, isDropdownVisible }; +}; + +export default useDropdown;