react-component/slider#32 implemented tipFormatter prop

This commit is contained in:
Thorben Ziemek
2015-11-05 12:43:05 +01:00
parent 9d62c64784
commit 3519ba24c0
3 changed files with 16 additions and 6 deletions
+3 -2
View File
@@ -24,7 +24,7 @@ export default class Handle extends React.Component {
render() {
const props = this.props;
const {className, tipTransitionName, offset, value} = props;
const {className, tipTransitionName, tipFormatter, offset, value} = props;
const {dragging, noTip} = props;
const style = { left: offset + '%' };
@@ -42,7 +42,7 @@ export default class Handle extends React.Component {
prefixCls={className.replace('handle', 'tooltip')}
placement={{points: ['bc', 'tc']}}
visible={isTooltipVisible}
overlay={<span>{value}</span>}
overlay={<span>{tipFormatter ? tipFormatter(value) : value}</span>}
delay={0}
transitionName={tipTransitionName}>
{handle}
@@ -54,6 +54,7 @@ Handle.propTypes = {
className: React.PropTypes.string,
offset: React.PropTypes.number,
tipTransitionName: React.PropTypes.string,
tipFormatter: React.PropTypes.func,
value: React.PropTypes.number,
dragging: React.PropTypes.bool,
noTip: React.PropTypes.bool,
+5 -4
View File
@@ -331,7 +331,7 @@ class Slider extends React.Component {
const {handle, upperBound, lowerBound} = this.state;
const props = this.props;
const {className, prefixCls, disabled, included, isIncluded, dots, withDots, range} = props;
const {marks, step, max, min, tipTransitionName, children} = props;
const {marks, step, max, min, tipTransitionName, tipFormatter, children} = props;
const marksLen = marks.length;
const sliderClassName = rcUtil.classSet({
@@ -350,13 +350,13 @@ class Slider extends React.Component {
}
const handleClassName = prefixCls + '-handle';
const isNoTip = marksLen > 0;
const upper = (<Handle className={handleClassName} tipTransitionName={tipTransitionName} noTip={isNoTip}
const isNoTip = (marksLen > 0) && !tipFormatter;
const upper = (<Handle className={handleClassName} tipTransitionName={tipTransitionName} noTip={isNoTip} tipFormatter={tipFormatter}
offset={upperOffset} value={upperBound} dragging={handle === 'upperBound'} />);
let lower = null;
if (range) {
lower = (<Handle className={handleClassName} tipTransitionName={tipTransitionName} noTip={isNoTip}
lower = (<Handle className={handleClassName} tipTransitionName={tipTransitionName} noTip={isNoTip} tipFormatter={tipFormatter}
offset={lowerOffset} value={lowerBound} dragging={handle === 'lowerBound'} />);
}
@@ -418,6 +418,7 @@ Slider.propTypes = {
onChange: React.PropTypes.func,
onAfterChange: React.PropTypes.func,
tipTransitionName: React.PropTypes.string,
tipFormatter: React.PropTypes.func,
withDots: React.PropTypes.bool, // @Deprecated
dots: React.PropTypes.bool,
range: React.PropTypes.bool,