flashpop 1.0.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Shyam
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,330 @@
1
+ # flashpop
2
+
3
+ [![npm version](https://img.shields.io/npm/v/flashpop.svg?style=flat-square)](https://www.npmjs.com/package/flashpop)
4
+ [![license](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://github.com/flashpop/flashpop/blob/main/LICENSE)
5
+ [![bundle size](https://img.shields.io/bundlephobia/minzip/flashpop?style=flat-square)](https://bundlephobia.com/package/flashpop)
6
+ [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://github.com/flashpop/flashpop/pulls)
7
+
8
+ A lightweight, modern, and highly customizable React notification and toast library. Built with **React Hooks**, the **Context API**, and **zero external icon/CSS runtime dependencies**.
9
+
10
+ ---
11
+
12
+ ## âœĻ Features
13
+
14
+ - ðŸŠķ **Ultra Lightweight**: Zero runtime dependencies. Clean inline SVGs for all status icons.
15
+ - ⚡ **React Context & Hooks**: Intuitive `useToast()` hook and `<ToastProvider>` wrapper.
16
+ - ðŸŽĻ **Modern Design**: Soft shadows, frosted glass effects, clean typography, and 3 built-in themes (`light`, `dark`, `colored`).
17
+ - ⏱ïļ **Auto-Dismiss & Progress Bar**: Smooth 60fps CSS countdown bar with **pause-on-hover** support.
18
+ - 📍 **6 Flexible Screen Positions**: `top-left`, `top-center`, `top-right`, `bottom-left`, `bottom-center`, `bottom-right`.
19
+ - 🔄 **Async Promises Support**: Effortlessly handle pending, success, and error states with `toast.promise()`.
20
+ - 🔘 **Interactive Action Buttons**: Support for interactive buttons inside toasts (e.g., "Undo", "Retry").
21
+ - 👆 **Swipe to Accept & Cancel**: Touch and mouse drag gestures to **swipe right to accept** and **swipe left to cancel/dismiss** with live visual badges.
22
+ - ðŸ“ą **Fully Responsive**: Adapts seamlessly to mobile screens and respects safe area insets.
23
+ - â™ŋ **Accessible**: Includes standard ARIA roles (`status`, `alert`) and live regions (`polite`, `assertive`).
24
+ - 📘 **TypeScript Ready**: Complete TypeScript definition files (`.d.ts`) included.
25
+
26
+ ---
27
+
28
+ ## ðŸ“Ķ Installation
29
+
30
+ Install `flashpop` via your package manager of choice:
31
+
32
+ ```bash
33
+ # Using npm
34
+ npm install flashpop
35
+
36
+ # Using yarn
37
+ yarn add flashpop
38
+
39
+ # Using pnpm
40
+ pnpm add flashpop
41
+ ```
42
+
43
+ ---
44
+
45
+ ## 🚀 Quick Start
46
+
47
+ ### 1. Wrap your application with `<ToastProvider>`
48
+
49
+ Wrap your root component (e.g., in `App.jsx`, `index.jsx`, or `_app.tsx` for Next.js) and import the CSS stylesheet:
50
+
51
+ ```jsx
52
+ import React from 'react';
53
+ import ReactDOM from 'react-dom/client';
54
+ import App from './App';
55
+
56
+ // 1. Import Provider and stylesheet
57
+ import { ToastProvider } from 'flashpop';
58
+ import 'flashpop/dist/toast.css';
59
+
60
+ const root = ReactDOM.createRoot(document.getElementById('root'));
61
+ root.render(
62
+ <React.StrictMode>
63
+ <ToastProvider position="top-right" autoClose={3000}>
64
+ <App />
65
+ </ToastProvider>
66
+ </React.StrictMode>
67
+ );
68
+ ```
69
+
70
+ ### 2. Trigger notifications with `useToast()`
71
+
72
+ Inside any component wrapped by `<ToastProvider>`, invoke the `useToast()` hook:
73
+
74
+ ```jsx
75
+ import React from 'react';
76
+ import { useToast } from 'flashpop';
77
+
78
+ function Dashboard() {
79
+ const toast = useToast();
80
+
81
+ return (
82
+ <div style={{ display: 'flex', gap: '8px' }}>
83
+ <button onClick={() => toast.success('Profile saved successfully!')}>
84
+ Success
85
+ </button>
86
+
87
+ <button onClick={() => toast.error('Failed to connect to server.')}>
88
+ Error
89
+ </button>
90
+
91
+ <button onClick={() => toast.warning('Your session will expire soon.')}>
92
+ Warning
93
+ </button>
94
+
95
+ <button onClick={() => toast.info('A new version is available.')}>
96
+ Info
97
+ </button>
98
+ </div>
99
+ );
100
+ }
101
+
102
+ export default Dashboard;
103
+ ```
104
+
105
+ ---
106
+
107
+ ## 📖 Usage Examples
108
+
109
+ ### 1. Titles & Detailed Messages
110
+
111
+ ```jsx
112
+ toast.info('Your password has been changed from another device.', {
113
+ title: 'Security Alert',
114
+ duration: 5000,
115
+ });
116
+ ```
117
+
118
+ ### 2. Action Buttons (e.g., "Undo")
119
+
120
+ ```jsx
121
+ toast.warning('Item removed from cart.', {
122
+ title: 'Cart Updated',
123
+ action: {
124
+ label: 'Undo',
125
+ onClick: (id) => {
126
+ restoreItem();
127
+ console.log(`Toast ${id} action clicked`);
128
+ },
129
+ dismissOnClick: true, // Automatically close toast when action clicked (default: true)
130
+ },
131
+ });
132
+ ```
133
+
134
+ ### 3. Handling Async Promises with `toast.promise`
135
+
136
+ `toast.promise` automatically creates a loading toast, keeps it alive during the asynchronous operation, and transitions smoothly into a success or error toast upon completion:
137
+
138
+ ```jsx
139
+ const uploadFile = async () => {
140
+ const uploadPromise = api.uploadDocument(file);
141
+
142
+ await toast.promise(uploadPromise, {
143
+ loading: 'Uploading document...',
144
+ success: (result) => `Document "${result.name}" uploaded successfully!`,
145
+ error: (err) => `Upload failed: ${err.message}`,
146
+ });
147
+ };
148
+ ```
149
+
150
+ ### 4. Custom Duration & Persistent Toasts
151
+
152
+ ```jsx
153
+ // Persistent toast (will not auto-dismiss)
154
+ toast.info('Please review the updated Terms of Service.', {
155
+ duration: false, // or Infinity
156
+ closeButton: true,
157
+ });
158
+
159
+ // Fast auto-dismiss
160
+ toast.success('Quick notice!', { duration: 1500 });
161
+ ```
162
+
163
+ ### 5. Custom Icons & Custom Styling
164
+
165
+ ```jsx
166
+ // Use custom SVG or React icon component
167
+ toast('Custom Star Alert', {
168
+ icon: <span>⭐</span>,
169
+ style: {
170
+ borderRadius: '16px',
171
+ border: '2px dashed #6366f1',
172
+ },
173
+ });
174
+
175
+ // Hide icon entirely
176
+ toast('Text-only notification', { icon: false });
177
+ ```
178
+
179
+ ### 6. Themes
180
+
181
+ Choose between 3 built-in themes: `light` (default), `dark`, or `colored`:
182
+
183
+ ```jsx
184
+ // Global theme on provider
185
+ <ToastProvider theme="dark">
186
+ <App />
187
+ </ToastProvider>
188
+
189
+ // Or override on individual toast
190
+ toast.error('Fatal crash!', { theme: 'colored' });
191
+ ```
192
+
193
+ ### 7. Dynamic Positioning
194
+
195
+ Position toasts dynamically per container or per toast:
196
+
197
+ ```jsx
198
+ // Set position on individual toast
199
+ toast.success('Bottom center notification', {
200
+ position: 'bottom-center',
201
+ });
202
+ ```
203
+
204
+ Available positions:
205
+ - `top-left`
206
+ - `top-center`
207
+ - `top-right` *(default)*
208
+ - `bottom-left`
209
+ - `bottom-center`
210
+ - `bottom-right`
211
+
212
+ ### 8. Programmatic Dismissal
213
+
214
+ ```jsx
215
+ const toastId = toast.loading('Processing heavy job...');
216
+
217
+ // Dismiss specific toast later
218
+ toast.dismiss(toastId);
219
+
220
+ ### 9. Swipe to Accept or Cancel Gestures
221
+
222
+ Users on mobile touch devices or desktop can swipe notification cards:
223
+ - **Swipe Right**: Triggers the `onAccept` handler (or `action.onClick`) and dismisses the toast. If no accept action is configured, swiping right dismisses the toast.
224
+ - **Swipe Left**: Triggers `onCancel` and dismisses the toast.
225
+
226
+ ```jsx
227
+ // Interactive access request with Swipe gestures
228
+ toast.info('Sarah requested access to the Analytics Dashboard.', {
229
+ title: 'Permission Request',
230
+ duration: 10000,
231
+ acceptLabel: 'Grant Access',
232
+ cancelLabel: 'Deny',
233
+ onAccept: (id) => {
234
+ console.log('Granted access!');
235
+ toast.success('Access granted to Sarah');
236
+ },
237
+ onCancel: (id) => {
238
+ console.log('Denied request');
239
+ toast.error('Access request rejected');
240
+ },
241
+ });
242
+
243
+ // Standard toast - swiping either left or right dismisses it
244
+ toast.success('Swipe in any direction to dismiss me!');
245
+ ```
246
+
247
+ ---
248
+
249
+ ## ⚙ïļ API Reference
250
+
251
+ ### `<ToastProvider>` Props
252
+
253
+ | Prop | Type | Default | Description |
254
+ | :--- | :--- | :--- | :--- |
255
+ | `position` | `string` | `'top-right'` | Default screen position for toasts. |
256
+ | `autoClose` | `number \| false` | `3000` | Auto-dismiss delay in ms. Set `false` to disable. |
257
+ | `pauseOnHover` | `boolean` | `true` | Pauses timer and countdown animation when hovered. |
258
+ | `showProgressBar`| `boolean` | `true` | Shows animated countdown progress bar. |
259
+ | `swipeable` | `boolean` | `true` | Enable touch/mouse swipe gestures globally. |
260
+ | `swipeThreshold` | `number` | `70` | Drag distance in px required to trigger swipe actions. |
261
+ | `theme` | `'light' \| 'dark' \| 'colored'` | `'light'` | Theme style applied to notifications. |
262
+ | `limit` | `number` | `undefined` | Maximum number of toasts displayed simultaneously. |
263
+ | `newestOnTop` | `boolean` | `false` | When `true`, newer toasts stack above older toasts. |
264
+ | `containerClassName` | `string` | `''` | Custom CSS class name for container. |
265
+ | `containerStyle` | `CSSProperties` | `{}` | Inline CSS styles for container wrapper. |
266
+
267
+ ### `toast(message, options)` / Toast Options
268
+
269
+ | Option | Type | Default | Description |
270
+ | :--- | :--- | :--- | :--- |
271
+ | `type` | `'default' \| 'success' \| 'error' \| 'warning' \| 'info' \| 'loading'` | `'default'` | Type variant of the toast. |
272
+ | `title` | `ReactNode` | `undefined` | Optional bold header title. |
273
+ | `duration` | `number \| false` | *Provider default* | Duration in ms before auto-dismissal. `false` disables timer. |
274
+ | `position` | `ToastPosition` | *Provider default* | Position anchor for this specific toast. |
275
+ | `theme` | `'light' \| 'dark' \| 'colored'` | *Provider default* | Theme for this specific toast. |
276
+ | `icon` | `ReactNode \| false` | *Default type icon* | Custom icon component or `false` to disable icon. |
277
+ | `action` | `{ label: string, onClick: (id) => void, dismissOnClick?: boolean }` | `undefined` | Interactive action button inside the toast. |
278
+ | `onAccept` | `(id: string) => void` | `undefined` | Callback fired when user swipes right to accept. |
279
+ | `onCancel` | `(id: string) => void` | `undefined` | Callback fired when user swipes left to cancel. |
280
+ | `acceptLabel` | `string` | `'Accept'` | Label displayed on badge when swiping right. |
281
+ | `cancelLabel` | `string` | `'Dismiss'` | Label displayed on badge when swiping left. |
282
+ | `swipeable` | `boolean` | `true` | Enable or disable swipe gestures for this toast. |
283
+ | `swipeThreshold`| `number` | `70` | Drag distance in px to trigger swipe action. |
284
+ | `showProgressBar`| `boolean` | *Provider default* | Toggle progress countdown bar for this toast. |
285
+ | `pauseOnHover` | `boolean` | *Provider default* | Pause timer on mouse enter. |
286
+ | `closeButton` | `boolean` | `true` | Show manual close 'X' button. |
287
+ | `onClose` | `(id: string) => void` | `undefined` | Callback fired when toast begins closing. |
288
+ | `className` | `string` | `''` | Custom class name for the toast item. |
289
+ | `style` | `CSSProperties` | `{}` | Custom inline style for the toast item. |
290
+
291
+ ### `useToast()` Methods
292
+
293
+ | Method | Description |
294
+ | :--- | :--- |
295
+ | `toast(message, options?)` | Displays a default toast. |
296
+ | `toast.success(message, options?)` | Displays a success toast with checkmark icon. |
297
+ | `toast.error(message, options?)` | Displays an error toast with error alert icon. |
298
+ | `toast.warning(message, options?)` | Displays a warning toast with warning triangle icon. |
299
+ | `toast.info(message, options?)` | Displays an info toast with info icon. |
300
+ | `toast.loading(message, options?)` | Displays a persistent loading toast with animated spinner. |
301
+ | `toast.promise(promise, messages, options?)` | Tracks a Promise and updates dynamically on resolution/rejection. |
302
+ | `toast.dismiss(id)` | Dismisses a specific toast with an exit animation. |
303
+ | `toast.dismissAll()` | Dismisses all currently visible toasts. |
304
+ | `toast.update(id, options)` | Updates properties of an active toast (e.g., message, type). |
305
+
306
+ ---
307
+
308
+ ## 🛠ïļ Building the Library
309
+
310
+ If you want to contribute or build the package locally:
311
+
312
+ ```bash
313
+ # 1. Install dependencies
314
+ npm install
315
+
316
+ # 2. Build the bundle for ESM, CJS, and CSS
317
+ npm run build
318
+ ```
319
+
320
+ This will produce the production-ready distribution in the `/dist` directory:
321
+ - `dist/index.esm.js` (ES Module bundle)
322
+ - `dist/index.cjs.js` (CommonJS bundle)
323
+ - `dist/index.d.ts` (TypeScript definitions)
324
+ - `dist/toast.css` (Compiled and minified CSS)
325
+
326
+ ---
327
+
328
+ ## 📄 License
329
+
330
+ MIT ÂĐ [Shyam](https://github.com/flashpop/flashpop)