-
Notifications
You must be signed in to change notification settings - Fork 1
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
Drawer 컴포넌트를 구현한다 #29
Changes from 1 commit
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,63 @@ | ||
import { Meta, StoryFn } from '@storybook/react'; | ||
import Drawer, { DrawerProps } from './Drawer'; | ||
import { PropsWithChildren } from 'react'; | ||
|
||
export default { | ||
title: 'payments/Drawer', | ||
component: Drawer, | ||
argTypes: { | ||
isOpen: { | ||
defaultValue: true, | ||
description: 'props 값으로 넘겨주어 drawer의 열고 닫음을 조작할 수 있습니다', | ||
control: { | ||
type: 'boolean' | ||
} | ||
}, | ||
anchor: { | ||
defaultValue: 'bottom', | ||
description: 'drawer가 열리는 방향에 따라서 값을 조정할 수 있습니다' | ||
} | ||
} | ||
} as Meta; | ||
|
||
const Template: StoryFn<PropsWithChildren<DrawerProps>> = args => ( | ||
<div | ||
style={{ | ||
width: '500px', | ||
height: '500px', | ||
position: 'relative', | ||
border: '1px solid black', | ||
display: 'flex', | ||
justifyContent: 'center', | ||
alignItems: 'center' | ||
}} | ||
> | ||
<div style={{ border: '1px solid red', width: '100px', height: '100px' }}> | ||
Example Component | ||
</div> | ||
<Drawer {...args}> | ||
<div | ||
style={{ | ||
width: '100%', | ||
height: '100%', | ||
display: 'flex', | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
flexDirection: 'column', | ||
gap: '20px' | ||
}} | ||
> | ||
<div>drawer를 감싸는 상위 부모 컴포넌트의 position을 relative로 해주세요</div> | ||
<div>drawer로 덮어주고 싶은 컴포넌트와 동일 레벨에 컴포넌트를 위치 시켜주세요</div> | ||
<div>drawer의 z-index 값은 500입니다</div> | ||
</div> | ||
</Drawer> | ||
</div> | ||
); | ||
|
||
export const Default = Template.bind({}); | ||
|
||
Default.args = { | ||
isOpen: true, | ||
anchor: 'bottom' | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import styled, { css } from 'styled-components'; | ||
|
||
export const Dimmed = styled.div` | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
right: 0; | ||
bottom: 0; | ||
|
||
opacity: 0; | ||
visibility: hidden; | ||
|
||
background-color: rgba(0, 0, 0, 0.5); | ||
|
||
z-index: ${({ theme }) => theme.zIndex.DRAWER}; | ||
|
||
&.is-open { | ||
opacity: 1; | ||
visibility: visible; | ||
} | ||
`; | ||
|
||
export const Container = styled.div<{ anchor: 'left' | 'right' | 'top' | 'bottom' }>` | ||
position: absolute; | ||
|
||
background-color: ${({ theme }) => theme.colors.WHITE}; | ||
box-sizing: border-box; | ||
|
||
width: 0; | ||
height: 0; | ||
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. 이제와 돌이켜보니 이유가 생각나지 않습니다... 일단 제거하겠습니다 👍 |
||
|
||
${({ anchor }) => | ||
((anchor === 'left' || anchor === 'right') && | ||
css` | ||
transition: width 1s ease-in-out; | ||
`) || | ||
((anchor === 'top' || anchor === 'bottom') && | ||
css` | ||
transition: height 1s ease-in-out; | ||
`)} | ||
|
||
&.is-open { | ||
${({ anchor }) => | ||
(anchor === 'top' && | ||
css` | ||
width: 100%; | ||
height: 50%; | ||
border-radius: 0 0 10px 10px; | ||
top: 0; | ||
`) || | ||
(anchor === 'left' && | ||
css` | ||
width: 50%; | ||
height: 100%; | ||
border-radius: 0 10px 10px 0; | ||
left: 0; | ||
`) || | ||
(anchor === 'right' && | ||
css` | ||
width: 50%; | ||
height: 100%; | ||
border-radius: 0 10px 10px 0; | ||
right: 0; | ||
`) || | ||
(anchor === 'bottom' && | ||
css` | ||
width: 100%; | ||
height: 50%; | ||
bottom: 0; | ||
border-radius: 10px 10px 0 0; | ||
Comment on lines
+41
to
+67
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. config로 빼는게 깔끔하지 않을까요? 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. config로 뺀다는 것이 어떤 의미일까요? 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. 제 pr에서 확인 부탁드립니다. |
||
`)} | ||
} | ||
`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { PropsWithChildren } from 'react'; | ||
import * as S from './Drawer.styled'; | ||
|
||
export interface DrawerProps { | ||
isOpen: boolean; | ||
anchor: 'left' | 'right' | 'top' | 'bottom'; | ||
} | ||
|
||
const Drawer = ({ isOpen, anchor, children }: PropsWithChildren<DrawerProps>) => { | ||
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. dimmer에 클릭 이벤트 부착하는건 어떤가요? 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. 오 좋은 생각입니다! |
||
return ( | ||
<S.Dimmed className={isOpen ? 'is-open' : ''}> | ||
<S.Container className={isOpen ? 'is-open' : ''} anchor={anchor}> | ||
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. isOpen가 내부에서 필요한가요? 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. isOpen을 통해서 Drawer가 열릴 때 드르릭 하는 애니메이션을 구현하기 위해 넣어주었습니다! |
||
{children} | ||
</S.Container> | ||
</S.Dimmed> | ||
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. Container가 Dimmed에 감싸져있을 필요가 있을까요? 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. Container 컴포넌트 위치를 고정시켜야해서 dimmer로 감싸는 것이 편리하다고 생각하였습니다 |
||
); | ||
}; | ||
|
||
export default Drawer; |
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.
radio로 보여주는 거 어때요?!