Fix tooltips position and proper growing to size

This commit is contained in:
Melvin Valster
2019-07-29 22:12:32 +02:00
parent c176d13a7e
commit 4478a43de7
6 changed files with 20 additions and 15 deletions
-8
View File
@@ -76,11 +76,3 @@ footer {
text-align: center; text-align: center;
animation: fadeIn 3s forwards; animation: fadeIn 3s forwards;
} }
#tooltip-root {
position: absolute;
z-index: $z-index-tooltips;
top: 0;
left: 0;
pointer-events: none;
}
+1
View File
@@ -8,6 +8,7 @@
span { span {
margin-left: 2em; margin-left: 2em;
animation: fadeIn .2s ease-out;
} }
} }
} }
+1 -1
View File
@@ -61,7 +61,7 @@ export class Calculator extends React.PureComponent<Props> {
<span>Talent points: {availablePoints}</span> <span>Talent points: {availablePoints}</span>
</div> </div>
<h4>Quick links</h4> <h4>Quick links (TODO)</h4>
<ul> <ul>
<li><Link to="/shaman/-5505000055523051-55">Shaman test</Link></li> <li><Link to="/shaman/-5505000055523051-55">Shaman test</Link></li>
<li><Link to="/shaman/-5595000055523051-55">Shaman test broken</Link></li> <li><Link to="/shaman/-5595000055523051-55">Shaman test broken</Link></li>
+1 -1
View File
@@ -43,7 +43,7 @@ export const TalentTree: React.FC<Props> = ({ specId, knownTalents, availablePoi
<Trigger> <Trigger>
<div className="tree__reset" onClick={handleResetSpec}>x</div> <div className="tree__reset" onClick={handleResetSpec}>x</div>
</Trigger> </Trigger>
<Tooltip>Reset spec</Tooltip> <Tooltip><span className="green">Reset points in {specNames[specId]}</span></Tooltip>
</Controller> </Controller>
} }
</div> </div>
+5 -4
View File
@@ -49,14 +49,14 @@ export class Controller extends React.PureComponent<Props> {
this.setState({ isVisible: false }) this.setState({ isVisible: false })
} }
componentDidUpdate(prevProps, prevState) { componentDidUpdate() {
if (this.state.isVisible) { if (this.state.isVisible) {
const { width, height } = (ReactDOM.findDOMNode(this.tooltip.current) as HTMLElement).getBoundingClientRect() const { width, height } = (ReactDOM.findDOMNode(this.tooltip.current) as HTMLElement).getBoundingClientRect()
const { style, tooltipDimensions } = this.state const { style, tooltipDimensions } = this.state
this.setState({ this.setState({
tooltipDimensions: tooltipDimensions.merge({ width, height }), tooltipDimensions: tooltipDimensions.merge({ width, height }),
style: style.merge(this.getPosition()) style: style.merge({ ...this.getPosition() })
}) })
} }
} }
@@ -105,6 +105,7 @@ const calculatePosition = (pos: TooltipPosition, trigger: Map<string, number>, t
let left = 0 let left = 0
const triggerTop = trigger.get('top') + window.pageYOffset const triggerTop = trigger.get('top') + window.pageYOffset
const triggerLeft = trigger.get('left') + window.pageXOffset
// Top // Top
switch (pos) { switch (pos) {
@@ -126,14 +127,14 @@ const calculatePosition = (pos: TooltipPosition, trigger: Map<string, number>, t
case 'left': case 'left':
case 'bottom-left': case 'bottom-left':
case 'top-left': { case 'top-left': {
left = (trigger.get('left')) - tooltip.get('width') left = triggerLeft - tooltip.get('width')
break break
} }
case 'right': case 'right':
case 'bottom-right': case 'bottom-right':
case 'top-right': { case 'top-right': {
left = (trigger.get('left')) + trigger.get('width') left = triggerLeft + trigger.get('width')
break break
} }
} }
+12 -1
View File
@@ -1,4 +1,7 @@
@import "../../sass/config";
@mixin tooltip-base { @mixin tooltip-base {
display: flex;
font-size: 12px; font-size: 12px;
font-family: Verdana, Geneva, Tahoma, sans-serif; font-family: Verdana, Geneva, Tahoma, sans-serif;
line-height: 1.4; line-height: 1.4;
@@ -50,7 +53,6 @@
.tooltip { .tooltip {
@include tooltip-base; @include tooltip-base;
display: flex;
&--inline { &--inline {
display: inline-block; display: inline-block;
@@ -82,4 +84,13 @@
margin-bottom: 2px; margin-bottom: 2px;
} }
} }
}
#tooltip-root {
position: absolute;
z-index: $z-index-tooltips;
top: 0;
left: 0;
min-width: 100%;
pointer-events: none;
} }