Socket
Socket
Sign inDemoInstall

droplab

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    droplab

A generic dropdown for all of your custom dropdown needs.


Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Install size
68.3 kB
Created
Weekly downloads
 

Readme

Source

DropLab

A generic dropdown for all of your custom dropdown needs.

Install

Usage

Adding the data-dropdown attribute to your dropdown will add a droplab hook for that element.

The id of the hooked element can be used as the value of the data-dropdown-trigger attribute of a different element to use it as a toggle.

<a href="#" data-dropdown-trigger="#some-dropdown">Toggle</a>

<ul id="some-dropdown" data-dropdown>
  <!-- ... -->
<ul>

You can also have an input as the trigger. When a user types, the dropdown will appear.

Static data

You can add static list items.

<a href="#" data-dropdown-trigger="#static-dropdown">Toggle</a>

<ul id="static-dropdown" data-dropdown>
  <li><a href="#">Jacob</a></li>
  <li><a href="#">Jeff</a></li>
  <!--  ... -->
</ul>

Dynamic data

Adding data-dynamic to your dropdown element will enable dynamic list rendering.

Data can be added using the DropLab.prototype.addData function. The first argument is the data-id of your trigger element and the second argument is an array of objects to render to list items.

You can template a list item using the keys of the data object provided.

<a href="#" data-dropdown-trigger="#dynamic-dropdown" data-id="dynamic-trigger">Toggle</a>

<ul id="dynamic-dropdown" data-dropdown data-dynamic>
  <li><a href="#" data-id="{{id}}">{{text}}</a></li>
</ul>
droplab.addData('dynamic-trigger', [{
    id: 0,
    text: 'Jacob'
  }, {
    id: 1,
    text: 'Jeff'
  }]);

Examples

Some example implementations are provided in /example.

Plugins

Plugins are functions that are registered to be executed when a droplab instance is initialised.

They are passed the DropLab function.

droplab.plugin(function somePluginFunction(DropLab) {
  // ...
});

Some plugins are available in /dist/plugins.

Plugin documentation

Development

To run the tests, you'll need to first start your static server: npm start.

Then you can run tests with npm test.

Scripts can be compiled into /dist with npm run compile.

Keywords

FAQs

Last updated on 09 Dec 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc