From c42dfc0b052a50d43d0bf665ea9959129e87d99c Mon Sep 17 00:00:00 2001 From: "Indoteknik ." Date: Thu, 17 Jul 2025 08:49:25 +0700 Subject: (andri) rev button close popup bottom & fix layout mobile --- src/lib/home/components/PopupBannerPromotion.jsx | 134 ++++++++++++++++------- 1 file changed, 94 insertions(+), 40 deletions(-) (limited to 'src/lib') diff --git a/src/lib/home/components/PopupBannerPromotion.jsx b/src/lib/home/components/PopupBannerPromotion.jsx index 1463840a..1ef166f2 100644 --- a/src/lib/home/components/PopupBannerPromotion.jsx +++ b/src/lib/home/components/PopupBannerPromotion.jsx @@ -4,6 +4,7 @@ import Image from 'next/image'; import Link from 'next/link'; import { getAuth } from '~/libs/auth'; import { X } from 'lucide-react'; +import useDevice from '@/core/hooks/useDevice'; const PagePopupInformation = () => { const router = useRouter(); @@ -19,6 +20,7 @@ const PagePopupInformation = () => { const dragStartPos = useRef({ x: 0, y: 0 }); const isDragging = useRef(false); const isTouching = useRef(false); + const { isDesktop } = useDevice(); const [isSnapping, setIsSnapping] = useState(false); // 🔥 Penanda kapan transisi diaktifkan @@ -80,8 +82,9 @@ const PagePopupInformation = () => { const popupHeight = popupRef.current?.offsetHeight || 0; const maxX = window.innerWidth - popupWidth - 20; const maxY = window.innerHeight - popupHeight - 20; + const minX = -containerLeft; - newX = Math.max(0, Math.min(newX, maxX)); + newX = Math.max(minX, Math.min(newX, maxX)); newY = Math.max(0, Math.min(newY, maxY)); setPosition({ x: newX, y: newY }); @@ -137,8 +140,9 @@ const PagePopupInformation = () => { const popupHeight = popupRef.current?.offsetHeight || 0; const maxX = window.innerWidth - popupWidth - 20; const maxY = window.innerHeight - popupHeight - 20; + const minX = -containerLeft; - newX = Math.max(0, Math.min(newX, maxX)); + newX = Math.max(minX, Math.min(newX, maxX)); newY = Math.max(0, Math.min(newY, maxY)); setPosition({ x: newX, y: newY }); @@ -179,61 +183,111 @@ const PagePopupInformation = () => { const banner = data[0]; - return ( -
+ if (isDesktop) { + // ✅ RENDER UNTUK DESKTOP + return (
-
-
+ { + if (isDragging.current) { + e.preventDefault(); + isDragging.current = false; + } else { + setActive(false); + } + }} + draggable="false" > - { - if (isDragging.current) { - e.preventDefault(); - isDragging.current = false; - } else { - setActive(false); - } - }} + {banner.name - {banner.name - -
+ /> +
+ ); + } + + // ✅ RENDER UNTUK MOBILE + return ( +
+
+ { + if (isDragging.current) { + e.preventDefault(); + isDragging.current = false; + } else { + setActive(false); + } + }} + draggable="false" + > + {banner.name + + + +
); + }; export default PagePopupInformation; -- cgit v1.2.3