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

dropmic

v0.3.3

Published

A lightweight dropdown plugin

Downloads

57

Readme

Logo dropmic

Introduction

dropmic is a lightweight dropdown plugin written in pure javascript

  • No dependencies required
  • No extra files to download
  • Fully customizable via CSS
  • Simple API

Documentation

Installation

Method | Procedure -------------------------- | --------- Bower | bower install dropmic --save NPM | npm install dropmic Yarn (obsolete since npm5) | yarn add dropmic Download | Download zip

Then dropmic have some css you will have to add (feel free to custom it for a better integration in your UI):

<link rel="stylesheet" href="dist/dropmic.min.css">

Finally just link the dropmic's code at the end of your document:

<!-- Browser build -->
<script src="dist/dropmic.min.js"></script>

Or as a JS module:

// ES6 module build
import dropmic from 'dropmic'

Use

Create the base layout for your button

  1. Add data-dropmic-btn attribute to your button
  2. Create a div with a dropmic css class
  3. Add a data-dropmic-direction attribute to the div (default behavior: bottom-right):
  • data-dropmic-direction="top-left"
  • data-dropmic-direction="top-right"
  • data-dropmic-direction="top-middle"
  • data-dropmic-direction="bottom-left"
  • data-dropmic-direction="bottom-right"
  • data-dropmic-direction="bottom-middle"
  1. You can also add a data-dropmic attribute to you div for target it.

Example:

<div class="dropmic" data-dropmic="42"
data-dropmic-direction="bottom-right">
  <button data-dropmic-btn>click me</button>
  <div class="dropmic-menu" aria-hidden="true">quality content</div>
</div>

Instantiate your new dropdown

var dropmic = new Dropmic(document.querySelector('[data-dropmic="42"]'));

Add content

You can create the content by yourself or use the API (cf. below)

Use this template (<div class="dropmic-menu" aria-hidden="true"> is needed, otherwise you can completely customize his content)

<div class="dropmic" data-dropmic="42" data-dropmic-direction="bottom-right" role="navigation">
    <button data-dropmic-btn>click me</button>
    <div class="dropmic-menu" aria-hidden="true">
        <div class="dropmic-menu__custom">Custom content</div>
        <ul class="dropmic-menu__list" role="menu">
            <li class="dropmic-menu__listItem" role="menuitem">
                <a class="dropmic-menu__listContent" href="http://example.com" tabindex="-1">label link</a>
            </li>
            <li class="dropmic-menu__listItem" role="menuitem">
                <button class="dropmic-menu__listContent" tabindex="-1">label button</button>
            </li>
        </ul>
    </div>
</div>

API

You can use the API to generate content and open or close your dropdown with JS:

Name | Parameter type(s) | Description ------------------------- | ----------------------- | ---------- addLink(label, url) | string or int, string | Add a link addBtn(label, callback) | string or int, function | Add a button addLabel(label) | string or int | Add a text label setCustomContent(content) | string | Set a custom content updateTargetBtn(content) | string | Update target button content open() | | Open your dropdown close() | | Close your dropdown

Example:

dropmic.setCustomContent("toto custom");
dropmic.addLink('link label', 'http://example.com');
dropmic.addBtn('close dropdown', function() {
  dropmic.close();
});
dropmic.addLabel('text label');

Options

Name | Type | Description ------------- | -------- | ----------------------------------------- onOpen | function | Callback to execute when dropmic is open onClose | function | Callback to execute when dropmic is closed beforeOpen | function | Callback to execute before opening dropmic beforeClose | function | Callback to execute before closing dropmic

Example:

var dropmic = new Dropmic(document.querySelector('[data-dropmic="1"]'), {
  onOpen: function() {
      dropmic.updateTargetBtn("Click to close");
  },
  onClose: function() {
      dropmic.updateTargetBtn("Bottom right (default)");
  }
});

Modify dropmic

  1. Setup dependencies: npm i (or npm ci if you don't want to impact package-lock)
  2. Run hot-reloads server for development npm run dev
  3. (Build for production npm run build)

Roadmap

  • [x] Add open and close public method in the API
  • [x] Add top-middle and bottom-middle direction
  • [x] A11y friendly (with keyboard navigation)
  • [x] Permit to update button content with dropdown is open
  • [ ] Instantiate severals dropmic with one initialization command
  • [ ] Permit to update a list item value

Licence

Released under the MIT LICENSE