Coder Social home page Coder Social logo

designtips / popper.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from floating-ui/floating-ui

0.0 2.0 0.0 927 KB

A ~3.5KB kickass library to manage your poppers

Home Page: https://popper.js.org

License: MIT License

JavaScript 98.37% CSS 1.63%

popper.js's Introduction

Popper.js

Popper.js is a library used to create poppers in web applications.

Build Status npm version Join the chat!

Wut? Poppers?

A popper is an element on the screen which "pops out" from the natural flow of your application. Common examples of poppers are tooltips and popovers.

So, yet another tooltip library?

Well, basically, no. Popper.js is built from the ground up to being modular and fully hackable customizable. It supports a plugin system you can use to add particular behaviors to your poppers. It's AMD and CommonJS compatible and it's well documented thanks to our JSDoc page.

The Library

Popper.js is mostly a library with the job of making sure your popper stays near the defined reference element (if you want so). Additionally, it provides an easy way to generate your popper element if you don't want to use one already in your DOM.

Installation

Popper.js is available on NPM and Bower:

NPM

npm install popper.js --save

Bower

bower install popper.js --save

jsDelivr

http://www.jsdelivr.com/projects/popper.js

Basic usage

Create a popper near a button:

var reference = document.querySelector('.my-button');
var thePopper = new Popper(
    reference,
    {
        content: 'My awesome popper!'
    },
    {
        // popper options here
    }
);

"Advanced" usage

Given an existing popper, ask Popper.js to position it near its button

var reference = document.querySelector('.my-button');
var popper = document.querySelector('.my-popper');
var anotherPopper = new Popper(
    reference,
    popper,
    {
        // popper options here
    }
);

Callbacks

var reference = document.querySelector('.my-button');
var popper = document.querySelector('.my-popper');
var anotherPopper = new Popper(reference, popper).onCreate(instance) {
  // instance is Popper.js instance
}).onUpdate(function(data) {
  // data is an object containing all the informations computed by Popper.js and used to style the popper and its arrow
});

React.js and Ember.js integration

If you prefer to let your framework apply the styles to your DOM objects, you can follow an approach like the one below:

var reference = document.querySelector('.my-button');
var popper = document.querySelector('.my-popper');
var anotherPopper = new Popper(reference, popper, {
    modifiersIgnored: ['applyStyle'] // prevent Popper.js from applying styles to your DOM
}).onUpdate(function(data) {
  // export data in your framework and use its content to apply the style to your popper
});

If you are wondering about the available options of the third argument, check out our documentation

Visit our GitHub Page to see a lot of examples of what you can do right now!

Notes

Credits

I want to thank some friends and projects for the work they did:

  • @AndreaScn for its work on the GitHub Page and the manual testing he did during the development;
  • @vampolo for the original idea and for the name of the library;
  • Sysdig for all the awesome things I learned during these years that made possible for me to write this library;
  • Tether.js for having inspired me in writing a positioning library ready for the real world;
  • you for the star you'll give to this project and for beeing so awesome to give this project a try :)

Copyright and license

Code and documentation copyright 2016 Federico Zivolo. Code released under the MIT license. Docs released under Creative Commons.

popper.js's People

Contributors

fezvrasta avatar fodonnel avatar coobaha avatar ishanray avatar

Watchers

Trey Brister avatar James Cloos 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.