0.6.10 • Published 4 years ago

@smartweb/vue-flash-message v0.6.10

Weekly downloads
1,056
License
MIT
Repository
github
Last release
4 years ago

vue-flash-message

The component to display single flash message to user. It has styles presets, but can be easily customized by passing style object as argument.

Live Demo

Setup

npm i @smartweb/vue-flash-message

Configuration

import Vue from 'vue';
import FlashMessage from '@smartweb/vue-flash-message';
Vue.use(FlashMessage);

You can pass configuration object as second argument

Vue.use(FlashMessage, config);

Configuration object

PropertyTypeDescriptionDefault
nameStringIt is a name of the component and alias for the EventBus global property.'flashMessage'
tagStringCustom tag for the component to use in your application.'FlashMesage'
timeNumberDuration (in ms) of the message display (can be customized during message call).8000
iconBooleanIf you would like to use icons as default.true

Usage

Put the component into your template

<FlashMessage></FlashMessage>

Now you can access it by using global EventBus alias (that is "flashMessage" by default) of your Vue instance

this.flashMessage.show({status: 'error', title: 'Error Message Title', message: 'Oh, you broke my heart! Shame on you!'})

Methods

You also can use shorthands without status property.

this.flashMessage.error({title: 'Error Message Title', message: 'Oh, you broke my heart! Shame on you!'});
this.flashMessage.warning({title: 'Warning Message Title', message: 'Don\'t stop me nooooow....!'});
this.flashMessage.info({title: 'Info Message Title', message: 'Just want you to know, that Vue is so cool'});
this.flashMessage.success({title: 'Success Message Title', message: 'Hoorah, it is my fist npm package and it works!'});

Data Object

The first argument - is data object.

PropertyTypeDescription
statusStringStatus of component. Default presets: 'error', 'warning', 'info', 'success'
titleStringTitle of your message
messageStringText of your message
timeNumberDuration (in ms) of the single message display
iconBooleanIf you would like to use icons for this single message
clickableBooleanAllows to control whether the user can remove message by click on it or not.
flashMessageStyleObjectstyle Object for flashMessage block
iconStyleObjectstyle Object for icon block. You can pass your own icon as 'backgroundImage'
contentStyleObjectStyle of content block
titleStyleObjectStyles for title
textStyleObjectStyles for text

Example:

    methods: {
        deleteTrouble() {
            this.$axios.delete(`/delete/trouble/${trouble.id}`)
                .then( res => {
                    let { status, data, error } = res.data;
                    if(status) {
                        this.flashMessage.success({
                            title: 'Don\'t Warry',
                            message: 'Be Happy!',
                            time: 5000,
                            flashMessageStyle: {
                                backgroundColor: 'linear-gradient(#e66465, #9198e5)'
                            }
                        });
                    }
                    else {
                        this.flashMessage.error({title: error.name || 'Error', message: error.message});
                    }
                })
                .catch(e);
        }
    }

Callbacks

As second argument you can pass object with two properties: "mounted" and "destroyed".

PropertyTypeDescription
mountedFunctionWill be invoked, when flashMessage appears
destroyedFunctionWill be invoked, when flashMessage gone

Example:

<p>{{ text }}</p>
<button @click="clickHandler" type="button" name="button">Show Text!</button>
    methods: {
        showText() {
            this.text = 'Hello from callback!'
        },
        clearText() {
            this.text = 'Bye... 1, ..2, ..3';
            setTimeout( () => this.text = '', 3000);
        },
        clickHandler() {
            this.flashMessage.info({
                title: 'Ooooooops!',
                message: 'Do you see this text? Wtf?'
            },
            {
                mounted: showText,
                destroyed: clearText
            })
        }
    }
1.0.0-alpha.10

4 years ago

1.0.0-alpha.12

4 years ago

1.0.0-alpha.11

4 years ago

1.0.0-alpha.9

4 years ago

1.0.0-alpha.8

4 years ago

1.0.0-alpha.7

4 years ago

1.0.0-alpha.6

4 years ago

1.0.0-alpha.5

4 years ago

1.0.0-alpha.4

4 years ago

1.0.0-alpha.3

4 years ago

1.0.0-alpha.2

4 years ago

0.6.10

4 years ago

0.6.9

4 years ago

1.0.0-alpha.1

4 years ago

1.0.0-alpha.0

4 years ago

0.7.0-rc7

4 years ago

0.7.0-rc3

4 years ago

0.7.0-rc4

4 years ago

0.7.0-rc5

4 years ago

0.7.0-rc6

4 years ago

0.7.0-2

4 years ago

0.6.5

4 years ago

0.6.3

5 years ago

0.6.4

5 years ago

0.6.2

5 years ago

0.6.1

5 years ago

0.6.0

5 years ago

0.5.3

5 years ago

0.5.2

5 years ago

0.5.0

5 years ago

0.4.8

5 years ago

0.4.7

5 years ago

0.4.6

5 years ago

0.4.5

5 years ago

0.4.4

5 years ago

0.4.3

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.4.2

5 years ago

0.4.1

6 years ago

0.4.0

6 years ago

0.4.0-rc1

6 years ago

0.3.22

6 years ago

0.3.21

6 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.3.0-rc1

6 years ago

0.2.2

6 years ago

0.2.19

6 years ago

0.2.18

6 years ago

0.2.17

6 years ago

0.2.16

6 years ago

0.2.15

6 years ago

0.2.14

6 years ago

0.2.13

6 years ago

0.2.12

6 years ago

0.2.11

6 years ago

0.2.1

6 years ago