All Projects → hoiheart → vue-universal-modal

hoiheart / vue-universal-modal

Licence: MIT license
Universal modal plugin for Vue3

Programming Languages

Vue
7211 projects
typescript
32286 projects
HTML
75241 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to vue-universal-modal

templates
tsParticles website templates collection
Stars: ✭ 42 (-26.32%)
Mutual labels:  vue3, vuejs3
vue-snippets
Visual Studio Code Syntax Highlighting For Vue3 And Vue2
Stars: ✭ 25 (-56.14%)
Mutual labels:  vue3, vuejs3
vue3-openlayers
Web map Vue 3.x components with the power of OpenLayers
Stars: ✭ 320 (+461.4%)
Mutual labels:  vue3, vuejs3
vue-pattern-input
Use RegExp to limit input
Stars: ✭ 25 (-56.14%)
Mutual labels:  vue3, vuejs3
vue-modal
A customizable, stackable, and lightweight modal component for Vue.
Stars: ✭ 96 (+68.42%)
Mutual labels:  modal, vue-modal
Newbee Mall
🔥 🎉newbee-mall 项目(新蜂商城)是一套电商系统,包括 newbee-mall 商城系统及 newbee-mall-admin 商城后台管理系统,基于 Spring Boot 2.X 及相关技术栈开发。 前台商城系统包含首页门户、商品分类、新品上线、首页轮播、商品推荐、商品搜索、商品展示、购物车、订单结算、订单流程、个人订单管理、会员中心、帮助中心等模块。 后台管理系统包含数据面板、轮播图管理、商品管理、订单管理、会员管理、分类管理、设置等模块。
Stars: ✭ 8,319 (+14494.74%)
Mutual labels:  vue3, vuejs3
vuestic-ui
Free and Open Source UI Library for Vue 3 🤘
Stars: ✭ 1,501 (+2533.33%)
Mutual labels:  vue3, vuejs3
lightvue
The Emerging UI Component library designed for Vue 3.x & Vue 2.x
Stars: ✭ 78 (+36.84%)
Mutual labels:  vue3, vuejs3
modaltor
modal component for vuejs
Stars: ✭ 82 (+43.86%)
Mutual labels:  modal, vue-modal
Newbee Mall Vue3 App
🔥 🎉Vue3 全家桶 + Vant 搭建大型单页面商城项目,新蜂商城 Vue3 版本,技术栈为 Vue 3.0 + Vue-Router 4.0 + Vuex 4.0 + Vant 3.0。
Stars: ✭ 3,011 (+5182.46%)
Mutual labels:  vue3, vuejs3
vuejs-3-examples
Some examples of Vue.js 3.0.
Stars: ✭ 26 (-54.39%)
Mutual labels:  vue3, vuejs3
vue3-table-lite
A simple and lightweight data table component for Vue.js 3. Features sorting, paging, row check, dynamic data rendering, supported TypeScript, and more.
Stars: ✭ 148 (+159.65%)
Mutual labels:  vue3, vuejs3
react-puzzle-confirm
React confirm modal, by matching puzzle piece
Stars: ✭ 15 (-73.68%)
Mutual labels:  modal
vue3-date-time-picker
Datepicker component for Vue 3
Stars: ✭ 157 (+175.44%)
Mutual labels:  vue3
troisjs.github.io
📖 Examples and documentation for TroisJS ✨
Stars: ✭ 119 (+108.77%)
Mutual labels:  vuejs3
rgutil
rgutil是基于ES6创建的函数库工具
Stars: ✭ 22 (-61.4%)
Mutual labels:  vue3
fireworks-js
🎆 A simple fireworks library! Ready to use components available for React, Vue 3, Svelte, Angular, Preact, Solid, and Web Components.
Stars: ✭ 550 (+864.91%)
Mutual labels:  vue3
tdesign-vue-next
A Vue3.x UI components lib for TDesign.
Stars: ✭ 799 (+1301.75%)
Mutual labels:  vue3
form-design-next
动态表单页面设计--自动生成页面--vue3.0版本
Stars: ✭ 57 (+0%)
Mutual labels:  vue3
howdyjs
一个包含Javascript插件、Vue3组件、Vue3指令的工具库
Stars: ✭ 77 (+35.09%)
Mutual labels:  vue3

vue-universal-modal

Universal modal plugin for Vue@3
Demo

⚠️ This plugin does not support Vue@2

Table of Contents

Introduction

vue-universal-modal plugin is based on the teleport.
It is very light and simple, but it provides essential features for modal use in applications.
(Such as Add & Remove, Visible & Hidden, Transition, Auto bind keyboard and mouse to close, Support SSR, A11Y...)
Here is the Demo

Features

  • Based on the teleport
  • Provides essential features for modal
  • A11Y
  • Support SSR (Insert rendering source into SSR context, Mount from Client-side)

Install plugin

npm install vue-universal-modal

Insert teleport element in your html

...
<div id="app"></div>
<!-- teleport target -->
<div id="modals"></div>
...

Because SSR cannot be implemented by dynamically creating and ref referencing teleport elements, teleport targets must be inserted into html first.

And install plugin in vue application

import 'vue-universal-modal/dist/index.css';

import VueUniversalModal from 'vue-universal-modal';

app.use(VueUniversalModal, {
  teleportTarget: '#modals',
});

Options

app.use(VueUniversalModal, {
  teleportTarget: '#my-modals',
  modalComponent: 'MyModal',
});
name type detault description
teleportTarget (required) string Teleport target
modalComponent string 'Modal' Global modal component name

Usage modal

Insert the component wrapped with the modal component. (Slot based)

<template>
  <p>
    <button @click="showModal">Show modal</button>
  </p>
  <!-- If the option changed modal component the name
  <MyModal>
  -->
  <Modal v-model="isShow" :close="closeModal">
    <div class="modal">
      <p>Hello</p>
      <button @click="closeModal">close</button>
    </div>
  </Modal>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue';

export default defineComponent({
  setup() {
    const isShow = ref(false);

    function showModal() {
      isShow.value = true;
    }

    function closeModal() {
      isShow.value = false;
    }

    return {
      isShow,
      showModal,
      closeModal,
    };
  },
});
</script>

<style scoped lang="scss">
.modal {
  width: 300px;
  padding: 30px;
  box-sizing: border-box;
  background-color: #fff;
  font-size: 20px;
  text-align: center;
}
</style>

v1.0.x -> v1.1.x change point

  • Use v-model instead of v-if for modal component insertion
  • If you control the insertion of components with v-if, the close animation will not work.
  • emitClose slot argument was deprecated.

props

name type detault description
close function () => {} Function to close a modal (apply when click dimmed)
disabled boolean false Handle just visibility (as in v-show)
options object {}

props.options

name type detault description
transition number | false 300 transition duration
closeClickDimmed boolean true Closes the modal when dimmed is clicked
closeKeyCode number | false 27 (esc) Closes the modal when press key
styleModalContent object {} Inject modal content style (.vue-universal-modal-content)

emit events

Supports emit properties for all transition events.

<template>
  <p>
    <button @click="showModal">Show modal</button>
  </p>
  <Modal
    v-model="isShow"
    :close="closeModal"
    @before-enter="beforeEnter"
    @after-enter="afterEnter"
    @before-leave="beforeLeave"
    @after-leave="afterLeave"
  >
    <div class="modal">
      <p>Hello</p>
      <button @click="closeModal">close</button>
    </div>
  </Modal>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue';

export default defineComponent({
  setup() {
    const isShow = ref(false);

    function showModal() {
      isShow.value = true;
    }

    function closeModal() {
      isShow.value = false;
    }

    function beforeEnter() {
      console.log('before enter');
    }

    function afterEnter() {
      console.log('after enter');
    }

    function beforeLeave() {
      console.log('before leave');
    }

    function afterLeave() {
      console.log('after leave');
    }

    return {
      isShow,
      showModal,
      closeModal,
      beforeEnter,
      afterEnter,
      beforeLeave,
      afterLeave,
    };
  },
});
</script>

Handle global CSS

You can change it directly to your own style by referring to the source

.vue-universal-modal {
  /* Change dimmed color */
  background-color: rgba(255, 255, 0, 0.3);
}
.vue-universal-modal-content {
  /* Align to top (flex-direction property value is set to column) */
  justify-content: flex-start;
}

Example

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].