Skip to content

Commit

Permalink
refactor : ModalWrapper > PortalWrapper로 수정하여 범용적으로 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
guesung committed Aug 23, 2023
1 parent e2f448c commit 448c29b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/components/Modal/Modal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ModalWrapper from './ModalWrapper';
import ModalWrapper from './PortalWrapper';
import { StrictPropsWithChildren } from '@/types';

interface PopupProps {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,37 @@
'use client';
import clsx from 'clsx';
import { useRef } from 'react';

import { AnimatedPortal } from '../Portal';
import { useOnClickOutside } from '@/hooks/useOnClickOutside';

import type { StrictPropsWithChildren } from '@/types';

interface ModalWrapperProps {
interface PortalWrapperProps {
onClose?: () => void;
isBackGroundBlur?: boolean;
}

export default function ModalWrapper({
export default function PortalWrapper({
onClose = () => {},
children,
}: StrictPropsWithChildren<ModalWrapperProps>) {
const modalRef = useRef<HTMLDivElement>(null);
isBackGroundBlur = true,
}: StrictPropsWithChildren<PortalWrapperProps>) {
const portalRef = useRef<HTMLDivElement>(null);

useOnClickOutside(modalRef, onClose);
useOnClickOutside(portalRef, onClose);

return (
<AnimatedPortal
motionProps={{ initial: { opacity: 0 }, animate: { opacity: 1 }, exit: { opacity: 0 } }}
>
<div className="fixed left-1/2 top-0 z-10 h-full w-full max-w-440 -translate-x-1/2 bg-neutral-900 bg-opacity-90">
<div
className={clsx('fixed left-1/2 top-0 z-10 h-full w-full max-w-440 -translate-x-1/2', {
'bg-neutral-900 bg-opacity-90': isBackGroundBlur,
})}
>
<div
ref={modalRef}
ref={portalRef}
className="absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 "
>
{children}
Expand Down

0 comments on commit 448c29b

Please sign in to comment.