Code Monkey home page Code Monkey logo

vue-toastify's Introduction

🔥Vue Toastify🔥

Simple and dependency free notification plugin.

install

npm i vue-toastify
import { createApp } from 'vue';
import plugin from 'vue-toastify';
import 'vue-toastify/index.css';
import type { Settings } from 'vue-toastify';

const app = createApp({  });
app.use<Settings>(plugin, {  });
app.mount('#app');

Options:

Custom styling

Styles include a 'dark'(default) and a 'light' theme. If you would like to create your own styles you may use the following helpers:

import { createVtTheme, getCssRules } from 'vue-toastify';

// this will create a stylesheet if doesn't exists and insert it into the head
createVtTheme('myThemeName', '#8f6b42');
// then you can set the theme of the status or the global settings
// alternatively, you can get an array of css rules using getCssRules
getCssRules('myThemeName', '#8f6b42').forEach(rule => {...});
// this will give you a good starting point to customise the theme

Custom notifications

You may create some methods on the useToast() so it will shortcut any repetition you may have in your app. To register them add a customNotifications key to the settings when registering the plugin.

app.use<Settings>(plugin, {
    customNotifications: {
        authenticationError: {
            body: 'Authentication error',
            // ... rest of the toast options here
        }
    }
});
// then later you can use it as
useToast().authenticationError();

Ambient declaration for custom notifications

import type { ToastPluginAPI, CustomMethods } from 'vue-toastify';

declare module 'vue-toastify' {
    interface MyMethods extends CustomMethods {
        authenticationError(): string;
    }

    function useToast(): ToastPluginAPI & MyMethods;
}

Events

The plugin emits events that you can listen to which allows for using callbacks at different points in the toast's lifecycle.

import { useVtEvents, useToast } from 'vue-toastify';

const toast = useToast().success({ body: 'Hello world', canTimeout: true });

useVtEvents().once('vtPaused', payload => {
    if (payload.id === toast.id) {
        // do something
    }
})

vue-toastify's People

Contributors

adydetra avatar dependabot[bot] avatar nandi95 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

vue-toastify's Issues

How can I make it disappear after some time as I have defined?

I am following the documentation and working with this for my project but it doesn't disappear until and unless I click on it.
Vue.use(VueToastify,{ position:"top-right", errorDuration:500, successDuration:500, alertInfoDuration:500, duration:500, });

Property '$vToastify' does not exist on type 'App'

  • TSC Could not find a declaration file for module 'vue-toastify'.
  • '/projets/client/node_modules/vue-toastify/dist/vue-toastify.umd.min.js' implicitly has an 'any' type.
  • TSLint doesn't see $vToastify property on a Vue instance. So you have to declare it manually each time inside your project.
// @/vue-toastify.d.ts
declare module 'vue-toastify';
// @/vtoastify.d.ts
import VueToastify from "vue-toastify";

declare module 'vue/types/vue' {
  interface Vue {
    $vToastify: VueToastify;
  }
}

It would be great to have this declarations inside the package.

Can I use it inside a method?

Hi, Thanks for this library.

Can I use it without <vue-toastify :your-props="here"></vue-toastify> this component?

I want to show notification inside a method and I don't want to mess around with template.

like simply: this.$toastify.success('Weird success text');

something like this?

Rectangle unwanted resizing

Hi!,

It seems that if the body message is made of 17 characters and you set a timeout on the popup window, at the final second the rectangle resizes itself and it puts the icon at the bottom of the message window.

You can try it at netlify by writing a body "Hellooooooooooooo". You can replicate if the title is made of 11 characters.

Major rewrite with vue 3 + typescript

I'm planning a major rebuild of the package with typescript and vue 3.
composition api will allow for much cleaner code. I excpect slight differences in the api from the current one but nothing too painful to upgrade.
With this rebuild I will aim for 100 test coverage and better documentation and demo site.

Error in render: "TypeError: Cannot read property 'length' of undefined"

Hi!

I have installed the vue-toastify 1.5.0 and upgraded my vue to 2.6.11. I followed the steps according to README and every time I call the this.$vToastify command everything is working fine except the icon (success, warning, error). During inspect on my web app I see the following errors:

  1. Error in render: "TypeError: Cannot read property 'length' of undefined"

  2. TypeError: Cannot read property 'length' of undefined
    at VueComponent.containerClasses (vue-toastify.umd.min.js?5ff6:1)
    at Watcher.get (vue.esm.js?efeb:4488)
    at Watcher.evaluate (vue.esm.js?efeb:4593)
    at Proxy.computedGetter (vue.esm.js?efeb:4845)
    at Proxy.m (vue-toastify.umd.min.js?5ff6:1)
    at VueComponent.Vue._render (vue.esm.js?efeb:3557)
    at VueComponent.updateComponent (vue.esm.js?efeb:4075)
    at Watcher.get (vue.esm.js?efeb:4488)
    at new Watcher (vue.esm.js?efeb:4477)
    at mountComponent (vue.esm.js?efeb:4082)

Note that I'm running on Node v13.6.0.
Could you please assist?

Custom styles object?

Hi, cool plugin. Thanks for this.

Is it possible to pass custom styles, or override the default styling? In particular, background colour, text colour, font-size.

Accepting a styles object would be a nice touch.

Many thanks

How to configure vue-toastify for Nuxt?

I'm trying to use it in Nuxt but I receive an error after adding it to plugins.
config in nuxt.config.js:
plugins: [ '~plugins/vtoastify.js' ],
setting up in plugins/vtoastify.js:

`import Vue from 'vue'
import VueToastify from 'vue-toastify'

Vue.use(VueToastify)`

after that, I receive an error in browser:

ReferenceError
window is not defined

in console:
Uncaught InternalError: too much recursion

And shows an error in import VueToastify

module "/nuxtproject/node_modules/vue-toastify/dist/vue-toastify.umd.min"
Could not find a declaration file for module 'vue-toastify'. '/nuxtproject/node_modules/vue-toastify/dist/vue-toastify.umd.min.js' implicitly has an 'any' type.
Try npm install @types/vue-toastify if it exists or add a new declaration (.d.ts) file containing declare module 'vue-toastify';ts(7016)

But the file vue-toastify.umd.min.js exists on that folder.
Any ideas how to setup vue-toastify on Nuxt?

Note: I'm not using typescript

t.extend is not a function

whenever i include this in my main.js file it compiles easily but gives me error in browser console and do nort eun my project
vue-toastify.umd.min.js?6838:1 Uncaught TypeError: t.extend is not a function
at Object.install (vue-toastify.umd.min.js?6838:1)
at Object.use (runtime-core.esm-bundler.js?5c40:2911)
at eval (main.js?56d7:8)
at Module../src/main.js (app.js:1099)
at webpack_require (app.js:854)
at fn (app.js:151)
at Object.1 (app.js:1136)
at webpack_require (app.js:854)
at checkDeferredModules (app.js:46)
at app.js:994

Use vue-toastify from Vuex Store

Hey, I was looking for a way to generate messages from my Vuex store.
I have tried

Vue.$vToastify.error('easy-peasy');
this.$vToastify.error('easy-peasy');

both fail as vToastify is undefined in both..

Please note, I am using a dynamic store, which gets registered at runtime.

Thanks!

Could not initialize vue-toastify

I am using Vue 2.6.10 and I have installed vue-toastify 1.8.0 using
npm i vue-toastify

I have added these two lines in main.js file

import VueToastify from "vue-toastify";
Vue.use(VueToastify);

But when I use this.$vToastify.success("easy-peasy"); the IDE is saying that
"Property '$vToastify' does not exist on type 'ChartComponent'. Did you mean '$bvToast'?"
I can use this.$bvToast.toast() which is Bootstrap's toast component but I cannot use this.$vToastify.success()
What I am missing here?

feature: JSX support

I'd like to be able to use JSX in the body of the toasts, which will remove the need for sanitizing user input if displaying any content from users.

I'm still using Vue2, and I can put in a PR for this change (for v1) as it's pretty straightforward to add.

Add in a Node.js file that will be the bridge between JSX land and vue template land:

import Vue from "vue";
export default Vue.component("VNodes", {
    functional: true,
    props: ["node"],
    render(h, context) {
        return context.props.node;
    }
});

In Toast.vue:

Add a new computed property:

        isJSXBody() {
            const body = this.status.body;
            // basic duck-typing check for jsx VNode
            if (typeof body === "object" && body.tag != null) {
                return true;
            }
            return false;
        }

Change the vt-paragraph div to:

- <p class="vt-paragraph" v-html="status.body" />
+ <div v-if="isJSXBody" class="vt-paragraph">
+   <Node :node="status.body" />
+ </div>
+ <p v-else class="vt-paragraph" v-html="status.body" />

Would you be okay with this PR and cutting a new v1 release?

Request feature to allow component import

I have been using this package from two years with laravel blade as well as with my vue projects. It used to work fine, but now (from few previous version), components import is disabled. To clarify more,

import Vue from 'vue';
import vToastify from 'vue-toastify';

window.EventBus = new Vue();
window.flash = function (message, type) {
    let statusObject = {
        title: type + " !!!",
        type: type,
        body: message,
        defaultTitle: true
    }
    EventBus.$emit('vtNotify', statusObject);
};

Vue.component('vue-toastify', vToastify);

And blade templates would like

@if(Session::has('success'))
<script>
    window.flash("{{session('success')}}", "success");
</script>
@endif

@if(Session::has('error'))
<script>
    window.flash("{{session('error')}}", "error");
</script>
@endif
@foreach($errors->all() as $error)
<script>
    window.flash("{{$error}}", "error");
</script>
@endforeach

Basically I am importing your src/components/VueToastify.vue component in flash js and define that in a window function, which later call from my php blade file.

Problem
Problem is I couldn't import that component now, and cause render error.

Solution
Allow to import src/components/VueToastify.vue this component.

@Finished event?

Hi again,

Getting great use out of this plugin, thanks so much!

Would it be possible to add some kind of event listener that would call when the popup has disappeared or the user clicks it to remove it?

This would be useful for refreshing the screen, or loading data, after an event has completed successfully and the user has been notified of a successful event.

Custom notification setting

Hello, is there way how to pass vuetify setting to each notification call?

For example I want notification A will have backdrop and notification B will not have backdrop.

I know there is this.$vToastify.setSettings(settingsObject); but it will set setting to all notifications, right?

help to understand the beginner :)

for example i have component.vue file

<template>
  <div>
    <vue-toastify :status="settings" />
    <button @click="clicked">click to show Toastify</button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      settings: {
        title: "toastified!",
        body: "This is the body.",
        canTimeout: true,
        defaultTitle: true,
        duration: 1000
      }
    }
  },

  methods: {
    clicked() {
      // what code should I write to call toastify?
    }
  }
}
</script>

p.s. your component is amazing

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.