Skip to content

Commit

Permalink
feat: lift the toasts when hoevered for a better feel (#506)
Browse files Browse the repository at this point in the history
* fix

* lift the toast slightly

* cleanup
  • Loading branch information
emilkowalski authored Nov 3, 2024
1 parent 1849ab4 commit f245f4a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
list-style: none;
outline: none;
z-index: 999999999;
transition: transform 400ms ease;
}

:where([data-sonner-toaster]:hover) {
transform: translateY(-10px);
}

:where([data-sonner-toaster][data-x-position='right']) {
Expand Down
18 changes: 12 additions & 6 deletions website/src/components/Position/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { toast } from 'sonner';
import { toast, useSonner } from 'sonner';
import { CodeBlock } from '../CodeBlock';
import React from 'react';

Expand All @@ -13,6 +13,12 @@ export const Position = ({
position: Position;
setPosition: React.Dispatch<React.SetStateAction<Position>>;
}) => {
const { toasts } = useSonner();

function removeAllToasts() {
toasts.forEach((t) => toast.dismiss(t.id));
}

return (
<div>
<h2>Position</h2>
Expand All @@ -23,11 +29,11 @@ export const Position = ({
data-active={activePosition === position}
className="button"
onClick={() => {
const toastsAmount = document.querySelectorAll('[data-sonner-toast]').length;
setPosition(position);
// No need to show a toast when there is already one
if (toastsAmount > 0 && position !== activePosition) return;

if (activePosition !== position) {
setPosition(position);
removeAllToasts();
}
toast('Event has been created', {
description: 'Monday, January 3rd at 6:00pm',
});
Expand Down

0 comments on commit f245f4a

Please sign in to comment.