vyrnReact+Next

Toast Library for React and Next.js

$npm i vyrn
Copied!

Test Toasts with Current Configuration (Click to show)

Position Configuration

Swipe Direction Configuration

Preview Configuration

Current Configuration:

<ClientToastProvider position="bottom-center" swipeDirection="left" maxToasts={5} layout="stack" showCloseButton={false} showProgressBar={true} color={true} > {children} </ClientToastProvider>

Implementation

1. Provider Setup

// In your root component
import { ToastProvider } from "vyrn";

export default function App() {
  return (
    <ToastProvider
      position="bottom-center"
      swipeDirection="left"
      maxToasts={5}
      layout="stack"
      showCloseButton={false}
      showProgressBar={true}
      color={true}
    >
      {/* Your app components */}
    </ToastProvider>
  );
}
typescript

2. Component Implementation

// Example component file (e.g., MyComponent.tsx)
import { useToast } from "vyrn";

export default function MyComponent() {
  const toast = useToast();

  const showToasts = () => {
    // Basic toasts
    toast.success("Success message");
    toast.error("Error message");
    toast.warning("Warning message");
    toast.info("Info message");

    // Custom styled toast
    toast.custom(
      <div className="font-bold">Custom styled toast</div>,
      {
        className: "bg-white text-black border-l-4 border-purple-500",
        duration: 5000
      }
    );

    // Complex toast with actions
    toast.custom(
      <div>
        <h3>Complex Toast</h3>
        <p>With actions and input</p>
      </div>,
      {
        className: "bg-gray-100 text-gray-800 border-l-4 border-blue-500",
        duration: 0,
        actions: [
          {
            label: "Action",
            onClick: () => console.log("Action clicked"),
            className: "bg-blue-500 text-white px-2 py-1 rounded"
          }
        ]
      }
    );
  };

  return (
    <button onClick={showToasts}>
      Show Toasts
    </button>
  );
}
typescript
Toast Library Documentation

Provider Configuration

PropTypeDefaultDescription
position'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right''bottom-center'Position where toasts will appear
swipeDirection'right' | 'left' | 'up' | 'down''left'Direction to swipe toast for dismissal
maxToastsnumber5Maximum number of toasts shown simultaneously
layout'stack' | 'normal''stack'How multiple toasts are displayed
showCloseButtonbooleanfalseWhether to show close button on toasts
showProgressBarbooleantrueWhether to show progress bar on toasts
colorbooleantrueWhether to show color on toasts

Toast Methods

MethodArgumentsDescription
toast.success(content, options?)Shows success toast with green styling
toast.error(content, options?)Shows error toast with red styling
toast.warning(content, options?)Shows warning toast with yellow styling
toast.info(content, options?)Shows info toast with blue styling
toast.custom(content, options?)Shows custom styled toast

Toast Options

OptionTypeDefaultDescription
durationnumber5000Duration in ms before auto-dismiss (0 for no auto-dismiss)
classNamestring-Custom CSS classes for toast
animation'slide' | 'fade' | 'zoom''slide'Toast appear/disappear animation