Skip to content

Commit

Permalink
feat(web): Add animation to dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
thien-do committed Sep 5, 2022
1 parent 08dfd81 commit 91de46d
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 20 deletions.
35 changes: 29 additions & 6 deletions src/web/animation/animation.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,46 @@
}

/* prettier-ignore */
@keyframes in {
@keyframes flip-in {
from { opacity: 0; transform: rotateX(-10deg); }
to { opacity: 1; transform: rotateX(0deg); }
}

/* prettier-ignore */
@keyframes out {
@keyframes flip-out {
from { opacity: 1; transform: rotateX(0deg); }
to { opacity: 0; transform: rotateX(-10deg); }
}

.flip[data-state="open"] {
animation-name: in;
animation-duration: 200ms;
animation-name: flip-in;
animation-duration: 0.2s;
}

.flip[data-state="closed"] {
animation-name: out;
animation-duration: 600ms;
animation-name: flip-out;
animation-duration: 0.6s;
}

/* Fade */

.fade {
will-change: opacity;
animation-timing-function: var(--ease);
}

/* prettier-ignore */
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* prettier-ignore */
@keyframes fade-out { from { opacity: 1; } to { opacity: 0; } }

.fade[data-state="open"] {
animation-name: fade-in;
animation-duration: 0.4s;
}

.fade[data-state="closed"] {
animation-name: fade-out;
animation-duration: 0.8s;
}
1 change: 1 addition & 0 deletions src/web/animation/animation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ import * as s from "./animation.module.css";

export const animation = {
flip: s.flip,
fade: s.fade,
};
17 changes: 11 additions & 6 deletions src/web/prompt/dialog.module.css
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
.overlay {
background-color: var(--color-base);
background-color: rgba(var(--color-base-rgb), 0.8);
position: fixed;
inset: 0;
opacity: 0.8;
}

.content {
.container {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
inset: 0;

display: flex;
align-items: center;
justify-content: center;

perspective: 100vh;
}

.content {
padding: 18px;
display: flex;
flex-direction: column;
Expand Down
24 changes: 16 additions & 8 deletions src/web/prompt/dialog.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as Radix from "@radix-ui/react-alert-dialog";
import { ReactNode } from "react";
import { animation } from "../animation/animation";
import { Card } from "../card/card";
import * as s from "./dialog.module.css";

Expand All @@ -15,14 +16,21 @@ const Content = (props: Props): JSX.Element => {
const { title, description, buttons } = props;
return (
<Radix.Portal>
<Radix.Overlay className={s.overlay} />
<Radix.Content className={[s.content, Card.glass].join(" ")}>
<Radix.Title className={s.title}>{title}</Radix.Title>
<Radix.Description className={s.description}>
{description}
</Radix.Description>
<div className={s.footer}>{buttons}</div>
</Radix.Content>
<Radix.Overlay
className={[s.overlay, animation.fade].join(" ")}
></Radix.Overlay>
{/* Container to apply transform animation to Content */}
<div className={s.container}>
<Radix.Content
className={[s.content, Card.glass, animation.flip].join(" ")}
>
<Radix.Title className={s.title}>{title}</Radix.Title>
<Radix.Description className={s.description}>
{description}
</Radix.Description>
<div className={s.footer}>{buttons}</div>
</Radix.Content>
</div>
</Radix.Portal>
);
};
Expand Down

1 comment on commit 91de46d

@vercel
Copy link

@vercel vercel bot commented on 91de46d Sep 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.