Skip to content

Commit a6c79d2

Browse files
youngminssclaude
authored andcommitted
feat: Toast 컴포넌트 및 유틸 함수 추가
- Toaster 컴포넌트: sonner Toaster 래퍼 (offset, mobileOffset, gap 지원) - toast.warning() 유틸 함수: className 방식으로 Figma 디자인 적용 - layout.tsx에 Toaster 추가 - ToastTest 컴포넌트 추가 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 786e9f6 commit a6c79d2

File tree

6 files changed

+66
-2
lines changed

6 files changed

+66
-2
lines changed

app/_test/ToastTest.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"use client";
2+
3+
import { Button } from "#/components/button";
4+
import { toast } from "#/utils/toast";
5+
6+
export const ToastTest = () => {
7+
return (
8+
<Button
9+
onClick={() =>
10+
toast.warning("이미 선택되었어요. 다른 메뉴를 골라주세요!")
11+
}
12+
>
13+
Toast 테스트
14+
</Button>
15+
);
16+
};

app/layout.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Metadata, Viewport } from "next";
22
import { Geist, Geist_Mono } from "next/font/google";
33
import "./globals.css";
4+
import { Toaster } from "#/components/toast";
45

56
const geistSans = Geist({
67
variable: "--font-geist-sans",

app/page.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { BackwardButton } from "#/components/backwardButton";
22
import { Layout } from "#/components/layout";
33
import { StepHeader } from "#/components/stepHeader";
44
import { colors } from "#/constants/color";
5+
import { ToastTest } from "./_test/ToastTest";
56

67
export default function Home() {
78
return (
@@ -54,8 +55,8 @@ export default function Home() {
5455
</div>
5556
</Layout.Content>
5657
<Layout.Footer>
57-
<div className="ygi:flex ygi:h-layout-footer-height ygi:w-full ygi:items-center ygi:justify-center ygi:bg-surface-gray">
58-
Footer
58+
<div className="ygi:flex ygi:h-layout-footer-height ygi:w-full ygi:items-center ygi:justify-center ygi:gap-md ygi:bg-surface-gray">
59+
<ToastTest />
5960
</div>
6061
</Layout.Footer>
6162
</Layout.Root>

src/components/toast/Toaster.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"use client";
2+
3+
import {
4+
Toaster as SonnerToaster,
5+
type ToasterProps as SonnerToasterProps,
6+
} from "sonner";
7+
8+
export type ToasterProps = Pick<
9+
SonnerToasterProps,
10+
"offset" | "mobileOffset" | "gap" | "toastOptions"
11+
>;
12+
13+
export const Toaster = ({ offset, mobileOffset, gap, toastOptions = { duration: 3000 } }: ToasterProps) => {
14+
return (
15+
<SonnerToaster
16+
position="bottom-center"
17+
offset={offset}
18+
mobileOffset={mobileOffset}
19+
gap={gap}
20+
toastOptions={toastOptions}
21+
/>
22+
);
23+
};

src/components/toast/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { Toaster, type ToasterProps } from "./Toaster";

src/utils/toast.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { toast as sonnerToast } from "sonner";
2+
import { AlertCircleIcon } from "#/icons/alertCircleIcon";
3+
4+
interface ToastOptions {
5+
duration?: number;
6+
className?: string;
7+
}
8+
9+
export const toast = {
10+
warning: (message: string, options?: ToastOptions) => {
11+
sonnerToast(message, {
12+
icon: AlertCircleIcon({
13+
size: 20,
14+
className: "ygi:text-palette-primary-500 ygi:mx-auto!",
15+
}),
16+
classNames: {
17+
toast: "ygi:bg-button-primary! ygi:text-text-inverse! ygi:body-14-md! ygi:rounded-sm! ygi:py-3! ygi:pl-4! ygi:pr-5! ygi:gap-2! ygi:flex! ygi:items-center! ygi:border-none!",
18+
},
19+
duration: options?.duration,
20+
});
21+
},
22+
};

0 commit comments

Comments
 (0)