|
| 1 | +import React from 'react'; |
| 2 | +import PropTypes from 'prop-types'; |
| 3 | +import {OverlayTrigger, Tooltip} from 'react-bootstrap'; |
| 4 | + |
| 5 | +/** |
| 6 | + * An alternative way of creating tooltips. |
| 7 | + */ |
| 8 | +const TooltipWrapper = ({ |
| 9 | + children, |
| 10 | + text, |
| 11 | + placement, |
| 12 | + flip, |
| 13 | + delay, |
| 14 | + class_name, |
| 15 | + className, |
| 16 | + setProps, |
| 17 | + loading_state, |
| 18 | + ...otherProps |
| 19 | +}) => { |
| 20 | + return ( |
| 21 | + <OverlayTrigger |
| 22 | + placement={placement} |
| 23 | + flip={flip} |
| 24 | + delay={delay} |
| 25 | + data-dash-is-loading={ |
| 26 | + (loading_state && loading_state.is_loading) || undefined |
| 27 | + } |
| 28 | + overlay={ |
| 29 | + <Tooltip className={class_name || className} {...otherProps}> |
| 30 | + {text} |
| 31 | + </Tooltip> |
| 32 | + } |
| 33 | + > |
| 34 | + <span>{children}</span> |
| 35 | + </OverlayTrigger> |
| 36 | + ); |
| 37 | +}; |
| 38 | + |
| 39 | +TooltipWrapper.defaultProps = { |
| 40 | + delay: {show: 0, hide: 50}, |
| 41 | + placement: 'auto', |
| 42 | + flip: true, |
| 43 | + autohide: true, |
| 44 | + fade: true |
| 45 | +}; |
| 46 | + |
| 47 | +TooltipWrapper.propTypes = { |
| 48 | + /** |
| 49 | + * The ID of this component, used to identify dash components |
| 50 | + * in callbacks. The ID needs to be unique across all of the |
| 51 | + * components in an app. |
| 52 | + */ |
| 53 | + id: PropTypes.string, |
| 54 | + |
| 55 | + /** |
| 56 | + * The children to wrap with the tooltip |
| 57 | + */ |
| 58 | + children: PropTypes.node, |
| 59 | + |
| 60 | + /** |
| 61 | + * The text to display inside the tooltip. |
| 62 | + */ |
| 63 | + text: PropTypes.string, |
| 64 | + |
| 65 | + style: PropTypes.object, |
| 66 | + |
| 67 | + class_name: PropTypes.string, |
| 68 | + |
| 69 | + className: PropTypes.string, |
| 70 | + |
| 71 | + /** |
| 72 | + * A unique identifier for the component, used to improve |
| 73 | + * performance by React.js while rendering components |
| 74 | + * See https://reactjs.org/docs/lists-and-keys.html for more info |
| 75 | + */ |
| 76 | + key: PropTypes.string, |
| 77 | + |
| 78 | + /** |
| 79 | + * How to place the tooltip. |
| 80 | + */ |
| 81 | + placement: PropTypes.oneOf([ |
| 82 | + 'auto', |
| 83 | + 'auto-start', |
| 84 | + 'auto-end', |
| 85 | + 'top', |
| 86 | + 'top-start', |
| 87 | + 'top-end', |
| 88 | + 'right', |
| 89 | + 'right-start', |
| 90 | + 'right-end', |
| 91 | + 'bottom', |
| 92 | + 'bottom-start', |
| 93 | + 'bottom-end', |
| 94 | + 'left', |
| 95 | + 'left-start', |
| 96 | + 'left-end' |
| 97 | + ]), |
| 98 | + |
| 99 | + /** |
| 100 | + * Whether to flip the direction of the popover if too close to the container |
| 101 | + * edge, default True. |
| 102 | + */ |
| 103 | + flip: PropTypes.bool, |
| 104 | + |
| 105 | + /** |
| 106 | + * Control the delay of hide and show events. |
| 107 | + */ |
| 108 | + delay: PropTypes.shape({show: PropTypes.number, hide: PropTypes.number}), |
| 109 | + |
| 110 | + /** |
| 111 | + * Space separated list of triggers (e.g. "click hover focus legacy"). These |
| 112 | + * specify ways in which the target component can toggle the tooltip. If |
| 113 | + * omitted you must toggle the tooltip yourself using callbacks. Options |
| 114 | + * are: |
| 115 | + * - "click": toggles the popover when the target is clicked. |
| 116 | + * - "hover": toggles the popover when the target is hovered over with the |
| 117 | + * cursor. |
| 118 | + * - "focus": toggles the popover when the target receives focus |
| 119 | + * - "legacy": toggles the popover when the target is clicked, but will also |
| 120 | + * dismiss the popover when the user clicks outside of the popover. |
| 121 | + * |
| 122 | + * Default is "hover focus" |
| 123 | + */ |
| 124 | + trigger: PropTypes.string |
| 125 | +}; |
| 126 | + |
| 127 | +export default TooltipWrapper; |
0 commit comments