Skip to content

Commit

Permalink
Animate <Dialog> (#4)
Browse files Browse the repository at this point in the history
Co-authored-by: Antony1060 <[email protected]>
  • Loading branch information
Jontes-Tech and Antony1060 authored Nov 27, 2023
1 parent 48ce20d commit 5125b8e
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 5 deletions.
4 changes: 3 additions & 1 deletion web/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
"v3xlabs"
],
"env": {
"node": true
"node": true,
"browser": true
},
"rules": {}
}

1 change: 1 addition & 0 deletions web/src/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ const postUpdateProfile = async (
console.log({ response });
};

// eslint-disable-next-line sonarjs/cognitive-complexity
export const Profile: FC<{ name: string }> = ({ name }) => {
const { data } = useSWR(name, getProfile);
const { address } = useAccount();
Expand Down
50 changes: 46 additions & 4 deletions web/src/dialog/Dialog.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { clsx } from 'clsx';
import { FC, PropsWithChildren } from 'react';
import { FC, PropsWithChildren, useRef } from 'react';
import { FiX } from 'react-icons/fi';

const variants = {
Expand Down Expand Up @@ -32,13 +32,20 @@ export const Dialog: FC<
const vstyle = variants[variant];
const closestyle = close_styling[closeVariant];

const dialog = useRef(null);
const backdrop = useRef(null);

return (
// eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
<div tabIndex={-1} className="fixed z-50">
<div className="fixed z-0 inset-0 bg-ens-light-grey-active/20 dark:bg-ens-light-grey-active/20 backdrop-blur-md"></div>
<div
ref={backdrop}
className="fixed z-0 inset-0 bg-ens-light-grey-active/20 dark:bg-ens-light-grey-active/20 backdrop-blur-md animate-backdrop"
></div>
<div
ref={dialog}
className={clsx(
'fixed z-10 flex items-center justify-center max-w-full',
'fixed z-10 flex items-center justify-center max-w-full animate-dialog',
vstyle.outer
)}
>
Expand All @@ -49,7 +56,42 @@ export const Dialog: FC<
)}
>
<button
onClick={() => {
onClick={async () => {
const dialogElm: HTMLElement = dialog.current;
const backdropElm: HTMLElement = backdrop.current;

await Promise.all([
dialogElm.animate(
[
{
top: '0px',
opacity: 1,
},
{
top: '-100px',
opacity: 0,
},
],
{
duration: 200,
fill: 'forwards',
}
).finished,
backdropElm.animate(
[
{
opacity: 1,
},
{
opacity: 0,
},
],
{
duration: 200,
fill: 'forwards',
}
).finished,
]);
onClose();
}}
className={clsx('absolute', closestyle)}
Expand Down
33 changes: 33 additions & 0 deletions web/src/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,38 @@
@tailwind utilities;
@tailwind variants;

@keyframes slideFromTop {
from {
opacity: 0;
top: -100px;
}

to {
opacity: 1;
top: 0px;
}
}

.animate-dialog {
/* Nice cubic besier eased animation */
animation: slideFromTop 0.2s cubic-bezier(0.250, 0.460, 0.450, 0.940) both;
}

@keyframes backdropAnimation {
from {
opacity: 0;
}

to {
opacity: 1;
}
}

.animate-backdrop {
/* Nice cubic besier eased animation */
animation: backdropAnimation 0.2s cubic-bezier(0.250, 0.460, 0.450, 0.940) both;
}

.btn {
@apply rounded-xl;
}
Expand Down Expand Up @@ -38,3 +70,4 @@
.input {
@apply border bg-ens-light-background-primary dark:bg-ens-dark-background-primary border-ens-light-border dark:border-ens-dark-border pl-9 rounded-md py-2 w-full;
}

0 comments on commit 5125b8e

Please sign in to comment.