Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type specific default options #571

Open
jwschram opened this issue May 26, 2018 · 7 comments
Open

Type specific default options #571

jwschram opened this issue May 26, 2018 · 7 comments

Comments

@jwschram
Copy link

jwschram commented May 26, 2018

While using toastr in my project I realised that I really wanted different default options per toast type (info/warning/error/etc.).

I could make a wrapper but that feels redundant given how simple the wrapper would be.

I can do the work and I can do it without causing a breaking change, but I wanted to make sure that maintainers agree it's worth implementing.

@leehoss
Copy link

leehoss commented May 30, 2018

this is what I expect would be awesome
toastr.load(status,message,blah);

@jwschram
Copy link
Author

I'm not sure I understand the load function. I'm suggesting something that isn't message specific, by building it into the global options object. Something like this.

toastr.options = {
  // default options
  "closeButton": false,
  "debug": false,
  "newestOnTop": false,
  "progressBar": false,
  "positionClass": "toast-top-right",
  "timeOut": 3000,
  "extendedTimeOut": 3000,
  ...
  "typeoverrides": {   // takes 0 or more of the available toast types
    "error": {   // toast type as object key
       // subset of option properties valid in calls to toastr (i.e. toastr["error"](msg, opts) )
      "timeOut": 0
    },
    "warning": {
      "progressBar": true
    }
  }
}

My thinking is that options would remain hierarchical as they are currently. So that toastr.error(msg, calloverrides) would use global -> global.typeoverrides.error -> calloverrides to determine the final set of options to use for the call.

What do you think? Is this in keeping with the design principles of the project?

@jwschram
Copy link
Author

jwschram commented Jun 2, 2018

Turns out this is about 5 lines so I did it and will publish it as a PR. The new property is

options = {
  typeBasedOverrides: {
    info: {},
    success: {},
    warning: {},
    error: {}
  }

jwschram added a commit to jwschram/toastr that referenced this issue Jun 2, 2018
…e options hierarchy.

-- uses new options object property typeBasedOverrides where typeBasedOverrides is an object
   with child objects of each type that accept the same parameters as overrideOptions

options = {
  typeBasedOverrides: {
    info: {},
    success: {},
    warning: {},
    error: {}
  }

see CodeSeven#571
@ivansammartino
Copy link

This would be very fine! I was just thinking that I'd like to persist error and warning messages instead of fading them after a while (while keeping success messages fading)
Hope it would be implemented soon! :-)

@jwschram
Copy link
Author

jwschram commented Jun 22, 2018 via email

@AlexH-HankIT
Copy link

I really could use that too. Is this gonna get merged soon by any chance? Thanks.

@banda13
Copy link

banda13 commented Jan 24, 2019

I'm waiting for this merge too!

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

No branches or pull requests

5 participants