Skip to content

Commit 53e23b0

Browse files
site: fix sudden success clipboard animation
1 parent b035290 commit 53e23b0

3 files changed

Lines changed: 80 additions & 7 deletions

File tree

apps/site/components/Common/CodeBox.tsx

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

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

packages/ui-components/src/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+
}

packages/ui-components/src/Providers/NotificationProvider/index.tsx

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,38 @@ export const useNotification = () => useContext(NotificationDispatch);
2727

2828
export const NotificationProvider: FC<PropsWithChildren> = ({ children }) => {
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
{notification && (
44-
<Notification duration={notification.duration}>
57+
<Notification
58+
open={isOpen}
59+
duration={notification.duration}
60+
onChange={handleOpenChange}
61+
>
4562
{notification.message}
4663
</Notification>
4764
)}

0 commit comments

Comments
 (0)