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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@determaer/vue-use-modal

v1.0.2

Published

This library was created to simplify utilization process of modal windows in Vue applications with use of async components.

Downloads

44

Readme

Vue Use Modal

This library was created to simplify utilization process of modal windows in Vue applications with use of async components.

Description

There are 2 main entities presented in library you can import:

  • useModal - a composable function for reusing the modal window work logic
  • Modal - a Vue component realizing modal wrapper

useModal

useModal function allows to work with preloaded modal wrappers and dynamically imported target content components. It using embedded vue API - createApp, defineComponent, h, defineAsyncComponent.

| Prop | Type | Destination | | ---------------- | ------------------ | -------------------------------------------------------------------- | | component | Promise | Required: Dynamically imported target content components | | loadingComponent | Component | Optional: Component using while target component not available | | errorComponent | Component | Optional: Component using in case of target component download error | | timeout | number | Optional: delay time to show an errorComponent | | attrs | generic | Optional: Target content component props from defineProps | | Modal | Component | Required: Modal wrapper component | | modalAttrs | generic | Optional: Modal wrapper component props from defineProps |

| Type of return value | In case | | -------------------- | ----------------------------------------------------------------- | | generic | Inner component emitted "change" according to passed generic type | | true | Inner component emitted "submit" with no data | | false | Inner component emitted "close" with no data |

You can set generic types for return value, attributes for target content component and attributes for modal wrapper component accordingly. They are optional, but make sure you define them in right order. You can define them by the aproach described below.

useModal<ReturnT>(...){...}
useModal<ReturnT, AttrsT>(...){...}
useModal<ReturnT, AttrsT, ModalAttrsT>(...){...}

useModal Lifecycle

Lifecycle of such modal window includes several events:

  • 'change' - changing inner Data object's field with {key: value} syntax
  • 'submit' - resolving modal window with return value (generic or true as mentioned in table before) and unmounting
  • 'close' - resolving modal window with return value false and unmounting

Modal Wrapper

Modal wrapper includes modal backdrop and active frame with slot #default. You can define your own style attributes via existing classes:

  • .use-modal-wrapper-backdrop
  • .use-modal-wrapper-frame

If necessary you can define your own modal wrapper and use it in Modal prop of useModal function

Usage

Make sure you have some component need to be presented in modal window. This component must have emits enlisted previously in useModal Lifecycle.

<script setup lang="ts">
//example of using in some vue component
const emit = defineEmits(['change', 'submit', 'close']);

const handleChange = (key: string, value: Define your type here) => {
  emit('change', {[key]: value})
}
</script>

Create useModal'...'.ts, where

import { Modal, useModal } from '@determaer/vue-use-modal'

export const useModalShowExample = async () : Promise<Define your return type here> => {
  const data = await useModal<ReturnT, AttrsT, ModalAttrsT>({ //here you can set generic types
    component: import('./ModalContent.vue'),
    Modal, //here you can use any another component
    attrs: {
      info: 2223
    },
    modalAttrs: {
      modalInfo: 'info in modal section'
    }
  })

  //some action with result
}

Call this function somewhere in your app

<script setup>
import { useModalShowExample } from "./useModalShowExample";

const handleClick = async () => {
  const data = await useModalShowExample();
  // some action with result
};
</script>

Installation

npm install @determaer/vue-use-modal