@financial-times/o3-tooltip
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

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 '@finacial-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';
Prop type required default description
targetId string true - Target element to attach tooltip to
content string true - Content of the tooltip
title string false - Title of the tooltip
contentId string true - id for aria-describedby element
placement Placement false 'top' Placement of the tooltip

TooltipToggle

The ToggleTooltip JSX element accepts the following props:

type Placement = 'top' | 'bottom' | 'left' | 'right';
Prop type required default description
content string true - Content of the tooltip
title string false - Title of the tooltip
placement Placement false 'top' Placement of the tooltip
infoLabel string false more information Label for screen readers

Migration Guide

State Major Version Last Minor Release Migration guide
✨ active 0 0.0.1 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.

Package Sidebar

Install

npm i @financial-times/o3-tooltip

Weekly Downloads

677

Version

2.0.0

License

MIT

Unpacked Size

41 kB

Total Files

25

Last publish

Collaborators

  • robgodfrey
  • robertboulton
  • seraph2000
  • hamza.samih
  • notlee
  • emmalewis
  • aendra
  • the-ft
  • rowanmanning
  • chee
  • alexwilson