Skip to content

fix: improve clipboard success animation in code blocks (#7946) #7950

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/site/components/Common/CodeBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const CodeBox: FC<PropsWithChildren<CodeBoxProps>> = props => {
copyToClipboard(text);

notify({
duration: 300,
duration: 800,
message: (
<div className="flex items-center gap-3">
<CodeBracketIcon className={styles.icon} />
Expand Down
30 changes: 23 additions & 7 deletions apps/site/providers/notificationProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,39 @@ export const NotificationProvider: FC<PropsWithChildren<NotificationProps>> = ({
children,
}) => {
const [notification, dispatch] = useState<NotificationContextType>(null);
const [isOpen, setIsOpen] = useState(false);

useEffect(() => {
const timeout = setTimeout(() => dispatch(null), notification?.duration);

return () => clearTimeout(timeout);
if (notification) {
setIsOpen(true);
const timeout = setTimeout(() => {
setIsOpen(false);
}, notification.duration);
return () => clearTimeout(timeout);
}
}, [notification]);

const handleOpenChange = (open: boolean) => {
setIsOpen(open);
if (!open) {
setTimeout(() => {
dispatch(null);
}, 200); // Match your exit animation duration
}
};

return (
<NotificationContext.Provider value={notification}>
<NotificationDispatch.Provider value={dispatch}>
<Toast.Provider>
<Toast.Provider swipeDirection="right">
{children}

<Toast.Viewport className={viewportClassName} />

{notification && (
<Notification duration={notification.duration}>
<Notification
open={isOpen}
duration={notification.duration}
onChange={handleOpenChange}
>
{notification.message}
</Notification>
)}
Expand Down
56 changes: 56 additions & 0 deletions packages/ui-components/Common/Notification/index.module.css
Copy link
Member

@avivkeller avivkeller Jul 4, 2025

Choose a reason for hiding this comment

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

Does setting the swipeDirection not do all of this for you?

Copy link
Author

Choose a reason for hiding this comment

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

swapDirection only indicates the direction of the animation. It only takes effect once the appropriate animation classes are added in the CSS module.

Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure about animation is required or not. But this implementation follows radix docs.
LGTM!

Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,64 @@
dark:bg-neutral-900;
}

.root[data-state='open'] {
animation: slide-in 300ms cubic-bezier(0.16, 1, 0.3, 1);
}

.root[data-state='closed'] {
animation: slide-out 200ms ease-in forwards;
}

.root[data-swipe='move'] {
transform: translateX(var(--radix-toast-swipe-move-x));
}

.root[data-swipe='cancel'] {
transform: translateX(0);
transition: transform 200ms ease-out;
}

.root[data-swipe='end'] {
animation: swipe-out 150ms ease-out forwards;
}
Comment on lines 15 to +35
Copy link
Member

Choose a reason for hiding this comment

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

A) I'm not sure how I feel about the added complexity of a swipe
B) use tailwinds @apply


.message {
@apply font-medium
text-green-600
dark:text-white;
}

@keyframes slide-in {
from {
opacity: 0;
transform: translateX(calc(100% + 24px));
}

to {
opacity: 1;
transform: translateX(0);
}
}

@keyframes slide-out {
from {
opacity: 1;
transform: translateX(0);
}

to {
opacity: 0;
transform: translateX(calc(100% + 24px));
}
}

@keyframes swipe-out {
from {
transform: translateX(var(--radix-toast-swipe-end-x));
}

to {
opacity: 0;
transform: translateX(calc(100% + 24px));
}
}