@zag-js/toast 0.1.9 → 0.1.12

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) 2021 Chakra UI
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/dist/index.d.ts CHANGED
@@ -1,11 +1,201 @@
1
- import { groupConnect } from "./toast-group.connect";
2
- import { groupMachine } from "./toast-group.machine";
3
- import { createToastMachine as createMachine } from "./toast.machine";
4
- export { connect } from "./toast.connect";
5
- export type { GroupMachineContext, MachineContext, MachineState, Placement, Service, Type } from "./toast.types";
6
- export { createMachine };
7
- export declare const group: {
1
+ import * as _zag_js_core from '@zag-js/core';
2
+ import { Machine, StateMachine } from '@zag-js/core';
3
+ import { RootProperties, CommonProperties, Direction, DirectionProperty, Context, RequiredBy, PropTypes, NormalizeProps } from '@zag-js/types';
4
+
5
+ declare type Type = "success" | "error" | "loading" | "info" | "custom";
6
+ declare type Placement = "top-start" | "top" | "top-end" | "bottom-start" | "bottom" | "bottom-end";
7
+ declare type SharedContext = {
8
+ /**
9
+ * Whether to pause toast when the user leaves the browser tab
10
+ */
11
+ pauseOnPageIdle?: boolean;
12
+ /**
13
+ * Whether to pause the toast when interacted with
14
+ */
15
+ pauseOnInteraction?: boolean;
16
+ };
17
+ declare type ToastOptions = {
18
+ /**
19
+ * The unique id of the toast
20
+ */
21
+ id: string;
22
+ /**
23
+ * The type of the toast
24
+ */
25
+ type: Type;
26
+ /**
27
+ * The placement of the toast
28
+ */
29
+ placement: Placement;
30
+ /**
31
+ * The message of the toast
32
+ */
33
+ title?: string;
34
+ /**
35
+ * The description of the toast
36
+ */
37
+ description?: string;
38
+ /**
39
+ * The duration the toast will be visible
40
+ */
41
+ duration: number;
42
+ /**
43
+ * Custom function to render the toast element.
44
+ */
45
+ render?: (options: RenderOptions) => any;
46
+ /**
47
+ * The duration for the toast to kept alive before it is removed.
48
+ * Useful for exit transitions.
49
+ */
50
+ removeDelay?: number;
51
+ /**
52
+ * Function called when the toast has been closed and removed
53
+ */
54
+ onClose?: VoidFunction;
55
+ /**
56
+ * Function called when the toast is leaving
57
+ */
58
+ onClosing?: VoidFunction;
59
+ /**
60
+ * Function called when the toast is shown
61
+ */
62
+ onOpen?: VoidFunction;
63
+ /**
64
+ * Function called when the toast is updated
65
+ */
66
+ onUpdate?: VoidFunction;
67
+ };
68
+ declare type Options = Partial<ToastOptions>;
69
+ declare type RenderOptions = Omit<ToastOptions, "render"> & {
70
+ dismiss(): void;
71
+ };
72
+ declare type MachineContext = SharedContext & RootProperties & CommonProperties & Omit<ToastOptions, "removeDelay"> & {
73
+ /**
74
+ * The duration for the toast to kept alive before it is removed.
75
+ * Useful for exit transitions.
76
+ */
77
+ removeDelay: number;
78
+ /**
79
+ * The document's text/writing direction.
80
+ */
81
+ dir?: Direction;
82
+ /**
83
+ * The time the toast was created
84
+ */
85
+ createdAt: number;
86
+ /**
87
+ * The time left before the toast is removed
88
+ */
89
+ remaining: number;
90
+ };
91
+ declare type MachineState = {
92
+ value: "active" | "active:temp" | "dismissing" | "inactive" | "persist";
93
+ tags: "visible" | "paused" | "updating";
94
+ };
95
+ declare type State = StateMachine.State<MachineContext, MachineState>;
96
+ declare type Send = StateMachine.Send;
97
+ declare type Service = Machine<MachineContext, MachineState>;
98
+ declare type GroupPublicContext = SharedContext & DirectionProperty & CommonProperties & {
99
+ /**
100
+ * The gutter or spacing between toasts
101
+ */
102
+ gutter: string;
103
+ /**
104
+ * The z-index applied to each toast group
105
+ */
106
+ zIndex: number;
107
+ /**
108
+ * The maximum number of toasts that can be shown at once
109
+ */
110
+ max: number;
111
+ /**
112
+ * The offset from the safe environment edge of the viewport
113
+ */
114
+ offsets: string | Record<"left" | "right" | "bottom" | "top", string>;
115
+ };
116
+ declare type UserDefinedGroupContext = RequiredBy<GroupPublicContext, "id">;
117
+ declare type GroupComputedContext = Readonly<{
118
+ /**
119
+ * @computed
120
+ * The total number of toasts in the group
121
+ */
122
+ readonly count: number;
123
+ }>;
124
+ declare type GroupPrivateContext = Context<{}>;
125
+ declare type GroupMachineContext = GroupPublicContext & GroupComputedContext & GroupPrivateContext;
126
+ declare type GroupState = StateMachine.State<GroupMachineContext>;
127
+ declare type GroupSend = (event: StateMachine.Event<StateMachine.AnyEventObject>) => void;
128
+ declare type MaybeFunction<Value, Args> = Value | ((arg: Args) => Value);
129
+ declare type PromiseOptions<Value> = {
130
+ loading: ToastOptions;
131
+ success: MaybeFunction<ToastOptions, Value>;
132
+ error: MaybeFunction<ToastOptions, Error>;
133
+ };
134
+ declare type GroupProps = {
135
+ placement: Placement;
136
+ label?: string;
137
+ };
138
+ declare type Toaster = {
139
+ count: number;
140
+ isVisible(id: string): boolean;
141
+ upsert(options: ToastOptions): string | undefined;
142
+ create(options: ToastOptions): string | undefined;
143
+ success(options: ToastOptions): string | undefined;
144
+ error(options: ToastOptions): string | undefined;
145
+ loading(options: ToastOptions): string | undefined;
146
+ dismiss(id?: string | undefined): void;
147
+ remove(id?: string | undefined): void;
148
+ promise<T>(promise: Promise<T>, options: PromiseOptions<T>, shared?: ToastOptions): Promise<T>;
149
+ };
150
+
151
+ declare function groupConnect<T extends PropTypes>(state: GroupState, send: GroupSend, normalize: NormalizeProps<T>): {
152
+ count: number;
153
+ toasts: Service[];
154
+ toastsByPlacement: Partial<Record<Placement, Service[]>>;
155
+ isVisible(id: string): boolean;
156
+ create(options: Options): string | undefined;
157
+ upsert(options: Options): string | undefined;
158
+ dismiss(id?: string): void;
159
+ remove(id?: string): void;
160
+ dismissByPlacement(placement: Placement): void;
161
+ update(id: string, options: Options): string | undefined;
162
+ loading(options: Options): string | undefined;
163
+ success(options: Options): string | undefined;
164
+ error(options: Options): string | undefined;
165
+ promise<T_1>(promise: Promise<T_1>, options: PromiseOptions<T_1>, shared?: Options): Promise<T_1>;
166
+ pause(id?: string): void;
167
+ resume(id?: string): void;
168
+ getGroupProps(options: GroupProps): T["element"];
169
+ createPortal(): HTMLElement;
170
+ subscribe(fn: (toasts: GroupMachineContext["toasts"]) => void): () => void;
171
+ };
172
+
173
+ declare function groupMachine(ctx: UserDefinedGroupContext): _zag_js_core.Machine<GroupMachineContext, _zag_js_core.StateMachine.StateSchema, _zag_js_core.StateMachine.AnyEventObject>;
174
+
175
+ declare function createToastMachine(options?: Options): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
176
+
177
+ declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): {
178
+ type: Type;
179
+ title: string | undefined;
180
+ description: string | undefined;
181
+ placement: Placement;
182
+ isVisible: boolean;
183
+ isPaused: boolean;
184
+ pause(): void;
185
+ resume(): void;
186
+ dismiss(): void;
187
+ rootProps: T["element"];
188
+ progressbarProps: T["element"];
189
+ titleProps: T["element"];
190
+ descriptionProps: T["element"];
191
+ closeButtonProps: T["button"];
192
+ render(): any;
193
+ };
194
+
195
+ declare const group: {
8
196
  connect: typeof groupConnect;
9
197
  machine: typeof groupMachine;
10
198
  };
11
- export declare function api(): import("./toast.types").Toaster;
199
+ declare function api(): Toaster | undefined;
200
+
201
+ export { GroupMachineContext, MachineContext, MachineState, Placement, Service, Type, api, connect, createToastMachine as createMachine, group };