-
Notifications
You must be signed in to change notification settings - Fork 1
[FEAT] 공통 모달 구현 (#248) #413
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f7acd3f
feat: 접근성을 고려한 Modal 컴포넌트 구현
kanghaeun ab8ae67
style: modal 컴포넌트 스타일링
kanghaeun 22a0d9d
feat: 모달 상태 관리 useModal hook 추가
kanghaeun e56b235
style: 모달 뒷배경 연한색으로 수정
kanghaeun 292a1bc
feat: 댓글 삭제 시 확인 모달 구현
kanghaeun a3c9b5d
refactor: 스크롤바 너비만큼 padding-right 추가
kanghaeun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| import { keyframes } from '@emotion/react'; | ||
| import styled from '@emotion/styled'; | ||
|
|
||
| const fadeIn = keyframes` | ||
| from { | ||
| opacity: 0; | ||
| } | ||
| to { | ||
| opacity: 1; | ||
| } | ||
| `; | ||
|
|
||
| const scaleIn = keyframes` | ||
| from { | ||
| opacity: 0; | ||
| transform: scale(0.95); | ||
| } | ||
| to { | ||
| opacity: 1; | ||
| transform: scale(1); | ||
| } | ||
| `; | ||
|
|
||
| type OverlayProps = { | ||
| $variant?: 'modal' | 'popover'; | ||
| }; | ||
|
|
||
| export const Overlay = styled.div<OverlayProps>(({ $variant = 'modal' }) => ({ | ||
| position: 'fixed', | ||
| inset: 0, | ||
| backgroundColor: $variant === 'popover' ? 'transparent' : 'rgba(0, 0, 0, 0.3)', | ||
| display: $variant === 'popover' ? 'block' : 'flex', | ||
| alignItems: $variant === 'popover' ? undefined : 'center', | ||
| justifyContent: $variant === 'popover' ? undefined : 'center', | ||
| zIndex: 50, | ||
| padding: $variant === 'popover' ? 0 : '1rem', | ||
| animation: `${fadeIn} 0.2s ease-out`, | ||
| })); | ||
|
|
||
| type ContentProps = { | ||
| $size?: 'sm' | 'md' | 'lg'; | ||
| $variant?: 'modal' | 'popover'; | ||
| $position?: { top: number; left: number }; | ||
| }; | ||
|
|
||
| const sizeMap = { | ||
| sm: '13rem', | ||
| md: '20rem', | ||
| lg: '30rem', | ||
| }; | ||
|
|
||
| export const Content = styled.div<ContentProps>( | ||
| ({ theme, $size = 'md', $variant = 'modal', $position }) => ({ | ||
| backgroundColor: '#fff', | ||
| borderRadius: theme.radius.lg, | ||
| boxShadow: | ||
| $variant === 'popover' | ||
| ? '0 4px 20px rgba(0, 0, 0, 0.15), 0 0 1px rgba(0, 0, 0, 0.1)' | ||
| : '0 25px 50px -12px rgba(0, 0, 0, 0.25)', | ||
| width: sizeMap[$size], | ||
| maxWidth: '100%', | ||
| maxHeight: $variant === 'popover' ? '80vh' : '90vh', | ||
| overflow: 'auto', | ||
| padding: $variant === 'popover' ? '1.5rem' : '2rem', | ||
| animation: `${scaleIn} 0.2s ease-out`, | ||
| display: 'flex', | ||
| flexDirection: 'column', | ||
|
|
||
| // popover일 때 position 계산 전에는 숨김 | ||
| ...($variant === 'popover' && | ||
| !$position && { | ||
| visibility: 'hidden', | ||
| position: 'fixed', | ||
| }), | ||
|
|
||
| // popover일 때 위치 지정 (fixed로 스크롤 시 따라감) | ||
| ...($variant === 'popover' && | ||
| $position && { | ||
| position: 'fixed', | ||
| top: $position.top - 10, | ||
| left: $position.left - 30, | ||
| }), | ||
|
|
||
| [`@media (max-width: ${theme.breakpoints.mobile})`]: { | ||
| padding: '1.5rem', | ||
| maxHeight: '85vh', | ||
| }, | ||
| }), | ||
| ); | ||
|
|
||
| export const Title = styled.h2(({ theme }) => ({ | ||
| fontSize: theme.font.size.base, | ||
| fontWeight: 700, | ||
| color: theme.colors.gray900, | ||
| marginBottom: '0.5rem', | ||
|
|
||
| '&:focus': { | ||
| outline: 'none', | ||
| }, | ||
| })); | ||
|
|
||
| export const Description = styled.p(({ theme }) => ({ | ||
| fontSize: '1rem', | ||
| color: theme.colors.gray500, | ||
| marginBottom: '1.5rem', | ||
| })); | ||
|
|
||
| export const CloseButton = styled.button(({ theme }) => ({ | ||
| position: 'absolute', | ||
| top: '1rem', | ||
| right: '1rem', | ||
| background: 'none', | ||
| border: 'none', | ||
| padding: '0.5rem', | ||
| cursor: 'pointer', | ||
| color: theme.colors.gray400, | ||
| borderRadius: theme.radius.sm, | ||
| transition: 'color 0.2s, background-color 0.2s', | ||
|
|
||
| '&:hover': { | ||
| color: theme.colors.gray600, | ||
| backgroundColor: theme.colors.gray100, | ||
| }, | ||
| })); | ||
|
|
||
| export const Header = styled.div({ | ||
| position: 'relative', | ||
| marginBottom: '1rem', | ||
| }); | ||
|
|
||
| export const Body = styled.div({ | ||
| flex: 1, | ||
| display: 'flex', | ||
| flexDirection: 'column', | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
popover의 위치를 조정하기 위해 하드코딩된-10,-30같은 매직 넘버를 사용하고 있습니다. 이렇게 하면 컴포넌트의 재사용성이 떨어지고, 다른 위치에popover를 표시하고 싶을 때 스타일 파일을 수정해야 하는 불편함이 있습니다. 이 로직을 스타일 컴포넌트에서 제거하고,Modal/index.tsx컴포넌트 내에서 위치를 계산할 때 offset을 적용하는 것이 좋습니다.offset값을 prop으로 받아 더욱 유연하게 만드는 것도 좋은 방법입니다.