-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from alkong-dalkong/feature/#39_bottom_sheet
feat: Bottom Sheet 컴포넌트 추가
- Loading branch information
Showing
20 changed files
with
277 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
This file contains 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 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 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,32 @@ | ||
import { type Meta } from '@storybook/react' | ||
import { domMax, LazyMotion } from 'framer-motion' | ||
|
||
import { useToggle } from '@/hooks' | ||
|
||
import { BottomSheet } from './BottomSheet' | ||
|
||
const meta: Meta<typeof BottomSheet> = { | ||
title: 'BottomSheet', | ||
component: BottomSheet, | ||
} | ||
|
||
export default meta | ||
|
||
export function Default() { | ||
const [isShowing, toggleShowing] = useToggle(true) | ||
|
||
return ( | ||
<LazyMotion features={domMax}> | ||
<button | ||
className="rounded border border-blue-500 bg-transparent px-4 py-2 text-blue-700 hover:border-transparent hover:bg-blue-500 hover:text-white" | ||
type="button" | ||
onClick={toggleShowing} | ||
> | ||
toggle | ||
</button> | ||
<BottomSheet onClickScrim={toggleShowing} isShowing={isShowing}> | ||
bottom sheet content | ||
</BottomSheet> | ||
</LazyMotion> | ||
) | ||
} |
This file contains 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,99 @@ | ||
import { type ComponentProps, type MouseEventHandler, useEffect } from 'react' | ||
import { m, type Variants } from 'framer-motion' | ||
|
||
import { zIndex } from '@/constants' | ||
import { useScrollLock } from '@/hooks' | ||
|
||
import { Icon } from '../icons' | ||
import { AnimatePortal } from '../portal/AnimatePortal' | ||
|
||
type BottomSheetProps = ComponentProps<typeof AnimatePortal> & { | ||
onClickScrim?: VoidFunction | ||
isShort?: boolean | ||
} | ||
|
||
export const BottomSheet = ({ | ||
onClickScrim, | ||
isShort = false, | ||
isShowing, | ||
children, | ||
mode, | ||
}: BottomSheetProps) => { | ||
const { lockScroll, unlockScroll } = useScrollLock() | ||
|
||
const handleClickScrim: MouseEventHandler<HTMLDivElement> = (e) => { | ||
if (e.target !== e.currentTarget) return | ||
if (onClickScrim) onClickScrim() | ||
} | ||
|
||
useEffect(() => { | ||
if (isShowing) { | ||
lockScroll() | ||
} else { | ||
unlockScroll() | ||
} | ||
}, [isShowing, lockScroll, unlockScroll]) | ||
|
||
const heightStyle = isShort ? 'h-[calc(100vh-252px)]' : 'h-[calc(100vh-55px)]' | ||
|
||
return ( | ||
<AnimatePortal isShowing={isShowing} mode={mode}> | ||
<m.div | ||
className={`fixed inset-0 ${zIndex.backdrop} h-full w-screen overflow-hidden bg-[rgba(15,23,42,0.5)]`} | ||
onClick={handleClickScrim} | ||
variants={bottomSheetFadeInVariants} | ||
initial="initial" | ||
animate="animate" | ||
exit="exit" | ||
> | ||
<m.div | ||
className={`flex-column-align ${heightStyle} absolute left-0 top-full ${zIndex.backdrop} w-full rounded-t-3xl bg-white px-[20px]`} | ||
variants={bottomSheetVariants} | ||
> | ||
<div className="pb-[17px] pt-[8px]"> | ||
<Icon name="handle-bar" /> | ||
</div> | ||
{children} | ||
</m.div> | ||
</m.div> | ||
</AnimatePortal> | ||
) | ||
} | ||
|
||
const easing = [0.6, -0.05, 0.01, 0.99] | ||
|
||
const bottomSheetFadeInVariants: Variants = { | ||
initial: { | ||
opacity: 0, | ||
transition: { duration: 0.3, ease: easing }, | ||
willChange: 'opacity', | ||
}, | ||
animate: { | ||
opacity: 1, | ||
transition: { duration: 0.3, ease: easing }, | ||
willChange: 'opacity', | ||
}, | ||
exit: { | ||
opacity: 0, | ||
transition: { duration: 0.3, ease: easing }, | ||
willChange: 'opacity', | ||
}, | ||
} | ||
|
||
const bottomSheetVariants: Variants = { | ||
initial: { | ||
y: 0, | ||
transition: { duration: 0.3, ease: easing }, | ||
willChange: 'transform', | ||
}, | ||
animate: { | ||
y: '-100%', | ||
transition: { duration: 0.3, ease: easing }, | ||
willChange: 'transform', | ||
}, | ||
exit: { | ||
y: 0, | ||
transition: { duration: 0.3, ease: easing }, | ||
willChange: 'transform', | ||
}, | ||
} |
This file contains 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,11 @@ | ||
import type { IconProps } from '.' | ||
|
||
export const HandleBar = (props: IconProps) => { | ||
const { color = '#B4B5B8' } = props | ||
|
||
return ( | ||
<svg xmlns="http://www.w3.org/2000/svg" width="84" height="13" viewBox="0 0 84 13" fill="none"> | ||
<rect x="24" y="4" width="36" height="5" rx="2.5" fill={color} /> | ||
</svg> | ||
) | ||
} |
This file contains 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 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,17 @@ | ||
import { type ComponentProps } from 'react' | ||
import { AnimatePresence } from 'framer-motion' | ||
|
||
import { Portal } from './Portal' | ||
|
||
type AnimatePortalProps = ComponentProps<typeof Portal> & { | ||
isShowing: boolean | ||
mode?: ComponentProps<typeof AnimatePresence>['mode'] | ||
} | ||
|
||
export const AnimatePortal = ({ children, isShowing, mode = 'wait' }: AnimatePortalProps) => { | ||
return ( | ||
<Portal> | ||
<AnimatePresence mode={mode}>{isShowing && children}</AnimatePresence> | ||
</Portal> | ||
) | ||
} |
This file contains 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,16 @@ | ||
import { type PropsWithChildren, useEffect, useState } from 'react' | ||
import { createPortal } from 'react-dom' | ||
|
||
export const Portal = ({ children }: PropsWithChildren) => { | ||
const [container, setContainer] = useState<Element | null>(null) | ||
|
||
useEffect(() => { | ||
if (document) { | ||
setContainer(document.body) | ||
} | ||
}, []) | ||
|
||
if (!container) return null | ||
|
||
return createPortal(<>{children}</>, container) | ||
} |
Empty file.
This file contains 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 @@ | ||
export * from './zIndex' |
This file contains 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,5 @@ | ||
export const zIndex = { | ||
fab: 'z-[999]', | ||
backdrop: 'z-[1000]', | ||
modal: 'z-[1001]', | ||
} |
This file contains 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 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,8 @@ | ||
'use client' | ||
|
||
import { type PropsWithChildren } from 'react' | ||
import { domMax, LazyMotion } from 'framer-motion' | ||
|
||
export const LazyMotionProvider = ({ children }: PropsWithChildren) => { | ||
return <LazyMotion features={domMax}>{children}</LazyMotion> | ||
} |
This file contains 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 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,5 @@ | ||
export * from './Hydration' | ||
export * from './LazyMotionProvider' | ||
export * from './QueryProvider' | ||
export * from './useScrollLock' | ||
export * from './useToggle' |
This file contains 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,18 @@ | ||
import React from 'react' | ||
|
||
export const useScrollLock = () => { | ||
const lockScroll = React.useCallback(() => { | ||
document.body.dataset.scrollLock = 'true' | ||
document.body.style.overflow = 'hidden' | ||
}, []) | ||
|
||
const unlockScroll = React.useCallback(() => { | ||
document.body.style.overflow = '' | ||
document.body.style.paddingRight = '' | ||
}, []) | ||
|
||
return { | ||
lockScroll, | ||
unlockScroll, | ||
} | ||
} |
This file contains 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