diff --git a/snippets/Tooltip.md b/snippets/Tooltip.md index 24dcac591..22cc792d1 100644 --- a/snippets/Tooltip.md +++ b/snippets/Tooltip.md @@ -24,6 +24,7 @@ class Tooltip extends React.Component { }; this.style = { tooltip: { + position: 'relative', backgroundColor: "rgba(0,0,0,0.7)", color: "white", visibility: "hidden", @@ -31,9 +32,17 @@ class Tooltip extends React.Component { padding: 5, borderRadius: 5 }, + tooltipArrow: { + position: 'absolute', + top: '100%', + left: '50%', + borderWidth: 5, + borderStyle: 'solid', + borderColor: "rgba(0,0,0,0.7) transparent transparent", + }, visible: { visibility: "visible" - } + }, }; this.showTooltip = this.toggleTooltip.bind(this, true); this.hideTooltip = this.toggleTooltip.bind(this, false); @@ -46,25 +55,29 @@ class Tooltip extends React.Component { }; render() { - const { children, ...rest } = this.props; + const { children, text, ...rest } = this.props; const { show } = this.state; - const { visible, tooltip } = this.style; + const { visible, tooltip, tooltipArrow } = this.style; const showTooltip = show ? visible : {}; return (
- This is a simple tooltip + {text} + +
+
+ {children}
- {React.cloneElement(children, { - ...rest, - onMouseEnter: this.showTooltip, - onMouseLeave: this.hideTooltip - })}
); } } ``` ```jsx - ReactDOM.render(, document.getElementById('root')); + ReactDOM.render( + + + , + document.getElementById('root') + ); ```