Skip to content

Commit 8f59ef6

Browse files
site: fix sudden success clipboard animation
1 parent 4ebead0 commit 8f59ef6

File tree

3 files changed

+80
-8
lines changed

3 files changed

+80
-8
lines changed

apps/site/components/Common/CodeBox.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const CodeBox: FC<PropsWithChildren<CodeBoxProps>> = props => {
2424
copyToClipboard(text);
2525

2626
notify({
27-
duration: 300,
27+
duration: 800,
2828
message: (
2929
<div className="flex items-center gap-3">
3030
<CodeBracketIcon className={styles.icon} />

apps/site/providers/notificationProvider.tsx

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,39 @@ export const NotificationProvider: FC<PropsWithChildren<NotificationProps>> = ({
2727
children,
2828
}) => {
2929
const [notification, dispatch] = useState<NotificationContextType>(null);
30+
const [isOpen, setIsOpen] = useState(false);
3031

3132
useEffect(() => {
32-
const timeout = setTimeout(() => dispatch(null), notification?.duration);
33-
34-
return () => clearTimeout(timeout);
33+
if (notification) {
34+
setIsOpen(true);
35+
const timeout = setTimeout(() => {
36+
setIsOpen(false);
37+
}, notification.duration);
38+
return () => clearTimeout(timeout);
39+
}
3540
}, [notification]);
3641

42+
const handleOpenChange = (open: boolean) => {
43+
setIsOpen(open);
44+
if (!open) {
45+
setTimeout(() => {
46+
dispatch(null);
47+
}, 200); // Match your exit animation duration
48+
}
49+
};
50+
3751
return (
3852
<NotificationContext.Provider value={notification}>
3953
<NotificationDispatch.Provider value={dispatch}>
40-
<Toast.Provider>
54+
<Toast.Provider swipeDirection="right">
4155
{children}
42-
4356
<Toast.Viewport className={viewportClassName} />
44-
4557
{notification && (
46-
<Notification duration={notification.duration}>
58+
<Notification
59+
open={isOpen}
60+
duration={notification.duration}
61+
onChange={handleOpenChange}
62+
>
4763
{notification.message}
4864
</Notification>
4965
)}

packages/ui-components/Common/Notification/index.module.css

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,64 @@
1313
dark:bg-neutral-900;
1414
}
1515

16+
.root[data-state='open'] {
17+
animation: slide-in 300ms cubic-bezier(0.16, 1, 0.3, 1);
18+
}
19+
20+
.root[data-state='closed'] {
21+
animation: slide-out 200ms ease-in forwards;
22+
}
23+
24+
.root[data-swipe='move'] {
25+
transform: translateX(var(--radix-toast-swipe-move-x));
26+
}
27+
28+
.root[data-swipe='cancel'] {
29+
transform: translateX(0);
30+
transition: transform 200ms ease-out;
31+
}
32+
33+
.root[data-swipe='end'] {
34+
animation: swipe-out 150ms ease-out forwards;
35+
}
36+
1637
.message {
1738
@apply font-medium
1839
text-green-600
1940
dark:text-white;
2041
}
42+
43+
@keyframes slide-in {
44+
from {
45+
opacity: 0;
46+
transform: translateX(calc(100% + 24px));
47+
}
48+
49+
to {
50+
opacity: 1;
51+
transform: translateX(0);
52+
}
53+
}
54+
55+
@keyframes slide-out {
56+
from {
57+
opacity: 1;
58+
transform: translateX(0);
59+
}
60+
61+
to {
62+
opacity: 0;
63+
transform: translateX(calc(100% + 24px));
64+
}
65+
}
66+
67+
@keyframes swipe-out {
68+
from {
69+
transform: translateX(var(--radix-toast-swipe-end-x));
70+
}
71+
72+
to {
73+
opacity: 0;
74+
transform: translateX(calc(100% + 24px));
75+
}
76+
}

0 commit comments

Comments
 (0)