Component

Toast

Toast notification component with Neo-Brutalism styling.

Preview

Installation

pnpm dlx brutx@latest add toast

Usage

import { Toast, ToastContainer, useToast } from "@/components/ui/toast"

function MyComponent() {
  const { toasts, addToast, removeToast, success, error } = useToast();

  return (
    <>
      <Button onClick={() => success('Saved!', 'Changes saved successfully.')}>
        Save
      </Button>
      
      <ToastContainer position="bottom-right">
        {toasts.map((toast) => (
          <Toast
            key={toast.id}
            variant={toast.variant}
            title={toast.title}
            description={toast.description}
            onClose={() => removeToast(toast.id)}
          />
        ))}
      </ToastContainer>
    </>
  );
}

Examples

All Variants

Different Sizes

Use size prop to control toast width.

Custom Icon

Use icon prop to provide a custom icon.

With Action Button

Use action prop to add action buttons.

Interactive Example

Try different toast types and positions.

API Reference

Toast

Individual toast notification component.

PropTypeDefaultDescription
variant"default" | "success" | "error" | "warning" | "info""default"Toast style variant
size"sm" | "default" | "lg""default"Toast width
titlestring-Toast title text
descriptionstring-Toast description text
iconReactNode(auto)Custom icon (defaults based on variant)
actionReactNode-Action button(s)
durationnumber5000Auto-dismiss time in ms (0 to disable)
onClose() => void-Callback when toast closes (enables close button)

ToastContainer

Container for positioning toasts.

PropTypeDefaultDescription
position"top-left" | "top-center" | "top-right" | "bottom-left" | "bottom-center" | "bottom-right""bottom-right"Position of toast container

useToast Hook

Hook for managing toast state.

ReturnTypeDescription
toastsToastItem[]Array of active toasts
addToast(toast) => stringAdd toast, returns ID
removeToast(id: string) => voidRemove toast by ID
clearToasts() => voidRemove all toasts
success(title, desc?) => stringShorthand for success toast
error(title, desc?) => stringShorthand for error toast
warning(title, desc?) => stringShorthand for warning toast
info(title, desc?) => stringShorthand for info toast

All Exports

ExportTypeDescription
ToastComponentIndividual toast notification
ToastContainerComponentPositioning container
useToastHookToast state management
toastVariantsCVA FunctionStyle variants for customization
ToastPropsTypeToast component props
ToastContainerPropsTypeContainer props
ToastItemTypeToast item type for hook