Skip to content

Toast

Toast notifications provide brief, non-intrusive feedback messages.

Preview

Installation

import { ToastProvider, useToast } from '@smc/darwin-ui';

Setup

Wrap your app with ToastProvider:

import { ToastProvider } from '@smc/darwin-ui';
function App() {
return (
<ToastProvider>
<YourApp />
</ToastProvider>
);
}

Usage

import { useToast, Button } from '@smc/darwin-ui';
export function Example() {
const { showToast } = useToast();
return (
<Button
onClick={() =>
showToast({
message: 'Action completed!',
type: 'success',
})
}
>
Show Toast
</Button>
);
}

Variants

TypeColorUse Case
infoBlueGeneral information
successGreenSuccessful actions
warningAmberWarnings, caution
errorRedErrors, failures

Duration

showToast({
message: 'Custom duration',
type: 'info',
duration: 5000, // 5 seconds
});

API Reference

useToast Hook

const { showToast } = useToast();

showToast Options

OptionTypeDefaultDescription
messagestring-Toast message
typeToastType"info"Toast variant
durationnumber3000Auto-dismiss time (ms)

ToastType

type ToastType = 'info' | 'success' | 'warning' | 'error';