Wraps a child component and displays a message when the child is hovered or
clicked on. Allows to be shown imperatively by calling .show()
or .hide()
on
its reference.
You should have the chayns-components
package installed. If that is not the
case already, run
yarn add chayns-components
or
npm i chayns-components
After the chayns-components
package is installed, you can import the component
and use it with React:
import React from 'react'
import { Tooltip } from 'chayns-components';
// ...
<Tooltip {...} />
The Tooltip
-component takes the following props:
Name | Type | Default | Required |
---|---|---|---|
content | { text: string, headline: string, imageUrl: string, buttonText: string, buttonOnClick: function } | { html: ReactNode } |
✓ | |
children | ReactNode |
||
bindListeners | boolean |
false |
|
position | number |
||
minWidth | number |
100 |
|
maxWidth | number |
250 |
|
removeIcon | boolean |
typeof chayns !== 'undefined' ? chayns.env.isIOS : false |
|
parent | custom |
||
coordinates | { x: number, y: number } |
||
childrenStyle | { [key: string]: string | number } |
||
childrenClassNames | string |
||
preventTriggerStyle | boolean |
false |
|
hideOnChildrenLeave | boolean |
false |
|
removeParentSpace | boolean |
false |
|
isIOS | boolean |
typeof chayns !== 'undefined' ? chayns.env.isIOS : false |
content: { text: string, headline: string, imageUrl: string, buttonText: string, buttonOnClick: function } | { html: ReactNode }
The content of the tooltip. Either specify an object with the accepted
properties or render custom elements by passing an object like so:
{ html: <div /> }
.
children?: ReactNode
The ReactNode
the tooltip should refer to. If the children
node is a
<span>
or <p>
element, it will be decorated with a dotted underline.
bindListeners?: boolean
Wether mouseover
and mouseleave
listeners should be added to the children
elements, which makes the tooltip automatically appear on hover.
position?: number
The position of the tooltip. 0
is top left, 1
is bottom left, 2
is bottom
right and 3
is top right.
minWidth?: number
The minimum width of the tooltip.
maxWidth?: number
The maximum width of the tooltip.
removeIcon?: boolean
Wether the close icon in the top right corner of the tooltip should be shown.
parent?: custom
A DOM node the tooltip should be rendered into.
coordinates?: { x: number, y: number }
An object with coordinates at which the tooltip should point.
childrenStyle?: { [key: string]: string | number }
A React style object that is applied to the children.
childrenClassNames?: string
A classname string that should be applied to the children.
preventTriggerStyle?: boolean
Prevent adding an underline to the children.
hideOnChildrenLeave?: boolean
Hide the tooltip when the cursor leaves the children, even if the cursor is over the bubble.
removeParentSpace?: boolean
Removes any padding of the page from the tooltip position. This is only needed when the parent is padded to the page and is relatively positioned.
isIOS?: boolean
Wether the target device is iOS (only relevant during serverside rendering).