Giter Club home page Giter Club logo

weasel.js's Introduction

popweasel

Collection of UI elements that behave as popovers

Static Menus

For simple menus, create a single instance of Menu, and reuse it for potentially many open/close calls. This is a good and simple pattern for a static menu.

const menu = new Menu(...);
setPopupToOpen(triggerElem, menu, options);

Dynamic menus

You can create a new Menu instance on every open, and destroy it on close. This should be preferred if the menu changes depending on context, or if its content subscribes to outside changes (which is wasteful when the menu is not shown).

setPopupToCreate(triggerElem, () => new Menu(...), options);

Existing DOM as a popup

You can use an existing DOM element to attach/detach on open/close, e.g. a tooltip:

const myDom = document.querySelector('.my-tooltip');
setPopupToAttach(triggerElem, myDom, options);

Custom popup class

You can define a custom popup class. It can then be used for either the static or dynamic usage pattern.

class SpecialMenu implements IPopupContent {
  constructor() { ... }
  openPopup(ctl) { ...; return content; };
  closePopup() { ... };
  dispose() { ... }  // Only needed for setPopupToCreate() usage.
}

// Calls .openPopup() on open, .closePopup() on close.
setPopupToOpen(triggerElem, new SpecialMenu(...), options);

// Calls constructor and .openPopup() on open; .closePopup() and .dispose() on close.
setPopupToCreate(triggerElem, () => new SpecialMenu(...), options);

Low-level interface.

You can use a low-level function-based interface to create a custom popup. It's the basis for all the more convenient interfaces above, and you may use it e.g. to create adapters for other libraries. See popupFunc() documentation for an example.

setPopupToFunc(triggerElem, (ctl) => {
  return () => { content, dispose };
}, options);

weasel.js's People

Contributors

dsagal avatar cpind avatar ysagal avatar jakubserafin avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.