npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@joe_kerr/vue-modal-dialogs

v1.1.1

Published

JavaScript's alert(), confirm() and propmt() as Vue components.

Downloads

30

Readme

Modal dialogs plugin for Vue

The Vue version of JavaScript's alert(), confirm() and propmt() dialogs.

Features

  • Alert dialog displaying a message and an "Ok"-button
  • Confirm dialog displaying a message and an "Ok"- and a "Cancel"-button.
  • Prompt dialog displaying a text area and an "Ok"- and a "Cancel"-button.
  • Dialogs return respective value of the user action (true, false, text).
  • When await'ed behave like native counter parts (i.e. blocking).
  • New: custom dialogs

Demo

See it in action.

Requirements

  • Vue
  • Vuex

Install

1)

npm install @joe_kerr/vue-modal-dialogs

2a) dev environment

import {installer, component} from "@joe_kerr/vue-modal-dialogs"; 

or

import * as modalDialogs_or_whatever from "@joe_kerr/vue-modal-dialogs"; 

2b) Pure node or browser

const modalDialogs = require("path_to_node_modules/@joe_kerr/vue-modal-dialogs/dist/modalDialogs.common.js");

or

<html> <script src="path_to_node_modules/@joe_kerr/vue-modal-dialogs/dist/modalDialogs.umd.min.js"></script>

and

3)

Vue.use(modalDialogs.installer, configuration); 

*4)

<section id="main">
	<modal-dialog-container />
</section>
import {component} from "@joe_kerr/vue-modal-dialogs";
//or
const {component} = require("path_to_node_modules/@joe_kerr/vue-context-menu/dist/modalDialogs.common.js");
//or
const component = contextMenu.component;

export default {
	name: "main",
	components: {"modal-dialog-container": component}
};

Use

Configuration

Provide configuration properties on the second parameter of the Vue.use(plugin, configProperties) call.

vuex (mandatory)

A reference to your Vuex store instance.

namespace

The namespace of the store module, i.e. what you put in the dispatch call: store.dispatch("namspace/open"). Default: "modalDialog"

customDialogs

An array of custom dialogs in form of {name, dialog} where

  • name: identifier name of the dialog used in the open action, i.e.: store.dispatch("namespace/open", {dialog: name})
  • dialog: the dialog component

Open dialogs

The default dialogs correspond to the native JavaScript counter parts:

  • alert
  • confirm
  • propmt
store.dispatch("modalDialog/open", {dialog: "alert|confirm|prompt[, parameters: "message"|{text, placeholder}]})

The dialogs alert and confirm take a string on the parameters propery while the prompt dialog takes an object with optional text (dialog body) and placeholder (dialog textarea) properties.

Returns a promise with the resulting user action (see below) or throws if another dialog is tried to be opened while a previous one is still being awaited.

Respond to dialogs

const response = await store.dispatch("modalDialog/open", {id, parameters});

The "response" promise resolves after a button on the dialog was pressed. It will contain

  • true for the alert dialog,
  • true or false for the confirm dialog,
  • the text content of the prompt dialog if ok'ed or null if cancled.

Create new dialogs

// ./src/dialogs/customDialog.vue
export default {
  name: "custom-dialog",
  props: ["parameters", "close"],
  //<base-modal-dialog> is available on all custom dialogs
  template: `
  <base-modal-dialog title="Custom dialog" :buttons="{'DoSth': doSth}">
    <div slot="header">custon header</div>
    <div slot="body">custon body</div>
    <div slot="footer">custon footer</div>
  </base-modal-dialog>
  `,
  methods: {
    doSth() {
      console.log("msg from doSth:", this.parameters.info);
      this.close("any data"); //This will resolve the dialog promise that was returned when the dialog was opened.
    }
  }
};
// Vue setup
import {installer, component} from "@joe_kerr/vue-modal-dialogs"; 
import customDialogComp from "./src/dialogs/customDialog.vue";

const vuex = new Vuex.Store();
const customDialog = {
  name: "customDialog",
  dialog: customDialogComp
};

Vue.use(installer, {vuex, customDialogs: [customDialog]})
// ./src/someVueComponent.vue
{
  const promise = this.$store.dispatch("modalDialogs/open", {dialog: "customDialog", parameters: {info: "hello world"}});
  // The promise will be resolved by calling the props.close callback in the custom dialog.
}

Style dialogs

The plugin comes with the following classes you can just override.

  • .modal-dialog_modal
  • .modal-dialog_container
  • .modal-dialog_header
  • .modal-dialog_body
  • .modal-dialog_footer
  • .modal-dialog_buttons
  • .modal-dialog_alert
  • .modal-dialog_confirm
  • .modal-dialog_prompt
  • .modal-dialog_textarea
  • #modal-dialog_buttons--{{name_of_button}}

Default styles are provided that center the dialogs mid screen. If you want to change these as well, do it like so:

div.modal-dialog_modal {/*overrides*/}

Notes

  • Be wary of coupling by having store calls all around the place.
  • Dialogs come with minimal styling.

Versions

1.1.0

  • Added: custom dialogs can be installed

1.0.5

  • Minor changes.

1.0.4

  • Fixed: gitignore not in the file list of the build script
  • Changed: made live demo a bit prettier

1.0.3

  • Added: live demo with github pages

1.0.2

  • Fixed: ohh, I see now: https://github.com/webpack/webpack/issues/7646

1.0.1

  • Changed: module import facilitated.

1.0.0

  • Public release.

Copyright

MIT (c) Joe Kerr 2019