@pixotope/toasts 0.0.0-stage → 0.0.1

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.
@@ -0,0 +1,134 @@
1
+ import { HTMLAttributes, ReactNode } from "react";
2
+ import "@pixotope/event-bus";
3
+ //#region src/types.d.ts
4
+ type ToastType = 'success' | 'error' | 'warning' | 'info' | 'clean' | 'insight';
5
+ type ToastIcon = 'info' | 'warning';
6
+ type ToastPosition = 'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right';
7
+ interface ToastAction {
8
+ label: ReactNode;
9
+ onClick: (toast: Toast) => void;
10
+ }
11
+ /** Everything about a toast except its title; also the shape of `<Toaster toastOptions>` defaults. */
12
+ interface ToastOptions {
13
+ /** Reusing the id of a shown toast updates it in place and bumps its `count`. */
14
+ id?: string;
15
+ type?: ToastType;
16
+ subtitle?: ReactNode;
17
+ description?: ReactNode;
18
+ /** Monospace block for codes, paths or error details. */
19
+ note?: ReactNode;
20
+ icon?: ToastIcon;
21
+ action?: ToastAction;
22
+ /** Milliseconds before the toast dismisses itself; `Infinity` keeps it until dismissed. */
23
+ duration?: number;
24
+ showTime?: boolean;
25
+ /** Text left of the time, e.g. "Message received:". */
26
+ timeLabel?: ReactNode;
27
+ /** Shows the close button. */
28
+ dismissible?: boolean;
29
+ /** Shows the copy-to-clipboard button. */
30
+ copyable?: boolean;
31
+ className?: string;
32
+ /** Called once when the user or the timer dismisses the toast; not called by `toast.remove`. */
33
+ onClose?: (toast: Toast) => void;
34
+ }
35
+ interface ToastInput extends ToastOptions {
36
+ title: ReactNode;
37
+ }
38
+ interface Toast extends Omit<ToastInput, 'id' | 'type'> {
39
+ id: string;
40
+ type: ToastType;
41
+ /** How many times this id was shown; 1 for a new toast. */
42
+ count: number;
43
+ createdAt: number;
44
+ updatedAt: number;
45
+ /** False while the toast plays its exit animation before removal. */
46
+ visible: boolean;
47
+ }
48
+ //#endregion
49
+ //#region src/toast.d.ts
50
+ type ToastShorthand = (title: ToastInput['title'], options?: Omit<ToastOptions, 'type'>) => string;
51
+ declare const show: (input: ToastInput) => string;
52
+ /**
53
+ * Shows a toast and returns its id. Works outside React; a mounted
54
+ * `<Toaster>` renders it.
55
+ */
56
+ declare const toast$1: typeof show & {
57
+ success: ToastShorthand;
58
+ error: ToastShorthand;
59
+ warning: ToastShorthand;
60
+ info: ToastShorthand;
61
+ clean: ToastShorthand;
62
+ insight: ToastShorthand;
63
+ /** Plays the exit animation, then removes; omit the id to dismiss all. */
64
+ dismiss: (id?: string) => void;
65
+ /** Removes immediately without calling `onClose`; omit the id to remove all. */
66
+ remove: (id?: string) => void;
67
+ };
68
+ //#endregion
69
+ //#region src/useToasts.d.ts
70
+ type ToastDefaults = Omit<ToastOptions, 'id'>;
71
+ interface UseToastsOptions {
72
+ /** Most toasts returned at once; the rest wait, and their timers do not run yet. */
73
+ limit?: number;
74
+ /** Defaults for fields a toast leaves undefined. */
75
+ toastOptions?: ToastDefaults;
76
+ }
77
+ interface UseToastsResult {
78
+ toasts: Toast[];
79
+ dismiss: (id?: string) => void;
80
+ remove: (id?: string) => void;
81
+ pause: (id: string) => void;
82
+ resume: (id: string) => void;
83
+ pauseAll: () => void;
84
+ resumeAll: () => void;
85
+ }
86
+ /**
87
+ * Headless access to the toast store, for rendering toasts with your own
88
+ * components. Starts the auto-dismiss timer of every toast it returns.
89
+ */
90
+ export declare const useToasts: ({ limit, toastOptions }?: UseToastsOptions) => UseToastsResult;
91
+ //#endregion
92
+ //#region src/Toaster.d.ts
93
+ interface ToastOffset {
94
+ top?: number;
95
+ right?: number;
96
+ bottom?: number;
97
+ left?: number;
98
+ }
99
+ interface RenderToastHelpers {
100
+ dismiss: () => void;
101
+ pause: () => void;
102
+ resume: () => void;
103
+ }
104
+ interface ToasterProps {
105
+ position?: ToastPosition;
106
+ /** Distance in px from the viewport edges the position touches. */
107
+ offset?: ToastOffset;
108
+ /** Most toasts shown at once; later ones wait for a free slot. */
109
+ limit?: number;
110
+ zIndex?: number;
111
+ className?: string;
112
+ /** Defaults for fields a toast leaves undefined. */
113
+ toastOptions?: ToastDefaults;
114
+ /** Replaces the default visual; render `ToastNotification` to wrap it. */
115
+ renderToast?: (toast: Toast, helpers: RenderToastHelpers) => ReactNode;
116
+ /** Portal target; defaults to `document.body`. */
117
+ container?: Element | null;
118
+ }
119
+ /** Renders toasts raised with `toast()`. Mount one per app. */
120
+ export declare const Toaster: ({ position, offset, limit, zIndex, className, toastOptions, renderToast, container }: ToasterProps) => import("react").ReactPortal | null;
121
+ //#endregion
122
+ //#region src/ToastNotification.d.ts
123
+ interface ToastNotificationProps extends Omit<HTMLAttributes<HTMLDivElement>, 'title'> {
124
+ toast: Toast;
125
+ onDismiss?: () => void;
126
+ }
127
+ /** The default Pixotope toast visual, also usable inside `renderToast`. */
128
+ export declare const ToastNotification: ({ toast, onDismiss, className, onMouseDown, onMouseEnter, ...rest }: ToastNotificationProps) => import("react").JSX.Element;
129
+ //#endregion
130
+ //#region src/core.d.ts
131
+ export declare const DEFAULT_TOAST_DURATION = 3000;
132
+ //#endregion
133
+ export { type RenderToastHelpers, type Toast, type ToastAction, type ToastDefaults, type ToastIcon, type ToastInput, type ToastNotificationProps, type ToastOffset, type ToastOptions, type ToastPosition, type ToastShorthand, type ToastType, type ToasterProps, type UseToastsOptions, type UseToastsResult, toast$1 as toast };
134
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1,134 @@
1
+ import { EventBus } from "@pixotope/event-bus";
2
+ import { HTMLAttributes, ReactNode } from "react";
3
+ //#region src/types.d.ts
4
+ type ToastType = 'success' | 'error' | 'warning' | 'info' | 'clean' | 'insight';
5
+ type ToastIcon = 'info' | 'warning';
6
+ type ToastPosition = 'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right';
7
+ interface ToastAction {
8
+ label: ReactNode;
9
+ onClick: (toast: Toast) => void;
10
+ }
11
+ /** Everything about a toast except its title; also the shape of `<Toaster toastOptions>` defaults. */
12
+ interface ToastOptions {
13
+ /** Reusing the id of a shown toast updates it in place and bumps its `count`. */
14
+ id?: string;
15
+ type?: ToastType;
16
+ subtitle?: ReactNode;
17
+ description?: ReactNode;
18
+ /** Monospace block for codes, paths or error details. */
19
+ note?: ReactNode;
20
+ icon?: ToastIcon;
21
+ action?: ToastAction;
22
+ /** Milliseconds before the toast dismisses itself; `Infinity` keeps it until dismissed. */
23
+ duration?: number;
24
+ showTime?: boolean;
25
+ /** Text left of the time, e.g. "Message received:". */
26
+ timeLabel?: ReactNode;
27
+ /** Shows the close button. */
28
+ dismissible?: boolean;
29
+ /** Shows the copy-to-clipboard button. */
30
+ copyable?: boolean;
31
+ className?: string;
32
+ /** Called once when the user or the timer dismisses the toast; not called by `toast.remove`. */
33
+ onClose?: (toast: Toast) => void;
34
+ }
35
+ interface ToastInput extends ToastOptions {
36
+ title: ReactNode;
37
+ }
38
+ interface Toast extends Omit<ToastInput, 'id' | 'type'> {
39
+ id: string;
40
+ type: ToastType;
41
+ /** How many times this id was shown; 1 for a new toast. */
42
+ count: number;
43
+ createdAt: number;
44
+ updatedAt: number;
45
+ /** False while the toast plays its exit animation before removal. */
46
+ visible: boolean;
47
+ }
48
+ //#endregion
49
+ //#region src/toast.d.ts
50
+ type ToastShorthand = (title: ToastInput['title'], options?: Omit<ToastOptions, 'type'>) => string;
51
+ declare const show: (input: ToastInput) => string;
52
+ /**
53
+ * Shows a toast and returns its id. Works outside React; a mounted
54
+ * `<Toaster>` renders it.
55
+ */
56
+ declare const toast$1: typeof show & {
57
+ success: ToastShorthand;
58
+ error: ToastShorthand;
59
+ warning: ToastShorthand;
60
+ info: ToastShorthand;
61
+ clean: ToastShorthand;
62
+ insight: ToastShorthand;
63
+ /** Plays the exit animation, then removes; omit the id to dismiss all. */
64
+ dismiss: (id?: string) => void;
65
+ /** Removes immediately without calling `onClose`; omit the id to remove all. */
66
+ remove: (id?: string) => void;
67
+ };
68
+ //#endregion
69
+ //#region src/useToasts.d.ts
70
+ type ToastDefaults = Omit<ToastOptions, 'id'>;
71
+ interface UseToastsOptions {
72
+ /** Most toasts returned at once; the rest wait, and their timers do not run yet. */
73
+ limit?: number;
74
+ /** Defaults for fields a toast leaves undefined. */
75
+ toastOptions?: ToastDefaults;
76
+ }
77
+ interface UseToastsResult {
78
+ toasts: Toast[];
79
+ dismiss: (id?: string) => void;
80
+ remove: (id?: string) => void;
81
+ pause: (id: string) => void;
82
+ resume: (id: string) => void;
83
+ pauseAll: () => void;
84
+ resumeAll: () => void;
85
+ }
86
+ /**
87
+ * Headless access to the toast store, for rendering toasts with your own
88
+ * components. Starts the auto-dismiss timer of every toast it returns.
89
+ */
90
+ export declare const useToasts: ({ limit, toastOptions }?: UseToastsOptions) => UseToastsResult;
91
+ //#endregion
92
+ //#region src/Toaster.d.ts
93
+ interface ToastOffset {
94
+ top?: number;
95
+ right?: number;
96
+ bottom?: number;
97
+ left?: number;
98
+ }
99
+ interface RenderToastHelpers {
100
+ dismiss: () => void;
101
+ pause: () => void;
102
+ resume: () => void;
103
+ }
104
+ interface ToasterProps {
105
+ position?: ToastPosition;
106
+ /** Distance in px from the viewport edges the position touches. */
107
+ offset?: ToastOffset;
108
+ /** Most toasts shown at once; later ones wait for a free slot. */
109
+ limit?: number;
110
+ zIndex?: number;
111
+ className?: string;
112
+ /** Defaults for fields a toast leaves undefined. */
113
+ toastOptions?: ToastDefaults;
114
+ /** Replaces the default visual; render `ToastNotification` to wrap it. */
115
+ renderToast?: (toast: Toast, helpers: RenderToastHelpers) => ReactNode;
116
+ /** Portal target; defaults to `document.body`. */
117
+ container?: Element | null;
118
+ }
119
+ /** Renders toasts raised with `toast()`. Mount one per app. */
120
+ export declare const Toaster: ({ position, offset, limit, zIndex, className, toastOptions, renderToast, container }: ToasterProps) => import("react").ReactPortal | null;
121
+ //#endregion
122
+ //#region src/ToastNotification.d.ts
123
+ interface ToastNotificationProps extends Omit<HTMLAttributes<HTMLDivElement>, 'title'> {
124
+ toast: Toast;
125
+ onDismiss?: () => void;
126
+ }
127
+ /** The default Pixotope toast visual, also usable inside `renderToast`. */
128
+ export declare const ToastNotification: ({ toast, onDismiss, className, onMouseDown, onMouseEnter, ...rest }: ToastNotificationProps) => import("react").JSX.Element;
129
+ //#endregion
130
+ //#region src/core.d.ts
131
+ export declare const DEFAULT_TOAST_DURATION = 3000;
132
+ //#endregion
133
+ export { type RenderToastHelpers, type Toast, type ToastAction, type ToastDefaults, type ToastIcon, type ToastInput, type ToastNotificationProps, type ToastOffset, type ToastOptions, type ToastPosition, type ToastShorthand, type ToastType, type ToasterProps, type UseToastsOptions, type UseToastsResult, toast$1 as toast };
134
+ //# sourceMappingURL=index.d.ts.map