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

@agence-webup/tiroir

v0.2.0

Published

A simple drawer menu vanilla plugin

Downloads

15

Readme

Tiroir.js

A simple but complete drawer menu plugin in vanilla JavaScript

⚠️ (Still in early development state)

Demo keyboard navigation

Documentation

Installation

Method | Procedure -------------------------- | --------- NPM | coming soon Download | Download zip

Then Tiroir 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/tiroir/tiroir.css">

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

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

Or as a JS module:

// ES6 module build
import tiroir from 'Tiroir'

Use

Instantiate your menu

var tiroir = new Tiroir({
  trigger: document.querySelectorAll('[data-tiroir-btn]') // If you alredy now which element clicks will open the menu
})

Add content

You can create the content by yourself or use the API to build your navigation with a JSON/JS-Object (cf. below)

Use a server side rendered content

You can give an HTML element as content option to init object. The plugin will send it into the menu.

  • If the content contain an element with a data-tiroir-nav attribute it gonna parse the contain and fill the stacking navigation with it.
  • If the content contain an element with a data-tiroir-footer attribute it gonna send it into the sticky footer element

Add complex content with a JSON/JS-Object

If you have a complex navigation or don't want your link to be indexed by search engines, you can fill the stacking navigation with a JSON/JS-Object using the setItems() function.

The object must respect this type of structure to be able to work:

const items = [
   {
       label: 'Home',
       link: 'https://example.com/'
   },
   {
       label: 'Blog',
       items: [
           {
               label: 'Posts',
               attributes: { // You can pass custom html attributes
                   class: 'test'
               },
               link: 'https://example.com/blog/',
               items: [
                   {
                       label: 'My super post 1',
                       link: 'https://example.com/blog/test1',
                   },
                   {
                       label: 'My super post 2',
                       link: 'https://example.com/blog/test2',
                   },
                   {
                       label: 'My super post 3',
                       link: 'https://example.com/blog/test3',
                   },
               ]
           },
           {
               label: 'Videos',
               items: [
                   {
                       label: 'My first vlog',
                       link: 'https://example.com/videos/1',
                   },
                   {
                       label: 'My presentation video',
                       link: 'https://example.com/videos/2',
                   },
                   {
                       label: 'Vlog 2',
                       link: 'https://example.com/videos/3',
                   },
               ]
           },
       ]
   },
   {
       label: 'Contact',
       link: 'https://example.com/contact'
   },
]

const menu = new Tiroir()
menu.setItems(items)

Options

Name | Type | Description ------------------ | ----------------- | ----------------------------------------- trigger | node list/element | Element(s) who will open the menu on click content | node element | Default menu content on load directionReverse | boolean | Inverse the menu opening's direction (on the right by default) onOpen | function | Callback to execute when tiroir is opening onClose | function | Callback to execute when tiroir is closing resetLabel | string | Custom back-home button's label in the navigation currentLabel | string | Custom current prefix's label in the navigation

Example:

const menu = new Tiroir({
  content: document.querySelector('[data-tiroir="menu-content"]'),
  trigger: document.querySelectorAll('[data-tiroir-btn]'),
  resetLabel: 'Back at first',
  currentLabel: 'All the ',
  onOpen: function () {
      console.log('menu opened')
  },
  onClose: function () {
      console.log('menu closed')
  }
});

API

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

Name | Parameter type(s) | Description ------------------------- | ----------------------- | ---------- open() | no parameter | Open your menu close() | no parameter | Close your menu setItems(items) | JSON or JS Array | Set a custom navigation (more info on the structure below) parseItems(el) | HTML element | Parse a navigation container and fill the navigation with it setContent(el) | HTML element | Set a custom content setFooter(el) | HTML element | Set a custom content

Example:

tiroir.setItems(navContent);
tiroir.open()

Modify Tiroir.js

  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)