From 3519ba24c0f49830ebe2074d3d98af6e8a462d12 Mon Sep 17 00:00:00 2001 From: Thorben Ziemek Date: Thu, 5 Nov 2015 12:43:05 +0100 Subject: [PATCH] react-component/slider#32 implemented tipFormatter prop --- examples/simple.js | 8 ++++++++ src/Handle.jsx | 5 +++-- src/Slider.jsx | 9 +++++---- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/examples/simple.js b/examples/simple.js index 32d738b..dfe310e 100644 --- a/examples/simple.js +++ b/examples/simple.js @@ -11,6 +11,10 @@ function onChange(v) { console.log(v); } +function percentFormatter(v) { + return v + " %"; +} + ReactDOM.render(
@@ -41,5 +45,9 @@ ReactDOM.render(

分段式滑块(并列关系)

+
+

基础滑块

+ +
, document.getElementById('__react-content')); diff --git a/src/Handle.jsx b/src/Handle.jsx index 3869059..0d77d86 100644 --- a/src/Handle.jsx +++ b/src/Handle.jsx @@ -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={{value}} + overlay={{tipFormatter ? tipFormatter(value) : value}} 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, diff --git a/src/Slider.jsx b/src/Slider.jsx index e312fed..5c7c542 100644 --- a/src/Slider.jsx +++ b/src/Slider.jsx @@ -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 = ( 0) && !tipFormatter; + const upper = (); let lower = null; if (range) { - lower = (); } @@ -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,