Skip to content

Commit

Permalink
fix(quasar+docs): Fix default actions handler and add details about d…
Browse files Browse the repository at this point in the history
…efaults to documentation

close quasarframework#3722
  • Loading branch information
pdanpdan committed Mar 29, 2019
1 parent 33ce04c commit 9d7f5be
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
35 changes: 35 additions & 0 deletions docs/src/pages/quasar-plugins/notify.md
Expand Up @@ -6,6 +6,10 @@ Notify is a Quasar plugin that can display animated messages (floating above eve
## Installation
<doc-installation plugins="Notify" :config="{ notify: 'Notify' }" />

::: 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
Expand Down Expand Up @@ -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).

Expand Down
9 changes: 9 additions & 0 deletions quasar/src/plugins/Notify.js
Expand Up @@ -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
Expand Down

0 comments on commit 9d7f5be

Please sign in to comment.