robot-toast 2.1.1 → 2.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +109 -328
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,24 +1,11 @@
|
|
|
1
1
|
# 🤖 robot-toast
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Lightweight toast notifications with an animated robot companion. 16 tree-shakeable robots, fully draggable, multiple themes, and optional React hook.
|
|
4
4
|
|
|
5
5
|
<p align="left">
|
|
6
|
-
<a href="https://
|
|
7
|
-
style="color:#e53935; font-weight:600; text-decoration:none;">
|
|
8
|
-
Demo
|
|
9
|
-
</a>
|
|
10
|
-
</p>
|
|
11
|
-
<p align="center">
|
|
12
|
-
<a href="https://pratham-potfolio.vercel.app/" target="_blank">
|
|
13
|
-
<img src="https://img.shields.io/badge/Portfolio-000?style=for-the-badge&logo=vercel&logoColor=white" />
|
|
14
|
-
</a>
|
|
15
|
-
<a href="https://www.linkedin.com/in/pratham-kumar-a6b672275/" target="_blank">
|
|
16
|
-
<img src="https://img.shields.io/badge/LinkedIn-0077B5?style=for-the-badge&logo=linkedin&logoColor=white" />
|
|
17
|
-
</a>
|
|
18
|
-
<a href="https://github.com/Pratham2703005" target="_blank">
|
|
19
|
-
<img src="https://img.shields.io/badge/GitHub-000?style=for-the-badge&logo=github&logoColor=white" />
|
|
20
|
-
</a>
|
|
6
|
+
<a href="https://robot-toast-client.vercel.app/" style="color:#e53935; font-weight:600; text-decoration:none;">Demo & Playground →</a>
|
|
21
7
|
</p>
|
|
8
|
+
|
|
22
9
|
<p align="center">
|
|
23
10
|
<a href="https://www.npmjs.com/package/robot-toast">
|
|
24
11
|
<img src="https://img.shields.io/npm/v/robot-toast?style=flat-square" />
|
|
@@ -27,55 +14,9 @@ A lightweight, zero-dependency, framework-agnostic toast notification library fe
|
|
|
27
14
|
<img src="https://img.shields.io/bundlephobia/minzip/robot-toast?style=flat-square" />
|
|
28
15
|
</p>
|
|
29
16
|
|
|
30
|
-
|
|
31
|
-
<img src="https://raw.githubusercontent.com/Pratham2703005/robot-toast/refs/heads/main/public/offiicial-page/lightmode.png" alt="Light mode" width="320" />
|
|
32
|
-
<img src="https://raw.githubusercontent.com/Pratham2703005/robot-toast/refs/heads/main/public/offiicial-page/darkmode.png" alt="Dark mode" width="320" />
|
|
33
|
-
<img src="https://raw.githubusercontent.com/Pratham2703005/robot-toast/refs/heads/main/public/offiicial-page/custom.png" alt="Custom styled" width="320" />
|
|
34
|
-
</p>
|
|
17
|
+
> **[GIF/video of robot in action]** ← [Add robot demo GIF here]
|
|
35
18
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
## What's new in v2
|
|
39
|
-
|
|
40
|
-
- **36% smaller core bundle** (61 KB → 39 KB). Robots moved to a tree-shakeable subpath — only the ones you import end up in your bundle.
|
|
41
|
-
- **Opt-in robots.** Omitting `robotVariant` renders *no robot* now. Pass `'default'` or import from `robot-toast/robots` to bring one back.
|
|
42
|
-
- **Inline buttons.** Pass a `buttons` array for Undo / Retry / Cancel-style inline CTAs — rendered in array order, optional `className` per button for custom visual hierarchy.
|
|
43
|
-
- **`toast.promise()`** — attach loading/success/error toasts to any promise.
|
|
44
|
-
- **React subpath.** `useRobotToast()` + `useToastOnMount()` as optional ergonomic bindings.
|
|
45
|
-
- **ARIA roles.** `role="alert"` for `error`/`warning`, `role="status"` elsewhere, plus `aria-atomic` and a labeled close button.
|
|
46
|
-
|
|
47
|
-
Upgrading from v1? See [MIGRATION.md](./MIGRATION.md) for the five-minute changeover.
|
|
48
|
-
|
|
49
|
-
---
|
|
50
|
-
|
|
51
|
-
## Features
|
|
52
|
-
|
|
53
|
-
| Category | Details |
|
|
54
|
-
|---|---|
|
|
55
|
-
| **Themes** | `light` · `dark` · `colored` |
|
|
56
|
-
| **Types** | `default` · `info` · `success` · `warning` · `error` |
|
|
57
|
-
| **Transitions** | `bounce` · `flip` · `zoom` · `slide` |
|
|
58
|
-
| **Positions** | `top-left` · `top-center` · `top-right` · `bottom-left` · `bottom-center` · `bottom-right` |
|
|
59
|
-
| **Robots** | 16 tree-shakeable built-ins — import what you use, pass any image path (svg, png, jpg, gif, webp), or skip the robot entirely |
|
|
60
|
-
| **Custom styles** | Pass a `style` object to customize the message bubble however you like |
|
|
61
|
-
| **Drag & drop** | Full XY drag with viewport clamping; snaps to the nearest screen edge on release |
|
|
62
|
-
| **Typewriter effect** | Characters appear one by one — configurable speed or instant |
|
|
63
|
-
| **Multi-toast** | Configurable `limit` for simultaneous toasts; excess is auto-queued |
|
|
64
|
-
| **Progress bar** | Countdown bar — show or hide it |
|
|
65
|
-
| **Pause on hover** | Timer pauses when you hover over the toast |
|
|
66
|
-
| **Pause on focus loss** | Timer pauses when the browser tab loses focus |
|
|
67
|
-
| **Promise helper** | `toast.promise(p, { loading, success, error })` |
|
|
68
|
-
| **React hook** | `useRobotToast()` + `useToastOnMount()` from `robot-toast/react` |
|
|
69
|
-
| **RTL** | Right-to-left layout support |
|
|
70
|
-
| **Newest on top** | Stack new toasts above existing ones |
|
|
71
|
-
| **Auto-close** | Configurable duration, or disable entirely |
|
|
72
|
-
| **Accessibility** | `role="alert"` / `role="status"`, `aria-live`, `aria-atomic`, labeled dismiss button |
|
|
73
|
-
| **SSR-safe** | All DOM access is guarded — safe for Next.js, Nuxt, etc. |
|
|
74
|
-
| **Zero dependencies** | Pure TypeScript — ESM + CJS builds, tree-shakeable |
|
|
75
|
-
|
|
76
|
-
---
|
|
77
|
-
|
|
78
|
-
## Installation
|
|
19
|
+
## Install
|
|
79
20
|
|
|
80
21
|
```bash
|
|
81
22
|
npm install robot-toast
|
|
@@ -85,346 +26,186 @@ npm install robot-toast
|
|
|
85
26
|
|
|
86
27
|
```ts
|
|
87
28
|
import { toast } from 'robot-toast';
|
|
29
|
+
import { wave } from 'robot-toast/robots';
|
|
88
30
|
|
|
89
|
-
|
|
90
|
-
toast('
|
|
91
|
-
|
|
92
|
-
// With options
|
|
93
|
-
toast({
|
|
94
|
-
message: 'Operation successful!',
|
|
95
|
-
type: 'success',
|
|
96
|
-
theme: 'dark',
|
|
97
|
-
position: 'top-right',
|
|
98
|
-
});
|
|
31
|
+
toast({ message: 'Hello! 🤖', robotVariant: wave });
|
|
32
|
+
toast.success('Operation successful!');
|
|
33
|
+
toast.error('Something went wrong');
|
|
99
34
|
```
|
|
100
35
|
|
|
101
|
-
|
|
36
|
+
**Explore all features & interactive demos →** [Full Playground](https://robot-toast-client.vercel.app/features)
|
|
37
|
+
|
|
38
|
+
## Features at a Glance
|
|
102
39
|
|
|
103
|
-
Robots
|
|
40
|
+
| Robots | Layout | Styling | Behavior |
|
|
41
|
+
|--------|--------|---------|----------|
|
|
42
|
+
| 16 built-in variants | 6 position options | 3 themes | Fully draggable |
|
|
43
|
+
| Tree-shakeable imports | Auto-queuing | Custom inline styles | Typewriter effect |
|
|
44
|
+
| Custom images (SVG/PNG) | Progress bar | Transitions (4 types) | Promise helpers |
|
|
45
|
+
| | | | React hook included |
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## Full API Reference
|
|
50
|
+
|
|
51
|
+
### Basic Usage
|
|
104
52
|
|
|
105
53
|
```ts
|
|
106
54
|
import { toast } from 'robot-toast';
|
|
107
55
|
import { wave, success, error } from 'robot-toast/robots';
|
|
108
56
|
|
|
109
|
-
toast(
|
|
110
|
-
toast({ message: '
|
|
111
|
-
toast(
|
|
57
|
+
toast('Simple notification');
|
|
58
|
+
toast({ message: 'With options', type: 'success', robotVariant: wave });
|
|
59
|
+
toast.success('Shorthand');
|
|
112
60
|
```
|
|
113
61
|
|
|
114
|
-
|
|
62
|
+
### All Options
|
|
115
63
|
|
|
116
64
|
```ts
|
|
117
|
-
toast({
|
|
65
|
+
toast({
|
|
66
|
+
// Content
|
|
67
|
+
message: 'Notification text',
|
|
68
|
+
|
|
69
|
+
// Appearance
|
|
70
|
+
type: 'default' | 'info' | 'success' | 'warning' | 'error',
|
|
71
|
+
theme: 'light' | 'dark' | 'colored',
|
|
72
|
+
transition: 'bounce' | 'flip' | 'zoom' | 'slide',
|
|
73
|
+
position: 'top-left' | 'top-center' | 'top-right' |
|
|
74
|
+
'bottom-left' | 'bottom-center' | 'bottom-right',
|
|
75
|
+
|
|
76
|
+
// Robot & Styling
|
|
77
|
+
robotVariant: wave | base | success | error | '...' | 'default' | '/path.svg',
|
|
78
|
+
nearScreen: true,
|
|
79
|
+
style: { background: '...', color: '...' },
|
|
80
|
+
|
|
81
|
+
// Timing & Behavior
|
|
82
|
+
autoClose: 5000 | false,
|
|
83
|
+
typeSpeed: 30,
|
|
84
|
+
hideProgressBar: false,
|
|
85
|
+
draggable: true,
|
|
86
|
+
pauseOnHover: true,
|
|
87
|
+
pauseOnFocusLoss: true,
|
|
88
|
+
rtl: false,
|
|
89
|
+
|
|
90
|
+
// Multi-toast
|
|
91
|
+
limit: 0,
|
|
92
|
+
newestOnTop: false,
|
|
93
|
+
|
|
94
|
+
// Buttons & Callbacks
|
|
95
|
+
buttons: [{ label: 'Undo', onClick: () => {...} }],
|
|
96
|
+
onOpen: () => {...},
|
|
97
|
+
onClose: () => {...},
|
|
98
|
+
});
|
|
118
99
|
```
|
|
119
100
|
|
|
120
|
-
|
|
101
|
+
### Built-in Robots
|
|
121
102
|
|
|
122
|
-
|
|
103
|
+
Import any of the 16 built-in robots from `robot-toast/robots`:
|
|
123
104
|
|
|
124
105
|
```ts
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
});
|
|
106
|
+
import {
|
|
107
|
+
wave, base, base2, success, error,
|
|
108
|
+
angry, angry2, shock, think, search,
|
|
109
|
+
loading, sleep, headPalm, typing,
|
|
110
|
+
validation, validation2,
|
|
111
|
+
} from 'robot-toast/robots';
|
|
132
112
|
|
|
133
|
-
//
|
|
134
|
-
toast
|
|
135
|
-
message: 'Send this email to 1,200 people?',
|
|
136
|
-
buttons: [
|
|
137
|
-
{ label: 'Cancel', onClick: () => abort() },
|
|
138
|
-
{ label: 'Send', onClick: () => send(), className: 'my-primary' },
|
|
139
|
-
],
|
|
140
|
-
});
|
|
113
|
+
// Or import directly for guaranteed tree-shaking:
|
|
114
|
+
import { wave } from 'robot-toast/robots/wave';
|
|
141
115
|
```
|
|
142
116
|
|
|
143
|
-
|
|
117
|
+
Custom images are supported: pass any SVG/PNG/JPG/GIF/WebP path to `robotVariant`.
|
|
144
118
|
|
|
145
|
-
|
|
119
|
+
### Inline Buttons
|
|
146
120
|
|
|
147
|
-
|
|
148
|
-
- **`style`** — inline CSS as a key/value object. Use for one-off styling without touching your stylesheet:
|
|
121
|
+
Add undo/confirm/cancel style buttons to toasts:
|
|
149
122
|
|
|
150
123
|
```ts
|
|
151
124
|
toast({
|
|
152
|
-
message: '
|
|
125
|
+
message: 'File deleted',
|
|
153
126
|
buttons: [
|
|
154
|
-
{ label: '
|
|
155
|
-
{
|
|
156
|
-
label: 'Send',
|
|
157
|
-
onClick: () => send(),
|
|
158
|
-
style: { background: 'black', color: 'white' },
|
|
159
|
-
},
|
|
127
|
+
{ label: 'Undo', onClick: () => restoreFile() },
|
|
128
|
+
{ label: 'Keep', onClick: () => {}, style: { color: 'gray' } },
|
|
160
129
|
],
|
|
161
130
|
});
|
|
162
131
|
```
|
|
163
132
|
|
|
164
|
-
|
|
133
|
+
### Promise Lifecycle
|
|
165
134
|
|
|
166
|
-
|
|
135
|
+
Attach loading/success/error messages to any promise:
|
|
167
136
|
|
|
168
137
|
```ts
|
|
169
138
|
toast.promise(fetch('/api/save').then(r => r.json()), {
|
|
170
139
|
loading: 'Saving…',
|
|
171
140
|
success: (data) => `Saved as ${data.name}`,
|
|
172
|
-
error:
|
|
141
|
+
error: (err) => `Failed: ${err.message}`,
|
|
173
142
|
});
|
|
174
143
|
```
|
|
175
144
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
## React bindings
|
|
145
|
+
### React Bindings
|
|
179
146
|
|
|
180
147
|
```tsx
|
|
181
148
|
import { useRobotToast, useToastOnMount } from 'robot-toast/react';
|
|
182
149
|
|
|
183
|
-
function
|
|
150
|
+
function App() {
|
|
184
151
|
const toast = useRobotToast();
|
|
185
152
|
return <button onClick={() => toast.success('Saved!')}>Save</button>;
|
|
186
153
|
}
|
|
187
154
|
|
|
188
|
-
function
|
|
189
|
-
|
|
190
|
-
useToastOnMount({ message: 'Fetching…', autoClose: false });
|
|
155
|
+
function InitBanner() {
|
|
156
|
+
useToastOnMount({ message: 'Welcome!', autoClose: false });
|
|
191
157
|
return null;
|
|
192
158
|
}
|
|
193
159
|
```
|
|
194
160
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
## Close Programmatically
|
|
161
|
+
### Programmatic Control
|
|
198
162
|
|
|
199
163
|
```ts
|
|
200
|
-
// Close a specific toast by id
|
|
201
164
|
const id = toast('Working…');
|
|
202
165
|
toast.closeById(id);
|
|
203
|
-
|
|
204
|
-
// Close all toasts at once
|
|
205
166
|
toast.closeAll();
|
|
206
167
|
```
|
|
207
168
|
|
|
208
|
-
|
|
209
|
-
## All Options at a Glance
|
|
210
|
-
|
|
211
|
-
A single `toast()` call using **every available option** so you can see the full API in one place:
|
|
169
|
+
### Themes & Custom Styles
|
|
212
170
|
|
|
213
171
|
```ts
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
// ─── Content ───────────────────────────────────────────
|
|
219
|
-
message: 'This is the full kitchen-sink example!',
|
|
220
|
-
|
|
221
|
-
// ─── Appearance ────────────────────────────────────────
|
|
222
|
-
type: 'success', // 'default' | 'info' | 'success' | 'warning' | 'error'
|
|
223
|
-
theme: 'dark', // 'light' | 'dark' | 'colored'
|
|
224
|
-
transition: 'bounce', // 'bounce' | 'flip' | 'zoom' | 'slide'
|
|
225
|
-
position: 'bottom-right', // 'top-left' | 'top-center' | 'top-right'
|
|
226
|
-
// 'bottom-left' | 'bottom-center' | 'bottom-right'
|
|
227
|
-
|
|
228
|
-
// ─── Robot ─────────────────────────────────────────────
|
|
229
|
-
// Omit (or '' / 'none') to hide. Use 'default' for the inline built-in SVG.
|
|
230
|
-
// For a built-in variant, import from 'robot-toast/robots' and pass the value.
|
|
231
|
-
// Custom image: pass any path with svg/png/jpg/jpeg/gif/webp extension.
|
|
232
|
-
robotVariant: wave,
|
|
233
|
-
nearScreen: true, // true = robot near screen edge, false = inner side
|
|
234
|
-
|
|
235
|
-
// ─── Timing ────────────────────────────────────────────
|
|
236
|
-
autoClose: 5000, // milliseconds, or false to disable auto-close
|
|
237
|
-
typeSpeed: 30, // ms per character (0 = instant, no typing effect)
|
|
238
|
-
|
|
239
|
-
// ─── Behaviour ─────────────────────────────────────────
|
|
240
|
-
hideProgressBar: false, // true to hide the countdown bar
|
|
241
|
-
draggable: true, // allow drag & drop; snaps to nearest edge on release
|
|
242
|
-
pauseOnHover: true, // pause countdown on mouse hover
|
|
243
|
-
pauseOnFocusLoss: true, // pause countdown when tab loses focus
|
|
244
|
-
rtl: false, // right-to-left layout
|
|
245
|
-
|
|
246
|
-
// ─── Multi-toast ───────────────────────────────────────
|
|
247
|
-
limit: 0, // max visible toasts (0 = unlimited, excess is queued)
|
|
248
|
-
newestOnTop: false, // stack new toasts above older ones
|
|
249
|
-
|
|
250
|
-
// ─── Custom Inline Styles ─────────────────────────────
|
|
172
|
+
toast({ message: 'Light', theme: 'light' });
|
|
173
|
+
toast({ message: 'Dark', theme: 'dark' });
|
|
174
|
+
toast({
|
|
175
|
+
message: 'Custom gradient',
|
|
251
176
|
style: {
|
|
252
|
-
background:
|
|
253
|
-
color:
|
|
177
|
+
background: 'linear-gradient(135deg, #667eea, #764ba2)',
|
|
178
|
+
color: '#fff',
|
|
254
179
|
borderRadius: '16px',
|
|
255
|
-
fontFamily: 'monospace',
|
|
256
180
|
},
|
|
257
|
-
|
|
258
|
-
// ─── Callbacks ─────────────────────────────────────────
|
|
259
|
-
onOpen: () => console.log('Toast appeared!'),
|
|
260
|
-
onClose: () => console.log('Toast dismissed!'),
|
|
261
181
|
});
|
|
262
182
|
```
|
|
263
183
|
|
|
264
|
-
###
|
|
265
|
-
|
|
266
|
-
```ts
|
|
267
|
-
// These set the `type` automatically — you can also pass a full options object
|
|
268
|
-
toast.success('Saved!');
|
|
269
|
-
toast.error('Something went wrong');
|
|
270
|
-
toast.info('Did you know…');
|
|
271
|
-
toast.warning('Check your input');
|
|
184
|
+
### Accessibility
|
|
272
185
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
186
|
+
- `error` / `warning` toasts: `role="alert"` + `aria-live="assertive"`
|
|
187
|
+
- Other types: `role="status"` + `aria-live="polite"`
|
|
188
|
+
- `aria-atomic="true"` ensures full message re-announcement
|
|
189
|
+
- Labeled close button for screen readers
|
|
277
190
|
|
|
278
|
-
|
|
279
|
-
## Options
|
|
280
|
-
|
|
281
|
-
| Option | Type | Default | Description |
|
|
282
|
-
|---|---|---|---|
|
|
283
|
-
| `message` | `string` | *required* | The text to display |
|
|
284
|
-
| `autoClose` | `number \| false` | `5000` | Auto-close after ms. `false` = stays until dismissed |
|
|
285
|
-
| `position` | `string` | `'bottom-right'` | One of the 6 position presets (see above) |
|
|
286
|
-
| `type` | `string` | `'default'` | `default` · `info` · `success` · `warning` · `error` |
|
|
287
|
-
| `theme` | `string` | `'light'` | `light` · `dark` · `colored` |
|
|
288
|
-
| `transition` | `string` | `'bounce'` | `bounce` · `flip` · `zoom` · `slide` |
|
|
289
|
-
| `style` | `Record<string, string \| number>` | — | Inline styles applied directly to the message bubble |
|
|
290
|
-
| `typeSpeed` | `number` | `30` | Typing speed in ms per character. `0` = instant |
|
|
291
|
-
| `robotVariant` | `string` | *hidden* | Data URL from `robot-toast/robots`, `'default'` for built-in SVG, image path, or omit for no robot |
|
|
292
|
-
| `hideProgressBar` | `boolean` | `false` | Hide the countdown progress bar |
|
|
293
|
-
| `draggable` | `boolean` | `true` | Allow the user to drag the toast; snaps to the nearest edge on release |
|
|
294
|
-
| `nearScreen` | `boolean` | `true` | `true` = robot near screen edge; `false` = robot on the inner side |
|
|
295
|
-
| `pauseOnHover` | `boolean` | `true` | Pause countdown while the cursor is over the toast |
|
|
296
|
-
| `pauseOnFocusLoss` | `boolean` | `true` | Pause countdown when the browser tab loses focus |
|
|
297
|
-
| `rtl` | `boolean` | `false` | Right-to-left layout |
|
|
298
|
-
| `limit` | `number` | `0` | Max toasts visible at once. `0` = unlimited. Excess is queued |
|
|
299
|
-
| `newestOnTop` | `boolean` | `false` | Stack newest toasts above older ones |
|
|
300
|
-
| `buttons` | `Array<{ label: string; onClick: (e: MouseEvent) => void; className?: string; style?: Record<string, string \| number> }>` | — | Inline buttons rendered in array order. Each click fires `onClick` then closes the toast. Use `className` for stylesheet classes, `style` for inline CSS. |
|
|
301
|
-
| `onOpen` | `() => void` | — | Callback fired when the toast finishes its entrance |
|
|
302
|
-
| `onClose` | `() => void` | — | Callback fired after the toast fully exits |
|
|
303
|
-
|
|
304
|
-
---
|
|
305
|
-
|
|
306
|
-
## Built-in Robots
|
|
307
|
-
|
|
308
|
-
All 16 robots are importable from `robot-toast/robots`. Each is a pre-encoded data URL — no network fetch, no external files, and bundlers drop the ones you don't use:
|
|
309
|
-
|
|
310
|
-
```ts
|
|
311
|
-
import {
|
|
312
|
-
wave, base, base2, success, error,
|
|
313
|
-
angry, angry2, shock, think, search,
|
|
314
|
-
loading, sleep, headPalm, typing,
|
|
315
|
-
validation, validation2,
|
|
316
|
-
} from 'robot-toast/robots';
|
|
317
|
-
```
|
|
318
|
-
|
|
319
|
-
> v1 → v2 renames: `head-palm` → `headPalm`, `type` → `typing` (the dash isn't a valid identifier; `type` clashes with TypeScript's type-only import syntax).
|
|
320
|
-
|
|
321
|
-
For guaranteed per-variant tree-shaking, you can also import from the direct subpath:
|
|
322
|
-
|
|
323
|
-
```ts
|
|
324
|
-
import { wave } from 'robot-toast/robots/wave';
|
|
325
|
-
```
|
|
326
|
-
|
|
327
|
-
### Custom Robot Image
|
|
328
|
-
|
|
329
|
-
Point to any image accessible in your app:
|
|
330
|
-
|
|
331
|
-
```ts
|
|
332
|
-
toast({
|
|
333
|
-
message: 'Custom bot!',
|
|
334
|
-
robotVariant: '/images/my-robot.png',
|
|
335
|
-
});
|
|
336
|
-
```
|
|
337
|
-
|
|
338
|
-
Supported formats: **svg, png, jpg, jpeg, gif, webp**. Failed loads fall back to the built-in default SVG. Omit `robotVariant` (or pass `''` / `'none'`) to hide the robot entirely.
|
|
339
|
-
|
|
340
|
-
---
|
|
341
|
-
|
|
342
|
-
## Themes & Custom Styles
|
|
343
|
-
|
|
344
|
-
### Built-in Themes
|
|
345
|
-
|
|
346
|
-
```ts
|
|
347
|
-
toast({ message: 'Light mode', theme: 'light' });
|
|
348
|
-
toast({ message: 'Dark mode', theme: 'dark' });
|
|
349
|
-
toast({ message: 'Colored', theme: 'colored', type: 'success' });
|
|
350
|
-
```
|
|
351
|
-
|
|
352
|
-
### Custom Inline Styles
|
|
353
|
-
|
|
354
|
-
Use the `style` option to fully customize the message bubble:
|
|
355
|
-
|
|
356
|
-
```ts
|
|
357
|
-
toast({
|
|
358
|
-
message: 'Fully custom look',
|
|
359
|
-
style: {
|
|
360
|
-
background: 'linear-gradient(135deg, #667eea, #764ba2)',
|
|
361
|
-
color: '#fff',
|
|
362
|
-
borderRadius: '16px',
|
|
363
|
-
fontFamily: 'monospace',
|
|
364
|
-
},
|
|
365
|
-
});
|
|
366
|
-
```
|
|
367
|
-
|
|
368
|
-
---
|
|
369
|
-
|
|
370
|
-
## Transitions
|
|
371
|
-
|
|
372
|
-
```ts
|
|
373
|
-
toast({ message: 'Bounce!', transition: 'bounce' });
|
|
374
|
-
toast({ message: 'Flip!', transition: 'flip' });
|
|
375
|
-
toast({ message: 'Zoom!', transition: 'zoom' });
|
|
376
|
-
toast({ message: 'Slide!', transition: 'slide' });
|
|
377
|
-
```
|
|
378
|
-
|
|
379
|
-
---
|
|
380
|
-
|
|
381
|
-
## Drag & responsive layout
|
|
382
|
-
|
|
383
|
-
When `draggable` is on (default):
|
|
384
|
-
|
|
385
|
-
- **Drag anywhere** on the toast to move it. On release it snaps to the nearest horizontal edge — including when you drag all the way across the screen.
|
|
386
|
-
- `touch-action: none` prevents the browser from fighting the drag, and rect dimensions are cached on pointerdown to eliminate layout-thrash jank on low-end devices.
|
|
387
|
-
- Use the **close button**, an **action button**, or `toast.closeById()` / `toast.closeAll()` to dismiss programmatically.
|
|
388
|
-
|
|
389
|
-
**On viewports ≤ 600 px** the toast shrinks slightly (tighter gutters, smaller robot, smaller font) but keeps its configured position preset. Drag still works everywhere.
|
|
390
|
-
|
|
391
|
-
---
|
|
392
|
-
|
|
393
|
-
## Accessibility
|
|
394
|
-
|
|
395
|
-
Every toast ships with the right ARIA hooks out of the box:
|
|
396
|
-
|
|
397
|
-
- `error` and `warning` toasts get `role="alert"` + `aria-live="assertive"` — screen readers announce them immediately.
|
|
398
|
-
- All other types get `role="status"` + `aria-live="polite"` — announced when the user is idle.
|
|
399
|
-
- `aria-atomic="true"` ensures the full message is re-announced on updates.
|
|
400
|
-
- The close button has `type="button"` + `aria-label="Dismiss notification"`.
|
|
401
|
-
|
|
402
|
-
---
|
|
403
|
-
|
|
404
|
-
## Framework Examples
|
|
405
|
-
|
|
406
|
-
### React / Next.js
|
|
191
|
+
### Framework Examples
|
|
407
192
|
|
|
193
|
+
**React / Next.js**
|
|
408
194
|
```tsx
|
|
409
195
|
'use client';
|
|
410
196
|
import { useRobotToast } from 'robot-toast/react';
|
|
411
197
|
import { wave } from 'robot-toast/robots';
|
|
412
|
-
import { useEffect } from 'react';
|
|
413
198
|
|
|
414
199
|
export default function App() {
|
|
415
200
|
const toast = useRobotToast();
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
toast({
|
|
419
|
-
message: '
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
});
|
|
426
|
-
}, [toast]);
|
|
427
|
-
|
|
428
|
-
return <div>My App</div>;
|
|
201
|
+
|
|
202
|
+
return (
|
|
203
|
+
<button onClick={() => toast.success({
|
|
204
|
+
message: 'Deployed!',
|
|
205
|
+
robotVariant: wave
|
|
206
|
+
})}>
|
|
207
|
+
Deploy
|
|
208
|
+
</button>
|
|
209
|
+
);
|
|
429
210
|
}
|
|
430
211
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "robot-toast",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.2",
|
|
4
4
|
"description": "A lightweight, framework-agnostic toast notification library with an animated robot character. Tree-shakeable robots, draggable with swipe-to-dismiss, toast.promise(), and an optional React hook.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|