Skip to content

Commit ca75ec6

Browse files
committed
refactor: navbar compound 패턴 코드 예시 추가
1 parent 680b49a commit ca75ec6

File tree

7 files changed

+135
-7
lines changed

7 files changed

+135
-7
lines changed

src/assets/svg/ic-logo.svg

Lines changed: 41 additions & 0 deletions
Loading

src/components/ui/Icon/Icon.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import CloseIcon from "@/assets/svg/ic-close.svg?react";
44
import EmptyCircleIcon from "@/assets/svg/ic-empty-circle.svg?react";
55
import GalleryIcon from "@/assets/svg/ic-gallery.svg?react";
66
import LeftArrowIcon from "@/assets/svg/ic-left-arrow.svg?react";
7+
import LogoIcon from "@/assets/svg/ic-logo.svg?react";
78
import PasteIcon from "@/assets/svg/ic-paste.svg?react";
89
import PlusIcon from "@/assets/svg/ic-plus.svg?react";
910

@@ -15,7 +16,8 @@ export type IconNameType =
1516
| "paste"
1617
| "plus"
1718
| "checkCircle"
18-
| "emptyCircle";
19+
| "emptyCircle"
20+
| "logo";
1921

2022
export interface IconProps {
2123
name: IconNameType;
@@ -30,6 +32,7 @@ export const ICONS = {
3032
plus: PlusIcon,
3133
checkCircle: CheckCircleIcon,
3234
emptyCircle: EmptyCircleIcon,
35+
logo: LogoIcon,
3336
};
3437

3538
// 추후 사이즈, 컬러등 추가 가능
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.NavbarV2 {
2+
display: flex;
3+
align-items: center;
4+
justify-content: space-between;
5+
width: 100%;
6+
height: 2.75rem;
7+
padding: 0.75rem 1.25rem;
8+
background-color: var(--color-white);
9+
10+
button {
11+
display: flex;
12+
}
13+
}
14+
15+
.RightButton {
16+
margin-left: auto;
17+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import type { ButtonHTMLAttributes, PropsWithChildren } from "react";
2+
3+
import classNames from "classnames";
4+
5+
import styles from "@/components/ui/NavbarV2/NavbarV2.module.scss";
6+
7+
const NavbarV2 = ({ children }: PropsWithChildren) => {
8+
return <div className={styles.NavbarV2}>{children}</div>;
9+
};
10+
11+
NavbarV2.LeftButton = ({
12+
children,
13+
// 확장성 고려해서 className 추가 현재 디자인상에서는 사실 필요 없기는 함
14+
className,
15+
...props
16+
}: ButtonHTMLAttributes<HTMLButtonElement>) => {
17+
return (
18+
<button {...props} className={className}>
19+
{children}
20+
</button>
21+
);
22+
};
23+
24+
NavbarV2.RightButton = ({
25+
children,
26+
className,
27+
...props
28+
}: ButtonHTMLAttributes<HTMLButtonElement>) => {
29+
return (
30+
<button className={classNames(styles.RightButton, className)} {...props}>
31+
{children}
32+
</button>
33+
);
34+
};
35+
36+
export default NavbarV2;

src/pages/HomePage.tsx

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
1+
import { useNavigate } from "react-router-dom";
2+
13
import Home from "@/components/Home/Home";
2-
import HomeNavbar from "@/components/ui/HomeNavbar/HomeNavbar";
4+
import Icon from "@/components/ui/Icon/Icon";
5+
import NavbarV2 from "@/components/ui/NavbarV2/NavbarV2";
6+
import Text from "@/components/ui/Text/Text";
37

48
const HomePage = () => {
9+
const navigate = useNavigate();
10+
11+
const handleLogoClick = () => {
12+
navigate("/");
13+
};
514
return (
615
<>
7-
<HomeNavbar />
16+
<NavbarV2>
17+
<NavbarV2.LeftButton onClick={handleLogoClick}>
18+
<Icon name="logo" />
19+
</NavbarV2.LeftButton>
20+
<NavbarV2.RightButton>
21+
<Text variant="bodySm" color="secondary">
22+
앱 공유하기
23+
</Text>
24+
</NavbarV2.RightButton>
25+
</NavbarV2>
26+
827
<Home />
928
</>
1029
);

src/pages/ReceiptEditPage.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import ReceiptEdit from "@/components/ReceiptEdit/ReceiptEdit";
2-
import ArrowNavbar from "@/components/ui/ArrowNavbar/ArrowNavbar";
2+
import Icon from "@/components/ui/Icon/Icon";
3+
import NavbarV2 from "@/components/ui/NavbarV2/NavbarV2";
34

45
const ReceiptEditPage = () => {
56
return (
67
<>
7-
<ArrowNavbar />
8+
<NavbarV2>
9+
<NavbarV2.LeftButton>
10+
<Icon name="leftArrow" />
11+
</NavbarV2.LeftButton>
12+
</NavbarV2>
13+
814
<ReceiptEdit />
915
</>
1016
);

src/pages/RecognitionFailPage.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import RecognitionFail from "@/components/RecognitionFail/RecognitionFail";
2-
import CloseNavbar from "@/components/ui/CloseNavbar/CloseNavbar";
2+
import Icon from "@/components/ui/Icon/Icon";
3+
import NavbarV2 from "@/components/ui/NavbarV2/NavbarV2";
34

45
const RecognitionFailPage = () => {
56
return (
67
<>
7-
<CloseNavbar />
8+
<NavbarV2>
9+
<NavbarV2.RightButton>
10+
<Icon name="close" />
11+
</NavbarV2.RightButton>
12+
</NavbarV2>
13+
814
<RecognitionFail />
915
</>
1016
);

0 commit comments

Comments
 (0)