notiflix / Notiflix

Notiflix is a pure JavaScript library for client-side non-blocking notifications, popup boxes, loading indicators, and more that makes your web projects much better.

Home Page:https://notiflix.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[FEAT] - Callback and timeout

vfrz opened this issue · comments

Is your feature request related to a problem? Please describe.

I wanted a notification with a timeout and a callback.

Describe the solution you'd like

I'd like to have the possibility to have a timeout and a callback together.

Additional context

It is currently not possible because of this line which prevent the timeout if callback is set: https://github.com/notiflix/Notiflix/blob/main/src/notiflix.js#L769

If you are okay with this, I can try to make a PR!

Hi @vfrz,

"The notifications with the callback function do not disappear until they were clicked."
https://notiflix.github.io/notify

So, it will be going to stay as it is. For your expectation; you can use your own solutions. For instance, an example of usage can be as below. (In addition, it is not related to the line(code) that you have mentioned.)

// example
var yourExpectationNotifySuccess = function (message, callback) {
  var yourTimeoutExpectation = 1923;
  Notiflix.Notify.success(message, {
    timeout: yourTimeoutExpectation,
  });
  
  var delay = setTimeout(function() {
    callback();
    clearTimeout(delay);
  }, yourTimeoutExpectation); 
};

// usage
yourExpectationNotifySuccess('Sol lucet omnibus', function () {
  // your callback codes...
  console.log('Notiflix');
});

Thanks,
Furkan.