tutkli / ngx-sonner

An opinionated toast component for Angular. A port of @emilkowalski's sonner.
https://tutkli.github.io/ngx-sonner/
MIT License
94 stars 8 forks source link

Dismissable setting doesn't work both ways #14

Closed charlieandroid55 closed 7 months ago

charlieandroid55 commented 7 months ago

Please provide the environment you discovered this bug in.

<ngx-sonner-toaster closeButton="false"/>
 toast.error('Error toast', {dismissable: true});

Description

The dismissable configuration, which is managed at the instance level, in my opinion, should override the global closeButton configuration in both directions. If I set closeButton to true, I expect most of my toasts to have that action, except for a few that cannot be closed. However, if I set closeButton to false, I mean that none of them should be closable by default, except for the one that has dismissable set to true. This way, I would have control over when and how a toast can be dismissed.

Currently, the behavior works as expected in version 0.4.1 for the following configuration: closeButton=true | dismissable=false.

However, the following configuration needs to be implemented: closeButton=false | dismissable=true.

Please provide the exception or error you saw

No response

Other information

No response

I would be willing to submit a PR to fix this issue

tutkli commented 7 months ago

Hi, @charlieandroid55 ! The dismissible property of the toast refer to the ability to swipe out a toast, which is currently not working (Fixing it in #16 ).

For this, I'll add a closeButton property to the toastOptions, so you can override the toaster config.

  1. Toast don't have a close button by default, except when instatiating then with closeButton: true:

    <ngx-sonner-toaster closeButton="false"/>
    toast('Some message', {closeButton: true});
  2. Toasts have a closeButton by default, but can be hidden when instatiating with closeButton: false

    <ngx-sonner-toaster closeButton />
    toast('Some message', {closeButton: false});

Also, I'll be adding some docs to the types so everything is clearer.

charlieandroid55 commented 7 months ago

Hi @tutkli, ok, it works for me, but I think you should keep the API simpler. Maybe another global property can be applied to indicate that toasts can be swipeable and marking the toast instance with dismissable:false blocks the gesture and hides the close button preventing to the user to close this instance, what I suggest is that we need a way to cancel any action that allows closing a toast instance, otherwise now to achieve this we must take into account two options.

tutkli commented 7 months ago

I understand, but I think it's okay to have the two options as they are two diferent actions. Adds more customization. The original API is also like this, and I did not included it in first time.

Bear with me as this is the first angular port I make , but I'm trying to make it as best as possible 😅

tutkli commented 7 months ago

:tada: This issue has been resolved in version 1.0.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: