Tiny vanilla javascript library to display popup menus next to button togglers.
The popup menu uses a fixed position calculated by javascript, allowing the toggler to be inside of scrollables elements, auto adjust margins, evaluate the position (to be on top or at the bottom of the toggler), etc.
If you want only one menu open at a time, use a unique instance. But if you want multiples menus opened at the same time, instead create multiples instances.
Example
See an online example/playground here.
Usage
Creating an instance
var tinyPopupMenu = new TinyPopupMenu({
autoclose: true,
position: TinyPopupMenu.Position.Bottom,
margin: 5,
offset: {
x: 0,
y: 0
},
className: '',
arrow: true,
stopClick: true,
menuItems: [
{
content: 'Display alert 😎',
callback: () => alert('Alert')
},
{
content: 'Display another alert',
callback: () => alert('Another alert')
},
'-',
{
content: 'Delete',
callback: () => alert('Delete!'),
className: 'delete'
}
]
});
myTogglerButton.onclick = function (event) {
tinyPopupMenu.open(event);
};
tinyPopupMenu.addToggler(myTogglerButton, {...customOptions}, 'click');
Events
tinyPopupMenu.on('open', () => console.log('Open event'));
tinyPopupMenu.on('close', () => console.log('Close event'));
tinyPopupMenu.on('updateposition', () => console.log('Update position event'));
Install
Browser
JS
Load tiny-popup-menu.js
. Tiny Popup Menu is available as TinyPopupMenu
.
<script src="https://unpkg.com/tiny-popup-menu@1.0.10"></script>
CSS
<link rel="stylesheet" href="https://unpkg.com/tiny-popup-menu@1.0.10/dist/css/tiny-popup-menu.min.css" />
Parcel, Webpack, etc.
NPM package: tiny-popup-menu.
Install the package via npm
npm install tiny-popup-menu
JS
import TinyPopupMenu from 'tiny-popup-menu';
CSS
import 'tiny-popup-menu/lib/style/css/tiny-popup-menu.min.css';
import 'tiny-popup-menu/lib/style/scss/tiny-popup-menu.scss';
TypeScript type definition
TypeScript types are shipped with the project in the dist directory and should be automatically used in a TypeScript project. Interfaces are provided for the Options.
TODO
- Add
left
and right
positions - Add transitions/animations
- Add hoverable option
- Improve README
- Themes
License
MIT (c) Gastón Zalba.