@d8660091/react-popper

中文文档
1.0.4发布于 2018/06/25MITESM + CJS近 30 天下载 2004

A React component for displaying popper based on popper.js

原始使用文档

React Popper

CircleCI npm version dependencies Status

React popper.js component.

Features:

  • Easy to use, check the usage below.
  • React to props change, re-render the popper when options change.
  • Nestable, for example, there can be two popup windows respond to mouseenter and click events of a button separately.

Try it

Usage

Install with yarn:

yarn add @d8660091/react-popper

Or npm:

npm install @d8660091/react-popper -P

Import in your source file:

import Popper from '@d8660091/react-popper'

// A simple popper
<Popper
  options={{ 
    placement: 'bottom'
  }}
  renderRef={({ setReference, toggle }) => (
    <span ref={setReference} onClick={toggle}>
      Popover Trigger
    </span>
  )}>
  <div>Popper content</div>
</Popper>

// A nested popper
<Popper
  options={{
    placement: 'right',
  }}
  renderRef={({ setReference, open, close, isOpened }) => (
    <Popper
      options={{
        placement: 'bottom',
      }}
      renderRef={({
        setReference: setInnerReference,
        toggle: innerToggle,
        isOpened: isInnerOpened
      }) => (
        <button
          ref={el => {
            setReference(el)
            setInnerReference(el)
          }}
          onClick={() => {
            close()
            innerToggle()
          }}
          onMouseEnter={() => {
            !isInnerOpened && open()
          }}
          onMouseLeave={() => {
            close()
          }}>
          A button which triggers two popper, one on hover, one on click
        </button>
      )}>
      <div>
        On click inner popper.
      </div>
    </Popper>
  )}>
  <div>
    On hover outer popper content.
  </div>
</Popper>

Types (index.d.ts):

declare module '@d8660091/react-popper' {
  import { PopperOptions } from 'popper.js'
  import * as React from 'react'

  interface RenderProps extends PopperProps {
    setReference: React.Ref<HTMLElement>
    setPop: React.Ref<HTMLElement>
    isOpened: boolean
    open: () => void
    close: () => void
    toggle: () => void
  }

  type PopperProps = {
    renderRef: (props: RenderProps) => React.ReactNode
    renderPop?: (props: RenderProps) => React.ReactNode
    options?: PopperOptions
    children?: React.ReactNode
    canClickOutside?: Boolean // default: false
    style?: Object
    className?: string
    defaultIsOpened?: Boolean // default: false
  }

  const Popper: React.ComponentClass<PopperProps>

  export default Popper
}
  • options: popper.js options.
  • renderRef: the function to render reference, i.e, the element used to position the popper.
  • children: content inside the popper.
  • canClickOutside: if true, popper will not hide itself when users click outside.
  • style and className: goes to the popper instead of the reference.
  • renderPop: if this function is set, the children, style and className will be ignored and the popper will be rendered using this function.
  • defaultIsOpened: whether open popper when it mounts

ClickableArea

You can click ClickableArea without closing popper, which is useful when you have an interactable Popper rendered by another parent Popper.

import { ClickableArea } from '@d8660091/react-popper'

<ClickableArea>
  clickable text
</ClickableArea>

Storybook - More usages, including specifying options, styles and nesting. You can also play with the components by live editing the options and placements.

版本与发布记录

@d8660091/react-popper 共发布 31 个版本,首次发布于 2018/01/27;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.4latest2018/06/258 年前
1.0.32018/06/228 年前
1.0.22018/06/228 年前
1.0.12018/06/218 年前
1.0.02018/06/218 年前
0.7.62018/06/218 年前

关于 @d8660091/react-popper 的常见问题

@d8660091/react-popper 是什么?

A React component for displaying popper based on popper.js

如何安装 @d8660091/react-popper?

在项目目录运行 npm install @d8660091/react-popper,或使用 pnpm add / yarn add / bun add。

@d8660091/react-popper 支持 TypeScript 吗?

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

@d8660091/react-popper 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@d8660091/react-popper 可以商用吗?

@d8660091/react-popper 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@d8660091/react-popper 的下载量有多少?

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

@d8660091/react-popper 还在维护吗?

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