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

app-drawer-polyfill

v1.0.0

Published

Polyfill for the app-drawer Built-in Module

Downloads

3

Readme

App Drawer

This document is an explainer for a potential browser-provided "App Drawer" component, implemented as a built-in module. App Drawer is delivered as a Custom Element, making it framework-agnostic and easy to integrate into existing applications. It supports the gestures users expect from experience with native mobile platforms, ensures a consistent UX for opening and dismissal, and solves accessibility issues common to web-based drawer implementations. It ships unstyled, and is easily customized via attributes and CSS Custom Properties.

Sample code

<app-drawer id="drawer">
  <header><h1>App</h1></header>
  <nav>
    <a href="/">Home</a>
    ...
  </nav>
</app-drawer>

<script type="module">
  import '@std/app-drawer';
  drawer.addEventListener('close', () => {
    console.log('closed');
  });
  drawer.open();
</script>

<!-- Future:  <script type="module" src="import:@std/app-drawer"></script> -->

Motivation

The concept of an "app drawer" is pervasive on the web. Also referred to as "off-canvas navigation" or modal sidebars, these represent an important component of many User Interfaces and often contain an web app's primary navigation.

There are a multitude of drawer implementations in userland, many of which suffer from usability or performance issues. The inconsistency and unreliability of important UX characteristics like gestures & keyboard support has fractured web users' expectations of the metaphor, demonstrating the need for a browser-provided solution.

(link to existing drawer impls?)

We want to win back the trust of web users by bringing consistency, reliability and performance to drawer UI's.


API

Slots

By default, any elements placed into <app-drawer> are rendered within the sliding drawer panel. Children can also be placed into other areas using Named Slots:

<app-drawer>
  <div slot="backdrop">Placed into the backdrop (grayed out) area</div>

  <div slot="header">Placed first in the drawer area</div>
  
  <div>Any other children are placed into the drawer (after the header)</div>
</app-drawer>

CSS Custom Properties

Styling can be adjusted using the following CSS Custom Properties:

  • --width: the drawer's default width (default: 200px)
  • --max-width: maximum drawer width as a percentage of the viewport (default: 100)
  • --background: background color for the sliding drawer panel (default: #eee)
  • --backdrop: background for the backdrop/shim behind the drawer (default: rgba(0, 0, 0, 0.5))

Additionally, the drawer exposes some of its state as CSS Custom Properties, which can be used to reactively style the drawer or any element within it:

  • --percent: the current percent visibility/openness of the drawer during a drag gesture
  • --tf-x: the current CSS transform (translateX(xx)) applied to the drawer during a drag gesture

AppDrawer

Custom Element constructor, inheriting from HTMLElement.

To create an App Drawer instance programmatically:

const appDrawer = document.createElement('app-drawer');

.toggle(forceState)

Opens or closes the drawer based on its current state.

If forceState is a Boolean value, the drawer will be opened or closed regardless of its current state.

.open()

Open the drawer if it is currently closed.

Note: If invoked during a drawer gesture, overrides the end state of the gesture.

.close()

Close the drawer if it is currently open.

Note: If invoked during a drawer gesture, overrides the end state of the gesture.

event: toggle(e)

Fired when the drawer finishes opening or closing. The event includes a .open property with a Boolean indicating the drawer's new state.

drawer.addEventListener('toggle', e => {
  console.log('Drawer is now ', e.open ? 'open' : 'closed');
})

Open issues and questions

Please see the issue tracker for open issues on the API surface detailed above.

Impact

This feature would be medium-effort, medium-reward.

  • Applications would no longer need to build and ship custom drawer implementations
  • Developers would not need to implement gesture support or platform-specific differences
  • Users of assistive technologies would benefit from a well-known and DOM-controllable interaction model

Comparison to existing solutions

There are a number of standalone drawer implementations available on npm that offer comparable functionality:

(All of the above statistics are as of 2019-02-06.)