Skip to content

Commit 91de46d

Browse files
committed
feat(web): Add animation to dialog
1 parent 08dfd81 commit 91de46d

File tree

4 files changed

+57
-20
lines changed

4 files changed

+57
-20
lines changed

src/web/animation/animation.module.css

+29-6
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,46 @@
55
}
66

77
/* prettier-ignore */
8-
@keyframes in {
8+
@keyframes flip-in {
99
from { opacity: 0; transform: rotateX(-10deg); }
1010
to { opacity: 1; transform: rotateX(0deg); }
1111
}
1212

1313
/* prettier-ignore */
14-
@keyframes out {
14+
@keyframes flip-out {
1515
from { opacity: 1; transform: rotateX(0deg); }
1616
to { opacity: 0; transform: rotateX(-10deg); }
1717
}
1818

1919
.flip[data-state="open"] {
20-
animation-name: in;
21-
animation-duration: 200ms;
20+
animation-name: flip-in;
21+
animation-duration: 0.2s;
2222
}
2323

2424
.flip[data-state="closed"] {
25-
animation-name: out;
26-
animation-duration: 600ms;
25+
animation-name: flip-out;
26+
animation-duration: 0.6s;
27+
}
28+
29+
/* Fade */
30+
31+
.fade {
32+
will-change: opacity;
33+
animation-timing-function: var(--ease);
34+
}
35+
36+
/* prettier-ignore */
37+
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
38+
39+
/* prettier-ignore */
40+
@keyframes fade-out { from { opacity: 1; } to { opacity: 0; } }
41+
42+
.fade[data-state="open"] {
43+
animation-name: fade-in;
44+
animation-duration: 0.4s;
45+
}
46+
47+
.fade[data-state="closed"] {
48+
animation-name: fade-out;
49+
animation-duration: 0.8s;
2750
}

src/web/animation/animation.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ import * as s from "./animation.module.css";
22

33
export const animation = {
44
flip: s.flip,
5+
fade: s.fade,
56
};

src/web/prompt/dialog.module.css

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
.overlay {
2-
background-color: var(--color-base);
2+
background-color: rgba(var(--color-base-rgb), 0.8);
33
position: fixed;
44
inset: 0;
5-
opacity: 0.8;
65
}
76

8-
.content {
7+
.container {
98
position: fixed;
10-
top: 50%;
11-
left: 50%;
12-
transform: translate(-50%, -50%);
9+
inset: 0;
10+
11+
display: flex;
12+
align-items: center;
13+
justify-content: center;
14+
15+
perspective: 100vh;
16+
}
1317

18+
.content {
1419
padding: 18px;
1520
display: flex;
1621
flex-direction: column;

src/web/prompt/dialog.tsx

+16-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as Radix from "@radix-ui/react-alert-dialog";
22
import { ReactNode } from "react";
3+
import { animation } from "../animation/animation";
34
import { Card } from "../card/card";
45
import * as s from "./dialog.module.css";
56

@@ -15,14 +16,21 @@ const Content = (props: Props): JSX.Element => {
1516
const { title, description, buttons } = props;
1617
return (
1718
<Radix.Portal>
18-
<Radix.Overlay className={s.overlay} />
19-
<Radix.Content className={[s.content, Card.glass].join(" ")}>
20-
<Radix.Title className={s.title}>{title}</Radix.Title>
21-
<Radix.Description className={s.description}>
22-
{description}
23-
</Radix.Description>
24-
<div className={s.footer}>{buttons}</div>
25-
</Radix.Content>
19+
<Radix.Overlay
20+
className={[s.overlay, animation.fade].join(" ")}
21+
></Radix.Overlay>
22+
{/* Container to apply transform animation to Content */}
23+
<div className={s.container}>
24+
<Radix.Content
25+
className={[s.content, Card.glass, animation.flip].join(" ")}
26+
>
27+
<Radix.Title className={s.title}>{title}</Radix.Title>
28+
<Radix.Description className={s.description}>
29+
{description}
30+
</Radix.Description>
31+
<div className={s.footer}>{buttons}</div>
32+
</Radix.Content>
33+
</div>
2634
</Radix.Portal>
2735
);
2836
};

0 commit comments

Comments
 (0)