-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: react-hot-toasts 🍞 * fix: remove imports * feat: add close icon for toats which are not immediately closed
- Loading branch information
Showing
65 changed files
with
170 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Toaster as HotToaster } from "react-hot-toast"; | ||
|
||
export default function Toaster() { | ||
return ( | ||
<HotToaster | ||
position="bottom-center" | ||
toastOptions={{ | ||
duration: 4_000, | ||
}} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { CrossIcon } from "@bitcoin-design/bitcoin-icons-react/outline"; | ||
import { Transition } from "@headlessui/react"; | ||
import { ReactNode } from "react"; | ||
import { | ||
CheckmarkIcon, | ||
ErrorIcon, | ||
ToastOptions, | ||
toast as hotToast, | ||
} from "react-hot-toast"; | ||
|
||
type ToastType = "error" | "success"; | ||
|
||
interface ToastMethods { | ||
success: (message: string | ReactNode, options?: ToastOptions) => void; | ||
error: (message: string | ReactNode, options?: ToastOptions) => void; | ||
custom: ( | ||
children: ReactNode, | ||
type: ToastType, | ||
options?: ToastOptions | ||
) => void; | ||
} | ||
|
||
const toast: ToastMethods = { | ||
success: (message: string | ReactNode, options?: ToastOptions) => { | ||
toast.custom(message, "success", options); | ||
}, | ||
error: (message: string | ReactNode, options?: ToastOptions) => { | ||
toast.custom(message, "error", { duration: options?.duration ?? 8_000 }); | ||
}, | ||
custom: (children: ReactNode, type: ToastType, options?: ToastOptions) => { | ||
hotToast.custom( | ||
(t: { visible: boolean; id: string }) => ( | ||
<Transition | ||
enter="transform transition duration-[400ms]" | ||
enterFrom="opacity-0 scale-0" | ||
enterTo="opacity-100 scale-1" | ||
leave="transform duration-200 transition ease-in-out" | ||
leaveFrom="opacity-100 scale-1" | ||
leaveTo="opacity-0 scale-0" | ||
show={t.visible} | ||
> | ||
<div className="bg-white dark:bg-surface-02dp px-4 py-3 drop-shadow-lg rounded-lg overflow-hidden flex flex-row items-center gap-3 text-gray-800 dark:text-neutral-200"> | ||
<div className="shrink-0"> | ||
{type == "success" && <CheckmarkIcon />} | ||
{type == "error" && <ErrorIcon />} | ||
</div> | ||
<div>{children}</div> | ||
{/* Add close icons for toasts that are displayed for a longer time */} | ||
{options?.duration && options?.duration > 10_000 && ( | ||
<CrossIcon | ||
className="w-4 h-4 cursor-pointer" | ||
onClick={() => hotToast.dismiss(t.id)} | ||
/> | ||
)} | ||
</div> | ||
</Transition> | ||
), | ||
options | ||
); | ||
}, | ||
}; | ||
|
||
export default toast; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.