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 🙏

© 2026 – Pkg Stats / Ryan Hefner

vanjs-modal

v0.1.1

Published

Controlled native modal dialogs for VanJS.

Readme

vanjs-modal

Controlled native modal dialogs for VanJS.

  • Composable VanJS content.
  • Centered and scrollable modals.
  • Multiple modals with focus restoration.
  • Page scroll locking.
  • Reactive options.
  • CSS customization.
  • Animations with reduced-motion support.
  • TypeScript support.

Installation

npm install vanjs-modal

Quick start

import van from 'vanjs-core'
import { Modal } from 'vanjs-modal'
import 'vanjs-modal/style.css'

const { h2, p, button } = van.tags
const open = van.state(false)

const modal = Modal(
  {
    open,
    title: 'Settings',
    class: 'settings-modal',
    onCloseRequest: () => {
      open.val = false
    },
  },
  h2('Settings'),
  p('Update your preferences.'),
  button({ onclick: () => (open.val = false) }, 'Save'),
)

van.add(document.body, button({ onclick: () => (open.val = true) }, 'Open settings'))

API

Modal(options: ModalOptions, ...children: readonly ChildDom[]): ModalHandle

Modal appends a <dialog> to document.body and returns a cleanup handle, which must not be passed to van.add.

Children use VanJS's ChildDom type, including elements, primitives, states, binding functions, nested arrays, null, and undefined.

Exported types are ModalOptions, ModalHandle, and ModalAnimationEvent.

Options

In the table below, Reactive<T> means T | StateView<T> | (() => T), where StateView comes from vanjs-core.

| Option | Type | Default | Description | | --- | --- | --- | --- | | open | StateView<boolean> \| (() => boolean) | Required | Controls whether the dialog is open. | | onCloseRequest | () => void | Required | Handles close requests from the topmost modal; update open to accept a request. | | center | Reactive<boolean> | false | Centers the dialog vertically with the package stylesheet or equivalent custom CSS. | | closeOnEscape | Reactive<boolean> | true | Allows Escape and native cancel events to request closure. | | closeOnOutsideClick | Reactive<boolean> | true | Allows a click that starts and finishes outside the dialog to request closure. | | showCloseButton | Reactive<boolean> | true | Shows the built-in close button. | | title | Reactive<string> | '' | Sets the native dialog title used as its accessible name. | | class | Reactive<string> | '' | Adds classes to the dialog. | | onAnimationEnd | (event: ModalAnimationEvent) => void | — | Receives { phase: 'opening' \| 'closing' } after a completed transition, including when motion is disabled, but not after interruption or disposal. |

Styling

Import vanjs-modal/style.css as shown in the quick start, or provide your own styles for .vanjs-modal, .vanjs-modal_center, and .vanjs-modal__close.

.settings-modal {
  width: 28rem;
  padding: 1.5rem;
  border-radius: 0.5rem;
}

.settings-modal::backdrop {
  background: rgb(0 0 0 / 40%);
}

The package stylesheet applies 300 ms fade animations to the dialog and backdrop using data-phase="opening" and data-phase="closing", and disables them for prefers-reduced-motion: reduce.

Cleanup

Call dispose() when the owning view is removed to release the dialog and its listeners; repeated calls are safe.

modal.dispose()

License

MIT