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

hyperdom-modal

v2.1.0

Published

Accessible modal built with Hyperdom that uses <dialog> element.

Downloads

14

Readme

Hyperdom Modal NPM version Dependency Status

Accessible modal component built with Hyperdom

  • Uses <dialog> element by default and loads a polyfill for older browsers
  • No need to worry about z-index since modal opens on its own layer
  • By default modal expands its dimensions to fit your content - adds styles to limit dimensions
  • Modal HTML is returned straight away to your app (rather than returning on show) and hidden with CSS. The open attribute is added to the <dialog> to reveal it

View Demo

Installation

$ yarn add hyperdom-modal

Usage

Instantiate a modal in your constructor then call .render() method where you want it on the page. The <dialog> will always be rendered to the page regardless of whether it's open or not.

Pass modal content to this method or options first and then the content. Example:

JS

const hyperdom = require('hyperdom')
const h = hyperdom.html
const HyperdomModal = require('hyperdom-modal')

class DemoApp {
  constructor() {
    this._favourite = 'undecided'
    this._choosing = false
    this._title = 'World'

    this._modal1 = new HyperdomModal()
    this._modal2 = new HyperdomModal()
  }

  render() {
    return h(
      'main.container',
      h(
        'h1.text-center',
        h(
          'a',
          { href: 'https://github.com/featurist/hyperdom-modal' },
          'Hyperdom Modal'
        ),
        ' Demo'
      ),
      h(
        '.text-center',
        h(
          'button',
          {
            onclick: () => this._modal1.open()
          },
          'Greet me'
        )
      ),
      h(
        '.text-center',
        h('p', 'Your favourite animal is: ', this._favourite),
        h(
          'button',
          {
            onclick: () => {
              this._previousFavourite = this._favourite
              this._modal2.open()
            }
          },
          'Choose an animal'
        )
      ),
      h(
        '.text-center',
        h(
          'button',
          {
            onclick: () => {
              this._title = 'Brand New World'
              this._modal1.open()
            }
          },
          'Update title and open modal'
        )
      ),
      this._modal1.render(
        h(
          '.modal-content',
          h('h2.modal-heading', `Hello ${this._title}!`),
          h(
            'button',
            {
              onclick: () => this._modal1.close()
            },
            'Goodbye!'
          )
        )
      ),
      this._modal2.render(
        {
          openBinding: [this, '_choosing'],
          onCancel: () => {
            this._favourite = this._previousFavourite
          },
          dialogOptions: { class: 'modal' }
        },
        h(
          '.modal-content',
          h('h2.modal-heading', 'Choose your favourite!'),
          h('p', 'What is your favourite animal?'),
          h(
            'p',
            h(
              'select',
              { binding: [this, '_favourite'] },
              h('option', 'undecided'),
              h('option', 'cat'),
              h('option', 'dog')
            )
          ),
          h(
            'button',
            {
              onclick: () => this._modal2.close()
            },
            'Confirm'
          ),
          h(
            'button',
            {
              onclick: () => this._modal2.cancel()
            },
            'Cancel'
          )
        )
      )
    )
  }
}

hyperdom.append(document.getElementById('root'), new DemoApp())

CSS

Supported browsers provide their own default styles for the modal and backdrop. You must include the polyfill stylesheet in your app for unsupported browsers to achieve the same default behaviour. You can include it from this package at node_modules/hyperdom-modal/dist/dialog-polyfill.css

You can add styles to override the defaults and style the content passed in to your modal. Example stylesheet.

Options

| Name | Type | Default | Description | | :-------------: | :--------: | :-----: | :---------------------------------------------------------------------------------- | | openBinding | binding | none | A hyperdom binding that determines whether the modal window is open | | dialogOptions | object | none | Any options such as attributes or event handlers passed to the <dialog> element | | onCancel | function | none | A function that is called when the modal dialog is closed e.g. using the escape key |

More About <dialog>

  • https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dialog
  • https://keithjgrant.com/posts/2018/meet-the-new-dialog-element/
  • https://demo.agektmr.com/dialog/

License

MIT © Featurist Ltd

We're Hiring!

Join our remote team and help us build amazing software. Check out our career opportunities.