0.2.7 • Published 3 years ago

@vtex-components/tooltip v0.2.7

Weekly downloads
50
License
-
Repository
github
Last release
3 years ago

VTEX Components Tooltip

Elementary tooltip component that can be reused by all VTEX Styleguides. You can use reakit full features (except the 'as' prop) and theme-ui's sx. It renders a tooltip element by default.

This is a styled base component, so any system can theme it. To customize this component, you just need to add the tooltip variant in your theme (check the theming section).

Install

yarn add @vtex-components/tooltip

or

npm install @vtex-components/tooltip

Usage

import Tooltip from '@vtex-components/tooltip'

function UseCase() {
  return <Tooltip label="Tooltip text here"><button>Children</button></Tooltip>
}

With arrow

If you want your tooltip to have an arrow, you can pass it to the tooltip as a prop. On the following example, it's shown how you can use the Reakit Reakit TooltipArrow with the tooltip, but you can design any arrow you want. The tooltip state is passed to the arrow, so you can access the placement and visibility of the tooltip.

import Tooltip from '@vtex-components/tooltip'
import { TooltipArrow } from 'reakit'

function Arrow(props) {
  return <TooltipArrow {...props} />;
}

function TooltipExample() {
  return(
    <Tooltip label="Tooltip label" placement="top" arrow={<Arrow />}>
      <button>Children component</button>
    </Tooltip>
  )
}

🎨 Theming

ModifierDescription
stylesbase styles

Example

You can define the theme with:

const theme = {
  tooltip: {
    backgroundColor: 'black',
    color: 'white',
    paddingY: 1,
    paddingX: 2,
  },
}

Props

proptypedescriptiondefaultrequired
childrenReactNodeElement that triggers the tooltip-✔️
labelStringText shown in the tooltip-✔️
arrowReactNodeArrow element, if you want your tooltip to have an arrow-🚫
placementPlacementThe placement of the tooltip relative to its childrentop🚫
visiblebooleanWhether the tooltip is visible or not-🚫
sxSxStylePropTheme-ui style prop-🚫
0.2.7

3 years ago

0.2.6

3 years ago

0.2.5

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.2.1

4 years ago

0.2.1-alpha.1

4 years ago

0.2.1-alpha.0

4 years ago

0.2.0

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago