-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from sergiocruz/placement
Position placement
- Loading branch information
Showing
14 changed files
with
258 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React, { Component, PropTypes } from 'react'; | ||
|
||
class DynamicPositionTooltip extends Component { | ||
|
||
static propTypes = { | ||
tooltip: PropTypes.node.isRequired, | ||
top: PropTypes.number.isRequired, | ||
left: PropTypes.number.isRequired, | ||
position: PropTypes.string.isRequired | ||
} | ||
|
||
static defaultProps = { | ||
position: 'top', | ||
} | ||
|
||
render() { | ||
const { top, left, position } = this.props; | ||
return React.cloneElement(this.props.tooltip, { | ||
dynamicPositioning: true, | ||
top, | ||
left, | ||
position | ||
}); | ||
} | ||
} | ||
|
||
export { | ||
DynamicPositionTooltip, | ||
DynamicPositionTooltip as default | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React, { Component } from 'react'; | ||
import { getStyles } from './styles'; | ||
|
||
class TooltipWrapper extends Component { | ||
render() { | ||
const { tooltipWrapper } = getStyles(); | ||
|
||
return ( | ||
<div style={tooltipWrapper}> | ||
{this.props.children} | ||
</div> | ||
) | ||
} | ||
} | ||
|
||
export { | ||
TooltipWrapper as default, | ||
TooltipWrapper, | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import positionTop from './positionTop'; | ||
import positionRight from './positionRight'; | ||
import positionBottom from './positionBottom'; | ||
import positionLeft from './positionLeft'; | ||
|
||
export function getCoordinates(el, position) { | ||
switch(position) { | ||
default: | ||
case 'top': | ||
return positionTop(el); | ||
|
||
case 'right': | ||
return positionRight(el); | ||
|
||
case 'bottom': | ||
return positionBottom(el); | ||
|
||
case 'left': | ||
return positionLeft(el); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { EXTRA_PAD } from './shared'; | ||
|
||
function topPosition(el) { | ||
const tooltipEl = el.firstChild; | ||
const top = el.offsetTop + tooltipEl.offsetHeight + EXTRA_PAD; | ||
return top; | ||
} | ||
|
||
function leftPosition(el) { | ||
const left = el.offsetLeft; | ||
return left; | ||
} | ||
|
||
export default function position(el) { | ||
return { | ||
top: topPosition(el), | ||
left: leftPosition(el), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { EXTRA_PAD, centerVerticallyAlign } from './shared'; | ||
|
||
function topPosition(el) { | ||
const tooltipEl = el.firstChild; | ||
return centerVerticallyAlign(el, tooltipEl); | ||
} | ||
|
||
function leftPosition(el) { | ||
const tooltipEl = el.firstChild; | ||
const left = el.offsetLeft - tooltipEl.offsetWidth - EXTRA_PAD; | ||
return left; | ||
} | ||
|
||
export default function position(el) { | ||
return { | ||
left: leftPosition(el), | ||
top: topPosition(el), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { EXTRA_PAD, centerVerticallyAlign } from './shared'; | ||
|
||
function topPosition(el) { | ||
const tooltipEl = el.firstChild; | ||
return centerVerticallyAlign(el, tooltipEl); | ||
} | ||
|
||
function leftPosition(el) { | ||
const left = el.offsetLeft + el.offsetWidth + EXTRA_PAD; | ||
return left; | ||
} | ||
|
||
export default function position(el) { | ||
const coordinates = { | ||
top: topPosition(el), | ||
left: leftPosition(el), | ||
} | ||
|
||
return coordinates; | ||
} |
Oops, something went wrong.