Skip to content

Commit

Permalink
fix(QNotify): defaults with actions with handlers when using setDefau…
Browse files Browse the repository at this point in the history
…lts() #3722
  • Loading branch information
rstoenescu committed Apr 19, 2019
1 parent 62b3346 commit 1b4212e
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
43 changes: 42 additions & 1 deletion docs/src/pages/quasar-plugins/notify.md
Expand Up @@ -35,7 +35,7 @@ If you define any actions, the notification will automatically be dismissed when
For a full list of options, check the API section.
:::

### Programmatically Closing Alert
### Programmatically closing
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).

```js
Expand All @@ -44,5 +44,46 @@ const dismiss = this.$q.notify({...})
dismiss()
```

### Setting defaults
There are two ways of setting default configuration that will apply to all Notifications: through quasar.conf.js > framework > config > notify Object (see Installation section) or programmatically (see below).

We'll describe setting the defaults through a [boot file](/quasar-cli/cli-documentation/boot-files) (works the same anywhere in your code, but a boot file ensures this is run before your app starts):

First we create the boot file. Let's name it "notify-defaults.js".

```bash
$ quasar new boot notify-defaults
# we then add 'notify-defaults' to quasar.conf.js > boot Array
```

We then edit the newly created `/src/boot/notify-defaults.js`:

```js
import { Notify } from 'quasar'

Notify.setDefaults({
position: 'top-right',
timeout: 2500,
textColor: 'white',
actions: [{ icon: 'close', color: 'white' }]
})
```

::: warning
You can only set default `actions` through this method. Specifying `actions` with handlers in quasar.conf.js cannot and will NOT work.
:::

We could also set the defaults in some Vue file:

```js
// inside of a Vue component
this.$q.setDefaults({
position: 'top-right',
timeout: 2500,
textColor: 'white',
actions: [{ icon: 'close', color: 'white' }]
})
```

## Notify API
<doc-api file="Notify" />
8 changes: 8 additions & 0 deletions quasar/dev/components/global/notify.vue
Expand Up @@ -119,5 +119,13 @@ export default {
*/
}
}
/*
mounted () {
this.$q.notify.setDefaults({
actions: [{ icon: 'close', handler () { console.log('cloooose') } }]
})
}
*/
}
</script>
7 changes: 5 additions & 2 deletions quasar/src/plugins/Notify.js
Expand Up @@ -76,8 +76,11 @@ const Notifications = {
this.remove(notif)
}

if (config.actions) {
notif.actions = config.actions.map(item => {
const actions =
(config.actions || []).concat(defaults.actions || [])

if (actions.length > 0) {
notif.actions = actions.map(item => {
const
handler = item.handler,
action = clone(item)
Expand Down

0 comments on commit 1b4212e

Please sign in to comment.