1- import React , { useEffect } from "react" ;
1+ import React from "react" ;
22import { createPortal } from "react-dom" ;
33
44import { useModal } from "@/shared/components/Modal/useModal" ;
5- import { useInitialStyle } from "@/shared/hooks" ;
5+ import { useOnMountAnimation } from "@/shared/hooks/useOnMountAnimation " ;
66import { cn } from "@/shared/lib" ;
77
88export interface ModalProps {
@@ -33,18 +33,18 @@ const Wrapper = ({ children }: { children?: React.ReactNode }) => {
3333const Overlay = ( ) => {
3434 const { closeModal } = useModal ( ) ;
3535
36- const { ref } = useInitialStyle < HTMLDivElement > ( {
37- opacity : "0" ,
38- transition : "all 200ms ease-in-out" ,
36+ const { ref } = useOnMountAnimation < HTMLDivElement > ( {
37+ initialStyles : {
38+ opacity : "0" ,
39+ } ,
40+ animationStyles : {
41+ opacity : "1" ,
42+ } ,
43+ duration : 200 ,
44+ delay : 0 ,
45+ timingFunction : "ease-in-out" ,
3946 } ) ;
4047
41- useEffect ( ( ) => {
42- const element = ref . current ;
43- if ( ! element ) return ;
44-
45- element . style . opacity = "1" ;
46- } , [ ref ] ) ;
47-
4848 return (
4949 < div
5050 ref = { ref }
@@ -55,27 +55,21 @@ const Overlay = () => {
5555} ;
5656
5757const Container = ( { children } : { children ?: React . ReactNode } ) => {
58- const { isOpen } = useModal ( ) ;
59-
60- const { ref } = useInitialStyle < HTMLDivElement > ( {
61- opacity : "0" ,
62- transform : "scale(0.7)" ,
63- } ) ;
64-
6558 const { closeModal } = useModal ( ) ;
6659
67- useEffect ( ( ) => {
68- const element = ref . current ;
69- if ( ! element ) return ;
70-
71- if ( isOpen ) {
72- element . style . opacity = "1" ;
73- element . style . transform = "scale(1)" ;
74- } else {
75- element . style . opacity = "0" ;
76- element . style . transform = "scale(0.7)" ;
77- }
78- } , [ isOpen , ref ] ) ;
60+ const { ref } = useOnMountAnimation < HTMLDivElement > ( {
61+ initialStyles : {
62+ opacity : "0" ,
63+ transform : "scale(0.7)" ,
64+ } ,
65+ animationStyles : {
66+ opacity : "1" ,
67+ transform : "scale(1)" ,
68+ } ,
69+ duration : 200 ,
70+ delay : 0 ,
71+ timingFunction : "ease-in-out" ,
72+ } ) ;
7973
8074 return (
8175 < div
0 commit comments