ant-design/components/slider/index.jsx

43 lines
904 B
React
Raw Normal View History

import React from 'react';
import Slider from 'rc-slider';
2015-07-13 08:00:31 +08:00
export default React.createClass({
2015-07-13 08:00:31 +08:00
getDefaultProps() {
return {
2015-08-24 16:43:46 +08:00
prefixCls: 'ant-slider',
tipTransitionName: 'zoom-down'
2015-07-13 08:00:31 +08:00
};
},
render() {
2015-11-18 16:54:38 +08:00
const {isIncluded, marks, index, defaultIndex, ...rest} = this.props;
if (isIncluded !== undefined) {
// 兼容 `isIncluded`
rest.included = isIncluded;
}
if (Array.isArray(marks)) {
// 兼容当 marks 为数组的情况
rest.min = 0;
rest.max = marks.length - 1;
rest.step = 1;
if (index !== undefined) {
rest.value = index;
}
if (defaultIndex !== undefined) {
rest.defaultValue = defaultIndex;
}
rest.marks = {};
marks.forEach((val, idx) => {
rest.marks[idx] = val;
});
} else {
rest.marks = marks;
}
return <Slider {...rest} />;
2015-07-13 08:00:31 +08:00
}
});