npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@flourish/popup

v3.1.0

Published

Popup UI component

Downloads

764

Readme

Flourish popup component

The Popup component provides a configurable popup box. We developed it for use in Flourish templates, but it’s open source and you can use it for anything.

import Popup from "@flourish/popup";

var popup = Popup();

// Hide the popup if the user clicks on it
popup.on("click", function() { this.hide(); });

// Draw the popup pointing to position (100, 100)
popup.point(100, 100).draw();

It’s developed as an ES6 module, and you can use it with rollup.js and rollup-plugin-node-resolve, or another ES6-compatible module bundler. Or you can include the file directly from the web:

<script src="https://cdn.flourish.rocks/popup-v1.full.min.js"></script>

Interactive example

Example on codepen

Full reference

Constructor

Popup() constructs a new popup. It’s possible to have several popups on the same page, though typically you would only need one. The constructor takes no arguments.

Methods

.draw()

Draws or redraws the popup to reflect the current value of its settings.

.hide()

Hides the popup.

### .on(event, handler) Attach an event handler. The only supported event is click. You can attach multiple handlers for the same event, and all of them will fire when appropriate.

## Events

The click event

The click event is fired when someone clicks on the popup. The event handler is passed the underlying MouseEvent as an argument, and its this object is the Popup instance.

Settings

Settings are applied by calling the method of the same name on the Popup object with the new value as an argument. These methods return the Popup object, so you can chain them. For example, you can set the position and contents with:

popup.point(100, 50).html("Look at me!");

You can retrieve the current value of a setting by calling the method with no arguments, e.g.

var current_point = popup.point();

container

A DOM element to which to constrain the popup. Defaults to document.body.

point

The point is an array of two positions [x, y] that determines where the popup points.

point(arr)

Pass x and y positions in a two-element array, [x, y].

point(x, y)

As a convenience, you can pass the x and y positions as separate arguments.

point(container)

Or you can pass a visible DOM element, which sets the point to the centre of that element.

html

The contents of the popup.

directions

An array of directions in priority order or a string specifying a single direction. Popup will use the first listed direction that allows the popup to be drawn within its container.

Supported directions are:

  • bottom: draw the little arrow in the centre of the bottom edge of the popup box, so the popup is above the point.
  • top: draw the little arrow in the centre of the top edge of the popup box, so the popup is below the point.
  • left: draw the little arrow in the centre of the left-hand edge of the popup box, so the popup is to the right of the point.
  • right: draw the little arrow in the centre of the right-hand edge of the popup box, so the popup is to the left of the point.
  • topLeft: draw the little arrow in the top-left corner of the popup box, so the popup is below and to the right of the point.
  • bottomLeft: draw the little arrow in the bottom-left corner of the popup box, so the popup is above and to the right of the point.
  • topRight: draw the little arrow in the top-right corner of the popup box, so the popup is below and to the left of the point.
  • bottomRight: draw the little arrow in the bottom-right corner of the popup box, so the popup is above and to the left of the point.
  • bottomFlexible: draw the little arrow somewhere on the bottom edge of the popup box, so the popup is (possibly asymmetrically) above the point.
  • topFlexible: draw the little arrow somewhere on the top edge of the popup box, so the popup is (possibly asymmetrically) below the point.
  • leftFlexible: draw the little arrow somewhere on the left-hand edge of the popup box, so the popup is (possibly asymmetrically) to the right of the point.
  • rightFlexible: draw the little arrow somewhere on the right-hand edge of the popup box, so the popup is (possibly asymmetrically) to the left the point.

The default priority order is the order listed above.

fallbackFit

Determines what Popup will do if it’s impossible to fit the popup into the container using any of the listed directions. Possible values are "horizontal" (which is the default), "vertical", and null.

If it’s impossible to fit the popup into the container using any of the listed directions then:

  • If fallbackFit is "horizontal", the popup will be as far as possible constrained horizontally by the container, but allowed to overlap its bounds vertically.
  • If fallbackFit is "vertical", the popup will be as far as possible constrained vertically by the container, but allowed to overlap its bounds horizontally.
  • If fallbackFit is null, Popup will log a warning to the console and use the first listed direction.

Style

You can style the popup using CSS. The popup container has class .flourish-popup, and contains an <svg> element with class .flourish-popup-svg and a <div> with class .flourish-popup-content. The SVG contains a <g> element that you can style to change the appearance of the popup box itself, and you can style the content div to change the appearance of the HTML within the popup.

For example, if you want your popup to have white text on a black background you can write:

.flourish-popup .flourish-popup-svg g { fill: black; }
.flourish-popup .flourish-popup-content { color: white; }

or if you want a translucent popup you can write:

.flourish-popup .flourish-popup-svg g { opacity: 0.6; }

Properties

.version

Popup.version is the version number of this library, using Semantic Versioning.