react-native-earl-toastify 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/CHANGELOG.md +71 -0
- package/LICENSE +21 -0
- package/README.md +513 -0
- package/dist/Toast.d.ts +12 -0
- package/dist/Toast.d.ts.map +1 -0
- package/dist/Toast.js +143 -0
- package/dist/Toast.js.map +1 -0
- package/dist/ToastContainer.d.ts +12 -0
- package/dist/ToastContainer.d.ts.map +1 -0
- package/dist/ToastContainer.js +46 -0
- package/dist/ToastContainer.js.map +1 -0
- package/dist/ToastProvider.d.ts +22 -0
- package/dist/ToastProvider.d.ts.map +1 -0
- package/dist/ToastProvider.js +163 -0
- package/dist/ToastProvider.js.map +1 -0
- package/dist/animations.d.ts +54 -0
- package/dist/animations.d.ts.map +1 -0
- package/dist/animations.js +118 -0
- package/dist/animations.js.map +1 -0
- package/dist/icons.d.ts +12 -0
- package/dist/icons.d.ts.map +1 -0
- package/dist/icons.js +110 -0
- package/dist/icons.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/styles.d.ts +63 -0
- package/dist/styles.d.ts.map +1 -0
- package/dist/styles.js +182 -0
- package/dist/styles.js.map +1 -0
- package/dist/types.d.ts +100 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/useToast.d.ts +40 -0
- package/dist/useToast.d.ts.map +1 -0
- package/dist/useToast.js +48 -0
- package/dist/useToast.js.map +1 -0
- package/dist/useToastAnimation.d.ts +24 -0
- package/dist/useToastAnimation.d.ts.map +1 -0
- package/dist/useToastAnimation.js +59 -0
- package/dist/useToastAnimation.js.map +1 -0
- package/package.json +58 -0
- package/src/Toast.tsx +250 -0
- package/src/ToastContainer.tsx +70 -0
- package/src/ToastProvider.tsx +271 -0
- package/src/animations.ts +161 -0
- package/src/icons.tsx +152 -0
- package/src/index.ts +41 -0
- package/src/styles.ts +208 -0
- package/src/types.ts +157 -0
- package/src/useToast.ts +53 -0
- package/src/useToastAnimation.ts +108 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [1.0.0] - 2026-01-17
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- 🎉 Initial release of react-native-earl-toastify
|
|
13
|
+
|
|
14
|
+
#### Toast Types
|
|
15
|
+
|
|
16
|
+
- `success` - Green themed toast for successful operations
|
|
17
|
+
- `warning` - Amber themed toast for warnings
|
|
18
|
+
- `error` - Red themed toast for errors
|
|
19
|
+
- `info` - Blue themed toast for informational messages
|
|
20
|
+
- `default` - Gray themed neutral toast
|
|
21
|
+
- `custom` - Fully customizable toast with custom colors
|
|
22
|
+
|
|
23
|
+
#### Animations
|
|
24
|
+
|
|
25
|
+
- `fade` - Smooth opacity fade in/out
|
|
26
|
+
- `up` - Slide up animation (from bottom for bottom position, to top for top position)
|
|
27
|
+
- `down` - Slide down animation (from top for top position, to bottom for bottom position)
|
|
28
|
+
- `left` - Slide from right to left
|
|
29
|
+
- `right` - Slide from left to right
|
|
30
|
+
- `none` - Instant appear/disappear without animation
|
|
31
|
+
|
|
32
|
+
#### Positioning
|
|
33
|
+
|
|
34
|
+
- `top` - Full-width positioning at top of screen with status bar padding
|
|
35
|
+
- `bottom` - Full-width positioning at bottom with home indicator padding
|
|
36
|
+
- `center` - Centered positioning with rounded corners and margins
|
|
37
|
+
|
|
38
|
+
#### Configuration Options
|
|
39
|
+
|
|
40
|
+
- `title` - Optional title (larger, bolder text displayed above the message)
|
|
41
|
+
- `message` - Main text or description (smaller when title is present)
|
|
42
|
+
- Flexible API: `toast.success("message")` OR `toast.success("title", "description")`
|
|
43
|
+
- `duration` - Auto-dismiss duration in milliseconds (0 for no auto-dismiss)
|
|
44
|
+
- `dismissable` - Toggle tap-to-dismiss functionality
|
|
45
|
+
- `icon` - Custom icon support (works with any icon library like lucide-react-native)
|
|
46
|
+
- `hideIcon` - Option to hide default icons
|
|
47
|
+
- `backgroundColor`, `textColor`, `borderColor` - Custom color overrides
|
|
48
|
+
- `style`, `textStyle` - Custom style overrides
|
|
49
|
+
- `onShow`, `onHide`, `onPress` - Event callbacks
|
|
50
|
+
|
|
51
|
+
#### Accessibility
|
|
52
|
+
|
|
53
|
+
- WCAG 2.1 AA compliant color schemes (4.5:1 contrast ratio)
|
|
54
|
+
- Screen reader announcements via AccessibilityInfo
|
|
55
|
+
- Proper accessibility roles and live regions
|
|
56
|
+
- Clear accessibility hints for dismissable toasts
|
|
57
|
+
|
|
58
|
+
#### API
|
|
59
|
+
|
|
60
|
+
- `ToastProvider` - Context provider component
|
|
61
|
+
- `useToast` - Hook for showing toasts with `success()`, `warning()`, `error()`, `info()`, `show()`
|
|
62
|
+
- `hide(id)` - Hide specific toast by ID
|
|
63
|
+
- `hideAll()` - Hide all visible toasts
|
|
64
|
+
- Full TypeScript support with exported types
|
|
65
|
+
|
|
66
|
+
#### Global Toast Utility Pattern
|
|
67
|
+
|
|
68
|
+
- Documented pattern for creating a global Toast utility
|
|
69
|
+
- Supports calling `Toast.success()`, `Toast.error()` etc. from anywhere in your app
|
|
70
|
+
- Customizable defaults for colors, animations, icons per toast type
|
|
71
|
+
- No deprecated APIs - uses simple variable-based context storage
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Rin
|
|
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,513 @@
|
|
|
1
|
+
# react-native-earl-toastify
|
|
2
|
+
|
|
3
|
+
A beautiful, customizable toast notification library for React Native with smooth animations, multiple toast types, and full accessibility support.
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+

|
|
8
|
+

|
|
9
|
+
|
|
10
|
+
## ✨ Features
|
|
11
|
+
|
|
12
|
+
- 🎬 **6 Animation Types**: fade, slide-up, slide-down, slide-left, slide-right, none
|
|
13
|
+
- 🎨 **5 Toast Types**: success, warning, error, info, default + fully customizable
|
|
14
|
+
- 📍 **3 Positions**: top, bottom, center
|
|
15
|
+
- ♿ **Accessible**: WCAG 2.1 AA compliant color schemes & screen reader support
|
|
16
|
+
- 🎯 **Always on Top**: Toasts render above all other content
|
|
17
|
+
- 🔧 **Highly Configurable**: duration, dismissable, custom icons, custom styles
|
|
18
|
+
- 📱 **Full-Width Edge Styling**: No rounded corners for top/bottom toasts
|
|
19
|
+
- 🪶 **Zero Dependencies**: Uses only React Native's built-in Animated API
|
|
20
|
+
|
|
21
|
+
## 📦 Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install react-native-earl-toastify
|
|
25
|
+
# or
|
|
26
|
+
yarn add react-native-earl-toastify
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## 🚀 Quick Start
|
|
30
|
+
|
|
31
|
+
### 1. Wrap your app with ToastProvider
|
|
32
|
+
|
|
33
|
+
```tsx
|
|
34
|
+
import { ToastProvider } from "react-native-earl-toastify";
|
|
35
|
+
|
|
36
|
+
export default function App() {
|
|
37
|
+
return (
|
|
38
|
+
<ToastProvider>
|
|
39
|
+
<YourApp />
|
|
40
|
+
</ToastProvider>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### 2. Use the useToast hook
|
|
46
|
+
|
|
47
|
+
```tsx
|
|
48
|
+
import { useToast } from "react-native-earl-toastify";
|
|
49
|
+
|
|
50
|
+
function MyComponent() {
|
|
51
|
+
const toast = useToast();
|
|
52
|
+
|
|
53
|
+
const handleSuccess = () => {
|
|
54
|
+
toast.success("Operation completed successfully!");
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const handleError = () => {
|
|
58
|
+
toast.error("Something went wrong");
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<View>
|
|
63
|
+
<Button title="Success" onPress={handleSuccess} />
|
|
64
|
+
<Button title="Error" onPress={handleError} />
|
|
65
|
+
</View>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## 🛠️ Creating a Toast Utility (Recommended)
|
|
71
|
+
|
|
72
|
+
For easier usage across your app, create a utility file that exposes toast functions globally with **your own custom defaults**:
|
|
73
|
+
|
|
74
|
+
### 1. Create `utils/Toast.tsx`
|
|
75
|
+
|
|
76
|
+
```tsx
|
|
77
|
+
// utils/Toast.tsx
|
|
78
|
+
import { ToastContextValue, ToastConfig } from "react-native-earl-toastify";
|
|
79
|
+
// Optional: import your icon library
|
|
80
|
+
// import { CheckCircle, AlertTriangle, XCircle, Info } from "lucide-react-native";
|
|
81
|
+
|
|
82
|
+
// ============================================
|
|
83
|
+
// Store toast context reference (simple variable)
|
|
84
|
+
// ============================================
|
|
85
|
+
let toastContext: ToastContextValue | null = null;
|
|
86
|
+
|
|
87
|
+
export const setToastContext = (context: ToastContextValue) => {
|
|
88
|
+
toastContext = context;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// ============================================
|
|
92
|
+
// 🎨 CUSTOMIZE YOUR TOAST DEFAULTS HERE
|
|
93
|
+
// ============================================
|
|
94
|
+
|
|
95
|
+
const CUSTOM_DEFAULTS: Record<string, Partial<ToastConfig>> = {
|
|
96
|
+
// Custom success style - your own green, animation, etc.
|
|
97
|
+
success: {
|
|
98
|
+
backgroundColor: "#D1FAE5", // Light green
|
|
99
|
+
textColor: "#065F46", // Dark green
|
|
100
|
+
borderColor: "#10B981", // Green border
|
|
101
|
+
animationIn: "up",
|
|
102
|
+
animationOut: "down",
|
|
103
|
+
position: "bottom",
|
|
104
|
+
duration: 3000,
|
|
105
|
+
// icon: <CheckCircle color="#10B981" size={20} />,
|
|
106
|
+
},
|
|
107
|
+
|
|
108
|
+
// Custom error style
|
|
109
|
+
error: {
|
|
110
|
+
backgroundColor: "#FEE2E2", // Light red
|
|
111
|
+
textColor: "#991B1B", // Dark red
|
|
112
|
+
borderColor: "#EF4444", // Red border
|
|
113
|
+
animationIn: "fade",
|
|
114
|
+
animationOut: "fade",
|
|
115
|
+
position: "top",
|
|
116
|
+
duration: 5000,
|
|
117
|
+
// icon: <XCircle color="#EF4444" size={20} />,
|
|
118
|
+
},
|
|
119
|
+
|
|
120
|
+
// Custom warning style
|
|
121
|
+
warning: {
|
|
122
|
+
backgroundColor: "#FEF3C7", // Light amber
|
|
123
|
+
textColor: "#92400E", // Dark amber
|
|
124
|
+
borderColor: "#F59E0B", // Amber border
|
|
125
|
+
animationIn: "right",
|
|
126
|
+
animationOut: "left",
|
|
127
|
+
position: "top",
|
|
128
|
+
duration: 4000,
|
|
129
|
+
// icon: <AlertTriangle color="#F59E0B" size={20} />,
|
|
130
|
+
},
|
|
131
|
+
|
|
132
|
+
// Custom info style
|
|
133
|
+
info: {
|
|
134
|
+
backgroundColor: "#DBEAFE", // Light blue
|
|
135
|
+
textColor: "#1E40AF", // Dark blue
|
|
136
|
+
borderColor: "#3B82F6", // Blue border
|
|
137
|
+
animationIn: "left",
|
|
138
|
+
animationOut: "right",
|
|
139
|
+
position: "top",
|
|
140
|
+
duration: 3000,
|
|
141
|
+
// icon: <Info color="#3B82F6" size={20} />,
|
|
142
|
+
},
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
// ============================================
|
|
146
|
+
// Helper to parse flexible arguments
|
|
147
|
+
// ============================================
|
|
148
|
+
const parseArgs = (
|
|
149
|
+
titleOrMessage: string,
|
|
150
|
+
descriptionOrConfig?: string | Partial<ToastConfig>,
|
|
151
|
+
config?: Partial<ToastConfig>,
|
|
152
|
+
): { title?: string; message: string; config?: Partial<ToastConfig> } => {
|
|
153
|
+
if (typeof descriptionOrConfig === "string") {
|
|
154
|
+
return { title: titleOrMessage, message: descriptionOrConfig, config };
|
|
155
|
+
}
|
|
156
|
+
return { message: titleOrMessage, config: descriptionOrConfig };
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
// ============================================
|
|
160
|
+
// Toast utility with custom defaults
|
|
161
|
+
// ============================================
|
|
162
|
+
const Toast = {
|
|
163
|
+
success: (
|
|
164
|
+
titleOrMessage: string,
|
|
165
|
+
descriptionOrConfig?: string | Partial<ToastConfig>,
|
|
166
|
+
config?: Partial<ToastConfig>,
|
|
167
|
+
) => {
|
|
168
|
+
const {
|
|
169
|
+
title,
|
|
170
|
+
message,
|
|
171
|
+
config: cfg,
|
|
172
|
+
} = parseArgs(titleOrMessage, descriptionOrConfig, config);
|
|
173
|
+
toastContext?.show({
|
|
174
|
+
...CUSTOM_DEFAULTS.success,
|
|
175
|
+
...cfg,
|
|
176
|
+
title,
|
|
177
|
+
message,
|
|
178
|
+
type: "custom", // Use custom to apply our colors
|
|
179
|
+
});
|
|
180
|
+
},
|
|
181
|
+
|
|
182
|
+
error: (
|
|
183
|
+
titleOrMessage: string,
|
|
184
|
+
descriptionOrConfig?: string | Partial<ToastConfig>,
|
|
185
|
+
config?: Partial<ToastConfig>,
|
|
186
|
+
) => {
|
|
187
|
+
const {
|
|
188
|
+
title,
|
|
189
|
+
message,
|
|
190
|
+
config: cfg,
|
|
191
|
+
} = parseArgs(titleOrMessage, descriptionOrConfig, config);
|
|
192
|
+
toastContext?.show({
|
|
193
|
+
...CUSTOM_DEFAULTS.error,
|
|
194
|
+
...cfg,
|
|
195
|
+
title,
|
|
196
|
+
message,
|
|
197
|
+
type: "custom",
|
|
198
|
+
});
|
|
199
|
+
},
|
|
200
|
+
|
|
201
|
+
warning: (
|
|
202
|
+
titleOrMessage: string,
|
|
203
|
+
descriptionOrConfig?: string | Partial<ToastConfig>,
|
|
204
|
+
config?: Partial<ToastConfig>,
|
|
205
|
+
) => {
|
|
206
|
+
const {
|
|
207
|
+
title,
|
|
208
|
+
message,
|
|
209
|
+
config: cfg,
|
|
210
|
+
} = parseArgs(titleOrMessage, descriptionOrConfig, config);
|
|
211
|
+
toastContext?.show({
|
|
212
|
+
...CUSTOM_DEFAULTS.warning,
|
|
213
|
+
...cfg,
|
|
214
|
+
title,
|
|
215
|
+
message,
|
|
216
|
+
type: "custom",
|
|
217
|
+
});
|
|
218
|
+
},
|
|
219
|
+
|
|
220
|
+
info: (
|
|
221
|
+
titleOrMessage: string,
|
|
222
|
+
descriptionOrConfig?: string | Partial<ToastConfig>,
|
|
223
|
+
config?: Partial<ToastConfig>,
|
|
224
|
+
) => {
|
|
225
|
+
const {
|
|
226
|
+
title,
|
|
227
|
+
message,
|
|
228
|
+
config: cfg,
|
|
229
|
+
} = parseArgs(titleOrMessage, descriptionOrConfig, config);
|
|
230
|
+
toastContext?.show({
|
|
231
|
+
...CUSTOM_DEFAULTS.info,
|
|
232
|
+
...cfg,
|
|
233
|
+
title,
|
|
234
|
+
message,
|
|
235
|
+
type: "custom",
|
|
236
|
+
});
|
|
237
|
+
},
|
|
238
|
+
|
|
239
|
+
// Generic show for full customization
|
|
240
|
+
show: (config: ToastConfig) => {
|
|
241
|
+
toastContext?.show(config);
|
|
242
|
+
},
|
|
243
|
+
|
|
244
|
+
hide: (id: string) => {
|
|
245
|
+
toastContext?.hide(id);
|
|
246
|
+
},
|
|
247
|
+
|
|
248
|
+
hideAll: () => {
|
|
249
|
+
toastContext?.hideAll();
|
|
250
|
+
},
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
export default Toast;
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
### 2. Create a wrapper component `components/ToastWrapper.tsx`
|
|
257
|
+
|
|
258
|
+
```tsx
|
|
259
|
+
// components/ToastWrapper.tsx
|
|
260
|
+
import React, { useEffect } from "react";
|
|
261
|
+
import { useToast } from "react-native-earl-toastify";
|
|
262
|
+
import { setToastContext } from "../utils/Toast";
|
|
263
|
+
|
|
264
|
+
export const ToastWrapper: React.FC<{ children: React.ReactNode }> = ({
|
|
265
|
+
children,
|
|
266
|
+
}) => {
|
|
267
|
+
const toast = useToast();
|
|
268
|
+
|
|
269
|
+
useEffect(() => {
|
|
270
|
+
// Set the toast context when component mounts
|
|
271
|
+
setToastContext(toast);
|
|
272
|
+
}, [toast]);
|
|
273
|
+
|
|
274
|
+
return <>{children}</>;
|
|
275
|
+
};
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
### 3. Update your App.tsx
|
|
279
|
+
|
|
280
|
+
```tsx
|
|
281
|
+
// App.tsx
|
|
282
|
+
import { ToastProvider } from "react-native-earl-toastify";
|
|
283
|
+
import { ToastWrapper } from "./components/ToastWrapper";
|
|
284
|
+
|
|
285
|
+
export default function App() {
|
|
286
|
+
return (
|
|
287
|
+
<ToastProvider>
|
|
288
|
+
<ToastWrapper>
|
|
289
|
+
<YourApp />
|
|
290
|
+
</ToastWrapper>
|
|
291
|
+
</ToastProvider>
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
### 4. Use anywhere in your app!
|
|
297
|
+
|
|
298
|
+
```tsx
|
|
299
|
+
// ANY file - no hooks needed!
|
|
300
|
+
import Toast from "../utils/Toast";
|
|
301
|
+
|
|
302
|
+
// Simple message (no title)
|
|
303
|
+
Toast.success("Data loaded successfully!");
|
|
304
|
+
|
|
305
|
+
// With title + description
|
|
306
|
+
Toast.success("Success!", "Data loaded successfully");
|
|
307
|
+
Toast.error("Error", "Failed to load data");
|
|
308
|
+
Toast.warning("Warning", "Please review before submitting");
|
|
309
|
+
Toast.info("Info", "New update available");
|
|
310
|
+
|
|
311
|
+
// With title, description, AND config
|
|
312
|
+
Toast.success("Uploaded!", "Your file is ready", { position: "bottom" });
|
|
313
|
+
|
|
314
|
+
// Custom toast
|
|
315
|
+
Toast.show({
|
|
316
|
+
message: "Custom notification",
|
|
317
|
+
type: "custom",
|
|
318
|
+
backgroundColor: "#8B5CF6",
|
|
319
|
+
textColor: "#FFFFFF",
|
|
320
|
+
position: "bottom",
|
|
321
|
+
animationIn: "up",
|
|
322
|
+
});
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
> [!TIP]
|
|
326
|
+
> This pattern lets you call `Toast.success()`, `Toast.error()`, etc. from **anywhere** - including utility functions, API handlers, and non-component files!
|
|
327
|
+
|
|
328
|
+
### ToastProvider Props
|
|
329
|
+
|
|
330
|
+
| Prop | Type | Default | Description |
|
|
331
|
+
| -------- | --------------------- | ------- | ----------------------------------- |
|
|
332
|
+
| `config` | `ToastProviderConfig` | `{}` | Global configuration for all toasts |
|
|
333
|
+
|
|
334
|
+
#### ToastProviderConfig
|
|
335
|
+
|
|
336
|
+
```typescript
|
|
337
|
+
interface ToastProviderConfig {
|
|
338
|
+
defaultPosition?: "top" | "bottom" | "center"; // Default: 'top'
|
|
339
|
+
defaultDuration?: number; // Default: 3000 (ms)
|
|
340
|
+
defaultAnimationIn?: ToastAnimation; // Default: 'fade'
|
|
341
|
+
defaultAnimationOut?: ToastAnimation; // Default: 'fade'
|
|
342
|
+
defaultAnimationDuration?: number; // Default: 300 (ms)
|
|
343
|
+
maxToasts?: number; // Default: 5
|
|
344
|
+
}
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
### useToast Hook
|
|
348
|
+
|
|
349
|
+
```typescript
|
|
350
|
+
const toast = useToast();
|
|
351
|
+
|
|
352
|
+
// Quick methods
|
|
353
|
+
toast.success(message: string, config?: Partial<ToastConfig>);
|
|
354
|
+
toast.warning(message: string, config?: Partial<ToastConfig>);
|
|
355
|
+
toast.error(message: string, config?: Partial<ToastConfig>);
|
|
356
|
+
toast.info(message: string, config?: Partial<ToastConfig>);
|
|
357
|
+
|
|
358
|
+
// Custom toast
|
|
359
|
+
toast.show(config: ToastConfig);
|
|
360
|
+
|
|
361
|
+
// Control methods
|
|
362
|
+
toast.hide(id: string); // Hide specific toast
|
|
363
|
+
toast.hideAll(); // Hide all toasts
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
### ToastConfig
|
|
367
|
+
|
|
368
|
+
| Option | Type | Default | Description |
|
|
369
|
+
| ------------------- | ---------------------------------------------------------------------- | ------------ | --------------------------------------------- |
|
|
370
|
+
| `message` | `string` | **required** | Toast message |
|
|
371
|
+
| `type` | `'success' \| 'warning' \| 'error' \| 'info' \| 'default' \| 'custom'` | `'default'` | Toast type |
|
|
372
|
+
| `position` | `'top' \| 'bottom' \| 'center'` | `'top'` | Screen position |
|
|
373
|
+
| `duration` | `number` | `3000` | Auto-dismiss time in ms (0 = no auto-dismiss) |
|
|
374
|
+
| `animationIn` | `ToastAnimation` | `'fade'` | Enter animation |
|
|
375
|
+
| `animationOut` | `ToastAnimation` | `'fade'` | Exit animation |
|
|
376
|
+
| `animationDuration` | `number` | `300` | Animation duration in ms |
|
|
377
|
+
| `dismissable` | `boolean` | `true` | Can dismiss by tapping |
|
|
378
|
+
| `icon` | `ReactNode` | - | Custom icon element |
|
|
379
|
+
| `hideIcon` | `boolean` | `false` | Hide the icon |
|
|
380
|
+
| `backgroundColor` | `string` | - | Custom background color |
|
|
381
|
+
| `textColor` | `string` | - | Custom text color |
|
|
382
|
+
| `borderColor` | `string` | - | Custom border color |
|
|
383
|
+
| `style` | `ViewStyle` | - | Custom container style |
|
|
384
|
+
| `textStyle` | `TextStyle` | - | Custom text style |
|
|
385
|
+
| `onShow` | `() => void` | - | Callback when shown |
|
|
386
|
+
| `onHide` | `() => void` | - | Callback when hidden |
|
|
387
|
+
| `onPress` | `() => void` | - | Callback when pressed |
|
|
388
|
+
|
|
389
|
+
### Animation Types
|
|
390
|
+
|
|
391
|
+
```typescript
|
|
392
|
+
type ToastAnimation = "fade" | "up" | "down" | "left" | "right" | "none";
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
| Animation | Description |
|
|
396
|
+
| --------- | ------------------------ |
|
|
397
|
+
| `fade` | Fade in/out |
|
|
398
|
+
| `up` | Slide from bottom |
|
|
399
|
+
| `down` | Slide from top |
|
|
400
|
+
| `left` | Slide from right |
|
|
401
|
+
| `right` | Slide from left |
|
|
402
|
+
| `none` | Instant appear/disappear |
|
|
403
|
+
|
|
404
|
+
## 🎨 Examples
|
|
405
|
+
|
|
406
|
+
### Custom Styled Toast
|
|
407
|
+
|
|
408
|
+
```tsx
|
|
409
|
+
toast.show({
|
|
410
|
+
message: "Custom purple toast!",
|
|
411
|
+
type: "custom",
|
|
412
|
+
backgroundColor: "#8B5CF6",
|
|
413
|
+
textColor: "#FFFFFF",
|
|
414
|
+
borderColor: "#7C3AED",
|
|
415
|
+
position: "bottom",
|
|
416
|
+
animationIn: "up",
|
|
417
|
+
animationOut: "down",
|
|
418
|
+
});
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
### With Custom Icon (react-native-lucide)
|
|
422
|
+
|
|
423
|
+
```tsx
|
|
424
|
+
import { CheckCircle } from "lucide-react-native";
|
|
425
|
+
|
|
426
|
+
toast.success("Saved!", {
|
|
427
|
+
icon: <CheckCircle color="#10B981" size={20} />,
|
|
428
|
+
});
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
### Non-Dismissable with Long Duration
|
|
432
|
+
|
|
433
|
+
```tsx
|
|
434
|
+
toast.info("Please wait...", {
|
|
435
|
+
dismissable: false,
|
|
436
|
+
duration: 0, // Won't auto-dismiss
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
// Later, dismiss programmatically
|
|
440
|
+
const id = toast.info("Loading...", { dismissable: false, duration: 0 });
|
|
441
|
+
// ... after loading complete
|
|
442
|
+
toast.hide(id);
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
### Centered Toast with Callback
|
|
446
|
+
|
|
447
|
+
```tsx
|
|
448
|
+
toast.warning("Session expiring soon", {
|
|
449
|
+
position: "center",
|
|
450
|
+
duration: 5000,
|
|
451
|
+
onPress: () => {
|
|
452
|
+
// Handle press - e.g., refresh session
|
|
453
|
+
refreshSession();
|
|
454
|
+
},
|
|
455
|
+
onHide: () => {
|
|
456
|
+
console.log("Toast dismissed");
|
|
457
|
+
},
|
|
458
|
+
});
|
|
459
|
+
```
|
|
460
|
+
|
|
461
|
+
### Different Animations
|
|
462
|
+
|
|
463
|
+
```tsx
|
|
464
|
+
// Slide from bottom
|
|
465
|
+
toast.success("Uploaded!", {
|
|
466
|
+
position: "bottom",
|
|
467
|
+
animationIn: "up",
|
|
468
|
+
animationOut: "down",
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
// Slide from side
|
|
472
|
+
toast.info("New message", {
|
|
473
|
+
animationIn: "right",
|
|
474
|
+
animationOut: "left",
|
|
475
|
+
});
|
|
476
|
+
|
|
477
|
+
// Instant (no animation)
|
|
478
|
+
toast.error("Error!", {
|
|
479
|
+
animationIn: "none",
|
|
480
|
+
animationOut: "none",
|
|
481
|
+
});
|
|
482
|
+
```
|
|
483
|
+
|
|
484
|
+
## 🎯 Positioning Behavior
|
|
485
|
+
|
|
486
|
+
| Position | Behavior |
|
|
487
|
+
| -------- | ----------------------------------------------------------- |
|
|
488
|
+
| `top` | Full-width, no rounded corners, accounts for status bar |
|
|
489
|
+
| `bottom` | Full-width, no rounded corners, accounts for home indicator |
|
|
490
|
+
| `center` | Centered with margins and rounded corners |
|
|
491
|
+
|
|
492
|
+
## 🎨 Default Color Schemes
|
|
493
|
+
|
|
494
|
+
| Type | Background | Text | Border |
|
|
495
|
+
| ------- | ---------- | --------- | --------- |
|
|
496
|
+
| Success | `#ECFDF5` | `#065F46` | `#10B981` |
|
|
497
|
+
| Warning | `#FFFBEB` | `#92400E` | `#F59E0B` |
|
|
498
|
+
| Error | `#FEF2F2` | `#991B1B` | `#EF4444` |
|
|
499
|
+
| Info | `#EFF6FF` | `#1E40AF` | `#3B82F6` |
|
|
500
|
+
| Default | `#F9FAFB` | `#374151` | `#D1D5DB` |
|
|
501
|
+
|
|
502
|
+
All color combinations meet **WCAG 2.1 AA** contrast requirements (4.5:1 minimum).
|
|
503
|
+
|
|
504
|
+
## ♿ Accessibility
|
|
505
|
+
|
|
506
|
+
- All toasts are announced to screen readers via `AccessibilityInfo.announceForAccessibility`
|
|
507
|
+
- Proper `accessibilityRole="alert"` and `accessibilityLiveRegion="polite"` attributes
|
|
508
|
+
- Dismissable toasts have clear accessibility hints
|
|
509
|
+
- Color contrasts meet WCAG 2.1 AA standards
|
|
510
|
+
|
|
511
|
+
## 📄 License
|
|
512
|
+
|
|
513
|
+
MIT © Earl
|
package/dist/Toast.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Toast as ToastData, ToastPosition } from "./types";
|
|
3
|
+
export interface ToastProps {
|
|
4
|
+
toast: ToastData;
|
|
5
|
+
position: ToastPosition;
|
|
6
|
+
onHide: (id: string) => void;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Individual Toast component with animations
|
|
10
|
+
*/
|
|
11
|
+
export declare const Toast: React.FC<ToastProps>;
|
|
12
|
+
//# sourceMappingURL=Toast.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Toast.d.ts","sourceRoot":"","sources":["../src/Toast.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAyC,MAAM,OAAO,CAAC;AAS9D,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,aAAa,EAAkB,MAAM,SAAS,CAAC;AAe5E,MAAM,WAAW,UAAU;IAC1B,KAAK,EAAE,SAAS,CAAC;IACjB,QAAQ,EAAE,aAAa,CAAC;IACxB,MAAM,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;CAC7B;AAED;;GAEG;AACH,eAAO,MAAM,KAAK,EAAE,KAAK,CAAC,EAAE,CAAC,UAAU,CAgNtC,CAAC"}
|