goey-toast 0.4.0 → 0.4.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.
package/README.md CHANGED
@@ -224,6 +224,7 @@ Props for the `<GooeyToaster />` component.
224
224
  | `queueOverflow` | `'drop-oldest' \| 'drop-newest'` | `'drop-oldest'` | Queue overflow strategy |
225
225
  | `dir` | `'ltr' \| 'rtl'` | `'ltr'` | Layout direction |
226
226
  | `swipeToDismiss` | `boolean` | `true` | Enable swipe-to-dismiss on mobile |
227
+ | `showTimestamp` | `boolean` | `true` | Show/hide timestamp on all toasts globally |
227
228
 
228
229
  ### `GooeyPromiseData<T>`
229
230
 
@@ -439,10 +440,12 @@ The close button inherits the toast's border and fill color styling. Hidden duri
439
440
 
440
441
  ### Hiding Timestamps
441
442
 
442
- Hide the timestamp from toasts:
443
-
444
443
  ```tsx
444
+ // Per-toast: hide timestamp for this toast only
445
445
  gooeyToast.success('Saved', { showTimestamp: false })
446
+
447
+ // Globally: hide timestamp for all toasts
448
+ <GooeyToaster showTimestamp={false} />
446
449
  ```
447
450
 
448
451
  ## Exports
package/dist/index.cjs CHANGED
@@ -86,6 +86,13 @@ function setGooeyShowProgress(show) {
86
86
  function getGooeyShowProgress() {
87
87
  return _showProgress;
88
88
  }
89
+ var _showTimestamp = true;
90
+ function setGooeyShowTimestamp(show) {
91
+ _showTimestamp = show;
92
+ }
93
+ function getGooeyShowTimestamp() {
94
+ return _showTimestamp;
95
+ }
89
96
  var _closeButton = false;
90
97
  function setGooeyCloseButton(value) {
91
98
  _closeButton = value;
@@ -341,23 +348,23 @@ function registerSonnerObserver(ol, callback) {
341
348
  let entry = observerRegistry.get(ol);
342
349
  if (!entry) {
343
350
  const callbacks = /* @__PURE__ */ new Set();
344
- let applying = false;
345
- const observer = new MutationObserver(() => {
346
- if (applying) return;
347
- applying = true;
348
- requestAnimationFrame(() => {
349
- callbacks.forEach((cb) => cb());
350
- requestAnimationFrame(() => {
351
- applying = false;
352
- });
353
- });
354
- });
355
- observer.observe(ol, {
351
+ const observeOptions = {
356
352
  attributes: true,
357
353
  attributeFilter: ["style", "data-visible"],
358
354
  subtree: true,
359
355
  childList: true
356
+ };
357
+ const observer = new MutationObserver(() => {
358
+ observer.disconnect();
359
+ try {
360
+ for (const cb of callbacks) {
361
+ cb();
362
+ }
363
+ } finally {
364
+ observer.observe(ol, observeOptions);
365
+ }
360
366
  });
367
+ observer.observe(ol, observeOptions);
361
368
  entry = { observer, callbacks };
362
369
  observerRegistry.set(ol, entry);
363
370
  }
@@ -385,17 +392,10 @@ function syncSonnerHeights(wrapperEl, includeOffsets = false) {
385
392
  const h = content ? content.getBoundingClientRect().height : 0;
386
393
  return h > 0 ? h : PH;
387
394
  });
388
- const isExpanded = includeOffsets && toasts[0]?.getAttribute("data-expanded") === "true";
389
- if (isExpanded) {
390
- for (const t of toasts) t.style.setProperty("transition", "none", "important");
391
- }
392
395
  for (let i = 0; i < toasts.length; i++) {
393
396
  toasts[i].style.setProperty("--initial-height", `${heights[i]}px`);
394
397
  }
395
398
  if (!includeOffsets) {
396
- if (isExpanded) {
397
- for (const t of toasts) t.style.removeProperty("transition");
398
- }
399
399
  return;
400
400
  }
401
401
  const gapStr = getComputedStyle(ol).getPropertyValue("--gap").trim();
@@ -411,10 +411,6 @@ function syncSonnerHeights(wrapperEl, includeOffsets = false) {
411
411
  runningOffset += heights[i] + gap;
412
412
  }
413
413
  }
414
- if (isExpanded) {
415
- void ol.offsetHeight;
416
- for (const t of toasts) t.style.removeProperty("transition");
417
- }
418
414
  }
419
415
  function memoizePath(fn) {
420
416
  let lastArgs = null;
@@ -545,7 +541,7 @@ var GooeyToast = ({
545
541
  preset,
546
542
  spring: springProp,
547
543
  bounce: bounceProp,
548
- showTimestamp = true,
544
+ showTimestamp: showTimestampProp,
549
545
  showProgress: showProgressProp,
550
546
  toastId
551
547
  }) => {
@@ -563,6 +559,7 @@ var GooeyToast = ({
563
559
  const useSpring = springProp ?? presetConfig?.spring ?? getGooeySpring();
564
560
  const bounceVal = bounceProp ?? presetConfig?.bounce ?? getGooeyBounce() ?? 0.4;
565
561
  const showProgress = showProgressProp ?? getGooeyShowProgress();
562
+ const showTimestamp = showTimestampProp ?? getGooeyShowTimestamp();
566
563
  const [actionSuccess, setActionSuccess] = react.useState(null);
567
564
  const [dismissing, setDismissing] = react.useState(false);
568
565
  const [progressKey, setProgressKey] = react.useState(0);
@@ -1767,7 +1764,8 @@ function GooeyToaster({
1767
1764
  closeOnEscape = true,
1768
1765
  maxQueue = Infinity,
1769
1766
  queueOverflow = "drop-oldest",
1770
- showProgress = false
1767
+ showProgress = false,
1768
+ showTimestamp = true
1771
1769
  }) {
1772
1770
  const presetConfig = preset ? animationPresets[preset] : void 0;
1773
1771
  const resolvedSpring = spring ?? presetConfig?.spring ?? true;
@@ -1820,6 +1818,9 @@ function GooeyToaster({
1820
1818
  react.useEffect(() => {
1821
1819
  setGooeyCloseButton(closeButton ?? false);
1822
1820
  }, [closeButton]);
1821
+ react.useEffect(() => {
1822
+ setGooeyShowTimestamp(showTimestamp);
1823
+ }, [showTimestamp]);
1823
1824
  react.useEffect(() => {
1824
1825
  let expandObs = null;
1825
1826
  let currentOl = null;