feat: allow user set step to null to make marks as steps

This commit is contained in:
Benjy Cui
2015-11-19 11:42:04 +08:00
parent 6f39212df5
commit 0a23a67f31
2 changed files with 6 additions and 11 deletions
+3 -3
View File
@@ -22,11 +22,11 @@ var log = function(value) {
ReactDOM.render(
<div>
<div style={style}>
<p>Slider with marks, `included=true`</p>
<Slider min={-10} marks={marks} onChange={log} defaultValue={20} />
<p>Slider with marks, `step=null`</p>
<Slider min={-10} marks={marks} step={null} onChange={log} defaultValue={20} />
</div>
<div style={style}>
<p>Slider with marks and steps, `included=true`</p>
<p>Slider with marks and steps</p>
<Slider min={-10} marks={marks} step={10} onChange={log} defaultValue={20} />
</div>
+3 -8
View File
@@ -25,10 +25,6 @@ function pauseEvent(e) {
e.preventDefault();
}
function isEmpty(collection) {
return Object.keys(collection).length === 0;
}
class Slider extends React.Component {
constructor(props) {
super(props);
@@ -194,7 +190,7 @@ class Slider extends React.Component {
getPoints() {
const {marks, step, min, max} = this.props;
const points = Object.keys(marks);
if (isEmpty(marks) || step > 1) {
if (step !== null) {
for (let i = min; i <= max; i = i + step) {
points.push(i);
}
@@ -291,9 +287,8 @@ class Slider extends React.Component {
render() {
const {handle, upperBound, lowerBound} = this.state;
const {className, prefixCls, disabled, dots, included, range,
const {className, prefixCls, disabled, dots, included, range, step,
marks, max, min, tipTransitionName, tipFormatter, children} = this.props;
const marksCount = Object.keys(marks).length;
const sliderClassName = classSet({
[prefixCls]: true,
@@ -311,7 +306,7 @@ class Slider extends React.Component {
}
const handleClassName = prefixCls + '-handle';
const isNoTip = (marksCount > 0) && !tipFormatter;
const isNoTip = (step === null) && !tipFormatter;
const upper = (<Handle className={handleClassName} tipTransitionName={tipTransitionName} noTip={isNoTip} tipFormatter={tipFormatter}
offset={upperOffset} value={upperBound} dragging={handle === 'upperBound'} />);