Skip to content

Enhance Promise to support ExternalToast propertiesfeat: Promise enhancement to allow ExternalToast props#547

Merged
emilkowalski merged 1 commit intoemilkowalski:canaryfrom
diegotraid:promise-enhancement
Feb 16, 2025
Merged

Enhance Promise to support ExternalToast propertiesfeat: Promise enhancement to allow ExternalToast props#547
emilkowalski merged 1 commit intoemilkowalski:canaryfrom
diegotraid:promise-enhancement

Conversation

@diegotraid
Copy link
Contributor

@diegotraid diegotraid commented Jan 25, 2025

Resolves #464

Introduce new types and extend existing functionality to allow for more detailed toast messages in promise handling. This enhancement improves the flexibility of toast notifications by incorporating additional properties.

Usage:

toast.promise<{ name: string }>(
  () =>
    new Promise((resolve, reject) => {
      setTimeout(() => {
        resolve({ name: 'Sonner' });
      }, 2000);
    }),
  {
    loading: 'Loading...',
    success: (data) => {
      return {
        message: `${data.name} toast has been added`,
        description: 'Custom description for the Success state',
      };
    },
    error: {
      message: 'An error occurred',
      description: undefined, // overrides default description set below
      action: {
        label: 'Retry',
        onClick: () => {
          console.log('retrying');
        },
      },
    },
    description: 'Global description',
  },
)

This is a non-breaking change, so you can still pass values as defined in the docs:

toast.promise<{ name: string }>(
  () =>
    new Promise((resolve, reject) => {
      setTimeout(() => {
        resolve({ name: 'Sonner' });
      }, 2000);
    }),
  {
    loading: 'Loading...',
    success: (data) => {
      return `${data.name} toast has been added`;
    },
    error: 'Error',
    description: 'Global description',
  },
)

@vercel
Copy link

vercel bot commented Jan 25, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
sonner ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 25, 2025 0:59am

@diegotraid diegotraid marked this pull request as ready for review January 25, 2025 13:03
@emilkowalski emilkowalski changed the base branch from main to canary February 15, 2025 13:11
@emilkowalski emilkowalski merged commit 99d3d93 into emilkowalski:canary Feb 16, 2025
2 checks passed
emilkowalski added a commit that referenced this pull request Feb 18, 2025
* refactor: remove unstyled prop (#557)

* fix: allow toats to grow properly (#559)

* chore: rename data-theme to data-sonner-theme (#560)

* fix: toast removal in strict mode (#563)

* refactor: maintain default styles when custom (#564)

* fix: check for promise properly (#565)

* chore: horizontal swiping improvements (#566)

* medium font weight

* chore: improve rich colors (#567)

* chore: improve base colors (#568)

* improve colors

* improve base colors

* chore: remove lift interaction, decrease default gap (#569)

* v2.0.0-beta.1

* chore: update toast lifetime (#570)

* build: use bunchee (#561)

* fix: failing tests (#572)

* Fix tests

* fix tests

* fix: unstyled prop not being applied to all elements (#573)

* Improve unstyled prop

* Cleanup

* fix: inability to remove a toast that has just been created (#574)

* Prevent batching

* Cleanup

* hero cleanup

* fix: close button background is transparent (#575)

* chore: bring back lift on hover (#576)

* v2.0.0-beta.2

* chore: remove deprecated props (#577)

* feat: drag damping (#578)

* dampen darg

* Adjust swipe threshold

* typo

* Enhance Promise to support ExternalToast propertiesfeat: Promise enhancement to allow ExternalToast props (#547)

* fix: make promises work with new Error (#579)

* wip

* Add test for error classin promises

* chore: Hide the close button when toastType is loading (#516)

#514 #476

* fix close button aria labels (#490)

Co-authored-by: Emil Kowalski <36730035+emilkowalski@users.noreply.github.com>

* fix: error promise test (#580)

* v2.0.0-beta.3

---------

Co-authored-by: Jiachi Liu <inbox@huozhi.im>
Co-authored-by: Diego Traid <35971053+diegotraid@users.noreply.github.com>
Co-authored-by: 알노리 <67145096+ynng3@users.noreply.github.com>
Co-authored-by: Miro Rauhala <4082806+mirorauhala@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enhanced Configuration for toast.promise States

2 participants

Comments