mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-06 22:36:29 +00:00
initial commit for new hats app
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
'use client'
|
||||
|
||||
import React, { ReactNode, useCallback, useEffect, useRef, useState } from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
|
||||
type Props = {
|
||||
children: ReactNode
|
||||
className?: string
|
||||
};
|
||||
|
||||
const InterceptModal: React.FC<Props> = ({ children, className }) => {
|
||||
const [isMounted, setIsMounted] = useState(false)
|
||||
|
||||
const overlay = useRef<any>(null);
|
||||
const wrapper = useRef<any>(null);
|
||||
const router = useRouter();
|
||||
|
||||
useEffect(() => {
|
||||
setIsMounted(true)
|
||||
|
||||
return () => {
|
||||
setIsMounted(false)
|
||||
}
|
||||
}, [])
|
||||
|
||||
const onDismiss = useCallback(() => {
|
||||
router.back();
|
||||
}, [router]);
|
||||
|
||||
const onClick = useCallback((e: any) => {
|
||||
// if (e.target === overlay.current || e.target === wrapper.current) {
|
||||
// if (onDismiss) onDismiss();
|
||||
// }
|
||||
onDismiss()
|
||||
}, [onDismiss, overlay, wrapper]);
|
||||
|
||||
const onKeyDown = useCallback((e: any) => {
|
||||
if (e.key === "Escape") onDismiss();
|
||||
}, [onDismiss]);
|
||||
|
||||
useEffect(() => {
|
||||
document.addEventListener("keydown", onKeyDown);
|
||||
return () => document.removeEventListener("keydown", onKeyDown);
|
||||
}, [onKeyDown]);
|
||||
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className={`${isMounted ? 'open' : 'close'} custom-modal-background`} style={{ backdropFilter: 'blur(2px)' }} onClick={onClick}>
|
||||
<div className={`${isMounted ? 'open' : 'close'} custom-modal border border-zinc-200 bg-soft dark:border-zinc-800 dark:bg-zinc-950 w-full lg:w-[98vw] 2xl:w-[1400px] mx-auto ${className}`} style={{ translate: '-50% -50%' }} onClick={(e) => e.stopPropagation()}>
|
||||
<div className="w-full overflow-y-auto p-6 relative" style={{ maxHeight: '90vh' }}>
|
||||
{children}
|
||||
<i className="ti ti-x absolute top-4 right-4 cursor-pointer text-4xl text-muted-foreground hover:opacity-70 duration-300" onClick={onClick}></i>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default InterceptModal;
|
||||
Reference in New Issue
Block a user