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

rwt-shadowbox

v1.0.41

Published

Popup box with titlebar and slotted contents, a standards-based DOM Component

Downloads

65

Readme

Open Source DOM Component

Shadowbox

A classy dialog box

Motivation

Dialog boxes are such a common design pattern that they need no explanation. HTML5 has a special dialog tag for that very purpose. Unfortunately, the HTML dialog tag does not provide any "standard" behavior for how it should appear. Nor does it provide a convenient way for the user to dismiss it.

The rwt-shadowbox DOM component has several features which overcome those limitations, and make for a more pleasant user experience.

  • The dialog box has a titlebar with caption and close button.
  • The contents may be slotted or provided with a template file.
  • The dialog has an event interface for showing and hiding itself.
  • The dialog emits a custom event to close sibling dialog boxes.
  • A keyboard listener is provided to allow a shortcut key to open/close the dialog.

In the wild

To see an example of this component in use, visit the READ WRITE TOOLS website and press F2 "Info" or F3 "Rights". To understand what's going on under the hood, use the browser's inspector to view the HTML source code and network activity, and follow along as you read this documentation.

Installation

Prerequisites

The rwt-shadowbox DOM component works in any browser that supports modern W3C standards. Templates are written using BLUE PHRASE notation, which can be compiled into HTML using the free Read Write View desktop app. It has no other prerequisites. Distribution and installation are done with either NPM or via Github.

Download

Using the DOM component

After installation, you need to add four things to your HTML page to make use of it.

  • Add a script tag to load the component's rwt-shadowbox.js file:
<script src='/node_modules/rwt-shadowbox/rwt-shadowbox.js' type=module></script>             
  • Add the component tag somewhere on the page.

    • For scripting purposes, apply an id attribute.
    • Apply a titlebar attribute with the text you want to appear as a caption.
    • Optionally, apply a shortcut attribute with something like F1, F2, etc. for hotkey access.
    • Optionally, apply a sourceref attribute with a reference to an HTML file containing the dialog's text and any CSS it needs.
    • And for WAI-ARIA accessibility apply a role=contentinfo attribute.
    • For simple dialog boxes, the sourceref may be omitted and the text of the dialog box may be slotted into the DOM component. Simply place the text directly between the <rwt-shadowbox> and </rwt-shadowbox> tags.
<rwt-shadowbox id=info titlebar=Info shortcut=F1 sourceref='/info.blue' role=contentinfo ></rwt-shadowbox>
  • Add a way for the visitor to show the dialog:
<a id='info-button' title="Info (F1)">ℹ</a>
  • Add a listener to respond to the click event:
<script type=module>
    document.getElementById('info-button').addEventListener('click', (e) => {
        document.getElementById('info').toggleDialog(e);
    });
</script>

Customization

Dialog size and position

The dialog is absolutely positioned towards the bottom left of the viewport. Its size may be overridden using CSS by defining new values for the size and position variables.

rwt-shadowbox#info {
    --min-width: 10rem;
    --optimal-width: 70vw;
    --max-width: 40rem;
    
    --min-height: 10rem;
    --optimal-height: 50vh;
    --max-height: 40rem;

    --bottom: 1rem;
    --left: 1rem;
    --z-index: 1;
}

Dialog color scheme

The default color palette for the dialog uses a dark mode theme. You can use CSS to override the variables' defaults:

rwt-shadowbox#info {
    --color: var(--white);
    --accent-color1: var(--yellow);
    --accent-color2: var(--js-blue);
    --background: var(--black);
    --accent-background1: var(--medium-black);
    --accent-background2: var(--pure-black);
    --accent-background3: var(--nav-black);
    --accent-background4: var(--black);
}

Life-cycle events

The component issues life-cycle events.

Event controllers

The dialog box can be controlled with its event interface.


Reference

License

The rwt-shadowbox DOM component is licensed under the MIT License.