@spark-ui/components 10.11.2 → 10.11.4
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 +12 -0
- package/dist/snackbar/index.d.mts +1 -46
- package/dist/snackbar/index.d.ts +1 -46
- package/dist/snackbar/index.js +37 -185
- package/dist/snackbar/index.js.map +1 -1
- package/dist/snackbar/index.mjs +12 -157
- package/dist/snackbar/index.mjs.map +1 -1
- package/package.json +8 -10
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,18 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [10.11.4](https://github.com/leboncoin/spark-web/compare/v10.11.3...v10.11.4) (2025-07-16)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- **components:** fixed version for react-aria toast ([d7cf39b](https://github.com/leboncoin/spark-web/commit/d7cf39b28e6a869c618ac58f46c2caf48a413e1e))
|
|
11
|
+
|
|
12
|
+
## [10.11.3](https://github.com/leboncoin/spark-web/compare/v10.11.2...v10.11.3) (2025-07-16)
|
|
13
|
+
|
|
14
|
+
### Bug Fixes
|
|
15
|
+
|
|
16
|
+
- **components:** forced beta version of react-stately toast ([452b321](https://github.com/leboncoin/spark-web/commit/452b32183e34719436020811088e0cadd8f958d4))
|
|
17
|
+
|
|
6
18
|
## [10.11.2](https://github.com/leboncoin/spark-web/compare/v10.11.1...v10.11.2) (2025-07-15)
|
|
7
19
|
|
|
8
20
|
### Bug Fixes
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { QueuedToast, ToastState, ToastOptions } from '@react-stately/toast';
|
|
1
2
|
import { ReactNode, ComponentPropsWithRef, PropsWithChildren, ReactElement, Ref } from 'react';
|
|
2
3
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
4
|
import * as class_variance_authority_types from 'class-variance-authority/types';
|
|
@@ -7,52 +8,6 @@ import { ButtonProps } from '../button/index.mjs';
|
|
|
7
8
|
import { IconButtonProps } from '../icon-button/index.mjs';
|
|
8
9
|
import { IconProps } from '../icon/index.mjs';
|
|
9
10
|
|
|
10
|
-
interface ToastOptions {
|
|
11
|
-
/** Handler that is called when the toast is closed, either by the user or after a timeout. */
|
|
12
|
-
onClose?: () => void;
|
|
13
|
-
/** A timeout to automatically close the toast after, in milliseconds. */
|
|
14
|
-
timeout?: number;
|
|
15
|
-
/** The priority of the toast relative to other toasts. Larger numbers indicate higher priority. */
|
|
16
|
-
priority?: number;
|
|
17
|
-
}
|
|
18
|
-
interface QueuedToast<T> extends ToastOptions {
|
|
19
|
-
/** The content of the toast. */
|
|
20
|
-
content: T;
|
|
21
|
-
/** A unique key for the toast. */
|
|
22
|
-
key: string;
|
|
23
|
-
/** A timer for the toast, if a timeout was set. */
|
|
24
|
-
timer?: Timer;
|
|
25
|
-
/** The current animation state for the toast. */
|
|
26
|
-
animation?: 'entering' | 'queued' | 'exiting' | null;
|
|
27
|
-
}
|
|
28
|
-
interface ToastState<T> {
|
|
29
|
-
/** Adds a new toast to the queue. */
|
|
30
|
-
add(content: T, options?: ToastOptions): string;
|
|
31
|
-
/**
|
|
32
|
-
* Closes a toast. If `hasExitAnimation` is true, the toast
|
|
33
|
-
* transitions to an "exiting" state instead of being removed immediately.
|
|
34
|
-
*/
|
|
35
|
-
close(key: string): void;
|
|
36
|
-
/** Removes a toast from the visible toasts after an exiting animation. */
|
|
37
|
-
remove(key: string): void;
|
|
38
|
-
/** Pauses the timers for all visible toasts. */
|
|
39
|
-
pauseAll(): void;
|
|
40
|
-
/** Resumes the timers for all visible toasts. */
|
|
41
|
-
resumeAll(): void;
|
|
42
|
-
/** The visible toasts. */
|
|
43
|
-
visibleToasts: QueuedToast<T>[];
|
|
44
|
-
}
|
|
45
|
-
declare class Timer {
|
|
46
|
-
private timerId;
|
|
47
|
-
private startTime;
|
|
48
|
-
private remaining;
|
|
49
|
-
private callback;
|
|
50
|
-
constructor(callback: () => void, delay: number);
|
|
51
|
-
reset(delay: number): void;
|
|
52
|
-
pause(): void;
|
|
53
|
-
resume(): void;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
11
|
declare const snackbarItemVariant: (props?: ({
|
|
57
12
|
design?: "filled" | "tinted" | null | undefined;
|
|
58
13
|
intent?: "main" | "success" | "alert" | "error" | "info" | "neutral" | "basic" | "support" | "accent" | "inverse" | null | undefined;
|
package/dist/snackbar/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { QueuedToast, ToastState, ToastOptions } from '@react-stately/toast';
|
|
1
2
|
import { ReactNode, ComponentPropsWithRef, PropsWithChildren, ReactElement, Ref } from 'react';
|
|
2
3
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
4
|
import * as class_variance_authority_types from 'class-variance-authority/types';
|
|
@@ -7,52 +8,6 @@ import { ButtonProps } from '../button/index.js';
|
|
|
7
8
|
import { IconButtonProps } from '../icon-button/index.js';
|
|
8
9
|
import { IconProps } from '../icon/index.js';
|
|
9
10
|
|
|
10
|
-
interface ToastOptions {
|
|
11
|
-
/** Handler that is called when the toast is closed, either by the user or after a timeout. */
|
|
12
|
-
onClose?: () => void;
|
|
13
|
-
/** A timeout to automatically close the toast after, in milliseconds. */
|
|
14
|
-
timeout?: number;
|
|
15
|
-
/** The priority of the toast relative to other toasts. Larger numbers indicate higher priority. */
|
|
16
|
-
priority?: number;
|
|
17
|
-
}
|
|
18
|
-
interface QueuedToast<T> extends ToastOptions {
|
|
19
|
-
/** The content of the toast. */
|
|
20
|
-
content: T;
|
|
21
|
-
/** A unique key for the toast. */
|
|
22
|
-
key: string;
|
|
23
|
-
/** A timer for the toast, if a timeout was set. */
|
|
24
|
-
timer?: Timer;
|
|
25
|
-
/** The current animation state for the toast. */
|
|
26
|
-
animation?: 'entering' | 'queued' | 'exiting' | null;
|
|
27
|
-
}
|
|
28
|
-
interface ToastState<T> {
|
|
29
|
-
/** Adds a new toast to the queue. */
|
|
30
|
-
add(content: T, options?: ToastOptions): string;
|
|
31
|
-
/**
|
|
32
|
-
* Closes a toast. If `hasExitAnimation` is true, the toast
|
|
33
|
-
* transitions to an "exiting" state instead of being removed immediately.
|
|
34
|
-
*/
|
|
35
|
-
close(key: string): void;
|
|
36
|
-
/** Removes a toast from the visible toasts after an exiting animation. */
|
|
37
|
-
remove(key: string): void;
|
|
38
|
-
/** Pauses the timers for all visible toasts. */
|
|
39
|
-
pauseAll(): void;
|
|
40
|
-
/** Resumes the timers for all visible toasts. */
|
|
41
|
-
resumeAll(): void;
|
|
42
|
-
/** The visible toasts. */
|
|
43
|
-
visibleToasts: QueuedToast<T>[];
|
|
44
|
-
}
|
|
45
|
-
declare class Timer {
|
|
46
|
-
private timerId;
|
|
47
|
-
private startTime;
|
|
48
|
-
private remaining;
|
|
49
|
-
private callback;
|
|
50
|
-
constructor(callback: () => void, delay: number);
|
|
51
|
-
reset(delay: number): void;
|
|
52
|
-
pause(): void;
|
|
53
|
-
resume(): void;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
11
|
declare const snackbarItemVariant: (props?: ({
|
|
57
12
|
design?: "filled" | "tinted" | null | undefined;
|
|
58
13
|
intent?: "main" | "success" | "alert" | "error" | "info" | "neutral" | "basic" | "support" | "accent" | "inverse" | null | undefined;
|
package/dist/snackbar/index.js
CHANGED
|
@@ -27,165 +27,17 @@ __export(snackbar_exports, {
|
|
|
27
27
|
module.exports = __toCommonJS(snackbar_exports);
|
|
28
28
|
|
|
29
29
|
// src/snackbar/Snackbar.tsx
|
|
30
|
-
var
|
|
30
|
+
var import_toast3 = require("@react-stately/toast");
|
|
31
|
+
var import_react9 = require("react");
|
|
31
32
|
var import_react_dom = require("react-dom");
|
|
32
33
|
|
|
33
|
-
// src/snackbar/local-toast/useToastState.ts
|
|
34
|
-
var import_react = require("react");
|
|
35
|
-
var import_shim = require("use-sync-external-store/shim/index.js");
|
|
36
|
-
function useToastQueue(queue) {
|
|
37
|
-
let subscribe = (0, import_react.useCallback)((fn) => queue.subscribe(fn), [queue]);
|
|
38
|
-
let getSnapshot = (0, import_react.useCallback)(() => queue.visibleToasts, [queue]);
|
|
39
|
-
let visibleToasts = (0, import_shim.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
40
|
-
return {
|
|
41
|
-
visibleToasts,
|
|
42
|
-
add: (content, options) => queue.add(content, options),
|
|
43
|
-
close: (key) => queue.close(key),
|
|
44
|
-
remove: (key) => queue.remove(key),
|
|
45
|
-
pauseAll: () => queue.pauseAll(),
|
|
46
|
-
resumeAll: () => queue.resumeAll()
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
var ToastQueue = class {
|
|
50
|
-
queue = [];
|
|
51
|
-
subscriptions = /* @__PURE__ */ new Set();
|
|
52
|
-
maxVisibleToasts;
|
|
53
|
-
hasExitAnimation;
|
|
54
|
-
/** The currently visible toasts. */
|
|
55
|
-
visibleToasts = [];
|
|
56
|
-
constructor(options) {
|
|
57
|
-
this.maxVisibleToasts = options?.maxVisibleToasts ?? 1;
|
|
58
|
-
this.hasExitAnimation = options?.hasExitAnimation ?? false;
|
|
59
|
-
}
|
|
60
|
-
/** Subscribes to updates to the visible toasts. */
|
|
61
|
-
subscribe(fn) {
|
|
62
|
-
this.subscriptions.add(fn);
|
|
63
|
-
return () => this.subscriptions.delete(fn);
|
|
64
|
-
}
|
|
65
|
-
/** Adds a new toast to the queue. */
|
|
66
|
-
add(content, options = {}) {
|
|
67
|
-
let toastKey = Math.random().toString(36);
|
|
68
|
-
let toast = {
|
|
69
|
-
...options,
|
|
70
|
-
content,
|
|
71
|
-
key: toastKey,
|
|
72
|
-
timer: options.timeout ? new Timer(() => this.close(toastKey), options.timeout) : void 0
|
|
73
|
-
};
|
|
74
|
-
let low = 0;
|
|
75
|
-
let high = this.queue.length;
|
|
76
|
-
while (low < high) {
|
|
77
|
-
let mid = Math.floor((low + high) / 2);
|
|
78
|
-
if ((toast.priority || 0) > (this.queue[mid]?.priority || 0)) {
|
|
79
|
-
high = mid;
|
|
80
|
-
} else {
|
|
81
|
-
low = mid + 1;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
this.queue.splice(low, 0, toast);
|
|
85
|
-
toast.animation = low < this.maxVisibleToasts ? "entering" : "queued";
|
|
86
|
-
let i = this.maxVisibleToasts;
|
|
87
|
-
while (i < this.queue.length) {
|
|
88
|
-
;
|
|
89
|
-
this.queue[i++].animation = "queued";
|
|
90
|
-
}
|
|
91
|
-
this.updateVisibleToasts({ action: "add" });
|
|
92
|
-
return toastKey;
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Closes a toast. If `hasExitAnimation` is true, the toast
|
|
96
|
-
* transitions to an "exiting" state instead of being removed immediately.
|
|
97
|
-
*/
|
|
98
|
-
close(key) {
|
|
99
|
-
let index = this.queue.findIndex((t) => t.key === key);
|
|
100
|
-
if (index >= 0) {
|
|
101
|
-
this.queue[index]?.onClose?.();
|
|
102
|
-
this.queue.splice(index, 1);
|
|
103
|
-
}
|
|
104
|
-
this.updateVisibleToasts({ action: "close", key });
|
|
105
|
-
}
|
|
106
|
-
/** Removes a toast from the visible toasts after an exiting animation. */
|
|
107
|
-
remove(key) {
|
|
108
|
-
this.updateVisibleToasts({ action: "remove", key });
|
|
109
|
-
}
|
|
110
|
-
updateVisibleToasts(options) {
|
|
111
|
-
let { action, key } = options;
|
|
112
|
-
let toasts = this.queue.slice(0, this.maxVisibleToasts);
|
|
113
|
-
if (action === "add" && this.hasExitAnimation) {
|
|
114
|
-
let prevToasts = this.visibleToasts.filter((t) => !toasts.some((t2) => t.key === t2.key)).map((t) => ({ ...t, animation: "exiting" }));
|
|
115
|
-
this.visibleToasts = prevToasts.concat(toasts).sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
|
|
116
|
-
} else if (action === "close" && this.hasExitAnimation) {
|
|
117
|
-
this.visibleToasts = this.visibleToasts.map((t) => {
|
|
118
|
-
if (t.key !== key) {
|
|
119
|
-
return t;
|
|
120
|
-
} else {
|
|
121
|
-
return { ...t, animation: "exiting" };
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
} else {
|
|
125
|
-
this.visibleToasts = toasts;
|
|
126
|
-
}
|
|
127
|
-
for (let fn of this.subscriptions) {
|
|
128
|
-
fn();
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
/** Pauses the timers for all visible toasts. */
|
|
132
|
-
pauseAll() {
|
|
133
|
-
for (let toast of this.visibleToasts) {
|
|
134
|
-
if (toast.timer) {
|
|
135
|
-
toast.timer.pause();
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
/** Resumes the timers for all visible toasts. */
|
|
140
|
-
resumeAll() {
|
|
141
|
-
for (let toast of this.visibleToasts) {
|
|
142
|
-
if (toast.timer) {
|
|
143
|
-
toast.timer.resume();
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
var Timer = class {
|
|
149
|
-
timerId;
|
|
150
|
-
startTime = null;
|
|
151
|
-
remaining;
|
|
152
|
-
callback;
|
|
153
|
-
constructor(callback, delay) {
|
|
154
|
-
this.remaining = delay;
|
|
155
|
-
this.callback = callback;
|
|
156
|
-
}
|
|
157
|
-
reset(delay) {
|
|
158
|
-
this.remaining = delay;
|
|
159
|
-
this.resume();
|
|
160
|
-
}
|
|
161
|
-
pause() {
|
|
162
|
-
if (this.timerId == null) {
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
clearTimeout(this.timerId);
|
|
166
|
-
this.timerId = null;
|
|
167
|
-
this.remaining -= Date.now() - this.startTime;
|
|
168
|
-
}
|
|
169
|
-
resume() {
|
|
170
|
-
if (this.remaining <= 0) {
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
this.startTime = Date.now();
|
|
174
|
-
this.timerId = setTimeout(() => {
|
|
175
|
-
this.timerId = null;
|
|
176
|
-
this.remaining = 0;
|
|
177
|
-
this.callback();
|
|
178
|
-
}, this.remaining);
|
|
179
|
-
}
|
|
180
|
-
};
|
|
181
|
-
|
|
182
34
|
// src/snackbar/SnackbarRegion.tsx
|
|
183
35
|
var import_toast2 = require("@react-aria/toast");
|
|
184
|
-
var
|
|
36
|
+
var import_react7 = require("react");
|
|
185
37
|
|
|
186
38
|
// src/snackbar/SnackbarItem.tsx
|
|
187
39
|
var import_toast = require("@react-aria/toast");
|
|
188
|
-
var
|
|
40
|
+
var import_react6 = require("react");
|
|
189
41
|
|
|
190
42
|
// src/snackbar/SnackbarItem.styles.ts
|
|
191
43
|
var import_class_variance_authority = require("class-variance-authority");
|
|
@@ -413,11 +265,11 @@ var import_class_variance_authority5 = require("class-variance-authority");
|
|
|
413
265
|
|
|
414
266
|
// src/button/Button.tsx
|
|
415
267
|
var import_class_variance_authority4 = require("class-variance-authority");
|
|
416
|
-
var
|
|
268
|
+
var import_react2 = require("react");
|
|
417
269
|
|
|
418
270
|
// src/slot/Slot.tsx
|
|
419
271
|
var import_radix_ui = require("radix-ui");
|
|
420
|
-
var
|
|
272
|
+
var import_react = require("react");
|
|
421
273
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
422
274
|
var Slottable = import_radix_ui.Slot.Slottable;
|
|
423
275
|
var Slot = ({ ref, ...props }) => {
|
|
@@ -425,7 +277,7 @@ var Slot = ({ ref, ...props }) => {
|
|
|
425
277
|
};
|
|
426
278
|
var wrapPolymorphicSlot = (asChild, children, callback) => {
|
|
427
279
|
if (!asChild) return callback(children);
|
|
428
|
-
return (0,
|
|
280
|
+
return (0, import_react.isValidElement)(children) ? (0, import_react.cloneElement)(
|
|
429
281
|
children,
|
|
430
282
|
void 0,
|
|
431
283
|
callback(children.props.children)
|
|
@@ -1263,7 +1115,7 @@ var Button = ({
|
|
|
1263
1115
|
}) => {
|
|
1264
1116
|
const Component = asChild ? Slot : "button";
|
|
1265
1117
|
const shouldNotInteract = !!disabled || isLoading;
|
|
1266
|
-
const disabledEventHandlers = (0,
|
|
1118
|
+
const disabledEventHandlers = (0, import_react2.useMemo)(() => {
|
|
1267
1119
|
const result = {};
|
|
1268
1120
|
if (shouldNotInteract) {
|
|
1269
1121
|
blockedEventHandlers.forEach((eventHandler) => result[eventHandler] = void 0);
|
|
@@ -1317,9 +1169,9 @@ var Button = ({
|
|
|
1317
1169
|
Button.displayName = "Button";
|
|
1318
1170
|
|
|
1319
1171
|
// src/snackbar/SnackbarItemContext.tsx
|
|
1320
|
-
var
|
|
1321
|
-
var SnackbarItemContext = (0,
|
|
1322
|
-
var useSnackbarItemContext = () => (0,
|
|
1172
|
+
var import_react3 = require("react");
|
|
1173
|
+
var SnackbarItemContext = (0, import_react3.createContext)({});
|
|
1174
|
+
var useSnackbarItemContext = () => (0, import_react3.useContext)(SnackbarItemContext);
|
|
1323
1175
|
|
|
1324
1176
|
// src/snackbar/SnackbarItemAction.tsx
|
|
1325
1177
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
@@ -1367,7 +1219,7 @@ var import_Close = require("@spark-ui/icons/Close");
|
|
|
1367
1219
|
var import_class_variance_authority8 = require("class-variance-authority");
|
|
1368
1220
|
|
|
1369
1221
|
// src/icon/Icon.tsx
|
|
1370
|
-
var
|
|
1222
|
+
var import_react4 = require("react");
|
|
1371
1223
|
|
|
1372
1224
|
// src/icon/Icon.styles.tsx
|
|
1373
1225
|
var import_internal_utils8 = require("@spark-ui/internal-utils");
|
|
@@ -1412,9 +1264,9 @@ var Icon = ({
|
|
|
1412
1264
|
children,
|
|
1413
1265
|
...others
|
|
1414
1266
|
}) => {
|
|
1415
|
-
const child =
|
|
1267
|
+
const child = import_react4.Children.only(children);
|
|
1416
1268
|
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
|
|
1417
|
-
(0,
|
|
1269
|
+
(0, import_react4.cloneElement)(child, {
|
|
1418
1270
|
className: iconStyles({ className, size, intent }),
|
|
1419
1271
|
"data-spark-component": "icon",
|
|
1420
1272
|
"aria-hidden": "true",
|
|
@@ -1533,7 +1385,7 @@ var SnackbarItemIcon = ({
|
|
|
1533
1385
|
SnackbarItemIcon.displayName = "Snackbar.ItemIcon";
|
|
1534
1386
|
|
|
1535
1387
|
// src/snackbar/useSwipe.ts
|
|
1536
|
-
var
|
|
1388
|
+
var import_react5 = require("react");
|
|
1537
1389
|
var SWIPE_THRESHOLD = 75;
|
|
1538
1390
|
var useSwipe = ({
|
|
1539
1391
|
swipeRef,
|
|
@@ -1543,10 +1395,10 @@ var useSwipe = ({
|
|
|
1543
1395
|
onSwipeEnd,
|
|
1544
1396
|
threshold = 10
|
|
1545
1397
|
}) => {
|
|
1546
|
-
const [state, setState] = (0,
|
|
1547
|
-
const direction = (0,
|
|
1548
|
-
const origin = (0,
|
|
1549
|
-
const delta = (0,
|
|
1398
|
+
const [state, setState] = (0, import_react5.useState)();
|
|
1399
|
+
const direction = (0, import_react5.useRef)(null);
|
|
1400
|
+
const origin = (0, import_react5.useRef)(null);
|
|
1401
|
+
const delta = (0, import_react5.useRef)(null);
|
|
1550
1402
|
const handleSwipeStart = (evt) => {
|
|
1551
1403
|
origin.current = { x: evt.clientX, y: evt.clientY };
|
|
1552
1404
|
document.addEventListener("selectstart", (e) => e.preventDefault());
|
|
@@ -1609,7 +1461,7 @@ var useSwipe = ({
|
|
|
1609
1461
|
document.removeEventListener("selectstart", (e) => e.preventDefault());
|
|
1610
1462
|
}
|
|
1611
1463
|
};
|
|
1612
|
-
(0,
|
|
1464
|
+
(0, import_react5.useEffect)(() => {
|
|
1613
1465
|
if (!swipeRef.current) return;
|
|
1614
1466
|
const swipeElement = swipeRef.current;
|
|
1615
1467
|
swipeElement.addEventListener("pointerdown", handleSwipeStart);
|
|
@@ -1642,7 +1494,7 @@ var SnackbarItem = ({
|
|
|
1642
1494
|
ref: forwardedRef,
|
|
1643
1495
|
...rest
|
|
1644
1496
|
}) => {
|
|
1645
|
-
const innerRef = (0,
|
|
1497
|
+
const innerRef = (0, import_react6.useRef)(null);
|
|
1646
1498
|
const ref = typeof forwardedRef !== "function" ? forwardedRef || innerRef : innerRef;
|
|
1647
1499
|
const { toast, state } = useSnackbarItemContext();
|
|
1648
1500
|
const { state: swipeState, direction: swipeDirection } = useSwipe({
|
|
@@ -1669,10 +1521,10 @@ var SnackbarItem = ({
|
|
|
1669
1521
|
state,
|
|
1670
1522
|
ref
|
|
1671
1523
|
);
|
|
1672
|
-
const findElement = (0,
|
|
1524
|
+
const findElement = (0, import_react6.useCallback)(
|
|
1673
1525
|
(elementDisplayName) => {
|
|
1674
|
-
const childrenArray =
|
|
1675
|
-
const match = childrenArray.filter(
|
|
1526
|
+
const childrenArray = import_react6.Children.toArray(children);
|
|
1527
|
+
const match = childrenArray.filter(import_react6.isValidElement).find(
|
|
1676
1528
|
(child) => !!child.type.displayName?.includes(
|
|
1677
1529
|
elementDisplayName
|
|
1678
1530
|
)
|
|
@@ -1735,7 +1587,7 @@ var SnackbarItem = ({
|
|
|
1735
1587
|
SnackbarItem.displayName = "Snackbar.Item";
|
|
1736
1588
|
var renderSubComponent = (childItem, defaultItem, props) => {
|
|
1737
1589
|
if (childItem) {
|
|
1738
|
-
return (0,
|
|
1590
|
+
return (0, import_react6.cloneElement)(childItem, { ...props, ...childItem.props });
|
|
1739
1591
|
} else if (defaultItem) {
|
|
1740
1592
|
const Item = defaultItem;
|
|
1741
1593
|
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Item, { ...props });
|
|
@@ -1783,7 +1635,7 @@ var SnackbarRegion = ({
|
|
|
1783
1635
|
ref: forwardedRef,
|
|
1784
1636
|
...rest
|
|
1785
1637
|
}) => {
|
|
1786
|
-
const innerRef = (0,
|
|
1638
|
+
const innerRef = (0, import_react7.useRef)(null);
|
|
1787
1639
|
const ref = forwardedRef && typeof forwardedRef !== "function" ? forwardedRef : innerRef;
|
|
1788
1640
|
const { regionProps } = (0, import_toast2.useToastRegion)(rest, state, ref);
|
|
1789
1641
|
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
@@ -1793,26 +1645,26 @@ var SnackbarRegion = ({
|
|
|
1793
1645
|
ref,
|
|
1794
1646
|
"data-position": position,
|
|
1795
1647
|
className: snackbarRegionVariant({ position, className }),
|
|
1796
|
-
children: state.visibleToasts.map((toast) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(SnackbarItemContext.Provider, { value: { toast, state }, children: (0,
|
|
1648
|
+
children: state.visibleToasts.map((toast) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(SnackbarItemContext.Provider, { value: { toast, state }, children: (0, import_react7.cloneElement)(children, { key: toast.key }) }, toast.key))
|
|
1797
1649
|
}
|
|
1798
1650
|
);
|
|
1799
1651
|
};
|
|
1800
1652
|
|
|
1801
1653
|
// src/snackbar/useSnackbarGlobalStore.ts
|
|
1802
|
-
var
|
|
1654
|
+
var import_react8 = require("react");
|
|
1803
1655
|
var useSnackbarGlobalStore = ({
|
|
1804
1656
|
providers,
|
|
1805
1657
|
subscriptions
|
|
1806
1658
|
}) => {
|
|
1807
|
-
const subscribe = (0,
|
|
1659
|
+
const subscribe = (0, import_react8.useCallback)(
|
|
1808
1660
|
(listener) => {
|
|
1809
1661
|
subscriptions.add(listener);
|
|
1810
1662
|
return () => subscriptions.delete(listener);
|
|
1811
1663
|
},
|
|
1812
1664
|
[subscriptions]
|
|
1813
1665
|
);
|
|
1814
|
-
const getLastSnackbarProvider = (0,
|
|
1815
|
-
const addProvider = (0,
|
|
1666
|
+
const getLastSnackbarProvider = (0, import_react8.useCallback)(() => [...providers].reverse()[0], [providers]);
|
|
1667
|
+
const addProvider = (0, import_react8.useCallback)(
|
|
1816
1668
|
(provider2) => {
|
|
1817
1669
|
providers.add(provider2);
|
|
1818
1670
|
for (const subscribeFn of subscriptions) {
|
|
@@ -1821,7 +1673,7 @@ var useSnackbarGlobalStore = ({
|
|
|
1821
1673
|
},
|
|
1822
1674
|
[providers, subscriptions]
|
|
1823
1675
|
);
|
|
1824
|
-
const deleteProvider = (0,
|
|
1676
|
+
const deleteProvider = (0, import_react8.useCallback)(
|
|
1825
1677
|
(provider2) => {
|
|
1826
1678
|
providers.delete(provider2);
|
|
1827
1679
|
for (const subscribeFn of subscriptions) {
|
|
@@ -1830,7 +1682,7 @@ var useSnackbarGlobalStore = ({
|
|
|
1830
1682
|
},
|
|
1831
1683
|
[providers, subscriptions]
|
|
1832
1684
|
);
|
|
1833
|
-
const provider = (0,
|
|
1685
|
+
const provider = (0, import_react8.useSyncExternalStore)(subscribe, getLastSnackbarProvider, getLastSnackbarProvider);
|
|
1834
1686
|
return {
|
|
1835
1687
|
provider,
|
|
1836
1688
|
addProvider,
|
|
@@ -1843,7 +1695,7 @@ var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
|
1843
1695
|
var GLOBAL_SNACKBAR_QUEUE = null;
|
|
1844
1696
|
var getGlobalSnackBarQueue = () => {
|
|
1845
1697
|
if (!GLOBAL_SNACKBAR_QUEUE) {
|
|
1846
|
-
GLOBAL_SNACKBAR_QUEUE = new ToastQueue({
|
|
1698
|
+
GLOBAL_SNACKBAR_QUEUE = new import_toast3.ToastQueue({
|
|
1847
1699
|
maxVisibleToasts: 1,
|
|
1848
1700
|
hasExitAnimation: true
|
|
1849
1701
|
});
|
|
@@ -1858,10 +1710,10 @@ var GLOBAL_SNACKBAR_STORE = {
|
|
|
1858
1710
|
subscriptions: /* @__PURE__ */ new Set()
|
|
1859
1711
|
};
|
|
1860
1712
|
var Snackbar = ({ ref: forwardedRef, ...props }) => {
|
|
1861
|
-
const ref = (0,
|
|
1862
|
-
const state = useToastQueue(getGlobalSnackBarQueue());
|
|
1713
|
+
const ref = (0, import_react9.useRef)(null);
|
|
1714
|
+
const state = (0, import_toast3.useToastQueue)(getGlobalSnackBarQueue());
|
|
1863
1715
|
const { provider, addProvider, deleteProvider } = useSnackbarGlobalStore(GLOBAL_SNACKBAR_STORE);
|
|
1864
|
-
(0,
|
|
1716
|
+
(0, import_react9.useEffect)(() => {
|
|
1865
1717
|
addProvider(ref);
|
|
1866
1718
|
return () => {
|
|
1867
1719
|
for (const toast of getGlobalSnackBarQueue().visibleToasts) {
|