apvarun / toastify-js

Pure JavaScript library for better notification messages
https://apvarun.github.io/toastify-js/
MIT License
2.09k stars 230 forks source link

Programmatic control over popups? #117

Open andregreeff opened 1 year ago

andregreeff commented 1 year ago

I've used ToastifyJS in a number of small projects so far, it's beautifully simple to use and easy to implement.. but now I find myself needing a little more functionality than I have previously.

I have a feeling that I know the answer to my question already, but in part just to confirm, and in part to (hopefully) plant a seed for possible future improvement: is it possible to control the ToastifyJS popups programmatically?

for example:

my first thought was to render the notification with a unique ID, and then find and manipulate that DOM node from my own custom code.. but this would introduce two rather serious problems:

firstly, it requires a great deal of very specific business logic. which would depend directly on the current DOM structure, and would obviously be prone to break with even minor library changes.

secondly, while I can target and manipulate the DOM nodes, this would not give me access to the methods from the Toastify object itself, so I wouldn't be able to use the hideToast method from outside of the code that handles toast creation, and would instead need to locate the toast and call removeChild myself.

@apvarun, would you consider adding this sort of functionality to ToastifyJS at some point?