sonner 2.0.1 → 2.0.2

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/dist/index.js CHANGED
@@ -187,8 +187,13 @@ class Observer {
187
187
  return id;
188
188
  };
189
189
  this.dismiss = (id)=>{
190
- this.dismissedToasts.add(id);
191
- if (!id) {
190
+ if (id) {
191
+ this.dismissedToasts.add(id);
192
+ requestAnimationFrame(()=>this.subscribers.forEach((subscriber)=>subscriber({
193
+ id,
194
+ dismiss: true
195
+ })));
196
+ } else {
192
197
  this.toasts.forEach((toast)=>{
193
198
  this.subscribers.forEach((subscriber)=>subscriber({
194
199
  id: toast.id,
@@ -196,10 +201,6 @@ class Observer {
196
201
  }));
197
202
  });
198
203
  }
199
- requestAnimationFrame(()=>this.subscribers.forEach((subscriber)=>subscriber({
200
- id,
201
- dismiss: true
202
- })));
203
204
  return id;
204
205
  };
205
206
  this.message = (message, data)=>{
@@ -278,7 +279,8 @@ class Observer {
278
279
  shouldDismiss = false;
279
280
  const promiseData = typeof data.error === 'function' ? await data.error(`HTTP error! status: ${response.status}`) : data.error;
280
281
  const description = typeof data.description === 'function' ? await data.description(`HTTP error! status: ${response.status}`) : data.description;
281
- const toastSettings = typeof promiseData === 'object' ? promiseData : {
282
+ const isExtendedResult = typeof promiseData === 'object' && !React__default.default.isValidElement(promiseData);
283
+ const toastSettings = isExtendedResult ? promiseData : {
282
284
  message: promiseData
283
285
  };
284
286
  this.create({
@@ -291,7 +293,8 @@ class Observer {
291
293
  shouldDismiss = false;
292
294
  const promiseData = typeof data.error === 'function' ? await data.error(response) : data.error;
293
295
  const description = typeof data.description === 'function' ? await data.description(response) : data.description;
294
- const toastSettings = typeof promiseData === 'object' ? promiseData : {
296
+ const isExtendedResult = typeof promiseData === 'object' && !React__default.default.isValidElement(promiseData);
297
+ const toastSettings = isExtendedResult ? promiseData : {
295
298
  message: promiseData
296
299
  };
297
300
  this.create({
@@ -304,7 +307,8 @@ class Observer {
304
307
  shouldDismiss = false;
305
308
  const promiseData = typeof data.success === 'function' ? await data.success(response) : data.success;
306
309
  const description = typeof data.description === 'function' ? await data.description(response) : data.description;
307
- const toastSettings = typeof promiseData === 'object' ? promiseData : {
310
+ const isExtendedResult = typeof promiseData === 'object' && !React__default.default.isValidElement(promiseData);
311
+ const toastSettings = isExtendedResult ? promiseData : {
308
312
  message: promiseData
309
313
  };
310
314
  this.create({
@@ -323,7 +327,8 @@ class Observer {
323
327
  shouldDismiss = false;
324
328
  const promiseData = typeof data.error === 'function' ? await data.error(error) : data.error;
325
329
  const description = typeof data.description === 'function' ? await data.description(error) : data.description;
326
- const toastSettings = typeof promiseData === 'object' ? promiseData : {
330
+ const isExtendedResult = typeof promiseData === 'object' && !React__default.default.isValidElement(promiseData);
331
+ const toastSettings = isExtendedResult ? promiseData : {
327
332
  message: promiseData
328
333
  };
329
334
  this.create({
@@ -636,6 +641,7 @@ const Toast = (props)=>{
636
641
  visible: toastType === 'loading'
637
642
  });
638
643
  }
644
+ const icon = toast.icon || (icons == null ? void 0 : icons[toastType]) || getAsset(toastType);
639
645
  var _toast_richColors, _icons_close;
640
646
  return /*#__PURE__*/ React__default.default.createElement("li", {
641
647
  tabIndex: 0,
@@ -779,10 +785,10 @@ const Toast = (props)=>{
779
785
  toast.onDismiss == null ? void 0 : toast.onDismiss.call(toast, toast);
780
786
  },
781
787
  className: cn(classNames == null ? void 0 : classNames.closeButton, toast == null ? void 0 : (_toast_classNames2 = toast.classNames) == null ? void 0 : _toast_classNames2.closeButton)
782
- }, (_icons_close = icons == null ? void 0 : icons.close) != null ? _icons_close : CloseIcon) : null, toastType || toast.icon || toast.promise ? /*#__PURE__*/ React__default.default.createElement("div", {
788
+ }, (_icons_close = icons == null ? void 0 : icons.close) != null ? _icons_close : CloseIcon) : null, (toastType || toast.icon || toast.promise) && toast.icon !== null && ((icons == null ? void 0 : icons[toastType]) !== null || toast.icon) ? /*#__PURE__*/ React__default.default.createElement("div", {
783
789
  "data-icon": "",
784
790
  className: cn(classNames == null ? void 0 : classNames.icon, toast == null ? void 0 : (_toast_classNames3 = toast.classNames) == null ? void 0 : _toast_classNames3.icon)
785
- }, toast.promise || toast.type === 'loading' && !toast.icon ? toast.icon || getLoadingIcon() : null, toast.type !== 'loading' ? toast.icon || (icons == null ? void 0 : icons[toastType]) || getAsset(toastType) : null) : null, /*#__PURE__*/ React__default.default.createElement("div", {
791
+ }, toast.promise || toast.type === 'loading' && !toast.icon ? toast.icon || getLoadingIcon() : null, toast.type !== 'loading' ? icon : null) : null, /*#__PURE__*/ React__default.default.createElement("div", {
786
792
  "data-content": "",
787
793
  className: cn(classNames == null ? void 0 : classNames.content, toast == null ? void 0 : (_toast_classNames4 = toast.classNames) == null ? void 0 : _toast_classNames4.content)
788
794
  }, /*#__PURE__*/ React__default.default.createElement("div", {
@@ -941,13 +947,12 @@ const Toaster = /*#__PURE__*/ React__default.default.forwardRef(function Toaster
941
947
  React__default.default.useEffect(()=>{
942
948
  return ToastState.subscribe((toast)=>{
943
949
  if (toast.dismiss) {
944
- const map = toasts.map((t)=>t.id === toast.id ? {
945
- ...t,
946
- delete: true
947
- } : t);
948
950
  // Prevent batching of other state updates
949
951
  requestAnimationFrame(()=>{
950
- setToasts(map);
952
+ setToasts((toasts)=>toasts.map((t)=>t.id === toast.id ? {
953
+ ...t,
954
+ delete: true
955
+ } : t));
951
956
  });
952
957
  return;
953
958
  }
package/dist/index.mjs CHANGED
@@ -180,8 +180,13 @@ class Observer {
180
180
  return id;
181
181
  };
182
182
  this.dismiss = (id)=>{
183
- this.dismissedToasts.add(id);
184
- if (!id) {
183
+ if (id) {
184
+ this.dismissedToasts.add(id);
185
+ requestAnimationFrame(()=>this.subscribers.forEach((subscriber)=>subscriber({
186
+ id,
187
+ dismiss: true
188
+ })));
189
+ } else {
185
190
  this.toasts.forEach((toast)=>{
186
191
  this.subscribers.forEach((subscriber)=>subscriber({
187
192
  id: toast.id,
@@ -189,10 +194,6 @@ class Observer {
189
194
  }));
190
195
  });
191
196
  }
192
- requestAnimationFrame(()=>this.subscribers.forEach((subscriber)=>subscriber({
193
- id,
194
- dismiss: true
195
- })));
196
197
  return id;
197
198
  };
198
199
  this.message = (message, data)=>{
@@ -271,7 +272,8 @@ class Observer {
271
272
  shouldDismiss = false;
272
273
  const promiseData = typeof data.error === 'function' ? await data.error(`HTTP error! status: ${response.status}`) : data.error;
273
274
  const description = typeof data.description === 'function' ? await data.description(`HTTP error! status: ${response.status}`) : data.description;
274
- const toastSettings = typeof promiseData === 'object' ? promiseData : {
275
+ const isExtendedResult = typeof promiseData === 'object' && !React.isValidElement(promiseData);
276
+ const toastSettings = isExtendedResult ? promiseData : {
275
277
  message: promiseData
276
278
  };
277
279
  this.create({
@@ -284,7 +286,8 @@ class Observer {
284
286
  shouldDismiss = false;
285
287
  const promiseData = typeof data.error === 'function' ? await data.error(response) : data.error;
286
288
  const description = typeof data.description === 'function' ? await data.description(response) : data.description;
287
- const toastSettings = typeof promiseData === 'object' ? promiseData : {
289
+ const isExtendedResult = typeof promiseData === 'object' && !React.isValidElement(promiseData);
290
+ const toastSettings = isExtendedResult ? promiseData : {
288
291
  message: promiseData
289
292
  };
290
293
  this.create({
@@ -297,7 +300,8 @@ class Observer {
297
300
  shouldDismiss = false;
298
301
  const promiseData = typeof data.success === 'function' ? await data.success(response) : data.success;
299
302
  const description = typeof data.description === 'function' ? await data.description(response) : data.description;
300
- const toastSettings = typeof promiseData === 'object' ? promiseData : {
303
+ const isExtendedResult = typeof promiseData === 'object' && !React.isValidElement(promiseData);
304
+ const toastSettings = isExtendedResult ? promiseData : {
301
305
  message: promiseData
302
306
  };
303
307
  this.create({
@@ -316,7 +320,8 @@ class Observer {
316
320
  shouldDismiss = false;
317
321
  const promiseData = typeof data.error === 'function' ? await data.error(error) : data.error;
318
322
  const description = typeof data.description === 'function' ? await data.description(error) : data.description;
319
- const toastSettings = typeof promiseData === 'object' ? promiseData : {
323
+ const isExtendedResult = typeof promiseData === 'object' && !React.isValidElement(promiseData);
324
+ const toastSettings = isExtendedResult ? promiseData : {
320
325
  message: promiseData
321
326
  };
322
327
  this.create({
@@ -629,6 +634,7 @@ const Toast = (props)=>{
629
634
  visible: toastType === 'loading'
630
635
  });
631
636
  }
637
+ const icon = toast.icon || (icons == null ? void 0 : icons[toastType]) || getAsset(toastType);
632
638
  var _toast_richColors, _icons_close;
633
639
  return /*#__PURE__*/ React.createElement("li", {
634
640
  tabIndex: 0,
@@ -772,10 +778,10 @@ const Toast = (props)=>{
772
778
  toast.onDismiss == null ? void 0 : toast.onDismiss.call(toast, toast);
773
779
  },
774
780
  className: cn(classNames == null ? void 0 : classNames.closeButton, toast == null ? void 0 : (_toast_classNames2 = toast.classNames) == null ? void 0 : _toast_classNames2.closeButton)
775
- }, (_icons_close = icons == null ? void 0 : icons.close) != null ? _icons_close : CloseIcon) : null, toastType || toast.icon || toast.promise ? /*#__PURE__*/ React.createElement("div", {
781
+ }, (_icons_close = icons == null ? void 0 : icons.close) != null ? _icons_close : CloseIcon) : null, (toastType || toast.icon || toast.promise) && toast.icon !== null && ((icons == null ? void 0 : icons[toastType]) !== null || toast.icon) ? /*#__PURE__*/ React.createElement("div", {
776
782
  "data-icon": "",
777
783
  className: cn(classNames == null ? void 0 : classNames.icon, toast == null ? void 0 : (_toast_classNames3 = toast.classNames) == null ? void 0 : _toast_classNames3.icon)
778
- }, toast.promise || toast.type === 'loading' && !toast.icon ? toast.icon || getLoadingIcon() : null, toast.type !== 'loading' ? toast.icon || (icons == null ? void 0 : icons[toastType]) || getAsset(toastType) : null) : null, /*#__PURE__*/ React.createElement("div", {
784
+ }, toast.promise || toast.type === 'loading' && !toast.icon ? toast.icon || getLoadingIcon() : null, toast.type !== 'loading' ? icon : null) : null, /*#__PURE__*/ React.createElement("div", {
779
785
  "data-content": "",
780
786
  className: cn(classNames == null ? void 0 : classNames.content, toast == null ? void 0 : (_toast_classNames4 = toast.classNames) == null ? void 0 : _toast_classNames4.content)
781
787
  }, /*#__PURE__*/ React.createElement("div", {
@@ -934,13 +940,12 @@ const Toaster = /*#__PURE__*/ React.forwardRef(function Toaster(props, ref) {
934
940
  React.useEffect(()=>{
935
941
  return ToastState.subscribe((toast)=>{
936
942
  if (toast.dismiss) {
937
- const map = toasts.map((t)=>t.id === toast.id ? {
938
- ...t,
939
- delete: true
940
- } : t);
941
943
  // Prevent batching of other state updates
942
944
  requestAnimationFrame(()=>{
943
- setToasts(map);
945
+ setToasts((toasts)=>toasts.map((t)=>t.id === toast.id ? {
946
+ ...t,
947
+ delete: true
948
+ } : t));
944
949
  });
945
950
  return;
946
951
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sonner",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "description": "An opinionated toast component for React.",
5
5
  "exports": {
6
6
  ".": {