Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Wip] 공통 컴포넌트 제작 (9) MyModal #46

Merged
merged 20 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
b076fdd
:sparkles: MyModal 컴포넌트 기초 레이아웃 생성
loevray Jan 4, 2024
688a4a3
:lipstick: 테마파일에 modal관련 스타일 정의
loevray Jan 4, 2024
505edea
:lipstick: MyModal컴포넌트 레이아웃 전부 완료
loevray Jan 4, 2024
7773f2b
:lipstick: MyModal header, 푸터쪽 버튼 폰트색상 수정
loevray Jan 4, 2024
c54d1f5
:truck: src/app폴더 생성및 App.tsx파일 이동
loevray Jan 4, 2024
db8b4f1
:heavy_plus_sign: redux-toolkit과 react-redux 패키지 추가
loevray Jan 4, 2024
60fb01d
:sparkles: redux-toolkit store추가
loevray Jan 4, 2024
97a3850
:sparkles: useSelector, useDispatch훅 useAppSelector, useAppDispatch로 추상화
loevray Jan 4, 2024
83ce9ab
:sparkles: myModalSlice추가
loevray Jan 4, 2024
d84653d
:art: App감싸는 reduxProvider추가
loevray Jan 4, 2024
241f686
:art: MyModal 컴포넌트 props로 모달 상태 받아오게 변경
loevray Jan 4, 2024
3a9e3d2
:fire: redux관련 로직 전부 삭제
loevray Jan 4, 2024
edd78a3
:heavy_minus_sign: redux-toolkit, react-redux 패키지 제거
loevray Jan 4, 2024
2cd1c93
:sparkles: MyModal storybook 수정 및 스토리 추가
loevray Jan 4, 2024
28ddb0f
:lipstick: MyModal컴포넌트의 헤더 color변경
loevray Jan 4, 2024
131838b
:lipstick: MyModal컴포넌트 footer버튼 텍스트 크기 조절
loevray Jan 4, 2024
e62c8bd
:art: MyModal컴포넌트 ...props로 받아오게 추가
loevray Jan 4, 2024
809c9d4
Merge branch 'dev' of https://github.com/prgrms-fe-devcourse/FEDC5_do…
loevray Jan 4, 2024
b0704a2
:art: MyModal 컴포넌트 onSubmit프롭스를 onButtonClick으로 변경 및 스토리북에도 수정사항 적용
loevray Jan 4, 2024
fbf9cf2
:art: MyModal컴포넌트 불필요한 프래그먼트 삭제
loevray Jan 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"framer-motion": "^10.16.16",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-icons": "^4.12.0",
"react-hook-form": "^7.49.2",
"react-icons": "^4.12.0",
"react-query": "^3.39.3",
"react-router-dom": "^6.21.1",
"storybook-addon-react-router-v6": "^2.0.10"
Expand Down
File renamed without changes.
73 changes: 73 additions & 0 deletions src/components/common/MyModal/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import {
Button,
Heading,
Modal,
ModalBody,
ModalCloseButton,
ModalContent,
ModalFooter,
ModalOverlay,
ModalProps,
Portal,
} from '@chakra-ui/react';
import { ReactNode } from 'react';

interface MyModal extends ModalProps {
onClose(): void;
isOpen: boolean;
title: string;
children: ReactNode;
buttonText: string;
onButtonClick: () => void;
}

const MyModal = ({
isOpen,
onClose,
title,
children,
buttonText,
onButtonClick,
...props
}: MyModal) => {
return (
<>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fragment는 제거해도 괜찮지 않을까요 ?!! 👀🧐
혹시 따로 사용해 주신 이유가 있으실까요 ?!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

어엇 Button넣고 테스트하다가 감빢햇네요 이거 지우고 merge하겠습니다 ㅎㅎ

<Portal>
<Modal isOpen={isOpen} onClose={onClose} {...props}>
<ModalOverlay />
<ModalContent maxW="modal.w" h="modal.h" borderRadius="10px">
<Heading
display="flex"
justifyContent="center"
alignItems="center"
fontSize="1.6rem"
bg="pink.300"
h="modal.header.h"
borderTopRadius="10px"
color="white"
>
{title}
</Heading>
<ModalCloseButton />
<ModalBody>{children}</ModalBody>
<ModalFooter justifyContent="center">
<Button
h="modal.button.h"
w="modal.button.w"
bg="pink.100"
onClick={onButtonClick}
mb="28px"
color="pink.300"
fontSize="1.4rem"
>
{buttonText}
</Button>
</ModalFooter>
</ModalContent>
</Modal>
</Portal>
</>
);
};

export default MyModal;
2 changes: 1 addition & 1 deletion src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import App from './App.tsx';
import App from './app/App.tsx';
import ReactDOM from 'react-dom/client';
import { ChakraProvider, ColorModeScript } from '@chakra-ui/react';
import { theme } from './theme/index.ts';
Expand Down
51 changes: 51 additions & 0 deletions src/stories/components/MyModal.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import MyModal from '@/components/common/MyModal';
import { Button, Text, useDisclosure } from '@chakra-ui/react';
import { Meta, StoryObj } from '@storybook/react';

const meta: Meta<typeof MyModal> = {
component: MyModal,
argTypes: {
isOpen: {
control: 'boolean',
},
onClose: {
type: 'function',
},
title: {
control: 'text',
},
buttonText: {
control: 'text',
},
onButtonClick: {
type: 'function',
},
},
};

export default meta;
type Story = StoryObj<typeof MyModal>;

const ModalTest = () => {
const { isOpen, onOpen, onClose } = useDisclosure();
return (
<>
<Button onClick={onOpen}>모달 켜세용</Button>
<MyModal
title="테스트 모달 제목"
isOpen={isOpen}
onClose={onClose}
buttonText="누르면 알림창"
onButtonClick={() => alert('하이')}
>
<Text align="center" fontSize="2rem">
하이 아임내용
</Text>
</MyModal>
</>
);
};

export const Deafult: Story = {
render: () => <ModalTest />,
};
11 changes: 11 additions & 0 deletions src/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ export const theme = extendTheme({
},
sizes: {
icon: '2.4rem',
modal: {
h: '343px',
w: '392px',
header: {
h: '54px',
},
button: {
w: '178px',
h: '36px',
},
},
Comment on lines +69 to +79
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

전역적으로 사이즈 지정해서 사용하는 것 너무 좋네요 ㅎㅎ 👍

},
zIndices: {
normal: 100,
Expand Down