-
Notifications
You must be signed in to change notification settings - Fork 0
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
[Feature/BAR-36] 모달 컴포넌트 개발 #21
Changes from 8 commits
c52dd7c
5ebb849
fdb7950
cb5d559
c7a4811
0d2c1e6
db7b4a9
9c410d1
7ecafe4
cad1752
124363a
eb6b42b
ac50fb7
fefeccc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import ModalContainer from './ModalContainer'; | ||
|
||
const meta: Meta<typeof ModalContainer> = { | ||
title: 'Components/Modal', | ||
component: ModalContainer, | ||
decorators: [ | ||
(Story) => ( | ||
<div style={{ height: '500px' }}> | ||
<Story /> | ||
</div> | ||
), | ||
], | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof ModalContainer>; | ||
|
||
export const Second: Story = { | ||
args: { title: '제목', children: '설명' }, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { useModalStore } from '@/src/stores/modalStore'; | ||
|
||
import DeleteArticle from './components/DeleteArticle'; | ||
|
||
const Modal = () => { | ||
const { type } = useModalStore(); | ||
|
||
if (type === 'deleteArticle') return <DeleteArticle />; | ||
|
||
return null; | ||
}; | ||
|
||
export default Modal; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import type { PropsWithChildren } from 'react'; | ||
import { assignInlineVars } from '@vanilla-extract/dynamic'; | ||
|
||
import { useModalStore } from '@/src/stores/modalStore'; | ||
import { COLORS } from '@/src/styles/tokens'; | ||
|
||
import * as styles from './style.css'; | ||
|
||
interface ModalButtonProps { | ||
text?: string; | ||
backgroundColor?: string; | ||
color?: string; | ||
onClick: () => void; | ||
} | ||
|
||
interface ModalContainerProps { | ||
title: string; | ||
firstButtonProps?: ModalButtonProps; | ||
secondButtonProps?: ModalButtonProps; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dmswl98 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. first, second는 2개 이상의 버튼을 내포할 수 있다고 생각됩니다 ! 보여주신 형태는 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
이 의견도 좋다고 생각합니다! |
||
|
||
const ModalContainer = ({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 현재 디자인 상으로 Modal 타입이 여러 가지라, 해당 컴포넌트 내부에서 모든 content 요소들을 prop으로 받아서 컴포넌트 내부에서 분기 처리하여 그려내기 보다, 제가 생각했던 Modal 컴포넌트의 대략적인 사용 코드는 다음과 같아요. const LoginModal = () => {
return (
<Modal>
<h1>바로 시작하기</h1>
<Button>구글 로그인</Button>
<Button>카카오 로그인</Button>
</Modal>
)
} |
||
children, | ||
title, | ||
firstButtonProps, | ||
secondButtonProps, | ||
}: PropsWithChildren<ModalContainerProps>) => { | ||
const { closeModal } = useModalStore(); | ||
|
||
const { | ||
text: firstButtonText = '취소', | ||
color: firstButtonColor = COLORS['Grey/600'], | ||
backgroundColor: firstButtonBackgroundColor = COLORS['Grey/150'], | ||
onClick: onClickFirstButton = closeModal, | ||
} = firstButtonProps || {}; | ||
|
||
const { | ||
text: secondButtonText = '만들기', | ||
color: secondButtonColor = COLORS['Grey/White'], | ||
backgroundColor: secondButtonBackgroundColor = COLORS['Blue/Default'], | ||
} = secondButtonProps || {}; | ||
|
||
return ( | ||
<> | ||
<div className={styles.dimmed} /> | ||
<div className={styles.modalStyle}> | ||
<strong className={styles.title}>{title}</strong> | ||
{typeof children === 'string' ? ( | ||
<p className={styles.body}>{children}</p> | ||
) : ( | ||
<>{children}</> | ||
)} | ||
<div> | ||
<button | ||
type="button" | ||
className={styles.button} | ||
style={assignInlineVars({ | ||
[styles.buttonColor]: firstButtonColor, | ||
[styles.buttonBackgroundColor]: firstButtonBackgroundColor, | ||
})} | ||
onClick={onClickFirstButton} | ||
> | ||
{firstButtonText} | ||
</button> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Button 컴포넌트도 따로 공통 컴포넌트로 만들면 좋을 것 같습니다. |
||
<button | ||
type="button" | ||
className={styles.button} | ||
style={assignInlineVars({ | ||
[styles.buttonColor]: secondButtonColor, | ||
[styles.buttonBackgroundColor]: secondButtonBackgroundColor, | ||
})} | ||
> | ||
{secondButtonText} | ||
</button> | ||
</div> | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
export default ModalContainer; |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,17 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import ModalContainer from '../ModalContainer'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const DeleteArticle = () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
<ModalContainer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
title="해당 글을 삭제할까요?" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
secondButtonProps={{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
text: '삭제하기', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
onClick: () => {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{'삭제한 글은 복구할 수 없어요!\n삭제하시겠어요'} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
</ModalContainer> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
추상화가 된다면 이렇게 활용할 수 있습니다! |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
export default DeleteArticle; |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { createVar, style } from '@vanilla-extract/css'; | ||
|
||
import { sprinkles } from '@/src/styles/sprinkles.css'; | ||
import { COLORS } from '@/src/styles/tokens'; | ||
import { middleLayer, positionCenter, topLayer } from '@/src/styles/utils.css'; | ||
|
||
export const modalStyle = style([ | ||
positionCenter, | ||
topLayer, | ||
{ | ||
padding: '32px', | ||
width: '400px', | ||
borderRadius: '16px', | ||
backgroundColor: COLORS['Grey/White'], | ||
}, | ||
]); | ||
|
||
export const dimmed = style([ | ||
middleLayer, | ||
{ | ||
backgroundColor: COLORS['Dim/50'], | ||
position: 'fixed', | ||
left: '0', | ||
top: '0', | ||
right: '0', | ||
bottom: '0', | ||
}, | ||
]); | ||
|
||
export const title = style([ | ||
sprinkles({ | ||
typography: '20/Title/Semibold', | ||
}), | ||
{ | ||
display: 'block', | ||
marginBottom: '18px', | ||
}, | ||
]); | ||
|
||
export const body = style([ | ||
sprinkles({ | ||
typography: '15/Body/Regular', | ||
}), | ||
{ | ||
display: 'block', | ||
}, | ||
]); | ||
|
||
export const buttonColor = createVar(); | ||
export const buttonBackgroundColor = createVar(); | ||
|
||
export const button = style([ | ||
sprinkles({ | ||
typography: '15/Title/Medium', | ||
}), | ||
{ | ||
width: '164px', | ||
color: buttonColor, | ||
backgroundColor: buttonBackgroundColor, | ||
padding: '16px 40px', | ||
borderRadius: '8px', | ||
marginTop: '24px', | ||
selectors: { | ||
'& + &': { | ||
marginLeft: '8px', | ||
}, | ||
}, | ||
}, | ||
]); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { createStore } from 'zustand'; | ||
import { shallow } from 'zustand/shallow'; | ||
import { useStoreWithEqualityFn as useStore } from 'zustand/traditional'; | ||
|
||
type ModalType = 'no' | 'deleteArticle'; | ||
|
||
interface State { | ||
type: ModalType; | ||
} | ||
|
||
interface Action { | ||
openModal: (type: ModalType) => void; | ||
closeModal: () => void; | ||
} | ||
|
||
export const modalStore = createStore<State & Action>((set) => ({ | ||
type: 'no', | ||
openModal: (type) => set({ type }), | ||
closeModal: () => set({ type: 'no' }), | ||
})); | ||
|
||
export const useModalStore = () => | ||
useStore( | ||
modalStore, | ||
(state) => ({ | ||
type: state.type, | ||
openModal: state.openModal, | ||
closeModal: state.closeModal, | ||
}), | ||
shallow, | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
{ | ||
"compilerOptions": { | ||
"strict": true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍🏻👍🏻👍🏻 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😭 |
||
"target": "es5", | ||
"lib": ["dom", "dom.iterable", "esnext"], | ||
"allowJs": true, | ||
"skipLibCheck": true, | ||
"strict": false, | ||
"noEmit": true, | ||
"esModuleInterop": true, | ||
"module": "esnext", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modal.tsx
가 하나의 파일에서 너무 많은 일을 하고 있는것 같습니다 !There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
디자인적 요소 (버튼 등)를 포함하지 않은 모달이 존재하면 더 좋을것 같아요