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

be-open-and-shut

v0.0.12

Published

Automatically close an element that has an "pen" state, after clicking away from the element.

Downloads

14

Readme

be-open-and-shut

Automatically close an element that has an "pen" state, after clicking away from the element.

Playwright Tests NPM version

Size of package, including custom element behavior framework (be-enhanced):

How big is this package in your project?

Size of new code in this package:

<side-nav be-open-and-shut>
    <menu >
        ...
    </menu>
</side-nav>

is shorthand for

<side-nav be-open-and-shut='{
        "set": "open",
        "onClosest": "*",
        "toVal": false,
        "when": "document",
        "is": "click",
        "outsideClosest": "*"
    }'>
    <menu >
        ...
    </menu>
</side-nav>

Technically, this only adds the event handler to the global document object when the value of the property doesn't match the value of "toVal", and the event handler is aborted when it matches. This allows for a huge number of open-and-shut elements to be active without burdening the global document object with lots of click handlers (typically only one will be active at any one time).

We are assuming the property "open" has a standard setter which can be subscribed to.

Some components, like the native details element, don't consistently call the "open" property setter when the value of open changes.

To accommodate such components, add an alternative event listener on the adorned element to monitor for:

<details be-open-and-shut=toggle>
    <summary>test</summary>
</side-nav>

which is short-hand for:

<details be-open-and-shut='{
        "set": "open",
        "onClosest": "*",
        "toVal": false,
        "when": "document",
        "is": "click",
        "outsideClosest": "*",
        "onEventType": "toggle"
    }'>
    <summary>test</summary>
</side-nav>

Hemingway notation [TODO]

<details be-open-and-shut='
    On toggle event of adorned element spring to action.
    Said action attaches to document an event listener with event type click.
    Said event listener does a check to see if event was triggered on an element outside closest *.
    If said check is satisfied set property open to false of closest * of adorned element.
'>
    <summary>test</summary>
</side-nav>

There is special logic for the dialog element, which doesn't come close to following this pattern. H/t on the implementation and for making me think about this scenario.

<dialog id=dialog be-open-and-shut>
        This is the dialog
</dialog>
<button onclick='openDialog()'>test</button>
<script>
    function openDialog(){
        dialog.showModal();
    }
    
</script>

Viewing Locally

  1. Install git.
  2. Fork/clone this repo.
  3. Install node.
  4. Open command window to folder where you cloned this repo.
  5. npm install

  6. npm run serve

  7. Open http://localhost:3030/demo in a modern browser.

Importing in ES Modules:

import 'be-open-and-shut/be-open-and-shut.js';


## Using from CDN:

```html
<script type=module crossorigin=anonymous>
    import 'https://esm.run/be-open-and-shut';
</script>