Skip to content

Commit

Permalink
feat:#9 useDeviceType 훅, react-responsive 사용
Browse files Browse the repository at this point in the history
  • Loading branch information
frombozztoang committed Feb 22, 2024
1 parent ef826e2 commit dcd0d07
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 12 deletions.
47 changes: 43 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"framer-motion": "^11.0.5",
"next": "14.1.0",
"react": "^18",
"react-dom": "^18"
"react-dom": "^18",
"react-responsive": "^9.0.2"
},
"devDependencies": {
"@storybook/addon-essentials": "^7.6.10",
Expand Down
17 changes: 12 additions & 5 deletions src/components/organisms/navigation/navigation/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@
import NoticeIcon from "../../../atoms/notice/noticeIcon/NoticeIcon";
import Image from "next/image";
import React, { useEffect, useState } from "react";
import logo from "../../../../../public/icons/logo.png";
import menu from "../../../../../public/icons/menu.png";
import logo from "@public/icons/logo.png";
import menu from "@public/icons/menu.png";

import Link from "next/link";
import { useRouter, useSearchParams } from "next/navigation";
import NavigationList from "../navigationList/NavigationList";

import ModalPortal from "@/utils/ModalPortal";
import useDeviceType from "@/hooks/useDeviceType";

const Navigation = () => {
const [isOpened, setIsOpened] = useState(false);
const deviceType = useDeviceType();
const handleIsOpened = () => {
setIsOpened(!isOpened);
};
Expand All @@ -25,9 +29,12 @@ const Navigation = () => {
return (
<>
<div className="relative z-header box-border">
{isOpened && (
<NavigationList isOpened={isOpened} setIsOpened={setIsOpened} />
)}
<ModalPortal>
{isOpened && (
<NavigationList isOpened={isOpened} setIsOpened={setIsOpened} />
)}
</ModalPortal>

<div className="fixed z-header flex items-center w-360 justify-between h-56 py-12 px-16 bg-main-background box-border">
<Link href={"/"}>
<Image className="w-67 h-32" src={logo} alt="logo" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import useDeviceType from "@/hooks/useDeviceType";
import Image from "next/image";
import Link from "next/link";
import React from "react";
Expand All @@ -19,9 +20,19 @@ const NavigationList = ({
isOpened,
setIsOpened,
}: navigationListProps) => {
const deviceType = useDeviceType();

return (
<div className="fixed z-navigatoinList bg-[#00000030] top-0 right-0 w-full h-full ">
<div className="absolute right-0 flex flex-col w-240 h-screen bg-main-point">
<div
className={`${
deviceType === "mobile" ? "w-screen" : "w-max pl-150"
} fixed h-screen flex bg-[#00000045] z-modal `}
>
<div
className={`${
deviceType === "mobile" ? "absolute right-0" : ""
} flex flex-col w-240 h-screen bg-main-point`}
>
<div
className="mb-24 cursor-pointer"
onClick={() => setIsOpened(false)}
Expand Down
19 changes: 19 additions & 0 deletions src/hooks/useDeviceType.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { useEffect, useState } from "react";
import { useMediaQuery } from "react-responsive";

const useDeviceType = () => {
const [deviceType, setDeviceType] = useState("");
const isMobile = useMediaQuery({ query: "(max-width: 999px)" });

useEffect(() => {
if (isMobile) {
setDeviceType("mobile");
} else {
setDeviceType("tablet");
}
}, [isMobile]);

return deviceType;
};

export default useDeviceType;

0 comments on commit dcd0d07

Please sign in to comment.