From 7929db8e54127588d43afbf54564268b17142889 Mon Sep 17 00:00:00 2001 From: Dan Popescu Date: Thu, 28 Mar 2019 19:47:08 +0200 Subject: [PATCH] fix(quasar+docs): Fix default actions handler and add details about defaults to documentation close #3722 --- docs/src/pages/quasar-plugins/notify.md | 35 +++++++++++++++++++++++++ quasar/src/plugins/Notify.js | 9 +++++++ 2 files changed, 44 insertions(+) diff --git a/docs/src/pages/quasar-plugins/notify.md b/docs/src/pages/quasar-plugins/notify.md index 0a9c856f495f..24ae6a132beb 100644 --- a/docs/src/pages/quasar-plugins/notify.md +++ b/docs/src/pages/quasar-plugins/notify.md @@ -6,6 +6,10 @@ Notify is a Quasar plugin that can display animated messages (floating above eve ## Installation +::: warning +You cannot define `actions` with handlers as defaults. If you define `actions` in defaults all of them will close the notification. If you specify `actions` when creating the notification the **default ones will be ignored**. You cannot set default `onDismiss` handler. +::: + ## Usage ``` js // outside of a Vue file @@ -35,6 +39,37 @@ If you define any actions, the notification will automatically be dismissed when For a full list of options, check the API section. ::: +### Setting Defaults from Code +Similar to how you can define Notify defaults in the configuration you can also define defaults in code, using `setDefaults` + +``` js +// outside of a Vue file, in a boot plugin +import { Notify } from 'quasar' + +Notify.setDefaults({ + position: 'top-right', + timeout: 2500, + textColor: 'white', + actions: [{ icon: 'close', color: 'white' }] +}) + +// inside of a Vue file +this.$q.setDefaults({ + position: 'top-right', + timeout: 2500, + textColor: 'white', + actions: [{ icon: 'close', color: 'white' }] +}) +``` + +::: warning +The defaults are not specific to a component, so changing them using `this.$q.setDefaults({...})` **will be global**. +::: + +::: warning +You cannot define `actions` with handlers as defaults. If you define `actions` in defaults all of them will close the notification. If you specify `actions` when creating the notification the **default ones will be ignored**. You cannot set default `onDismiss` handler. +::: + ### Programmatically Closing Alert Notifications are meant to be dismissed only by the user, however for exceptional cases you can do it programmatically. Especially useful when you set indefinite timeout (0). diff --git a/quasar/src/plugins/Notify.js b/quasar/src/plugins/Notify.js index 159a73078714..06a8de791e56 100644 --- a/quasar/src/plugins/Notify.js +++ b/quasar/src/plugins/Notify.js @@ -92,6 +92,15 @@ const Notifications = { return action }) } + else if (notif.actions) { + notif.actions = notif.actions.map(item => { + const action = clone(item) + + action.handler = () => close() + + return action + }) + } if (typeof config.onDismiss === 'function') { notif.onDismiss = config.onDismiss