react-native-notitoast 0.0.0-stage → 2.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.
Files changed (46) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +201 -2
  3. package/lib/commonjs/ToastItem.js +504 -0
  4. package/lib/commonjs/ToastItem.js.map +1 -0
  5. package/lib/commonjs/ToastProvider.js +84 -0
  6. package/lib/commonjs/ToastProvider.js.map +1 -0
  7. package/lib/commonjs/index.js +26 -0
  8. package/lib/commonjs/index.js.map +1 -0
  9. package/lib/commonjs/package.json +1 -0
  10. package/lib/commonjs/theme.js +41 -0
  11. package/lib/commonjs/theme.js.map +1 -0
  12. package/lib/commonjs/toast.js +39 -0
  13. package/lib/commonjs/toast.js.map +1 -0
  14. package/lib/commonjs/types.js +6 -0
  15. package/lib/commonjs/types.js.map +1 -0
  16. package/lib/module/ToastItem.js +500 -0
  17. package/lib/module/ToastItem.js.map +1 -0
  18. package/lib/module/ToastProvider.js +80 -0
  19. package/lib/module/ToastProvider.js.map +1 -0
  20. package/lib/module/index.js +5 -0
  21. package/lib/module/index.js.map +1 -0
  22. package/lib/module/theme.js +37 -0
  23. package/lib/module/theme.js.map +1 -0
  24. package/lib/module/toast.js +33 -0
  25. package/lib/module/toast.js.map +1 -0
  26. package/lib/module/types.js +4 -0
  27. package/lib/module/types.js.map +1 -0
  28. package/lib/typescript/src/ToastItem.d.ts +12 -0
  29. package/lib/typescript/src/ToastItem.d.ts.map +1 -0
  30. package/lib/typescript/src/ToastProvider.d.ts +7 -0
  31. package/lib/typescript/src/ToastProvider.d.ts.map +1 -0
  32. package/lib/typescript/src/index.d.ts +6 -0
  33. package/lib/typescript/src/index.d.ts.map +1 -0
  34. package/lib/typescript/src/theme.d.ts +21 -0
  35. package/lib/typescript/src/theme.d.ts.map +1 -0
  36. package/lib/typescript/src/toast.d.ts +23 -0
  37. package/lib/typescript/src/toast.d.ts.map +1 -0
  38. package/lib/typescript/src/types.d.ts +93 -0
  39. package/lib/typescript/src/types.d.ts.map +1 -0
  40. package/package.json +77 -6
  41. package/src/ToastItem.tsx +597 -0
  42. package/src/ToastProvider.tsx +93 -0
  43. package/src/index.ts +14 -0
  44. package/src/theme.ts +39 -0
  45. package/src/toast.ts +51 -0
  46. package/src/types.ts +109 -0
package/src/theme.ts ADDED
@@ -0,0 +1,39 @@
1
+ import type { ToastType } from './types';
2
+
3
+ export const typeColors: Record<ToastType, string> = {
4
+ success: '#16A34A',
5
+ error: '#DC2626',
6
+ warning: '#F59E0B',
7
+ info: '#2563EB',
8
+ };
9
+
10
+ export const typeGlyphs: Record<ToastType, string> = {
11
+ success: '✓',
12
+ error: '✕',
13
+ warning: '!',
14
+ info: 'i',
15
+ };
16
+
17
+ export const defaultDurations: Record<ToastType, number> = {
18
+ success: 3500,
19
+ error: 5000,
20
+ warning: 4000,
21
+ info: 3500,
22
+ };
23
+
24
+ export const palettes = {
25
+ light: {
26
+ card: '#FFFFFF',
27
+ border: 'rgba(0,0,0,0.06)',
28
+ title: '#111827',
29
+ message: '#4B5563',
30
+ track: 'rgba(0,0,0,0.05)',
31
+ },
32
+ dark: {
33
+ card: '#1F2023',
34
+ border: 'rgba(255,255,255,0.08)',
35
+ title: '#F9FAFB',
36
+ message: '#D1D5DB',
37
+ track: 'rgba(255,255,255,0.08)',
38
+ },
39
+ };
package/src/toast.ts ADDED
@@ -0,0 +1,51 @@
1
+ import type { ToastOptions, ToastType } from './types';
2
+
3
+ interface Handler {
4
+ show: (options: ToastOptions) => string;
5
+ hide: (id?: string) => void;
6
+ hideAll: () => void;
7
+ }
8
+
9
+ let handler: Handler | null = null;
10
+
11
+ /** @internal */
12
+ export function setToastHandler(next: Handler | null) {
13
+ handler = next;
14
+ }
15
+
16
+ function show(options: ToastOptions): string {
17
+ if (!handler) {
18
+ console.warn(
19
+ '[react-native-notitoast] <ToastProvider> is not mounted. Wrap your app root with it.'
20
+ );
21
+ return '';
22
+ }
23
+ return handler.show(options);
24
+ }
25
+
26
+ type ShortcutOptions = Omit<ToastOptions, 'type' | 'title' | 'message'>;
27
+ type Shortcut = (
28
+ title: string,
29
+ message?: string,
30
+ options?: ShortcutOptions
31
+ ) => string;
32
+
33
+ const make =
34
+ (type: ToastType): Shortcut =>
35
+ (title, message, options) =>
36
+ show({ ...options, type, title, message });
37
+
38
+ export const toast = Object.assign(show, {
39
+ success: make('success'),
40
+ error: make('error'),
41
+ warning: make('warning'),
42
+ info: make('info'),
43
+ hide: (id?: string) => handler?.hide(id),
44
+ hideAll: () => handler?.hideAll(),
45
+ });
46
+
47
+ export type Toast = typeof toast;
48
+
49
+ export function useToast(): Toast {
50
+ return toast;
51
+ }
package/src/types.ts ADDED
@@ -0,0 +1,109 @@
1
+ import type {
2
+ DimensionValue,
3
+ ImageSourcePropType,
4
+ StyleProp,
5
+ TextStyle,
6
+ ViewStyle,
7
+ } from 'react-native';
8
+
9
+ export type ToastType = 'success' | 'error' | 'warning' | 'info';
10
+ export type ToastPosition = 'top' | 'bottom';
11
+ export type ToastTheme = 'light' | 'dark' | 'system';
12
+ export type ToastVariant = 'default' | 'tinted' | 'filled';
13
+ export type ToastImagePosition = 'left' | 'right';
14
+
15
+ /**
16
+ * Look & behaviour options. Every one of these can be set globally on
17
+ * <ToastProvider> and overridden per toast.
18
+ */
19
+ export interface ToastAppearance {
20
+ position?: ToastPosition;
21
+ /** Milliseconds before auto-hide. 0 = stays until dismissed. */
22
+ duration?: number;
23
+ /** Thin countdown bar at the bottom. Default: false. */
24
+ showProgress?: boolean;
25
+
26
+ /** Master switch for swipe-to-dismiss. `false` turns off every direction. Default: true. */
27
+ swipeable?: boolean;
28
+ /** Swipe left to dismiss. Default: true. */
29
+ swipeLeft?: boolean;
30
+ /** Swipe right to dismiss. Default: true. */
31
+ swipeRight?: boolean;
32
+ /** Swipe up to dismiss. Default: true for top toasts, false for bottom toasts. */
33
+ swipeUp?: boolean;
34
+ /** Swipe down to dismiss. Default: true for bottom toasts, false for top toasts. */
35
+ swipeDown?: boolean;
36
+
37
+ /** Show the success/error/warning/info icon. Default: true. */
38
+ showIcon?: boolean;
39
+ /** Small type badge on the corner of a left image / app icon. Default: true. */
40
+ showTypeBadge?: boolean;
41
+ /** Colored stripe on the left edge. Default: shown automatically when there is no left icon. */
42
+ showAccentBar?: boolean;
43
+ /** Where `image` goes. Default: 'right'. */
44
+ imagePosition?: ToastImagePosition;
45
+ /** App icon shown on the left (like a basic Android toast). Leave unset to hide. */
46
+ appIcon?: ImageSourcePropType;
47
+
48
+ /** 'default' = plain card, 'tinted' = soft type color, 'filled' = solid type color. */
49
+ variant?: ToastVariant;
50
+ backgroundColor?: string;
51
+ borderColor?: string;
52
+ titleColor?: string;
53
+ messageColor?: string;
54
+
55
+ /** Max lines for the title. Default 1. 0 = unlimited. */
56
+ titleLines?: number;
57
+ /** Max lines for the message. Default 3. 0 = unlimited. */
58
+ messageLines?: number;
59
+
60
+ width?: DimensionValue;
61
+ /** Default 560 so it looks right on tablets. */
62
+ maxWidth?: DimensionValue;
63
+ minHeight?: DimensionValue;
64
+ height?: DimensionValue;
65
+ /** Default 18. */
66
+ borderRadius?: number;
67
+ /** Left icon / app icon size. Default 40. */
68
+ iconSize?: number;
69
+ /** Right image size. Default 44. */
70
+ imageSize?: number;
71
+
72
+ style?: StyleProp<ViewStyle>;
73
+ titleStyle?: StyleProp<TextStyle>;
74
+ messageStyle?: StyleProp<TextStyle>;
75
+ }
76
+
77
+ export interface ToastOptions extends ToastAppearance {
78
+ /** Pass an existing id to update a toast in place (e.g. "Uploading…" → "Uploaded"). */
79
+ id?: string;
80
+ type?: ToastType;
81
+ title?: string;
82
+ message?: string;
83
+ /** Picture shown left or right (see imagePosition). */
84
+ image?: ImageSourcePropType;
85
+ /** Custom left icon (avatar, logo). Replaces the type icon for this toast. */
86
+ icon?: ImageSourcePropType;
87
+ /** Override the type color for this toast only. */
88
+ accentColor?: string;
89
+ onPress?: () => void;
90
+ onHide?: () => void;
91
+ }
92
+
93
+ export interface ToastConfig extends ToastAppearance {
94
+ /** Distance from the top edge. Tip: pass useSafeAreaInsets().top + 8. */
95
+ topOffset?: number;
96
+ bottomOffset?: number;
97
+ theme?: ToastTheme;
98
+ /** Type colors. */
99
+ colors?: Partial<Record<ToastType, string>>;
100
+ /** Default duration per type, e.g. { error: 6000 }. */
101
+ durations?: Partial<Record<ToastType, number>>;
102
+ }
103
+
104
+ /** @internal */
105
+ export interface ToastData extends ToastOptions {
106
+ id: string;
107
+ rev: number;
108
+ dismissing?: boolean;
109
+ }