@financial-times/o3-tooltip

中文文档
3.2.2发布于 2026/03/04MITTypeScriptESM + CJS近 30 天下载 2573

Provides a viewport-aware tooltip for annotating or or highlighting other aspects of a product's UI

原始使用文档
文档目录10 节
  1. Markup
  2. JavaScript
  3. css
  4. JSX
  5. TooltipOnboarding
  6. TooltipToggle
  7. Hooks
  8. Migration Guide
  9. Contact
  10. Licence

o3-tooltipMIT licensed

o3-tooltip is hosting two components: o3-tooltip-onboarding and o3-tooltip-toggle. Onboarding Tooltips help for a smoother introduction to new features or functionality. Toggletips are compact pieces of information designed to offer additional insights when needed. See our design guidelines for usage information and brand support.

Markup

We provide custom elements <o3-tooltip-onboarding> and <o3-tooltip-toggle>. React users may include these using our JSX template.

<o3-tooltip-onboarding> is used to display a tooltip on a HTML target element that can have an aria-describedby attribute. It is used to provide additional information about the target element and is shown immediately once the page is loaded. It can be only closed by clicking the close button.

<o3-tooltip-toggle> does not have a close button and is used with an information icon. It can be triggered by clicking on the information icon and will be removed from the DOM if the user clicks outside the tooltip, presses ESC, or clicks the info icon again.

Below are examples of how to use <o3-tooltip-onboarding> and <o3-tooltip-toggle> custom elements:

<!-- <o3-tooltip-onboarding> -->
<div data-o3-brand="[your brand]">
    <button
        id="demo-o3-tooltip-id"
        class="o3-button o3-button--secondary o3-button--big demo-tooltip-target"
        aria-describedby="demo-o3-tooltip-content"
    >
        Share
    </button>
    <o3-tooltip-onboarding
        role="tooltip"
        placement="top"
        target-id="demo-o3-tooltip-id"
        class="o3-tooltip"
        content="Tool tip content that is quite long, Tool tip content that is quite long, Tool tip content that is quite long"
        title="Title"
        content-id="demo-o3-tooltip-content"
    >
    </o3-tooltip-onboarding>
</div>

content-id is used to link the tooltip to the target element. It is used to provide additional information about the target element.

<!-- <o3-tooltip-toggle> -->
<div data-o3-brand="[your brand]">
    <o3-tooltip-toggle
        placement="bottom"
        class="o3-tooltip"
        content="click the button to see the tooltip"
        title="Title"
        info-label="more information"
    >
    </o3-tooltip-toggle>
</div>

info-label attribute is used to provide a label for info icon to have better screen reader experience. By default, it is set to "more information".

JavaScript

No code will run automatically unless you import the client side JavaScript. To import the JavaScript, you can use the following code:

import '@financial-times/o3-tooltip';

css

To style o3-tooltip import brand specific css, this varies depending on your project. For example:

@import '@financial-times/o3-tooltip/css/[your brand].css';

JSX

o3-tooltip exports two JSX templates, TooltipOnboarding and TooltipToggle for each tooltip component. JSX templates are exported as cjs (common JS) and esm (ECMAScript) modules, so depending on your system configuration, you may need to import the correct module type. TSX templates can help to avoid copy-pasting html. For example:

import {
    TooltipOnboarding,
    TooltipToggle,
} from '@financial-times/o3-tooltip/cjs';

import '@financial-times/o3-tooltip'; // import the JavaScript needed for custom elements on client side

import '@financial-times/o3-tooltip/css/[your brand].css'; // tooltip styling

<div className="o3-brand-[your brand]">
    <button id="target" aria-describedby="contentId">
        Target element
    </button>
    <TooltipOnboarding {...props} />;
    <TooltipToggle {...props} />
</div>;

TooltipOnboarding

The TooltipOnboarding JSX element accepts the following props:

type Placement =
    | 'top'
    | 'bottom'
    | 'left'
    | 'right'
    | 'top-start'
    | 'top-end'
    | 'bottom-start'
    | 'bottom-end'
    | 'left-start'
    | 'left-end'
    | 'right-start'
    | 'right-end';
Proptyperequireddefaultdescription
targetIdstringtrue-Target element to attach tooltip to
contentstringtrue-Content of the tooltip
titlestringfalse-Title of the tooltip
contentIdstringtrue-id for aria-describedby element
placementPlacementfalse'top'Placement of the tooltip

TooltipToggle

The ToggleTooltip JSX element accepts the following props:

type Placement = 'top' | 'bottom' | 'left' | 'right';
Proptyperequireddefaultdescription
contentstringtrue-Content of the tooltip
titlestringfalse-Title of the tooltip
placementPlacementfalse'top'Placement of the tooltip
infoLabelstringfalsemore informationLabel for screen readers

Hooks

o3-tooltip provides an onClose hook allowing you to perform actions before the tooltip is closed.

TSX

import {TooltipOnboarding} from "@financial-times/o3-tooltip";

<TooltipOnboarding id='my-tooltip' onClose={() => {/* behaviour to execute when onClose is called */}} />

JS

Make sure your Tooltip exists in your HTML using our example above.

const tooltip = document.querySelector('#my-tooltip');

tooltip.onClose = () => {/* custom onClose code goes here */}

Migration Guide

StateMajor VersionLast Minor ReleaseMigration guide
✨ active3N/Amigrate to v3
╳ deprecated22.3-
╳ deprecated1-N/A

Contact

If you have any questions or comments about this component, or need help using it, please either raise an issue, visit #origami-support or email Origami Support.


Licence

This software is published by the Financial Times under the MIT licence.

版本与发布记录

@financial-times/o3-tooltip 共发布 23 个版本,首次发布于 2024/03/07;过去 12 个月发布了 3 个版本。

版本发布日期距今
3.2.2latest2026/03/048 个月前
3.2.12026/01/219 个月前
3.2.02026/01/1210 个月前
3.1.12025/10/221.1 年前
3.1.02025/09/241.1 年前
3.0.32025/09/111.2 年前

关于 @financial-times/o3-tooltip 的常见问题

@financial-times/o3-tooltip 是什么?

Provides a viewport-aware tooltip for annotating or or highlighting other aspects of a product's UI

如何安装 @financial-times/o3-tooltip?

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

@financial-times/o3-tooltip 支持 TypeScript 吗?

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

@financial-times/o3-tooltip 支持 ESM 还是 CommonJS?

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

@financial-times/o3-tooltip 可以商用吗?

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

@financial-times/o3-tooltip 的下载量有多少?

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

@financial-times/o3-tooltip 还在维护吗?

最新版本 3.2.2 发布于 2026/03/04(8 个月前);至今共发布 23 个版本,其中过去 12 个月发布了 3 个;首次发布于 2024/03/07。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。