All Projects → javisperez → Vuedals

javisperez / Vuedals

Licence: mit
Vue modals with a single component

Projects that are alternatives of or similar to Vuedals

Django Admin Interface
django's default admin interface made customizable. popup windows replaced by modals. :mage: ⚡️
Stars: ✭ 717 (+602.94%)
Mutual labels:  window, modals
Modals
Simple modal dialogue windows
Stars: ✭ 85 (-16.67%)
Mutual labels:  modals
Howm
A lightweight, X11 tiling window manager that behaves like vim
Stars: ✭ 619 (+506.86%)
Mutual labels:  window
Electron Tray Window
🖼️ Generates custom tray windows with Electron.js
Stars: ✭ 71 (-30.39%)
Mutual labels:  window
Awesome Transit
Community list of transit APIs, apps, datasets, research, and software 🚌🌟🚋🌟🚂
Stars: ✭ 713 (+599.02%)
Mutual labels:  bus
Blurrycontrols
Small design library for blured controls in XAML and WPF for C#
Stars: ✭ 77 (-24.51%)
Mutual labels:  window
2bwm
A fast floating WM written over the XCB library and derived from mcwm.
Stars: ✭ 609 (+497.06%)
Mutual labels:  window
Static Gtfs Manager
GUI interface for creating, editing, exporting of static GTFS data for a public transit authority
Stars: ✭ 98 (-3.92%)
Mutual labels:  bus
Bsb Lan
LAN interface for Boiler-System-Bus (BSB) and Local Process Bus (LPB) and Punkt-zu-Punkt Schnittstelle (PPS) used by Elco Thision, Brötje and similar heating systems
Stars: ✭ 83 (-18.63%)
Mutual labels:  bus
Script Reset Windows Update Tool
This script reset the Windows Update Components.
Stars: ✭ 68 (-33.33%)
Mutual labels:  window
Debuguisystem
Create a runtime menu system with buttons and windows for debugging in one line of code.
Stars: ✭ 48 (-52.94%)
Mutual labels:  window
People Counting Dataset
the large-scale data set for people counting (LOI counting)
Stars: ✭ 37 (-63.73%)
Mutual labels:  bus
Rxbus
Android reactive event bus that simplifies communication between Presenters, Activities, Fragments, Threads, Services, etc.
Stars: ✭ 79 (-22.55%)
Mutual labels:  bus
Layx
Layx 新一代Web弹窗组件。
Stars: ✭ 659 (+546.08%)
Mutual labels:  window
Nextbussg
An app to show everything bus related in Singapore, including arrival times and a directory
Stars: ✭ 86 (-15.69%)
Mutual labels:  bus
Ngx Bootstrap
Fast and reliable Bootstrap widgets in Angular (supports Ivy engine)
Stars: ✭ 5,343 (+5138.24%)
Mutual labels:  modals
Jalert
jQuery alert/modal/lightbox plugin
Stars: ✭ 73 (-28.43%)
Mutual labels:  modals
Windtalk
Simplest way to communicate with iFrames and other windows
Stars: ✭ 100 (-1.96%)
Mutual labels:  window
Wheel
Quick navigation framework for Vim and Neovim : buffer groups, mru, locate, find, grep, outline, yank, ...
Stars: ✭ 94 (-7.84%)
Mutual labels:  window
Window Size
Reliable way to to get the height and width of the terminal/console in a node.js environment.
Stars: ✭ 79 (-22.55%)
Mutual labels:  window

Vuedals

VueJS (2.x) Plugin for multiple modals windows with a single component instance.

DEMO

View demo on jsFiddle

What is this?

A plugin to open stocked modals windows, event based, with just one component in your DOM.

What do you mean with "just one component"?

e.g. if you want to have 3 modals, you don't need to add the component 3 times, just one (preferably in the root of your app) and open as many modals as you want by using an Event Bus

Install

Install with npm:

npm install --save vuedals

Example

import Vue from 'vue';
import {default as Vuedals, Component as Vuedal, Bus as VuedalsBus} from 'vuedals';

Vue.use(Vuedals);

var myComp = Vue.extend({
    template: `<div>
            <h1>Hello World!</h1>
            <button @click="showIt()">Show me the money</button>
        </div>`,

    methods: {
        showIt() {
            VuedalsBus.$emit('new', {
                name: 'showing-the-money',

                component: {
                    name: 'the-money',

                    template: `
                        <div>
                            <h1>THE MONEY!</h1>
                            <p>Money, money, money, moooneeyyy $ $ $ $</p>
                        </div>
                    `
                }
            });
        }
    }
});

var vm = new Vue({
    el: '#app',

    components: {
        myComp,
        Vuedal
    },

    template: `<div>
        <my-comp></my-comp>

        <vuedal></vuedal>
    </div>`
});

Usage

Opening a new modal window

You can emit an event in your component:

this.$emit('vuedals:new', { option });

or a method:

this.$vuedals.new({ options });

or the Vuedals Event Bus:

import {Bus as Vuedals} from 'vuedals';

...

methods: {
    openNewModal() {
        Vuedals.$emit('new', { options });
    }
}

Closing a modal

You can emit an event in your component:

this.$emit('vuedals:close'[, data]);

a method:

this.$vuedals.close([data]);

or the Vuedals Event Bus:

import {Bus as Vuedals} from 'vuedals';

...

methods: {
    openNewModal() {
        Vuedals.$emit('close'[, data]);
    }
}

Closing an especific modal

If you need to close a specific modal index, you can pass it as an $index property of the data.

this.$vuedals.close({
    $index: 3
})

$index can be an integer or a function. In case $index is a function, the additional data and all the vuedals that is currently present is index(data, this.vuedals) passed as argument so that you can determine the index of the vudedal to close and return the index of it

this.$vuedals.close({
    $index(data, vuedals) {
        // this will always close the latest modal
        return vuedals.length - 1;
    }
})

Events

Depending if you're creating the modal from the component or from the Vuedals Event Bus, these are the events (component / bus):

vuedals:new / new

Open a new modal window, with the given options

vuedals:close / close

Close the most recently opened modal window, if data is given, will pass it to the onClose option.

vuedals:opened / opened

When a modal was open. Returns an object with:

  1. The index of the recently opened modal
  2. The options passed to that modal instance

vuedals:closed / closed

When a modal was closed. Returns an object with:

  1. The index of the closed modal
  2. The options passed to that modal instance
  3. The data given when close was called

vuedals:destroyed / destroyed

Emitted when the last modal instance is closed. i.e. there's not more open modals left

  1. The index of the closed modal
  2. The options passed to that modal instance
  3. The data given when close was called

Options

When creating a new modal, you'll need to pass the given options:

name

A reference name of the modal. Use to define the css class of that modal

Default: null

component

A Vue component to display inside the modal

props

A props object that will be passed to the component inside the modal.

example:

import {Bus as Vuedals} from 'vuedals';

...

methods: {
    openModal() {
        this.$vuedals.open({
            name: 'test-component',

            // Pass these props to the component
            props: {
                firstname: 'John',
                lastname: 'Doe'
            },

            component: {
                name: 'show-john-doe',

                // Expect these props values
                props: ['firstname', 'lastname'],

                template: `
                    <div>
                        Hi {{ firstname }} {{ lastname }}
                    </div>
                `
            }
        });
    }
}

size

The size of the modal.

Possible values are:

  • xs: 350px width
  • sm: 550px width
  • md: 650px width
  • lg: 850px width
  • xl: 1024px width

Default: md

dismissable

Should the modal include an "X" to be closed?

Default: true

escapable

Can this modal be closed by pression the esc key?

Default: false

closeOnBackdrop

Optionally prevent closing when clicking on backdrop

Default: true

title

Title of the modal window

Default: ''

header

An object that will be used to generate a custom header

Default: null

header: {
    component: 'header-component',
    props: {
        custom: 'Props'
    }
}

onClose

Callback function to call when the modal is closed. Any given data is passed as a parameter for that callback. Example:

this.$vuedals.open({
    name: 'test-component',

    // Pass these props to the component
    props: {
        firstname: 'John',
        lastname: 'Doe'
    },

    component: {
        name: 'show-john-doe',

        // Pass these props to the component
        props: ['firstname', 'lastname'],

        template: `
            <div>
                Hi {{ firstname }} {{ lastname }}
            </div>
        `
    },

    onClose(data) {
        console.log('Data received from the vuedal instance': data);
    }
});

onDismiss

Callback function to call when the modal is closed.

Please notice that even close and dismiss both close the active modal instance (closes the modal) only the close event accepts data argument that can be passed to the callback, while dismiss just send the modal to close.

The callback may prevent the modal closing by returning false.

Example:

this.$vuedals.open({
    name: 'test-component',

    // Pass these props to the component
    props: {
        firstname: 'John',
        lastname: 'Doe'
    },

    component: {
        name: 'show-john-doe',

        // expect these props
        props: ['firstname', 'lastname'],

        template: `
            <div>
                Hi {{ firstname }} {{ lastname }}
            </div>
        `
    },

    onDismiss() {
        console.log('The user dismissed the modal');
    }
});
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].