Docs
Toast
Toast
A succinct message that is displayed temporarily.
import { toaster } from "@kobalte/core";
import { Button } from "@repo/tailwindcss/default/button";
import {
Toast,
ToastContent,
ToastDescription,
ToastProgress,
ToastTitle,
} from "@repo/tailwindcss/default/toast";
const ToastDemo = () => {
const showToast = () => {
toaster.show((props) => (
<Toast toastId={props.toastId}>
<ToastContent>
<ToastTitle>Scheduled: Catch up</ToastTitle>
<ToastDescription>
Friday, February 10, 2023 at 5:57 PM
</ToastDescription>
</ToastContent>
<ToastProgress />
</Toast>
));
};
return (
<Button variant="outline" onClick={showToast}>
Add to calendar
</Button>
);
};
export default ToastDemo;
import { toaster } from "@kobalte/core";
import { Button } from "@repo/tailwindcss/solid/button";
import {
Toast,
ToastContent,
ToastDescription,
ToastProgress,
ToastTitle,
} from "@repo/tailwindcss/solid/toast";
const ToastDemo = () => {
const showToast = () => {
toaster.show((props) => (
<Toast toastId={props.toastId}>
<ToastContent>
<ToastTitle>Scheduled: Catch up</ToastTitle>
<ToastDescription>
Friday, February 10, 2023 at 5:57 PM
</ToastDescription>
</ToastContent>
<ToastProgress />
</Toast>
));
};
return (
<Button variant="outline" onClick={showToast}>
Add to calendar
</Button>
);
};
export default ToastDemo;
Installation
npx shadcn-solid@latest add toast
Install the following dependencies:
npm install @kobalte/core
Copy and paste the following code into your project:
Install the following dependencies:
npm install @kobalte/core
Copy and paste the following code into your project:
Usage
import { toaster } from "@kobalte/core";
import {
Toast,
ToastContent,
ToastProgress,
ToastTitle
} from "@/components/ui/toast";
toaster.show(props => (
<Toast toastId={props.toastId}>
<ToastContent>
<ToastTitle>Toast</ToastTitle>
</ToastContent>
<ToastProgress />
</Toast>
))
import { ToastRegion, ToastList } from "@/components/ui/toast"
const App = () => {
return (
<Router
root={props => (
<Suspense>
<ColorModeScript />
<ColorModeProvider>
{props.children}
<ToastRegion>
<ToastList />
</ToastRegion>
</ColorModeProvider>
</Suspense>
)}
>
<FileRoutes />
</Router>
);
};
export default App;
Examples
Destructive
import { toaster } from "@kobalte/core";
import { Button } from "@repo/tailwindcss/default/button";
import {
Toast,
ToastContent,
ToastDescription,
ToastProgress,
ToastTitle,
} from "@repo/tailwindcss/default/toast";
const ToastDestructive = () => {
const showToast = () =>
toaster.show((props) => (
<Toast toastId={props.toastId} variant="destructive">
<ToastContent>
<ToastTitle>Uh oh! Something went wrong.</ToastTitle>
<ToastDescription>
There was a problem with your request.
</ToastDescription>
</ToastContent>
<ToastProgress />
</Toast>
));
return (
<Button variant="outline" onClick={showToast}>
Add to calendar
</Button>
);
};
export default ToastDestructive;
import { toaster } from "@kobalte/core";
import { Button } from "@repo/tailwindcss/solid/button";
import {
Toast,
ToastContent,
ToastDescription,
ToastProgress,
ToastTitle,
} from "@repo/tailwindcss/solid/toast";
const ToastDestructive = () => {
const showToast = () =>
toaster.show((props) => (
<Toast toastId={props.toastId} variant="destructive">
<ToastContent>
<ToastTitle>Uh oh! Something went wrong.</ToastTitle>
<ToastDescription>
There was a problem with your request.
</ToastDescription>
</ToastContent>
<ToastProgress />
</Toast>
));
return (
<Button variant="outline" onClick={showToast}>
Add to calendar
</Button>
);
};
export default ToastDestructive;