Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/gregolive/dropdown-menu

A Javascript dropdown menu npm module.
https://github.com/gregolive/dropdown-menu

css javascript npm npm-module

Last synced: 25 days ago
JSON representation

A Javascript dropdown menu npm module.

Awesome Lists containing this project

README

        

# Dropdown Menu

A simple Javascript-powered dropdown menu. Can be activated by click or hover.

[Live demo](https://gregolive.github.io/dynamic-ui-design/#dropdown-demo) 👈

[npm package](https://www.npmjs.com/package/@gregolive/dropdown) 📦

## Prerequisites

For icons to display, please install [font-awesome](https://www.npmjs.com/package/font-awesome).

## Installation

On the command line run:

```
npm i @gregolive/dropdown
```

Import the function in your Javascript file with:

```
import dropdown from '@gregolive/dropdown';
```

## Usage

Pass 2 or 3 arguments into the dropdown function:

1. title string for the dropdown button
2. links object containing the text and href for the menu items
3. hover boolean (optional, defaults to false)

Append to the DOM.

Examples:

```
const links = [
{ text: 'Hello there 👋', href: '#' },
{ text: "I'm a dropdown link 🔗", href: '#' },
{ text: 'Me too 🤙', href: '#' },
];

const clickDropdown = dropdown('Click Me', links);
document.body.appendChild(clickDropdown);

const hoverDropdown dropdown('Hover Me', links, true);
document.body.appendChild(hoverkDropdown);
```

Default styling (colors, padding, etc.) can be overridden by overriding the CSS variables in:

```
:root {
...
}
```

## License

ISC