Installation
v2v2 is tree-shakeable by design, ships a React hook, and adds toast.promise(), swipe-to-dismiss, and ARIA roles. See the migration guide if you're coming from v1.
Install
npm install robot-toast
Minimal
By default, v2 shows no robot unless you explicitly ask for one. This keeps bundles small.
import { toast } from 'robot-toast';
// Minimal β shows text only, no robot (v2 default is opt-in)
toast({
message: 'Hello, World!',
position: 'bottom-right',
});With a built-in robot
Import the robot you want as a data URL β only the ones you import end up in your bundle.
import { toast } from 'robot-toast';
import { wave } from 'robot-toast/robots'; // tree-shakeable
toast({
message: 'Hello, World!',
position: 'bottom-right',
robotVariant: wave,
});toast.promise()
Attach a loading/success/error lifecycle to a promise.
toast.promise(fetch('/api/save'), {
loading: 'Savingβ¦',
success: 'Saved!',
error: 'Save failed',
});React hook (optional)
A thin wrapper exposing toast as a stable-ref hook. React is an optional peer dep.
import { useRobotToast } from 'robot-toast/react';
function SaveButton() {
const toast = useRobotToast();
return <button onClick={() => toast.success('Saved!')}>Save</button>;
}All 16 built-in variants
Import the ones you need from `robot-toast/robots`.
wave
base
base2
success
error
angry
angry2
shock
think
search
loading
sleep
headPalm
typing
validation
validation2
Two were renamed from v1: head-palm β headPalm, type β typing.
What's new vs v1
- β’ Bundle dropped 36%. Core: 61 KB β 39 KB. Robots are lazy-imported.
- β’ Opt-in robots. Omitting
robotVariantshows no robot now. Use"default"or import fromrobot-toast/robots. - β’ Mobile drag fixed.
touch-action: none, cached rects, swipe-to-dismiss. - β’ ARIA roles.
role="alert"for errors/warnings;role="status"otherwise. - β’ React subpath.
useRobotToast()+useToastOnMount(). - β’
toast.promise()with callbacks for dynamic messages.