diff --git a/examples/simple.js b/examples/simple.js index fe3ec84..63223c3 100644 --- a/examples/simple.js +++ b/examples/simple.js @@ -9,6 +9,10 @@ var style = {width:400,margin:50}; var log = console.log.bind(console); +function percentFormatter(v) { + return v + " %"; +} + ReactDOM.render(
@@ -39,5 +43,9 @@ ReactDOM.render(

分段式滑块(并列关系)

+
+

基础滑块

+ +
, document.getElementById('__react-content')); diff --git a/src/Handle.jsx b/src/Handle.jsx index f9dfbae..80df82e 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="top" 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 2a23a94..076cfef 100644 --- a/src/Slider.jsx +++ b/src/Slider.jsx @@ -309,7 +309,7 @@ class Slider extends React.Component { const {handle, upperBound, lowerBound} = this.state; const props = this.props; const {className, prefixCls, disabled, included, isIncluded, dots, 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 = classSet({ @@ -328,14 +328,14 @@ class Slider extends React.Component { } const handleClassName = prefixCls + '-handle'; - const isNoTip = marksLen > 0; - const upper = (); + const isNoTip = (marksLen > 0) && !tipFormatter; + const upper = (); let lower = null; if (range) { - lower = (); + lower = (); } const upperIndex = this.getIndex(upperBound); @@ -396,6 +396,7 @@ Slider.propTypes = { onChange: React.PropTypes.func, onAfterChange: React.PropTypes.func, tipTransitionName: React.PropTypes.string, + tipFormatter: React.PropTypes.func, dots: React.PropTypes.bool, range: React.PropTypes.bool, };