ig.rizaldy.club/components/Overlay.js

57 lines
1.4 KiB
JavaScript
Raw Normal View History

2024-01-31 00:49:51 +07:00
import { MEDIA_TYPE } from "../constants";
const OverlayContent = ({ overlayContent }) => {
if (overlayContent?.type === MEDIA_TYPE.PHOTOS) {
return (
<img
alt={overlayContent?.url}
src={overlayContent?.url}
className="z-20 cursor-default"
/>
);
} else if (overlayContent?.type === MEDIA_TYPE.VIDEOS) {
return (
<iframe
2024-01-31 02:44:12 +07:00
className="md:w-6/12 w-full h-1/2"
2024-01-31 00:49:51 +07:00
allow="fullscreen"
sandbox="allow-same-origin allow-scripts allow-popups"
src={overlayContent?.url}
></iframe>
);
}
};
const Overlay = ({ overlayContent, closeOverlay }) => {
const isOverlayOpen = overlayContent?.type !== undefined;
return (
<div
onClick={closeOverlay}
className={`${
isOverlayOpen
2024-01-31 02:44:12 +07:00
? "bg-neutral-800/95 fixed w-full h-full left-0 top-0 cursor-pointer"
2024-01-31 00:49:51 +07:00
: ""
}`}
>
{isOverlayOpen ? (
<p
onClick={closeOverlay}
2024-02-01 00:45:24 +07:00
className="fixed right-0 bottom-0 md:mx-5 my-5 text-white rounded text-sm text-center w-full z-30"
2024-01-31 00:49:51 +07:00
>
Click anywhere or press "Escape" to close
</p>
) : null}
<div
className={`flex justify-center items-center ${
2024-01-31 02:44:12 +07:00
isOverlayOpen ? "h-full w-full" : "h-0 w-0"
2024-01-31 00:49:51 +07:00
}`}
>
<OverlayContent overlayContent={overlayContent} />
</div>
</div>
);
};
export default Overlay;