forked from react-bootstrap/react-bootstrap
-
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 react-bootstrap#1304 from taion/tooltip-prop-types
Remove extraneous Tooltip prop types
- Loading branch information
Showing
1 changed file
with
73 additions
and
78 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 |
---|---|---|
@@ -1,87 +1,82 @@ | ||
import React from 'react'; | ||
import classNames from 'classnames'; | ||
import BootstrapMixin from './BootstrapMixin'; | ||
import CustomPropTypes from './utils/CustomPropTypes'; | ||
|
||
const Tooltip = React.createClass({ | ||
mixins: [BootstrapMixin], | ||
|
||
propTypes: { | ||
/** | ||
* An html id attribute, necessary for accessibility | ||
* @type {string} | ||
* @required | ||
*/ | ||
id: CustomPropTypes.isRequiredForA11y( | ||
React.PropTypes.oneOfType([ | ||
React.PropTypes.string, | ||
React.PropTypes.number | ||
]) | ||
), | ||
|
||
/** | ||
* Sets the direction the Tooltip is positioned towards. | ||
*/ | ||
placement: React.PropTypes.oneOf(['top', 'right', 'bottom', 'left']), | ||
|
||
/** | ||
* The "left" position value for the Tooltip. | ||
*/ | ||
positionLeft: React.PropTypes.number, | ||
/** | ||
* The "top" position value for the Tooltip. | ||
*/ | ||
positionTop: React.PropTypes.number, | ||
/** | ||
* The "left" position value for the Tooltip arrow. | ||
*/ | ||
arrowOffsetLeft: React.PropTypes.oneOfType([ | ||
React.PropTypes.number, React.PropTypes.string | ||
]), | ||
/** | ||
* The "top" position value for the Tooltip arrow. | ||
*/ | ||
arrowOffsetTop: React.PropTypes.oneOfType([ | ||
React.PropTypes.number, React.PropTypes.string | ||
]), | ||
/** | ||
* Title text | ||
*/ | ||
title: React.PropTypes.node | ||
}, | ||
import React from 'react'; | ||
|
||
getDefaultProps() { | ||
return { | ||
placement: 'right' | ||
}; | ||
}, | ||
import CustomPropTypes from './utils/CustomPropTypes'; | ||
|
||
export default class Tooltip extends React.Component { | ||
render() { | ||
const classes = { | ||
'tooltip': true, | ||
[this.props.placement]: true | ||
}; | ||
|
||
const style = { | ||
'left': this.props.positionLeft, | ||
'top': this.props.positionTop, | ||
...this.props.style | ||
}; | ||
|
||
const arrowStyle = { | ||
'left': this.props.arrowOffsetLeft, | ||
'top': this.props.arrowOffsetTop | ||
}; | ||
const { | ||
placement, | ||
positionLeft, | ||
positionTop, | ||
arrowOffsetLeft, | ||
arrowOffsetTop, | ||
className, | ||
style, | ||
children, | ||
...props | ||
} = this.props; | ||
|
||
return ( | ||
<div role="tooltip" {...this.props} className={classNames(this.props.className, classes)} style={style}> | ||
<div className="tooltip-arrow" style={arrowStyle} /> | ||
<div className="tooltip-inner"> | ||
{this.props.children} | ||
</div> | ||
<div | ||
role="tooltip" | ||
{...props} | ||
className={classNames(className, 'tooltip', placement)} | ||
style={{left: positionLeft, top: positionTop, ...style}} | ||
> | ||
<div | ||
className="tooltip-arrow" | ||
style={{left: arrowOffsetLeft, top: arrowOffsetTop}} | ||
/> | ||
|
||
<div className="tooltip-inner"> | ||
{children} | ||
</div> | ||
); | ||
</div> | ||
); | ||
} | ||
}); | ||
} | ||
|
||
Tooltip.propTypes = { | ||
/** | ||
* An html id attribute, necessary for accessibility | ||
* @type {string} | ||
* @required | ||
*/ | ||
id: CustomPropTypes.isRequiredForA11y( | ||
React.PropTypes.oneOfType([ | ||
React.PropTypes.string, | ||
React.PropTypes.number | ||
]) | ||
), | ||
|
||
/** | ||
* The direction the tooltip is positioned towards | ||
*/ | ||
placement: React.PropTypes.oneOf(['top', 'right', 'bottom', 'left']), | ||
|
||
/** | ||
* The `left` position value for the tooltip | ||
*/ | ||
positionLeft: React.PropTypes.number, | ||
/** | ||
* The `top` position value for the tooltip | ||
*/ | ||
positionTop: React.PropTypes.number, | ||
/** | ||
* The `left` position value for the tooltip arrow | ||
*/ | ||
arrowOffsetLeft: React.PropTypes.oneOfType([ | ||
React.PropTypes.number, React.PropTypes.string | ||
]), | ||
/** | ||
* The `top` position value for the tooltip arrow | ||
*/ | ||
arrowOffsetTop: React.PropTypes.oneOfType([ | ||
React.PropTypes.number, React.PropTypes.string | ||
]) | ||
}; | ||
|
||
export default Tooltip; | ||
Tooltip.defaultProps = { | ||
placement: 'right' | ||
}; |