Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] TooltipWrapper component #1007

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 127 additions & 0 deletions src/components/tooltip/TooltipWrapper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import React from 'react';
import PropTypes from 'prop-types';
import {OverlayTrigger, Tooltip} from 'react-bootstrap';

/**
* An alternative way of creating tooltips.
*/
const TooltipWrapper = ({
children,
text,
placement,
flip,
delay,
class_name,
className,
setProps,
loading_state,
...otherProps
}) => {
return (
<OverlayTrigger
placement={placement}
flip={flip}
delay={delay}
data-dash-is-loading={
(loading_state && loading_state.is_loading) || undefined
}
overlay={
<Tooltip className={class_name || className} {...otherProps}>
{text}
</Tooltip>
}
>
<span>{children}</span>
</OverlayTrigger>
);
};

TooltipWrapper.defaultProps = {
delay: {show: 0, hide: 50},
placement: 'auto',
flip: true,
autohide: true,
fade: true
};

TooltipWrapper.propTypes = {
/**
* The ID of this component, used to identify dash components
* in callbacks. The ID needs to be unique across all of the
* components in an app.
*/
id: PropTypes.string,

/**
* The children to wrap with the tooltip
*/
children: PropTypes.node,

/**
* The text to display inside the tooltip.
*/
text: PropTypes.string,

style: PropTypes.object,

class_name: PropTypes.string,

className: PropTypes.string,

/**
* A unique identifier for the component, used to improve
* performance by React.js while rendering components
* See https://reactjs.org/docs/lists-and-keys.html for more info
*/
key: PropTypes.string,

/**
* How to place the tooltip.
*/
placement: PropTypes.oneOf([
'auto',
'auto-start',
'auto-end',
'top',
'top-start',
'top-end',
'right',
'right-start',
'right-end',
'bottom',
'bottom-start',
'bottom-end',
'left',
'left-start',
'left-end'
]),

/**
* Whether to flip the direction of the popover if too close to the container
* edge, default True.
*/
flip: PropTypes.bool,

/**
* Control the delay of hide and show events.
*/
delay: PropTypes.shape({show: PropTypes.number, hide: PropTypes.number}),

/**
* Space separated list of triggers (e.g. "click hover focus legacy"). These
* specify ways in which the target component can toggle the tooltip. If
* omitted you must toggle the tooltip yourself using callbacks. Options
* are:
* - "click": toggles the popover when the target is clicked.
* - "hover": toggles the popover when the target is hovered over with the
* cursor.
* - "focus": toggles the popover when the target receives focus
* - "legacy": toggles the popover when the target is clicked, but will also
* dismiss the popover when the user clicks outside of the popover.
*
* Default is "hover focus"
*/
trigger: PropTypes.string
};

export default TooltipWrapper;
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,4 @@ export {default as Table} from './components/table/Table';
export {default as Textarea} from './components/input/Textarea';
export {default as Toast} from './components/toast/Toast';
export {default as Tooltip} from './components/tooltip/Tooltip';
export {default as TooltipWrapper} from './components/tooltip/TooltipWrapper';
Loading