GithubHelp home page GithubHelp logo

petervdn / notivuecation Goto Github PK

View Code? Open in Web Editor NEW
5.0 5.0 1.0 538 KB

Promise-based alert and confirm modal for Vue.js

License: MIT License

JavaScript 29.59% HTML 19.45% TypeScript 44.23% Vue 6.73%
alert confirm notification promise vue vuejs

notivuecation's People

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

jameshibbard

notivuecation's Issues

Add TypeScript types

I suggest you add types to use it with typescript easily.

See the message below about it.

8<--------------------------------------------------------------------------------

PS C:\Users\marceladmin\Documents\GitHub\replayer-pwa> npm i --save-dev @types/notivuecation
npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/@types%2fnotivuecation - Not found
npm ERR! 404
npm ERR! 404 '@types/notivuecation@*' is not in this registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\marceladmin\AppData\Local\npm-cache_logs\2022-03-02T16_17_25_430Z-debug-0.log

How to use in nuxt js?

I installed plugin.
In nuxt.config.js added to plugins array
plugins: ["~/plugins/vee-validate.js", "~/plugins/notevuecation.js"],
In file notivuecation.js wrote:

import notivuecation from "notivuecation";

Vue.use(notivuecation);

And the browser go in to infinite loop.

Missing words in readme

"These two methods to show either a notification with Ok/Cancel buttons or just a single Ok-button"

Focus first button when modal is opened

Hi,

Currently, when the modal is opened it does not receive focus. This make is somewhat inaccessible for keyboard users.

It would be possible to make the first button receive focus like so:

In src/lib/Notification.vue:

<button
+  ref="notivuecationButton"
   v-for="button in buttons"
   :class="button.css"
   @click="resolve(button.value)"
>{{button.label}}</button>

In src/lib/componentMixin.js

onShowNotification(notification) {
  this.notifications.push(notification);
+ this.$nextTick(() => this.$refs.notivuecationButton[0].focus());
},

But this creates a new problem, that when the modal is shut, focus is returned to the top of the page and not wherever the user was previously.

This could be solved like so:

In src/lib/componentMixin.js

data() {
  return {
+   activeElement: null,
    notifications: [],
  };
},
methods: {
  onShowNotification(notification) {
    this.notifications.push(notification);
+   this.activeElement = document.activeElement;
+   this.$nextTick(() => this.$refs.notivuecationButton[0].focus());
  },
  onHideNotification(notification) {
    const index = this.notifications.indexOf(notification);
    if (index > -1) {
      this.notifications.splice(index, 1);
    }
+   if (this.activeElement) this.activeElement.focus();
  },

But now the plugin is reaching into the DOM, which feels a bit messy.

My question(s): would you be interested in adding this functionality to your plugin?
If so, and presuming the above is an acceptable way of approaching things, I'd be happy to send a PR.
Otherwise, do you have any thoughts on a better way to handle this?

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.