1.0.7 • Published 4 years ago

shapla-notifications v1.0.7

Weekly downloads
5
License
MIT
Repository
github
Last release
4 years ago

shapla-notifications

npm npm vue2

A simple dependency-free JavaScript notification component for VueJS

Table of contents

Installation

npm install --save shapla-notifications

Usage

Add the component:

import notification from 'shapla-notifications';

export default {
  name: 'Hello',

  components: {
    notification
  },

  data () {
    return {
        note:{},
    };
  },
}
<notification v-model="note"></notification>
<notification ref="notify"></notification>

notification will show the notification whenever the note property is updated (normal Vue reactivity). Alternatively, by default notification listens to vm.$root for the 'show-notification' event. To show the notification, emit the event passing the notification data object

<button @click="showNotification">Show Notification</button>
<notification v-model="note"></notification>
methods: {
    showNotification() {
        this.note = {
            type: 'success',
            message: 'This is success message.',
        };
    }
}

or using global event bus

<button @click="showNotification">Show Notification</button>
<notification ref="notify"></notification>
methods: {
    showNotification() {
        vm.$root.$emit('show-notification', {
            type: 'error',
            title: 'Error!',
            message: 'This is error message.'
        });
    },
}

Alternatively, you can also use the show method to trigger the display of the snackbar.

<notification ref="notify"></notification>
vm.$refs.notify.show({ message: 'Message' })

props

propsTypeDefaultDescription
optionsObjectoptional v-model when set shows notification
eventStringshow-notificationspecifies the name of the event the notification listens to.
event-sourceVuevm.$rootspecifies the source of the event. must be a vue instance or component ref
show-dismissesBooleantrueIf set true, a cross icon will be show to dismiss notification.
timeoutNumber2750The amount of time in milliseconds to show the notification.
positionStringtop-rightTwo acceptable value top-right or bottom-left.

methods

methodDescription
show(data)trigger the display of a message with optional action.

notification data object

The options prop, event, and show method takes an object for notification data. The table below shows the properties and their usage.

PropertyEffectRemarksType
messageThe text message to display.RequiredString
timeoutThe amount of time in milliseconds to show the snackbar.Optional (default 2750)Integer
typeSupported types are success, info,warning, errorOptional (default info)String
1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago