Skip to content

Commit

Permalink
Merge pull request #122 from Kernel360/common-component-modal-ui-edit
Browse files Browse the repository at this point in the history
공통 컴포넌트 수정: Modal
  • Loading branch information
bottlewook authored Jan 24, 2024
2 parents f8b1f40 + e46be59 commit d00837f
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 39 deletions.
8 changes: 4 additions & 4 deletions src/app/withdraw/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ function WithdrawPage() {
open({
title: '회원 탈퇴',
description: '회원을 탈퇴하면 차량용품 추천 서비스를 제공받을 수 없습니다. 정말로 탈퇴하시겠습니까?',
topButtonLabel: '예',
bottomButtonLabel: '아니오',
onTopButtonClick: () => {
leftButtonLabel: '예',
rightButtonLabel: '아니오',
onLeftButtonClick: () => {
// 회원탈퇴
},
onBottomButtonClick: () => {
onRightButtonClick: () => {
// 모달닫기
},
});
Expand Down
12 changes: 10 additions & 2 deletions src/components/shared/modal/Modal.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,19 @@
box-sizing: border-box;
flex-direction: column;
align-items: center;
width: 280px;
width: 327px;
height: 220px;
padding: 24px;
padding: 24px 16px;
overflow: hidden;
transform: translate(-50%, -50%);
border-radius: 10px;
background-color: var(--white);

.description {
width: 244px;
}

.buttonContainer {
width: 100%;
}
}
38 changes: 25 additions & 13 deletions src/components/shared/modal/Modal.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ const meta = {
withReactContext({
Context: ModalContext,
initialState: {
open: true,
title: '탈퇴하시겠습니까?',
description: '회원을 탈퇴하면 차량용품 추천 서비스를 제공받을 수 없습니다. 정말로 탈퇴하시겠습니까?',
topButtonLabel: '예',
bottomButtonLabel: '아니오',
onTopButtonClick: () => { },
onBottomButtonClick: () => { },
open: false,
title: null,
description: null,
leftButtonLabel: null,
rightButtonLabel: null,
onLeftButtonClick: () => { },
onRightButtonClick: () => { },
},
}),
],
Expand All @@ -37,11 +37,23 @@ type Story = StoryObj<typeof meta>;
export const normal: Story = {
args: {
open: true,
title: '탈퇴하시겠습니까?',
description: '회원을 탈퇴하면 차량용품 추천 서비스를 제공받을 수 없습니다. 정말로 탈퇴하시겠습니까?',
topButtonLabel: '예',
bottomButtonLabel: '아니오',
onTopButtonClick: () => { },
onBottomButtonClick: () => { },
title: '정말 탈퇴하시겠습니까?',
description: '탈퇴하시면 차량용품 추천 서비스를 제공받을 수 없습니다. 정말로 탈퇴하시겠습니까?',
leftButtonLabel: '예',
rightButtonLabel: '아니오',
onLeftButtonClick: () => { },
onRightButtonClick: () => { },
},
};

export const oneButtonModal = {
args: {
open: true,
title: '정말 탈퇴하시겠습니까?',
description: '탈퇴하시면 차량용품 추천 서비스를 제공받을 수 없습니다. 정말로 탈퇴하시겠습니까?',
leftButtonLabel: '예',
rightButtonLabel: null,
onLeftButtonClick: () => { },
onRightButtonClick: () => { },
},
};
25 changes: 14 additions & 11 deletions src/components/shared/modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import Dimmed from '@shared/dimmed/Dimmed';
import Spacing from '@shared/spacing/Spacing';
import Text from '@shared/text/Text';

import Flex from '../flex/Flex';

import styles from './Modal.module.scss';

const cx = classNames.bind(styles);
Expand All @@ -18,15 +20,15 @@ interface ModalProps {
open: boolean
title: React.ReactNode
description: React.ReactNode
topButtonLabel: React.ReactNode
bottomButtonLabel: React.ReactNode
onTopButtonClick: () => void
onBottomButtonClick: () => void
leftButtonLabel: React.ReactNode
rightButtonLabel: React.ReactNode
onLeftButtonClick: () => void
onRightButtonClick: () => void
}

function Modal({
// eslint-disable-next-line max-len
open, title, description, topButtonLabel, bottomButtonLabel, onTopButtonClick, onBottomButtonClick,
open, title, description, leftButtonLabel, rightButtonLabel, onLeftButtonClick, onRightButtonClick,
}: ModalProps) {
const { close } = useModal();
const modalRef = useOutsideClick(close);
Expand All @@ -38,13 +40,14 @@ function Modal({
return (
<Dimmed>
<div className={cx('container')} ref={modalRef}>
<Text bold>{title}</Text>
<Text typography="t4" bold>{title}</Text>
<Spacing size={8} />
<Text typography="t7" color="gray200">{description}</Text>
<Spacing size={24} />
<Button onClick={onTopButtonClick} full color="secondary">{topButtonLabel}</Button>
<Spacing size={12} />
<Button onClick={onBottomButtonClick} full>{bottomButtonLabel}</Button>
<Text typography="t6" color="gray200" textAlign="center" wordBreak="keep-all" className={cx('description')}>{description}</Text>
<Spacing size={32} />
<Flex justify="space-between" align="center" gap={8} className={cx('buttonContainer')}>
<Button onClick={onLeftButtonClick} full color="primary" size="large">{leftButtonLabel}</Button>
{rightButtonLabel && <Button onClick={onRightButtonClick} full size="large" color="gray" weak>{rightButtonLabel}</Button>}
</Flex>
</div>
</Dimmed>
);
Expand Down
18 changes: 9 additions & 9 deletions src/contexts/ModalContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ const defaultValues: ModalProps = {
open: false,
title: null,
description: null,
topButtonLabel: null,
bottomButtonLabel: null,
onTopButtonClick: () => { },
onBottomButtonClick: () => { },
leftButtonLabel: null,
rightButtonLabel: null,
onLeftButtonClick: () => { },
onRightButtonClick: () => { },
};

export const ModalContext = createContext<ModalContextValue | undefined>(undefined);
Expand All @@ -38,16 +38,16 @@ export function ModalContextProvider({ children }: { children: React.ReactNode }
}, []);

// eslint-disable-next-line max-len
const open = useCallback(({ onTopButtonClick, onBottomButtonClick, ...options }: ModalOptions) => {
const open = useCallback(({ onLeftButtonClick, onRightButtonClick, ...options }: ModalOptions) => {
setModalState({
...options,
onTopButtonClick: () => {
onLeftButtonClick: () => {
close();
onTopButtonClick();
onLeftButtonClick();
},
onBottomButtonClick: () => {
onRightButtonClick: () => {
close();
onBottomButtonClick();
onRightButtonClick();
},
open: true,
});
Expand Down

0 comments on commit d00837f

Please sign in to comment.