Jenesius vue modal is simple library for Vue 3 only

Related tags

Vue.js vue-modal
Overview

Jenesius Vue Modal

Jenesius vue modal is simple library for Vue 3 only .

Greet everyone

Installation

npm i jenesius-vue-modal

For add modals in your project you need to put the modal's container in the App component:

App.vue

<template>
    <widget-container-modal />
</template>
<script>
    import {container} from "jenesius-vue-modal";
    
    export default {
        components: {WidgetContainerModal: container},
        name: "App"
    }
</script>

OpenModal

Methods openModal and pushModal used to display modal windows.

  • openModal - close all previous modals and then display provided component.
  • pushModal - display provided component
    import {openModal} from "jenesius-vue-modal";
    import SomeVueComponent from "SomeVueComponent.vue";

    openModal(SomeVueComponent, props);
  • props will provide in your component, example

Methods return promise, in this case promise is resolved - modalObject

    const modal = await openModal(SomeVueComponent); // {id, close, onclose}

Methods

  • openModal - close all modals and then open provided modal.
  • pushModal - add one more provided modal.
  • closeModal- close all modals.
  • popModal - close last opened modal.

Lifecycle Hooks

There are three ways to track the closing of a modal:


Versions is higher than 1.2.0 NOT support 'next'. Now All hooks use only returned value(Boolean) for navigation hooks. If function return false or throwing an Error modal window will not be closed.


  • onclose
const modal = await openModal(Modal);
modal.onclose = () => {
    console.log("Close");
    return false; //Modal will not be closed
}
  • default component
    export default {
        props: {},
        data: () => ({isValidate: false}),
        beforeModalClose(){
            console.log("Close");
            
            if (!isValidate) return false; //modal will not be closed while isValidate === false
            
        }
    }
  • Composition style
    export default{
        setup() {
            onBeforeModalClose(() => {
                console.log("Close");
            });
        }
    }

Async/Await

Hooks also can be asynchronous functions:

    async beforeModalClose(){
        await doSome();
        return false; // This modal can not be closed!
    }

or

    beforeModalClose(){
        return Promise(resolve => {
            setTimeout(() => resolve(true), 2000); //Modal will closed after 2 second
        })
    }

Example VueModalComponent

WidgeTestModal.vue

    <template>
        <p>{{title}}</p>
    </template>
    <script>
        export default {
            props: {
                title: String
            }
        }
    </script>

To show this component

    import {openModal} from "jenesius-vue-modal"
    import WidgeTestModal from "WidgeTestModal.vue";

    openModal(WidgeTestModal, {
        title: "Hello World!"
    });

Do you like this module? Put a star on GitHub

Comments
  • Build error with latest version

    Build error with latest version

    It seems that an error occurs in 1.1.0 and later versions.

    ERROR  Failed to compile with 1 error                                                                                                                     18:37:10
    error  in ./node_modules/jenesius-vue-modal/plugin/index.js
    
    Module parse failed: Unexpected token (44:6)
    You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
    | class ModalObject{
    |
    >     id;
    |     component;
    |     params;
    
     @ ./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader-v16/dist??ref--0-1!./src/App.vue?vue&type=script&lang=js 4:0-45 10:26-35
     @ ./src/App.vue?vue&type=script&lang=js
     @ ./src/App.vue
     @ ./src/main.js
     @ multi (webpack)-dev-server/client?http://192.168.0.101:8080&sockPath=/sockjs-node (webpack)/hot/dev-server.js ./src/main.js
    
    bug 
    opened by ina6ra 14
  • prevent close when click outside

    prevent close when click outside

    Hello,

    I want to know if there is any way to prevent modal close when click modal outside .

    I know I can prevent it like below but it is not good for me because I want to close it with emmited event and this can't do that

      modal.onclose = () => {
        return false;
      }
    

    is there any way ?

    Feature current task 
    opened by morteza-mortezai 5
  • promptModal

    promptModal

    Main goal: to add the ability to connect to linear modal windows. A linear modal window is a window whose main task is to return a value. Referencing promt in JavaScript. Tasks:

    • implementation of the promtModal method (Or another name, while being discussed)
    • value return implementation

    Principle of operation:

    const result = promptModal(VueModal);
    
    // VueModal.vue
    <template>
      <div>
        <button @click = "change(1)">up</button>
        <button @click = "change(-1)">down</button>
      </div>
    </template>
    <script setup>
      function change(v) {
        emit('close', v);
      }
    </script>
    

    This example demonstrates a modal window that will return either 1 or -1 (undefined if it was closed with Esc or background)

    Feature current task 
    opened by Jenesius 4
  • Prevent ESC from closing modal in VueRouter

    Prevent ESC from closing modal in VueRouter

    Is your feature request related to a problem? Please describe. Maybe this exists and I haven't seen it, but it would be nice to be able to pass configuration options when using VueRouter. For instance, I would like to disable closing the modal on ESC key press when using VueRouter.

    Describe the solution you'd like When I open a modal page using the VueRouter integration, I may have other functionality on that page that requires users to use the ESC key. In this case, if the user presses on the ESC key, the entire page closes. I'd like a solution where I can disable the ESC key when using VueRouter.

    Describe alternatives you've considered Maybe something like this to the composable?

    useModalRouter.init(router, { escClose: false });
    

    I know that in theory, we can tap into the onBeforeModalClose hook like this:

    // App.vue
    
    onBeforeModalClose((event) => {
        // prevent modal from closing if the user pressed the `ESC` key
       return false
    });
    

    However, in this case, it will be nice to add a flag in the event to show that the user pressed the ESC key. at the moment, the event contains only one flag called background, which I believe indicates that the user clicked on the background to close the modal. I suggest adding another flag, eg isESC or something similar.

    Feature 
    opened by nfunwigabga 4
  •  Uncaught (in promise) TypeError: Class constructor EventEmitter cannot be invoked without 'new'

    Uncaught (in promise) TypeError: Class constructor EventEmitter cannot be invoked without 'new'

    Hi, I am using Vue 3 Composition api

    and , I've done setup as document

    But i have this error when I want to open it

    image

    jenesius-vue-modal.cjs.js:495 Uncaught (in promise) TypeError: Class constructor EventEmitter cannot be invoked without 'new'

    app.vue

    <script setup lang="ts">
    import { RouterView } from 'vue-router'
    import {container} from "jenesius-vue-modal";
    </script>
    
    <template>
     <container  />
      <RouterView />
    </template>
    

    homeComponent.vue

    import { openModal } from "jenesius-vue-modal";
    import MyCom from '@/components/Common/MyCom.vue'
    
    function open() {
      openModal(MyCom, { message: "Welcome" })
    }
    

    MyCom.vue

    <script setup lang="ts">
    </script>
    <template>
      <div class="header1">
        Hello
      </div>
    </template>
    

    How can I fix this ?

    bug 
    opened by morteza-mortezai 4
  • Typescript support

    Typescript support

    Hello, this is more a question than an issue but could not use a label :)

    Do you plan on adding Typescript support adding the types, to enable the usage of your library in a TS project without shutting down TS on every import?

    // @ts-expect-error no TS types available yet
    import { openModal } from 'jenesius-vue-modal'
    

    Thanks in anticipate.

    Feature 
    opened by pluxain 4
  • add event closed

    add event closed

    Hello,

    there are many times that it's needed to call API request after modal has been closed and result of modal was true

    because sometime you need to just call API when a modal closed and also result of modal was true .

    so it's needed to pass variable in when closing modal with closeModal() Function

    and this variable is used like this

      modal.onClosed = (result) => {
        if (result) {
          // get data from api
        }else{
          // do nothing
        }
      }
    

    imagine if a user just opened a modal and do nothing in this situation API call should not fired .

    Feature current task 
    opened by morteza-mortezai 3
  • [ConfigInterface] The definition of backgroundClose is missing in d.ts.

    [ConfigInterface] The definition of backgroundClose is missing in d.ts.

    https://github.com/Jenesius/vue-modal/blob/main/dist/dts/utils/config.d.ts#L5

    In the original Typescript, it looks like this. https://github.com/Jenesius/vue-modal/blob/22728664e80d736e6f2288954bc07154bd5f2d5e/plugin/utils/config.ts#L7

    opened by masatada-kurihara 3
  • Lifecycle injection APIs can only be used during execution of setup()

    Lifecycle injection APIs can only be used during execution of setup()

    Hello,

    I try to integrate the library in a Vue3/TS project mostly using the Composition API but I face some issues. First there are those warnings in the console and then when trying to use openModal to open a Component in the modal container there is an error. This is probably related to the warnings.

    // App.vue
    <script lang="ts">
    import { defineComponent } from 'vue'
    // @ts-expect-error no TS types available yet
    import { container } from 'jenesius-vue-modal'
    export default defineComponent({
      components: {
        WidgetContainerModal: container,
      },
    })
    </script>
    <template>
      <div id="app">
        <router-view />
        <WidgetContainerModal />
      </div>
    </template>
    
    // Component.vue simplified
    <script setup lang="ts">
    // @ts-expect-error no TS types available yet
    import { openModal } from 'jenesius-vue-modal'
    import ExampleModal from './ExampleModal.vue'
    
    </script>
    <template>
      <div>
        <button text="Open Modal" @click="openModal(ExampleModal)">Open Modal</button>
      </div>
    </template>
    

    Here are the console warnings

    [Vue warn]: onMounted is called when there is no active component instance to be associated with. Lifecycle injection APIs can only be used during execution of setup(). If you are using async setup(), make sure to register lifecycle hooks before the first await statement.
    

    which seems related to this

    // extracted from jenesius-vue-modal.cjs.js
    var script = {
      setup(){
    
        vue.onMounted(initialize);
    
      return () => {
        return vue.h(vue.TransitionGroup, {name: configuration.animation}, {
          default: () =>modalQueue.value.map(modalObject => {
            return vue.h(script$1, {component: modalObject.component, params: modalObject.params, key: modalObject.id, id: 
              modalObject.id});
    	})
          })
        }
      },
      components: {WidgetContainerModalItem: script$1}
    };
    

    and probably related to useTransitionState() from the dependencies

    I also have this warning

    runtime-core.esm-bundler.js:6870 [Vue warn]: Invalid VNode type: Symbol(Fragment) (symbol) 
      at <TransitionGroup name="modal-list" > 
      at <WidgetModalContainer> 
      at <App>
    

    And finally the error when I try to open the modal

    jenesius-vue-modal.cjs.js:771 Modal Container not found. Put container from jenesius-vue-modal in App's template. Check documentation for more information
    
    localhost/:1 Uncaught (in promise) Modal Container not found. Put container from jenesius-vue-modal in App's template. Check documentation for more information
    

    I probably make something wrong but do not understand what.

    Thanks for the help

    opened by pluxain 3
  • Responsive not supported?

    Responsive not supported?

    Thank you for the wonderful library 😄 It is helpful because there was no modal library that can be used properly with Vue3.

    It doesn't seem to be responsive, but I solved it by adding the following CSS.

    .widget__modal-container__item-back {
      position: absolute;
    }
    
    .widget__modal-container__item {
      display: flex;
      align-items: center;
      justify-content: center;
    }
    
    opened by ina6ra 2
  • Current modal (Access to last opened window anywhere)

    Current modal (Access to last opened window anywhere)

    It's can be comfortable to have access to last opened window.

    • currentModal or const modal = useModal() // computed or
    • lastModal( currentModal better)
    opened by Jenesius 1
Owner
Архипцев Евгений
Архипцев Евгений
Mosha-vue-toastify - A light weight and fun Vue 3 toast or notification or snack bar or however you wanna call it library.

Mosha Vue Toastify A lightweight and fun Vue 3 toast or notification or snack bar or however you wanna call it library. English | 简体中文 Talk is cheap,

Baidi Liu 187 Jan 2, 2023
:tada: A magical vue admin https://panjiachen.github.io/vue-element-admin

English | 简体中文 | 日本語 | Spanish SPONSORED BY 活动服务销售平台 客户消息直达工作群 Introduction vue-element-admin is a production-ready front-end solution for admin inter

花裤衩 80.1k Dec 31, 2022
:eyes: Vue in React, React in Vue. Seamless integration of the two. :dancers:

vuera NOTE: This project is looking for a maintainer! Use Vue components in your React app: import React from 'react' import MyVueComponent from './My

Aleksandr Komarov 4k Dec 30, 2022
🎉 基于 vite 2.0 + vue 3.0 + vue-router 4.0 + vuex 4.0 + element-plus 的后台管理系统vue3-element-admin

vue3-element-admin ?? 基于 Vite 2.0 + Vue3.0 + Vue-Router 4.0 + Vuex 4.0 + element-plus 的后台管理系统 简介 vue3-element-admin 是一个后台前端解决方案,它基于 vue3 和 element-plu

雪月欧巴 84 Nov 28, 2022
A template repository / quick start to build Azure Static Web Apps with a Node.js function. It uses Vue.js v3, Vue Router, Vuex, and Vite.js.

Azure Static Web App Template with Node.js API This is a template repository for creating Azure Static Web Apps that comes pre-configured with: Vue.js

Marc Duiker 6 Jun 25, 2022
A plugin that can help you create project friendly with Vue for @vue/cli 4.5

vue-cli-plugin-patch A plugin that can help you create project friendly with Vue for @vue/cli 4.5. Install First you need to install @vue/cli globally

null 2 Jan 6, 2022
Veloce: Starter template that uses Vue 3, Vite, TypeScript, SSR, Pinia, Vue Router, Express and Docker

Veloce Lightning-fast cold server start Instant hot module replacement (HMR) and dev SSR True on-demand compilation Tech Stack Vue 3: UI Rendering lib

Alan Morel 10 Oct 7, 2022
A lightweight Vue.js UI library with a simple API, inspired by Google's Material Design.

Keen UI Keen UI is a Vue.js UI library with a simple API, inspired by Google's Material Design. Keen UI is not a CSS framework. Therefore, it doesn't

Josephus Paye II 4.1k Jan 2, 2023
PDF.js Read Only is an additional readonly mode for PDF.js

PDF.js Read Only PDF.js Read Only is an additional readonly mode for PDF.js, a Portable Document Format (PDF) viewer that is built with HTML5 which is

Aprillio Latuminggi 19 Dec 22, 2022
Try Vant in the Playground. Currently only Vant 3+ is supported

SFC Playground with Vant This is an Vant SFC Playground. Detail vercel.app Or zhixiaoqiang.github.io NOTE! The reason why this is designed to manually

jzone 16 Dec 14, 2022
Simple, lightweight model-based validation for Vue.js

vuelidate Simple, lightweight model-based validation for Vue.js Sponsors Gold Silver Bronze Features & characteristics: Model based Decoupled from tem

Vuelidate 6.5k Jan 3, 2023
A simple picture clipping plugin for vue

vue-cropper 一个优雅的图片裁剪插件 [ 查看演示 Demo ] [ README_english ] [ 更新日志 ] 一、安装使用 1. 安装 # npm 安装 npm install vue-cropper # yarn 安装 yarn add vue-cropper 如果你没有使用

xyxiao001 3.6k Jan 5, 2023
🎉 A Vue.js 3.0 UI Library made by Element team

Element Plus - A Vue.js 3.0 UI library ?? Vue 3.0 Composition API ?? Written in TypeScript Status: Beta This project is still under heavy development.

null 18.3k Jan 9, 2023
The first truly composable CSS animation library. Built for Vue, React, SCSS, and CSS, AnimXYZ will bring your website to life.

AnimXYZ animxyz.com AnimXYZ helps you create, customize, and compose animations for your website. Powered by CSS variables to allow a nearly limitless

Ingram Projects 2.1k Jan 2, 2023
📓 The UI component explorer. Develop, document, & test React, Vue, Angular, Web Components, Ember, Svelte & more!

Build bulletproof UI components faster Storybook is a development environment for UI components. It allows you to browse a component library, view the

Storybook 75.9k Jan 9, 2023
A Vue.js 2.0 UI Toolkit for Web

A Vue.js 2.0 UI Toolkit for Web. Element will stay with Vue 2.x For Vue 3.0, we recommend using Element Plus from the same team Links Homepage and doc

饿了么前端 53k Jan 3, 2023
The Intuitive Vue Framework

Build your next Vue.js application with confidence using Nuxt: a framework making web development simple and powerful. Links ?? Documentation: https:/

Nuxt 41.8k Jan 5, 2023
🐉 Material Component Framework for Vue

Supporting Vuetify Vuetify is a MIT licensed project that is developed and maintained full-time by John Leider and Heather Leider; with support from t

vuetify 36.2k Jan 3, 2023
🛠️ Standard Tooling for Vue.js Development

Vue CLI Vue CLI is the Standard Tooling for Vue.js Development. Documentation Docs are available at https://cli.vuejs.org/ - we are still working on r

vuejs 29.6k Jan 4, 2023