imrove: animate bottomsheet and drag support

This commit is contained in:
Mahyar Khanbolooki
2025-07-12 23:55:37 +03:30
parent 817af6e2e0
commit b04c468315
@@ -1,32 +1,66 @@
import React from 'react' import React, { useRef } from 'react'
import BlurredOverlayContainer, { BlurredOverlayContainerProps } from '../overlays/BlurredOverlayContainer' import BlurredOverlayContainer, { BlurredOverlayContainerProps } from '../overlays/BlurredOverlayContainer'
import clsx from 'clsx' import clsx from 'clsx'
import CloseIcon from '../icons/CloseIcon' import CloseIcon from '../icons/CloseIcon'
import { motion, PanInfo, Variants } from 'framer-motion'
type Props = { type Props = {
title: string title: string
} & BlurredOverlayContainerProps } & BlurredOverlayContainerProps
const AnimatedBottomSheet = (props: Props) => { const AnimatedBottomSheet = (props: Props) => {
const closeRef: React.Ref<HTMLDivElement> | undefined = useRef(null);
const variants: Variants = {
hidden: {
y: '100%',
},
visible: {
y: 0,
transition: {
duration: 0.1,
ease: 'easeInOut',
},
},
};
const onDrag = (_event: MouseEvent | TouchEvent | PointerEvent, info: PanInfo) => {
if (info.offset.y > 200) {
if (closeRef.current) {
closeRef.current.click();
}
}
}
return ( return (
<BlurredOverlayContainer {...props} inDelay={150}> <BlurredOverlayContainer {...props} outDelay={100}>
<div <motion.div
drag='y'
dragConstraints={{ top: 0, bottom: 0 }}
transition={{ type: "spring", stiffness: 200, damping: 20 }}
dragTransition={{ bounceDamping: 10, bounceStiffness: 600 }}
dragElastic={0.05}
onDragEnd={onDrag}
data-visible={props.visible} data-visible={props.visible}
className={clsx( className={clsx(
'border border-solid border-white absolute -bottom-full left-0 w-full bg-white/64 rounded-t-4xl pt-[39px] pb-6', 'absolute left-0 w-full bg-white/64 rounded-t-4xl pt-[39px] pb-6',
'data-[visible=true]:bottom-0 transition-all duration-150 backdrop-blur-2xl' 'bottom-0'
)}> )}
initial="hidden"
animate={props.visible ? 'visible' : 'hidden'}
variants={variants}
>
<div className="ps-[31px] pe-[33px] flex justify-between"> <div className="ps-[31px] pe-[33px] flex justify-between">
<div className='text-lg font-medium text-black leading-8 mt-2.5'>{props.title}</div> <div className='text-lg font-medium text-black leading-8 mt-2.5'>{props.title}</div>
<div onClick={props.onClick} className="bg-white/38 w-8 h-8 rounded-full p-1.5"> <div ref={closeRef} onClick={props.onClick} className="bg-white/38 w-8 h-8 rounded-full p-1.5">
<CloseIcon size={20} /> <CloseIcon size={20} />
</div> </div>
</div> </div>
{props.children} {props.children}
</div> </motion.div>
</BlurredOverlayContainer> </BlurredOverlayContainer>
) )
} }
export default AnimatedBottomSheet export default AnimatedBottomSheet