Skip to main content

Toast

The Toast component is a non-disruptive message that appears temporarily to provide feedback or information to users. Your app should be wrapped with the ToastsProvider component to use the toast in order to use the useToasts hook.

Basic Usage

import {
ToastsProvider,
useToasts,
ThemeProvider,
} from "@carton-org/react-neumorphism";
import { useColorMode } from "@docusaurus/theme-common";

// Create a separate component that uses the toast
const ToastDemo = () => {
const { createToast } = useToasts();
const { colorMode } = useColorMode();

return (
<Button
onClick={() => {
createToast(
{
type: "info",
title: "Hello",
description: "This is a toast message",
},
{
duration: 3000,
position: "bottom-right",
size: "md",
isClosable: true,
bordered: false,
}
);
}}
>
Show Toast
</Button>
);
};

Live Example

Props

Toast Object

NameTypeDescriptionRequiredDefault Value
type"info" | "success" | "warning" | "error"Type of toast messageNo"info"
titlestringTitle of the toastNo-
descriptionstringDescription of the toast messageNo-

ToastConfig Object

NameTypeDescriptionRequiredDefault Value
durationnumberDuration in milliseconds before auto-closingNo3000
position"bottom-right" | "bottom-left" | "bottom-center" | "top-right" | "top-left" | "top-center"Position of the toast on screenNo"bottom-right"
size"xs" | "sm" | "md" | "lg" | "xl"Size of the toastNo"md"
isClosablebooleanWhether the toast can be manually closedNofalse
borderedbooleanWhether the toast has a borderNofalse

Examples

Different Positions

Different Sizes

Bordered Toasts