@flourish/popup

中文文档
3.1.1发布于 2025/01/10BSD-3-ClauseES Module近 30 天下载 5168

Popup UI component

原始使用文档
文档目录17 节
  1. Constructor
  2. Methods
  3. .draw()
  4. .hide()
  5. The click event
  6. Settings
  7. container
  8. point
  9. point(arr)
  10. point(x, y)
  11. point(container)
  12. html
  13. directions
  14. fallbackFit
  15. Style
  16. Properties
  17. .version

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.

版本与发布记录

@flourish/popup 共发布 20 个版本,首次发布于 2017/01/10;过去 12 个月发布了 0 个版本。

版本发布日期距今
3.1.1latest2025/01/101.8 年前
3.1.02024/11/112 年前
3.0.02024/07/312 年前
2.1.52020/11/106 年前
2.1.42020/10/026 年前
2.1.32020/07/306 年前

其他发布通道:next → 2.1.0。

关于 @flourish/popup 的常见问题

@flourish/popup 是什么?

Popup UI component

如何安装 @flourish/popup?

在项目目录运行 npm install @flourish/popup,或使用 pnpm add / yarn add / bun add。

@flourish/popup 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/flourish__popup 是否存在。

@flourish/popup 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@flourish/popup 可以商用吗?

@flourish/popup 使用 BSD-3-Clause 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。另外不得用原作者名义为衍生产品背书。以上为概括,不构成法律意见,请以许可原文为准。

@flourish/popup 的下载量有多少?

根据 npm 官方下载统计,@flourish/popup 在 2026/10/15 – 2026/11/13 这 30 天内被下载 5,168 次,日均约 172 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@flourish/popup 还在维护吗?

最新版本 3.1.1 发布于 2025/01/10(1.8 年前);至今共发布 20 个版本,其中过去 12 个月发布了 0 个;首次发布于 2017/01/10。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。