2016-07-07 20:25:03 +08:00
|
|
|
import * as React from 'react';
|
2016-03-21 09:22:14 +08:00
|
|
|
import RcSlider from 'rc-slider';
|
2016-06-22 13:18:43 +08:00
|
|
|
import splitObject from '../_util/splitObject';
|
2016-03-21 09:22:14 +08:00
|
|
|
export default class Slider extends React.Component {
|
2016-03-29 14:01:10 +08:00
|
|
|
static defaultProps = {
|
|
|
|
prefixCls: 'ant-slider',
|
2016-05-11 09:32:33 +08:00
|
|
|
tipTransitionName: 'zoom-down',
|
2016-03-29 14:01:10 +08:00
|
|
|
}
|
|
|
|
|
2015-07-13 08:00:31 +08:00
|
|
|
render() {
|
2016-06-22 13:18:43 +08:00
|
|
|
const [{isIncluded, marks, index, defaultIndex}, others] = splitObject(this.props,
|
|
|
|
['isIncluded', 'marks', 'index', 'defaultIndex']);
|
|
|
|
|
2015-11-18 16:54:38 +08:00
|
|
|
if (isIncluded !== undefined) {
|
|
|
|
// 兼容 `isIncluded`
|
2016-06-22 13:18:43 +08:00
|
|
|
others.included = isIncluded;
|
2015-11-18 16:54:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Array.isArray(marks)) {
|
|
|
|
// 兼容当 marks 为数组的情况
|
2016-06-22 13:18:43 +08:00
|
|
|
others.min = 0;
|
|
|
|
others.max = marks.length - 1;
|
|
|
|
others.step = 1;
|
2015-11-18 16:54:38 +08:00
|
|
|
|
|
|
|
if (index !== undefined) {
|
2016-06-22 13:18:43 +08:00
|
|
|
others.value = index;
|
2015-11-18 16:54:38 +08:00
|
|
|
}
|
|
|
|
if (defaultIndex !== undefined) {
|
2016-06-22 13:18:43 +08:00
|
|
|
others.defaultValue = defaultIndex;
|
2015-11-18 16:54:38 +08:00
|
|
|
}
|
|
|
|
|
2016-06-22 13:18:43 +08:00
|
|
|
others.marks = {};
|
2015-11-18 16:54:38 +08:00
|
|
|
marks.forEach((val, idx) => {
|
2016-06-22 13:18:43 +08:00
|
|
|
others.marks[idx] = val;
|
2015-11-18 16:54:38 +08:00
|
|
|
});
|
|
|
|
} else {
|
2016-06-22 13:18:43 +08:00
|
|
|
others.marks = marks;
|
2015-11-18 16:54:38 +08:00
|
|
|
}
|
|
|
|
|
2016-06-22 13:18:43 +08:00
|
|
|
return <RcSlider {...others} />;
|
2015-07-13 08:00:31 +08:00
|
|
|
}
|
2016-03-21 09:22:14 +08:00
|
|
|
}
|