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

wc-menu-button

v6.0.0

Published

A simple, animating menu button built as a Web Component

Downloads

262

Readme

Build Published on webcomponents.org npm

wc-menu-button

A simple, animating side drawer built as a Web Component

wc-menu-button demo

Demo

Installation

You can integrate wc-menu-button via <script> tag or via NPM.

Via <script> tag

In the <head> of your index.html put a script tag like this:

<script
  type="module"
  src="https://cdn.jsdelivr.net/npm/[email protected]/+esm"
></script>

<!-- Or if you want the unminified version -->
<script
  type="module"
  src="https://cdn.jsdelivr.net/npm/[email protected]/wc-menu-button.js"
></script>

Now you can use the wc-menu-button element anywhere in your html, JSX, template, etc.

Via NPM

npm install wc-menu-button --save

And then you need to import the module before you can use it in your html/jsx/template:

import "wc-menu-button";

Web Component Browser Support

This web component uses HTML templates, the shadow DOM, and custom elements. If you need to polyfill for any of these standards then take a look at the web components polyfill.

API and Customization

Attributes/Properties

  • open
    • Add this attribute to put the menu button in the "open" state.
      • Example: <wc-menu-button open></wc-menu-button>
    • Set the property in Javascript to imperatively toggle the drawer
      • Example: drawer.open = true
    • In (p)react you might need to set undefined in your JSX (since false !== undefined for html attribute existence)
      • Example: <wc-menu-button open={this.state.isMenuOpen || undefined}></wc-menu-button>

Events

  • opened
    • Raised when the menu button changes to the "open" state.
    • Example: menu.addEventListener("opened", handleOpen())
    • When subscribing in html listen for onopened
      • Ex: <wc-menu-button onopened="handleOpen()">
  • closed
    • Raised when the menu button changes to the not "open" state.
    • Example: menu.addEventListener("closed", handleClose())
    • When subscribing in html listen for onclosed
      • Ex: <wc-menu-button onclosed="handleClose()">

Styling

You can style the wc-menu-button element as you would any regular element, in CSS. A list of supported CSS properties are below, along with the default values.

:root {
  /* Menu button color is set with CSS variable */
  --wc-menu-button-color: #000000;

  /* The default mouse cursor is used by default */
  --wc-menu-button-cursor: default;
}

/* You only need to set the width, the height is calculated to maintain proportion */
wc-menu-button {
  width: 37px;
}

/* Set to `1.0` if you do not want any hover opacity effect */
wc-menu-button:hover {
  opacity: 0.75;
}

Contribute

This project is built with standard HTML/CSS/TS, no frameworks or special web-component compilers here (for maximum simplicity and minimum size). If you want to learn more about writing custom elements see MDN or this web fundamentals page.

The source for this web component is contained in wc-menu-button.js and example usage is in index.html. To debug/run the example you can just open index.html in a browser. For a hot-reload developer experience try using live server in vscode.

You will need the dev dependencies of this project installed to run the post-commit hooks.

npm install

Acknowledgements

Thanks to BrowserStack for cross browser testing.

BrowserStack