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 🙏

© 2026 – Pkg Stats / Ryan Hefner

smart-overlay

v1.0.2

Published

Framework-agnostic imperative overlay factory for React. Bring your own container (popup / modal / drawer / toast / dialog).

Readme

smart-overlay

npm version bundle size types license

English

安装

npm i smart-overlay

示例

import createOverlay from 'smart-overlay'
import { Popup } from 'your-ui-kit'

export const { OverlayProvider, useOverlay } = createOverlay({
  component: Popup,
  display: 'show',
  className: 'app-overlay',
  duration: 300,
  defaultOptions: { position: 'bottom', round: true }
})

export function App() {
  return (
    <OverlayProvider>
      <YourRoutes />
    </OverlayProvider>
  )
}

function ProductPage() {
  const overlay = useOverlay()

  const openCart = () => {
    const close = overlay.show({
      children: <Cart />,
      onClose: () => console.log('购物车已关闭')
    })
    // 需要时调用 close() 关闭当前这一个实例
  }

  return <button onClick={openCart}>打开</button>
}

每次 show() 都会挂载一个新实例;无参 close() 关闭最近打开的一个(LIFO);需要关闭指定实例,使用 show() 返回的函数。

参数

createOverlay(options)

| 字段 | 类型 | 默认 | | ---------------- | ---------------------------- | -------- | | component | ComponentType<TProps> | — | | display | 'show' \| 'visible' | 'show' | | defaultOptions | OverlayShowOptions<TProps> | — | | className | string | — | | duration | number | 300 |

duration 为关闭后延迟卸载的毫秒数,让容器有机会播放关闭过渡;设为 0 立即卸载。

返回 { OverlayProvider, useOverlay }

useOverlay()

必须在 <OverlayProvider /> 内部使用,返回:

| 字段 | 类型 | 说明 | | ------- | ------------------------- | --------------------------------------------- | | show | (options) => () => void | 挂载一个新实例,返回绑定到该实例的关闭函数 | | close | () => void | 关闭最近打开的一个实例(LIFO) |

show(options)

除容器自身的 props 原样透传,以下两个字段会被特殊处理:

| 字段 | 说明 | | ---------------- | -------------------------------------------------------------------------------------------------- | | onClose | 该实例被关闭时触发一次(用户交互、close()show() 返回的函数,任一路径触发后只会调用一次) | | onClickOverlay | 原样转发给容器;是否同时关闭浮层由容器自身的配置(如 closeOnClickOverlay)决定 |

容器协议

interface OverlayBaseProps {
  show?: boolean
  visible?: boolean
  onClose?: () => void
  onClickOverlay?: () => void
  className?: string
}

License

MIT © iamgx

⚠️ 谨慎使用:仅针对内部指定业务场景。