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

@commercetools-uikit/tooltip

v20.4.0

Published

Tooltips display informative text when users hover over or focus on an element.

Downloads

23,092

Readme

Tooltip

Description

Tooltips display informative text when users hover over or focus on an element.

Installation

yarn add @commercetools-uikit/tooltip
npm --save install @commercetools-uikit/tooltip

Additionally install the peer dependencies (if not present)

yarn add react
npm --save install react

Usage

import { forwardRef } from 'react';
import PropTypes from 'prop-types';
import ReactDOM from 'react-dom';
import styled from '@emotion/styled';
import Tooltip from '@commercetools-uikit/tooltip';

/* 1. Standard example */
const ExampleStandard = () => (
  <Tooltip
    placement="left"
    title="If you buy a pizza, you will also get a free ice cream :)"
  >
    <button onClick={() => {}}>Submit</button>
  </Tooltip>
);

/**
 * 2. Working with disabled child elements
 *
 * When you use a tooltip with a disabled element, you should define the
 * style `pointer-events: none` to the disabled element to stop it from capturing events.
 * The Button components from UIKit already support this functionality.
 */
const ExampleWithDisabledElements = () => (
  <Tooltip
    placement="left"
    title="You do not have permission to delete the database"
  >
    <button disabled onClick={() => {}} style={{ pointerEvents: 'none' }}>
      Delete production database
    </button>
  </Tooltip>
);

/**
 * 3. Customizing the wrapper
 *
 * The tooltip applies event listeners (`onMouseOver`, `onMouseLeave`, `onFocus`,
 * and `onBlur`) to a wrapping `div` component around the children element.
 * By default, this wrapper is displayed with style `inline-block`.
 * If you want to customize this behaviour, then you can pass in a custom element.
 * Be sure to use `React.forwardRef`, as we need the to pass the ref to the wrapper.
 */
const Wrapper = forwardRef((props, ref) => (
  <div ref={ref} style={{ display: 'block' }} {...props}>
    {props.children}
  </div>
));
Wrapper.propTypes = {
  children: PropTypes.node.isRequired,
};
const FullWidthButton = styled.button`
  display: block;
  width: 100%;
`;
const ExampleWithCustomWrapper = () => (
  <Tooltip title="Delete" components={{ WrapperComponent: Wrapper }}>
    <FullWidthButton>Submit</FullWidthButton>
  </Tooltip>
);

/**
 * 4. Customizing the tooltip body
 *
 * You can customize the look and feel of the tooltip body by passing in a custom `BodyComponent`.
 */
const Body = styled.div`
  color: red;
`;
const ExampleWithCustomBody = () => (
  <Tooltip title="Delete" components={{ BodyComponent: Body }}>
    <button>Submit</button>
  </Tooltip>
);

/**
 * 5. Customizing where the portal is rendered
 *
 * When you are dealing with virtualized components, it can be useful to render
 * the tooltip into another part of the document.
 * You can define a `TooltipWrapperComponent` to do this.
 */
const Portal = (props) => ReactDOM.createPortal(props.children, document.body);
const ExampleWithCustomPortal = () => (
  <Tooltip title="Delete" components={{ TooltipWrapperComponent: Portal }}>
    <button>Submit</button>
  </Tooltip>
);

/**
 * 6. Conditionally displaying tooltips
 *
 * There may be cases when you only want to enable the display of a tooltip under
 * a certain condition. In these cases, you may want to use the `off` prop.
 * In the following example, the tooltip text only appears on hover when the button is disabled.
 */
const ExampleWithConditionals = (props) => (
  <Tooltip
    off={props.isDisabled}
    title="You do not have permission to perform this action"
  >
    <button disabled={props.isDisabled}>Submit</button>
  </Tooltip>
);
ExampleWithConditionals.propTypes = {
  isDisabled: PropTypes.bool,
};

/**
 * 7. Fine-tuning underlying Popper.js behavior
 *
 * This component uses [Popper.js](https://popper.js.org/) under the hood.
 * Popper provides a way to adjust how tooltip element should behave, by providing
 * a [set of `modifiers`](https://popper.js.org/popper-documentation.html#modifiers).
 * For instance, forcing tooltip to stay in the original placement and not to try
 * flipping when it's getting out of boundaries, can be implemented as following:
 */
const ExampleWithCustomPopperBehavior = (props) => (
  <Tooltip
    placement="left"
    title="I will always be on the left side"
    modifiers={{
      preventOverflow: {
        enabled: false,
      },
      flip: {
        enabled: false,
      },
    }}
  >
    <button disabled={props.isDisabled}>Submit</button>
  </Tooltip>
);
ExampleWithCustomPopperBehavior.propTypes = {
  isDisabled: PropTypes.bool,
};

export {
  ExampleStandard,
  ExampleWithDisabledElements,
  ExampleWithCustomWrapper,
  ExampleWithCustomBody,
  ExampleWithCustomPortal,
  ExampleWithConditionals,
  ExampleWithCustomPopperBehavior,
};

Properties

| Props | Type | Required | Default | Description | | ---------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------: | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | children | ReactElement | ✅ | | | | showAfter | number | | 300 | Delay (in milliseconds) between the start of the user interaction, and showing the tooltip. | | closeAfter | number | | 200 | Delay (in milliseconds) between the end of the user interaction, and the closing of the tooltip. | | styles | Record | | | Custom css-in-js object styles for the tooltip body. | | off | boolean | | false | Determines if the tooltip should not appear. | | id | string | | | An identifier for the tooltip, used for aria-describedby. | | onClose | FunctionSee signature. | | | A callback function, called when the tooltip is closing. | | onOpen | FunctionSee signature. | | | A callback function, called when the tooltip is opening. | | isOpen | boolean | | | | | placement | unionPossible values:, 'top', 'top-start', 'top-end', 'right', 'right-start', 'right-end', 'bottom', 'bottom-start', 'bottom-end', 'left', 'left-start', 'left-end' | | 'top' | How the tooltip is positioned relative to the child element. | | title | string | ✅ | | The message to show in the tooltip. | | modifiers | Modifiers | | | Provides a way to fine-tune an appearance of underlying Popper tooltip element. For more information, please check Popper.js documentation. | | components | ObjectSee signature. | | | Customize the appearance of certain elements of the tooltip. | | horizontalConstraint | unionPossible values:, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto' | | 'scale' | Horizontal size limit of the tooltip. |

Signatures

Signature onClose

(e?: ChangeEvent | FocusEvent) => void

Signature onOpen

(e?: ChangeEvent | FocusEvent) => void

Signature components

{
  /**
   * The component rendered as the tooltip body.
   */
  BodyComponent?: ComponentType;
  /**
   * Where the tooltip should be rendered. This can be useful to render the tooltip into another part of the document, using React portal.
   */
  TooltipWrapperComponent?: ComponentType;
  /**
   * A custom component wrapper for the tooltip.
   */
  WrapperComponent?: ComponentType;
}