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

@ybais/center-toast

v1.0.1

Published

Centered user-facing toast for YBAIS WebView apps

Readme

@ybais/center-toast — 面向用户的错误轻提示

自研居中 Toast,API 与交互对齐 antd-mobile Toast:屏幕正中(或 top/bottom)、黑底半透明、白字,命令式调用,不依赖 sonner。

Install

pnpm add @ybais/center-toast react react-dom
# npm i @ybais/center-toast react react-dom
# yarn add @ybais/center-toast react react-dom

Requirements

| 依赖 | 类型 | 说明 | |------|------|------| | react | peer | — | | react-dom | peer | — |

必须在应用入口引入样式:

import "@ybais/center-toast/style.css";

无其它 @ybais/* 硬依赖。常与 @ybais/error-guard 分工使用(见使用边界)。

Get started

import "@ybais/center-toast/style.css";
import { showCenterToast } from "@ybais/center-toast";

// 仅面向用户的失败提示
showCenterToast("提交失败,请稍后重试");
showCenterToast.fail("支付未完成");

const handler = showCenterToast({
  content: "处理中…",
  duration: 0,
  icon: "loading",
});
handler.close();

使用边界(硬约定)

| 场景 | 用什么 | |------|--------| | 面向用户的错误文案(提交失败、支付失败、需用户感知的业务失败) | showCenterToast / .fail | | 可恢复系统/接口错误、reportError / showApiError | sonner(@ybais/error-guard) | | Bridge 不可用、开发调试、浏览器预览提示 | reportDebug(@ybais/error-guard) | | 成功态、已复制、加载中、随手提示 | 禁止 showCenterToast;改 sonner / 业务 UI / 不加提示 |

业务代码不得把本模块当通用 toast。

API

| 方法 | 说明 | |------|------| | showCenterToast(content \| options) | 展示提示,返回 { close } | | showCenterToast.fail(content, options?) | 失败图标(用户向错误) | | showCenterToast.success / .loading | 保留 API 兼容;新代码勿用于非错误场景 | | showCenterToast.clear() | 关闭当前提示 | | showCenterToast.config(partial) | 全局默认 duration / position / maskClickable |

ShowCenterToastOptions

| 字段 | 类型 | 默认 | 说明 | |------|------|------|------| | content | ReactNode | — | 文案或自定义内容 | | duration | number | 2000(loading 为 0) | 毫秒;0 不自动关闭 | | icon | 'success' \| 'fail' \| 'loading' \| ReactNode | — | 图标 | | position | 'top' \| 'center' \| 'bottom' | 'center' | 垂直位置 | | maskClickable | boolean | true | false 时阻止背景点击 | | afterClose | () => void | — | 退场动画结束后回调 | | getContainer | () => HTMLElement | document.body | 挂载容器 |

边界行为

  • 空内容:'' / 纯空白 / null / undefined / false 不展示,返回空操作的 { close }。
  • 重复调用:新 Toast 立即替换旧 Toast,旧 Toast 的 afterClose 不会触发。
  • 幂等 close:对已关闭或已被替换的实例调用 close() 无副作用。
  • duration: 0:不启动自动关闭定时器,需 handler.close() 或 showCenterToast.clear()。
  • SSR / 无 document:安全降级为 no-op。
  • WebView:样式避免 inset / gap / overflow-wrap: anywhere;支持 prefers-reduced-motion 关闭动画。