Skip to content

Commit

Permalink
refactor: navbar compound 패턴 코드 예시 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
sikkzz committed Feb 2, 2025
1 parent 00ef97b commit cc37e53
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 7 deletions.
41 changes: 41 additions & 0 deletions src/assets/svg/ic-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion src/components/ui/Icon/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import CameraIcon from "@/assets/svg/ic-camera.svg?react";
import CloseIcon from "@/assets/svg/ic-close.svg?react";
import GalleryIcon from "@/assets/svg/ic-gallery.svg?react";
import LeftArrowIcon from "@/assets/svg/ic-left-arrow.svg?react";
import LogoIcon from "@/assets/svg/ic-logo.svg?react";
import PasteIcon from "@/assets/svg/ic-paste.svg?react";
import PlusIcon from "@/assets/svg/ic-plus.svg?react";

export type IconNameType = "camera" | "close" | "gallery" | "leftArrow" | "paste" | "plus";
export type IconNameType = "camera" | "close" | "gallery" | "leftArrow" | "paste" | "plus" | "logo";

export interface IconProps {
name: IconNameType;
Expand All @@ -18,6 +19,7 @@ export const ICONS = {
leftArrow: LeftArrowIcon,
paste: PasteIcon,
plus: PlusIcon,
logo: LogoIcon,
};

// 추후 사이즈, 컬러등 추가 가능
Expand Down
17 changes: 17 additions & 0 deletions src/components/ui/NavbarV2/NavbarV2.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.NavbarV2 {
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
height: 2.75rem;
padding: 0.75rem 1.25rem;
background-color: var(--color-white);

button {
display: flex;
}
}

.RightButton {
margin-left: auto;
}
36 changes: 36 additions & 0 deletions src/components/ui/NavbarV2/NavbarV2.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import type { ButtonHTMLAttributes, PropsWithChildren } from "react";

import classNames from "classnames";

import styles from "@/components/ui/NavbarV2/NavbarV2.module.scss";

const NavbarV2 = ({ children }: PropsWithChildren) => {
return <div className={styles.NavbarV2}>{children}</div>;
};

NavbarV2.LeftButton = ({
children,
// 확장성 고려해서 className 추가 현재 디자인상에서는 사실 필요 없기는 함
className,
...props
}: ButtonHTMLAttributes<HTMLButtonElement>) => {
return (
<button {...props} className={className}>
{children}
</button>
);
};

NavbarV2.RightButton = ({
children,
className,
...props
}: ButtonHTMLAttributes<HTMLButtonElement>) => {
return (
<button className={classNames(styles.RightButton, className)} {...props}>
{children}
</button>
);
};

export default NavbarV2;
23 changes: 21 additions & 2 deletions src/pages/HomePage.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
import { useNavigate } from "react-router-dom";

import Home from "@/components/Home/Home";
import HomeNavbar from "@/components/ui/HomeNavbar/HomeNavbar";
import Icon from "@/components/ui/Icon/Icon";
import NavbarV2 from "@/components/ui/NavbarV2/NavbarV2";
import Text from "@/components/ui/Text/Text";

const HomePage = () => {
const navigate = useNavigate();

const handleLogoClick = () => {
navigate("/");
};
return (
<>
<HomeNavbar />
<NavbarV2>
<NavbarV2.LeftButton onClick={handleLogoClick}>
<Icon name="logo" />
</NavbarV2.LeftButton>
<NavbarV2.RightButton>
<Text variant="bodySm" color="secondary">
앱 공유하기
</Text>
</NavbarV2.RightButton>
</NavbarV2>

<Home />
</>
);
Expand Down
10 changes: 8 additions & 2 deletions src/pages/ReceiptEditPage.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import ReceiptEdit from "@/components/ReceiptEdit/ReceiptEdit";
import ArrowNavbar from "@/components/ui/ArrowNavbar/ArrowNavbar";
import Icon from "@/components/ui/Icon/Icon";
import NavbarV2 from "@/components/ui/NavbarV2/NavbarV2";

const ReceiptEditPage = () => {
return (
<>
<ArrowNavbar />
<NavbarV2>
<NavbarV2.LeftButton>
<Icon name="leftArrow" />
</NavbarV2.LeftButton>
</NavbarV2>

<ReceiptEdit />
</>
);
Expand Down
10 changes: 8 additions & 2 deletions src/pages/RecognitionFailPage.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import RecognitionFail from "@/components/RecognitionFail/RecognitionFail";
import CloseNavbar from "@/components/ui/CloseNavbar/CloseNavbar";
import Icon from "@/components/ui/Icon/Icon";
import NavbarV2 from "@/components/ui/NavbarV2/NavbarV2";

const RecognitionFailPage = () => {
return (
<>
<CloseNavbar />
<NavbarV2>
<NavbarV2.RightButton>
<Icon name="close" />
</NavbarV2.RightButton>
</NavbarV2>

<RecognitionFail />
</>
);
Expand Down

0 comments on commit cc37e53

Please sign in to comment.