@felte/reporter-tippy

中文文档
1.1.10发布于 2024/10/30MITTypeScriptESM + CJS近 30 天下载 2719

[DEPRECATED] An error reporter for Felte using Tippy.js

原始使用文档
文档目录7 节
  1. Installation
  2. Usage
  3. Options
  4. Warnings
  5. Opting out
  6. Custom controls
  7. Custom positioning

@felte/reporter-tippy

Tests Bundle size NPM Version codecov

A Felte reporter that uses Tippy.js to display your error messages.

[!WARNING] Tippy.js has not been maintained for the last few years (and floating-ui seems to be its replacement) Therefore I would not recommend using this package anymore and should be considered deprecated.

Installation

npm install --save @felte/reporter-tippy tippy.js

# Or, if you use yarn

yarn add @felte/reporter-tippy tippy.js

Usage

The default export is a function that returns the reporter. Add it to the extend property of Felte's createForm configuration object.

import reporter from '@felte/reporter-tippy';

const { form } = createForm({
  // ...
  extend: reporter(),
  // ...
});

You might want to add Tippy's styles somewhere in your repo as well

import 'tippy.js/dist/tippy.css';

Options

You can pass options to Tippy when calling the reporter like so:

reporter({
  tippyProps: {
    /* tippy options */
  },
});

You can also pass a setContent function that will receive the current validation messages and the field path. Here you can modify your validation messages, which can come in useful if you want to display HTML content inside of Tippy. The messages argument will either be an array of strings (it can be more than one message depending on your validation strategy) or undefined. The path argument will be a string with the full path of your field (e.g. email, account.email, etc).

reporter({
  setContent: (messages, path) => {
    return messages?.map((message) => `<p>${message}</p>`);
  },
  tippyProps: {
    allowHTML: true,
  },
});

You may also pass options to a specific Tippy instance using the tippyPropsMap property. It expects an object with the same shape as your data:

reporter({
  tippyPropsMap: {
    account: {
      email: {
        allowHTML: true,
        /* other tippy props */
      },
    },
  },
});

Warnings

This reporter can also display your warning messages. In order to do so you'll need to pass the property level to your reporter with a value of warning.

reporter({
  level: 'warning',
});

In order to avoid cluttering your UI it'd be recommended to use Tippy to report errors OR warnings, not both.

Opting out

If this package does not satisfy your needs for all cases, do know we are working on improving this, but you may as well opt-out of reporting a specific field's error by adding data-felte-reporter-tippy-ignore as an attribute to your input.

<input name="email" data-felte-reporter-tippy-ignore />

Custom controls

If you're using a custom control not managed by Felte, you can still make use of @felte/reporter-tippy. For this you can use two data attributes:

  • data-felte-reporter-tippy-for: tells this package to use the element with this attribute as a control for the specified field.
  • data-felte-reporter-tippy-trigger-for: tells this package to use the element(s) with this attribute as a trigger to show Tippy for the specified field.

The custom control will always be a trigger for tippy, the second argument is useful if you want to trigger Tippy with another element such as a label to mimic this package's default behaviour.

<span id="email-label" data-felte-reporter-tippy-trigger-for="email"
  >Email:</span
>
<div
  contenteditable
  data-felte-reporter-tippy-for="email"
  aria-labelledby="email-label"
  tabindex="0"
/>

Custom positioning

If you need to show your Tippy in a different position, you may use the data-felte-reporter-tippy-position-for attribute. This would be useful if you're using a custom control that does use a valid HTML input behind the scenes but hides it:

<!-- Tippy will be shown on top of this div -->
<div data-felte-reporter-tippy-position-for="email" />
<!-- Not on top of this input -->
<input name="email" type="email" />

版本与发布记录

@felte/reporter-tippy 共发布 81 个版本,首次发布于 2021/02/10;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.1.10latest2024/10/302 年前
1.1.92023/08/303 年前
1.1.82023/06/173 年前
1.1.72023/06/153 年前
1.1.52023/01/123 年前
1.1.42022/09/274 年前

其他发布通道:next → 1.0.0-next.23。

关于 @felte/reporter-tippy 的常见问题

@felte/reporter-tippy 是什么?

[DEPRECATED] An error reporter for Felte using Tippy.js

如何安装 @felte/reporter-tippy?

在项目目录运行 npm install @felte/reporter-tippy,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:tippy.js(^6.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@felte/reporter-tippy 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@felte/reporter-tippy 支持 ESM 还是 CommonJS?

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

@felte/reporter-tippy 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js ^12.20.0 || ^14.13.1 || >=16.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@felte/reporter-tippy 可以商用吗?

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

@felte/reporter-tippy 的下载量有多少?

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

@felte/reporter-tippy 还在维护吗?

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