react-native-notitoast 0.0.0-stage → 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 +21 -0
- package/README.md +199 -2
- package/lib/commonjs/ToastItem.js +467 -0
- package/lib/commonjs/ToastItem.js.map +1 -0
- package/lib/commonjs/ToastProvider.js +84 -0
- package/lib/commonjs/ToastProvider.js.map +1 -0
- package/lib/commonjs/index.js +26 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/theme.js +43 -0
- package/lib/commonjs/theme.js.map +1 -0
- package/lib/commonjs/toast.js +39 -0
- package/lib/commonjs/toast.js.map +1 -0
- package/lib/commonjs/types.js +6 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/module/ToastItem.js +463 -0
- package/lib/module/ToastItem.js.map +1 -0
- package/lib/module/ToastProvider.js +80 -0
- package/lib/module/ToastProvider.js.map +1 -0
- package/lib/module/index.js +5 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/theme.js +39 -0
- package/lib/module/theme.js.map +1 -0
- package/lib/module/toast.js +33 -0
- package/lib/module/toast.js.map +1 -0
- package/lib/module/types.js +4 -0
- package/lib/module/types.js.map +1 -0
- package/lib/typescript/src/ToastItem.d.ts +12 -0
- package/lib/typescript/src/ToastItem.d.ts.map +1 -0
- package/lib/typescript/src/ToastProvider.d.ts +7 -0
- package/lib/typescript/src/ToastProvider.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +6 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/theme.d.ts +23 -0
- package/lib/typescript/src/theme.d.ts.map +1 -0
- package/lib/typescript/src/toast.d.ts +23 -0
- package/lib/typescript/src/toast.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +86 -0
- package/lib/typescript/src/types.d.ts.map +1 -0
- package/package.json +77 -6
- package/src/ToastItem.tsx +561 -0
- package/src/ToastProvider.tsx +93 -0
- package/src/index.ts +14 -0
- package/src/theme.ts +41 -0
- package/src/toast.ts +51 -0
- package/src/types.ts +101 -0
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,101 @@
|
|
|
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
|
+
/** Show the success/error/warning/info icon. Default: true. */
|
|
27
|
+
showIcon?: boolean;
|
|
28
|
+
/** Small type badge on the corner of a left image / app icon. Default: true. */
|
|
29
|
+
showTypeBadge?: boolean;
|
|
30
|
+
/** Colored stripe on the left edge. Default: shown automatically when there is no left icon. */
|
|
31
|
+
showAccentBar?: boolean;
|
|
32
|
+
/** Where `image` goes. Default: 'right'. */
|
|
33
|
+
imagePosition?: ToastImagePosition;
|
|
34
|
+
/** App icon shown on the left (like a basic Android toast). Leave unset to hide. */
|
|
35
|
+
appIcon?: ImageSourcePropType;
|
|
36
|
+
|
|
37
|
+
/** 'default' = plain card, 'tinted' = soft type color, 'filled' = solid type color. */
|
|
38
|
+
variant?: ToastVariant;
|
|
39
|
+
backgroundColor?: string;
|
|
40
|
+
borderColor?: string;
|
|
41
|
+
titleColor?: string;
|
|
42
|
+
messageColor?: string;
|
|
43
|
+
|
|
44
|
+
/** Max lines for the title. Default 1. 0 = unlimited. */
|
|
45
|
+
titleLines?: number;
|
|
46
|
+
/** Max lines for the message. Default 3. 0 = unlimited. */
|
|
47
|
+
messageLines?: number;
|
|
48
|
+
|
|
49
|
+
width?: DimensionValue;
|
|
50
|
+
/** Default 560 so it looks right on tablets. */
|
|
51
|
+
maxWidth?: DimensionValue;
|
|
52
|
+
minHeight?: DimensionValue;
|
|
53
|
+
height?: DimensionValue;
|
|
54
|
+
/** Default 18. */
|
|
55
|
+
borderRadius?: number;
|
|
56
|
+
/** Left icon / app icon size. Default 40. */
|
|
57
|
+
iconSize?: number;
|
|
58
|
+
/** Right image size. Default 44. */
|
|
59
|
+
imageSize?: number;
|
|
60
|
+
|
|
61
|
+
style?: StyleProp<ViewStyle>;
|
|
62
|
+
titleStyle?: StyleProp<TextStyle>;
|
|
63
|
+
messageStyle?: StyleProp<TextStyle>;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface ToastOptions extends ToastAppearance {
|
|
67
|
+
/** Pass an existing id to update a toast in place (e.g. "Uploading…" → "Uploaded"). */
|
|
68
|
+
id?: string;
|
|
69
|
+
type?: ToastType;
|
|
70
|
+
title?: string;
|
|
71
|
+
message?: string;
|
|
72
|
+
/** Picture shown left or right (see imagePosition). */
|
|
73
|
+
image?: ImageSourcePropType;
|
|
74
|
+
/** Custom left icon (avatar, logo). Replaces the type icon for this toast. */
|
|
75
|
+
icon?: ImageSourcePropType;
|
|
76
|
+
/** Override the type color for this toast only. */
|
|
77
|
+
accentColor?: string;
|
|
78
|
+
onPress?: () => void;
|
|
79
|
+
onHide?: () => void;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface ToastConfig extends ToastAppearance {
|
|
83
|
+
/** Distance from the top edge. Tip: pass useSafeAreaInsets().top + 8. */
|
|
84
|
+
topOffset?: number;
|
|
85
|
+
bottomOffset?: number;
|
|
86
|
+
theme?: ToastTheme;
|
|
87
|
+
/** Small header line like a system notification: "MY APP · now". */
|
|
88
|
+
appName?: string;
|
|
89
|
+
timeLabel?: string;
|
|
90
|
+
/** Type colors. */
|
|
91
|
+
colors?: Partial<Record<ToastType, string>>;
|
|
92
|
+
/** Default duration per type, e.g. { error: 6000 }. */
|
|
93
|
+
durations?: Partial<Record<ToastType, number>>;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** @internal */
|
|
97
|
+
export interface ToastData extends ToastOptions {
|
|
98
|
+
id: string;
|
|
99
|
+
rev: number;
|
|
100
|
+
dismissing?: boolean;
|
|
101
|
+
}
|