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

feat(toast): add ability to register custom toasts #271

Merged
merged 4 commits into from Apr 8, 2019

Conversation

mcoope31
Copy link
Contributor

@mcoope31 mcoope31 commented Mar 28, 2019

Trying to add the ability to register custom toasts from nuxt config.

It would look like this:

toast: {
    position: 'bottom-right',
    register: [
      {
        name: 'test',
        message: (payload) => {
          if(!payload.message) return "Default message"
          return payload.message
        },
        options: {
          type : 'success',
          duration: 3000,
        }
      },
    ]
  },

Usage:

this.$toast.global.test()
this.$toast.global.test({ message: "Custom message here" } )

@@ -1,8 +1,19 @@
import Vue from 'vue'
import Toasted from 'vue-toasted'

Vue.use(Toasted, <%= serialize(options) %>)
const opts = <%= serialize(options) %>
var globals = []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please separate register from options at module level?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So instead of register being inside the toast {} options they should be another option like register_toasts [] ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean a code like this in index.js:

module.exports = function nuxtToast (moduleOptions) {
  const { register, ...toastOptions } = Object.assign({}, this.options.toast, moduleOptions)

  // Register plugin
  this.addPlugin({
    src: path.resolve(__dirname, 'plugin.js'),
    ssr: false,
    fileName: 'toast.js',
    options: {
       register,
       toastOptions
    }
  })
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, much cleaner.. works well. I updated the readme.

@pi0 pi0 changed the title Adding ability to register custom toasts feat(toast): add ability to register custom toasts Apr 8, 2019
@pi0 pi0 merged commit b9ecbbd into nuxt-community:master Apr 8, 2019
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.

None yet

2 participants