blob: c244330c46d3a77a5e9f90947dd6c8d7afa575b9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
import { XMarkIcon } from '@heroicons/react/24/outline'
import { AnimatePresence, motion } from 'framer-motion'
import { useEffect } from 'react'
import MobileView from '../../views/MobileView'
import DesktopView from '../../views/DesktopView'
const transition = { ease: 'linear', duration: 0.2 }
const BottomPopup = ({ children, active = false, title, close }) => {
useEffect(() => {
if (active) {
document.querySelector('html, body').classList.add('overflow-hidden')
} else {
document.querySelector('html, body').classList.remove('overflow-hidden')
}
}, [active])
return (
<>
<AnimatePresence>
{active && (
<>
<motion.div
className='overlay'
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
transition={transition}
onClick={close}
/>
<MobileView>
<motion.div
initial={{ bottom: '-100%' }}
animate={{ bottom: 0 }}
exit={{ bottom: '-100%' }}
transition={transition}
className='fixed left-0 w-full border-t border-gray_r-6 rounded-t-xl z-[60] p-4 pt-0 bg-white'
>
<div className='flex justify-between py-4'>
<div className='font-semibold text-h-sm'>{title}</div>
<button type='button' onClick={close}>
<XMarkIcon className='w-5 stroke-2' />
</button>
</div>
{children}
</motion.div>
</MobileView>
<DesktopView>
<motion.div
initial={{ bottom: '35%', opacity: 0 }}
animate={{ bottom: '30%', opacity: 1 }}
exit={{ bottom: '25%', opacity: 0 }}
transition={transition}
className='fixed left-1/2 -translate-x-1/2 w-2/5 border border-gray_r-6 rounded-xl z-[60] p-4 pt-0 bg-white'
>
<div className='flex justify-between py-4'>
<div className='font-semibold text-h-sm'>{title}</div>
<button type='button' onClick={close}>
<XMarkIcon className='w-5 stroke-2' />
</button>
</div>
{children}
</motion.div>
</DesktopView>
</>
)}
</AnimatePresence>
</>
)
}
export default BottomPopup
|