ant-design/components/slider/index.jsx
Bruce Mitchener eaae43abdd More ES2015 classes.
This covers Carousel, InputNumber, Select, Slider, Switch, TreeSelect
and Tree.
2016-03-21 08:26:05 +07:00

42 lines
900 B
JavaScript

import React from 'react';
import RcSlider from 'rc-slider';
export default class Slider extends React.Component {
render() {
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 <RcSlider {...rest} />;
}
}
Slider.defaultProps = {
prefixCls: 'ant-slider',
tipTransitionName: 'zoom-down'
};