Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add exit animation to mobile dialog drawer #1108

Merged
merged 16 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions account-kit/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"@storybook/test-runner": "^0.13.0",
"@storybook/testing-library": "^0.2.2",
"@tanstack/react-query": "^5.28.9",
"@types/react-transition-group": "^4.4.11",
"autoprefixer": "^10.4.20",
"msw": "^2.4.4",
"msw-storybook-addon": "^2.0.3",
Expand All @@ -73,6 +74,7 @@
"@tanstack/zod-form-adapter": "^0.33.0",
"@wagmi/connectors": "^5.1.15",
"react-remove-scroll": "^2.5.10",
"react-transition-group": "^4.4.5",
iykazrji marked this conversation as resolved.
Show resolved Hide resolved
"tailwindcss": "^3.4.3",
"zod": "^3.22.4",
"zustand": "^5.0.0-rc.2"
Expand Down
55 changes: 32 additions & 23 deletions account-kit/react/src/components/dialog/dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useCallback, useEffect, useState, type ReactNode } from "react";
import { createPortal } from "react-dom";
import { RemoveScroll } from "react-remove-scroll";
import { FocusTrap } from "./focustrap.js";
import { Transition } from "react-transition-group";

type DialogProps = {
isOpen: boolean;
Expand Down Expand Up @@ -40,27 +41,35 @@ export const Dialog = ({ isOpen, onClose, children }: DialogProps) => {
setScrollLocked(getComputedStyle(document.body).overflow !== "hidden");
}, []);

return isOpen
? createPortal(
<RemoveScroll enabled={isScrollLocked}>
{/* Overlay */}
<div
aria-modal
role="dialog"
className="fixed inset-0 bg-black/80 flex items-end md:items-center justify-center z-[999999] animate-fade-in"
onClick={handleBackgroundClick}
>
<FocusTrap>
<div
className="animate-fade-in animate-slide-up max-md:w-screen md:max-w-sm"
onClick={(event) => event.stopPropagation()}
>
{children}
</div>
</FocusTrap>
</div>
</RemoveScroll>,
document.body
)
: null;
return createPortal(
<RemoveScroll enabled={isScrollLocked}>
{/* Overlay */}
<Transition in={isOpen} timeout={150} mountOnEnter unmountOnExit>
{(state) => {
return (
<div
aria-modal
role="dialog"
className={`fixed inset-0 bg-black/80 flex items-end md:items-center justify-center z-[999999] ${
state === "exited" && "hidden"
} ${state === "entered" && "block"}`}
onClick={handleBackgroundClick}
>
<FocusTrap>
<div
className={`max-md:w-screen md:max-w-sm block ${
state === "entering" && "animate-slide-up"
} ${state === "exiting" && "animate-slide-down"}`}
onClick={(event) => event.stopPropagation()}
>
{children}
</div>
</FocusTrap>
</div>
);
}}
</Transition>
</RemoveScroll>,
document.body
);
};
10 changes: 10 additions & 0 deletions account-kit/react/src/tailwind/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,20 @@ export const accountKitUi: (
"0%": { transform: "translateY(100%)", opacity: "0" },
"100%": { transform: "translateY(0%)", opacity: "1" },
},
"fade-out": {
"0%": { opacity: "1" },
"100%": { opacity: "0" },
},
"slide-down": {
"0%": { transform: "translateY(0%)", opacity: "1" },
"100%": { transform: "translateY(100%)", opacity: "0" },
},
},
animation: {
"fade-in": "fade-in 150ms ease",
"slide-up": "slide-up 350ms cubic-bezier(.15,1.15,0.6,1.00)",
"fade-out": "fade-out 150ms ease",
"slide-down": "slide-down 350ms cubic-bezier(.15,1.15,0.6,1.00)",
},
},
},
Expand Down
34 changes: 33 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1810,6 +1810,13 @@
dependencies:
regenerator-runtime "^0.14.0"

"@babel/runtime@^7.5.5", "@babel/runtime@^7.8.7":
version "7.26.0"
resolved "https://registry.npmjs.org/@babel/runtime/-/runtime-7.26.0.tgz#8600c2f595f277c60815256418b85356a65173c1"
integrity sha512-FDSOghenHTiToteC/QRlv2q3DhPZ/oOXTBoirfWNx1Cx3TMVcGWQtMMmQcSvb/JjpNeGzx8Pq/b4fKEJuWm1sw==
dependencies:
regenerator-runtime "^0.14.0"

"@babel/template@^7.22.15", "@babel/template@^7.22.5", "@babel/template@^7.24.0", "@babel/template@^7.24.7", "@babel/template@^7.25.0", "@babel/template@^7.25.7", "@babel/template@^7.3.3":
version "7.25.7"
resolved "https://registry.npmjs.org/@babel/template/-/template-7.25.7.tgz"
Expand Down Expand Up @@ -7094,6 +7101,13 @@
dependencies:
"@types/react" "*"

"@types/react-transition-group@^4.4.11":
version "4.4.11"
resolved "https://registry.npmjs.org/@types/react-transition-group/-/react-transition-group-4.4.11.tgz#d963253a611d757de01ebb241143b1017d5d63d5"
integrity sha512-RM05tAniPZ5DZPzzNFP+DmrcOdD0efDUxMy3145oljWSl3x9ZV5vhme98gTxFrj2lhXvmGNnUiuDyJgY9IKkNA==
dependencies:
"@types/react" "*"

"@types/react@*", "@types/react@^16.8.0 || ^17.0.0 || ^18.0.0", "@types/react@^18":
version "18.2.43"
resolved "https://registry.npmjs.org/@types/react/-/react-18.2.43.tgz"
Expand Down Expand Up @@ -10793,6 +10807,14 @@ dom-accessibility-api@^0.6.3:
resolved "https://registry.npmjs.org/dom-accessibility-api/-/dom-accessibility-api-0.6.3.tgz"
integrity sha512-7ZgogeTnjuHbo+ct10G9Ffp0mif17idi0IyWNVA/wcwcm7NPOD/WEHVP3n7n3MhXqxoIYm8d6MuZohYWIZ4T3w==

dom-helpers@^5.0.1:
version "5.2.1"
resolved "https://registry.npmjs.org/dom-helpers/-/dom-helpers-5.2.1.tgz#d9400536b2bf8225ad98fe052e029451ac40e902"
integrity sha512-nRCa7CK3VTrM2NmGkIy4cbK7IZlgBE/PYMn55rrXefr5xXDP0LdtfPnblFDoVdcAfslJ7or6iqAUnx0CCGIWQA==
dependencies:
"@babel/runtime" "^7.8.7"
csstype "^3.0.2"

dom-serializer@0:
version "0.2.2"
resolved "https://registry.npmjs.org/dom-serializer/-/dom-serializer-0.2.2.tgz"
Expand Down Expand Up @@ -18781,7 +18803,7 @@ prool@^0.0.15:
http-proxy "^1.18.1"
tar "7.2.0"

prop-types@^15.7.2, prop-types@^15.8.1:
prop-types@^15.6.2, prop-types@^15.7.2, prop-types@^15.8.1:
version "15.8.1"
resolved "https://registry.npmjs.org/prop-types/-/prop-types-15.8.1.tgz"
integrity sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg==
Expand Down Expand Up @@ -19142,6 +19164,16 @@ react-syntax-highlighter@^15.5.0:
prismjs "^1.27.0"
refractor "^3.6.0"

react-transition-group@^4.4.5:
version "4.4.5"
resolved "https://registry.npmjs.org/react-transition-group/-/react-transition-group-4.4.5.tgz#e53d4e3f3344da8521489fbef8f2581d42becdd1"
integrity sha512-pZcd1MCJoiKiBR2NRxeCRg13uCXbydPnmB4EOeRrY7480qNWO8IIgQG6zlDkm6uRMsURXPuKq0GWtiM59a5Q6g==
dependencies:
"@babel/runtime" "^7.5.5"
dom-helpers "^5.0.1"
loose-envify "^1.4.0"
prop-types "^15.6.2"

"react@^16.8.0 || ^17.0.0 || ^18.0.0", react@^18, react@^18.2.0:
version "18.2.0"
resolved "https://registry.npmjs.org/react/-/react-18.2.0.tgz"
Expand Down
Loading