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

nuxt-modal

v1.0.2

Published

Custom modal component for Nuxt 3.

Downloads

102

Readme

Nuxt Modal

Nuxt 3 Modal

npm version Nuxt

Custom modal component for Nuxt 3.

Features

  • 🔧 Fully customizable (colors, functions, slots)
  • 🤳🏻 Slides up on mobile
  • ✨ Nice fade in/out
  • ⚡ Setup in seconds
  • ✅ Access modals from anywhere

Install

Install the layer:

npm i -D nuxt-modal

Add the layer in the extends array in nuxt.config.ts:

export default defineNuxtConfig({
  extends: ['nuxt-modal'],
})

Usage (inline modal)

<template>
  <NuxtModal v-model="isModalOpen">
    <template v-slot:header>Inline Modal</template>
    <template v-slot:content>
      <p>This modal an inline modal, that doesn't need it's own component.</p>
    </template>
  </NuxtModal>

  <button @click="openModal">Open</button>
</template>

<script>
const isModalOpen = ref(false)
const openModal = () => (isModalOpen.value = true)
</script>

Usage (component modal)

<!-- components/ModalComponent.vue -->
<template>
  <NuxtModal :name="name">
    <template v-slot:header>Hello! 👋🏼</template>
    <template v-slot:content>
      <p>This is a simple nuxt-modal component</p>
    </template>
    <template v-slot:buttons>
      <button @click="close">Cancel</button>
      <button @click="close">Got it!</button>
    </template>
  </NuxtModal>
</template>

<script setup lang="ts">
const props = defineProps<{
  name: string
}>()

const { close } = useModal(props.name)
</script>
<!-- app.vue -->
<template>
  <ModalComponent :name="name" />
  <button @click="modalComponent.open">Open</button>
</template>

<script>
const name = ref('myModal)
const modal = useModal(name.value)
</script>

That's it, you've got a fully functional modal component in your project. Keep reading to customize the modal to suit your needs.

Components

<NuxtModal />

The main component used to display modals is NuxtModal. Here's the full default configuration:

<template>
  <NuxtModal
    v-model // boolean with visible value
    :name="'modalName'"
    :header="true"
    :buttons="true"
    :borders="true"
    @close="modal.close()"
    @proceed="modal.close()"
  />
</template>

Composables

useModal()

You can access your modals anywhere in your app as we store the data with useState().

Example

const { open, close, toggle, visible } = useModal('modalName')

Slots

  • header: shown at the top of the modal
  • content: main content of the modal
  • buttons: close/proceed buttons, if you don't add any we'll show a cancel & proceed button fallback

Example

<NuxtModal>
  <template v-slot:header></template>
  <template v-slot:content></template>
  <template v-slot:buttons></template>
</NuxtModal>

Props

| Prop | Type | Default | Description | | --------- | --------- | ------- | ------------------------------------------- | | v-model | boolean | false | the visibility of the modal | | name | string | `` | (optional) the unique name of the modal | | header | boolean | true | show/hide the modal header | | buttons | boolean | true | show/hide the modal buttons | | borders | boolean | true | show/hide the modal header & button borders |

Events

closed

Fired when the users clicks the cancel button, or the modal background.

Example

<NuxtModal @close="doSomething()" />

proceed

Fired when the user accepts the modal. You can put any function in here to do something based on what the modal is for.

Example

<NuxtModal @proceed="doSomething()" />