From 670fd38c352ac30f4b923e33df8c0613562ec3ef Mon Sep 17 00:00:00 2001 From: Arnaud Date: Tue, 8 Oct 2024 13:03:01 +0200 Subject: [PATCH] Add effect to modal component --- src/components/Backdrop/backdrop.css | 9 ++++++++- src/components/Modal/Modal.tsx | 25 +++++++++++++++++++++---- src/components/Modal/modal.css | 12 +++++++----- 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/src/components/Backdrop/backdrop.css b/src/components/Backdrop/backdrop.css index 90cf8bf..3c73896 100644 --- a/src/components/Backdrop/backdrop.css +++ b/src/components/Backdrop/backdrop.css @@ -1,4 +1,6 @@ -.backdrop[aria-expanded] { +.backdrop { + opacity: 0; + transition: opacity 0.25s; height: 100%; width: 100%; position: fixed; @@ -7,7 +9,12 @@ background: var(--codex-background-backdrop); backdrop-filter: blur(2px); display: block; + z-index: -1; +} + +.backdrop[aria-expanded] { z-index: 10; + opacity: 1; } .document-noOverflow { diff --git a/src/components/Modal/Modal.tsx b/src/components/Modal/Modal.tsx index 86ce49e..3d3a61b 100644 --- a/src/components/Modal/Modal.tsx +++ b/src/components/Modal/Modal.tsx @@ -1,4 +1,4 @@ -import { ReactNode } from "react"; +import { ReactNode, useEffect, useState } from "react"; import { Backdrop } from "../Backdrop/Backdrop"; import { Button } from "../Button/Button"; import { classnames } from "../utils/classnames"; @@ -67,11 +67,28 @@ export function Modal({ children, onAction, }: Props) { + const [internalOpen, setInternalOpen] = useState(open); + + useEffect(() => { + setInternalOpen(open); + }, [open]); + + const internalClose = () => { + setInternalOpen(false); + setTimeout(onClose, 250); + }; + return ( <> - + -
+
{open && children}
)} diff --git a/src/components/Modal/modal.css b/src/components/Modal/modal.css index fcafc51..76c5fc7 100644 --- a/src/components/Modal/modal.css +++ b/src/components/Modal/modal.css @@ -1,5 +1,7 @@ .modal { - transition: transform 0.15s; + transition: + transform 0.25s, + opacity 0.25s; max-width: 800px; overflow-y: auto; overflow-x: hidden; @@ -8,7 +10,7 @@ max-height: 100%; left: 50%; top: 50%; - transform: translate(-50%, -50%) scale(0); + transform: translateX(-50%); position: fixed; display: flex; flex-direction: column; @@ -17,12 +19,12 @@ border-radius: var(--codex-border-radius); } -.modal--open { - transform: translate(-50%, -50%) scale(1); +.modal--internalOpen { + transform: translate(-50%, -50%); + opacity: 1; } .modal--open { - opacity: 1; z-index: 10; }