diff --git a/src/contexts/ModalProvider.tsx b/src/contexts/ModalProvider.tsx index 13244cc..c63bce2 100644 --- a/src/contexts/ModalProvider.tsx +++ b/src/contexts/ModalProvider.tsx @@ -1,12 +1,17 @@ import { createContext, type PropsWithChildren, useContext, useState } from 'react'; +import { type ButtonProps } from '@/domain/_common/components'; import Modal from '@/domain/_common/components/Modal'; interface ModalData { title: string; message: string; - closeButton?: { label: string; onClick?: () => void }; - confirmButton?: { label: string; onClick: () => void }; + closeButton?: { + text: string; + } & Omit; + confirmButton?: { + text: string; + } & Omit; } interface ModalContextType { diff --git a/src/domain/_common/components/Button.tsx b/src/domain/_common/components/Button.tsx index 761dea6..5ee4f2d 100644 --- a/src/domain/_common/components/Button.tsx +++ b/src/domain/_common/components/Button.tsx @@ -1,6 +1,6 @@ import React, { type ReactNode } from 'react'; -interface ButtonProps { +export interface ButtonProps { disabled?: boolean; variant?: 'text' | 'contained'; color?: 'grey' | 'primary' | 'red'; diff --git a/src/domain/_common/components/Modal.tsx b/src/domain/_common/components/Modal.tsx index 5da3a34..3a2788d 100644 --- a/src/domain/_common/components/Modal.tsx +++ b/src/domain/_common/components/Modal.tsx @@ -1,42 +1,41 @@ -import React, { Fragment } from 'react'; - import { ReactComponent as CloseIcon } from '@/assets/close.svg'; -import { Button } from '@/domain/_common/components/Button'; +import { Button, type ButtonProps } from '@/domain/_common/components/Button'; interface ModalProps { title: string; message: string; onClose: () => void; closeButton?: { - label: string; - }; + text: string; + } & Omit; confirmButton?: { - label: string; - onClick: () => void; - }; + text: string; + } & Omit; } export default function Modal({ title, message, onClose, closeButton, confirmButton }: ModalProps) { return ( <>
-
-
+
+
{title}
{message}
-
- {closeButton && ( - - )} - {confirmButton && ( - - )} -
+ {(!!closeButton || !!confirmButton) && ( +
+ {closeButton && ( + + )} + {confirmButton && ( + + )} +
+ )}
diff --git a/src/stories/Modal.stories.tsx b/src/stories/Modal.stories.tsx index ca3b138..cd95915 100644 --- a/src/stories/Modal.stories.tsx +++ b/src/stories/Modal.stories.tsx @@ -2,32 +2,83 @@ import type { Meta, StoryObj } from '@storybook/react'; import { useModal } from '@/contexts/ModalProvider'; import { Button } from '@/domain/_common/components'; +import Modal from '@/domain/_common/components/Modal'; export default { title: 'Components/Modal', parameters: { - layout: 'centered', - design: { - type: 'figma', - url: 'https://www.figma.com/file/KHvd0JBcID35sOdr61Iief/Main?type=design&node-id=216-7319&mode=design&t=jq3LIMBJupzd6oGf-4', + docs: { + story: { + height: '500px', + }, }, }, -} satisfies Meta; + component: Modal, + tags: ['autodocs'], +} satisfies Meta; -type Story = StoryObj; -export const Basic: Story = { +type Story = StoryObj; + +export const CloseConfirm: Story = { render: () => { const { openModal } = useModal(); + const onClickNormal = () => { + openModal({ + title: '제목', + message: '메시지', + }); + }; + + const onClickConfirmClose = () => { + openModal({ + title: '제목', + message: '메시지', + closeButton: { + text: '닫기', + }, + confirmButton: { + text: '확인', + onClick: () => { + alert('확인'); + }, + }, + }); + }; + + const onClickConfirm = () => { + openModal({ + title: '제목', + message: '메시지', + confirmButton: { + text: '확인', + onClick: () => { + alert('확인'); + }, + }, + }); + }; + + const onClickClose = () => { + openModal({ + title: '제목', + message: '메시지', + closeButton: { + text: '닫기', + }, + }); + }; - const onClick = () => { + const onClickCustom = () => { openModal({ title: '제목', message: '메시지', closeButton: { - label: '닫기', + text: '닫기', + variant: 'text', }, confirmButton: { - label: '확인', + text: '확인', + variant: 'text', onClick: () => { alert('확인'); }, @@ -36,9 +87,23 @@ export const Basic: Story = { }; return ( - +
+ + + + + +
); }, };