Merge pull request #24 from react-component/step-marks-fix

Step marks fix
This commit is contained in:
Benjy Cui
2015-10-15 11:26:49 +08:00
6 changed files with 50 additions and 29 deletions
+6
View File
@@ -142,6 +142,12 @@ React.render(<Rcslider />, container);
<td>''</td>
<td>Set the animation for tooltip if it shows.</td>
</tr>
<tr>
<td>withDots</td>
<td>bool</td>
<td>false</td>
<td>For linear slider, when the `step` value is greater than 1, you can set the `withDots` to `true` if you want to render the slider bar with dots.</td>
</tr>
</tbody>
</table>
+3 -3
View File
@@ -121,13 +121,13 @@
background-color: @disabledColor;
}
.@{prefixClass}-handle {
.@{prefixClass}-handle, .@{prefixClass}-dot {
border-color: @disabledColor;
background-color: #fff;
cursor: not-allowed;
}
.@{prefixClass}-mark-text, .dot {
.@{prefixClass}-mark-text, .@{prefixClass}-dot {
cursor: not-allowed!important;
}
}
@@ -240,4 +240,4 @@
transform-origin: 50% 100%;
transform: scale(0, 0);
}
}
}
+1
View File
@@ -10,5 +10,6 @@ function onChange(v){
}
// React.render(<div style={{width:400,margin:100}}><Slider marks={["一","二","三","四","五"]} defaultIndex={2} /></div>, document.getElementById('__react-content'));
// React.render(<div style={{width:400,margin:100}}><Slider withDots className='rc-slider' step={20}/></div>, document.getElementById('__react-content'));
// React.render(<div style={{width:400,margin:100}}><Slider className='rc-slider' step={20}/></div>, document.getElementById('__react-content'));
React.render(<div style={{width:400,margin:100}}><Slider onChange={onChange} tipTransitionName='rc-slider-tooltip-zoom-down'/></div>, document.getElementById('__react-content'));
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "rc-slider",
"version": "1.5.0",
"version": "1.5.1",
"description": "slider ui component for react",
"keywords": [
"react",
+31 -23
View File
@@ -57,6 +57,7 @@ const Slider = React.createClass({
onChange: React.PropTypes.func,
onAfterChange: React.PropTypes.func,
tipTransitionName: React.PropTypes.string,
withDots: React.PropTypes.bool,
},
getDefaultProps() {
@@ -72,6 +73,7 @@ const Slider = React.createClass({
disabled: false,
defaultIndex: 0,
tipTransitionName: '',
withDots: false,
};
},
@@ -208,37 +210,43 @@ const Slider = React.createClass({
renderSteps() {
const props = this.props;
const marksLen = props.marks.length;
const stepNum = marksLen > 0 ? marksLen : Math.floor((props.max - props.min) / props.step) + 1;
const unit = 100 / (stepNum - 1);
const withDots = props.withDots;
const prefixCls = props.prefixCls;
const stepClassName = prefixClsFn(prefixCls, 'step');
if (marksLen || withDots) {
const stepNum = marksLen ? marksLen : Math.floor((props.max - props.min) / props.step) + 1;
const unit = 100 / (stepNum - 1);
const elements = [];
for (let i = 0; i < stepNum; i++) {
const offset = unit * i + '%';
const style = {
left: offset,
};
let className = prefixClsFn(prefixCls, 'dot');
if (props.isIncluded) {
if (i <= this.getIndex()) {
className = prefixClsFn(prefixCls, 'dot', 'dot-active');
const prefixCls = props.prefixCls;
const stepClassName = prefixClsFn(prefixCls, 'step');
const elements = [];
for (let i = 0; i < stepNum; i++) {
const offset = unit * i + '%';
const style = {
left: offset,
};
let className = prefixClsFn(prefixCls, 'dot');
if (props.isIncluded) {
if (i <= this.getIndex()) {
className = prefixClsFn(prefixCls, 'dot', 'dot-active');
}
} else {
className = (i === this.getIndex()) ? prefixClsFn(prefixCls, 'dot', 'dot-active') : className;
}
} else {
className = (i === this.getIndex()) ? prefixClsFn(prefixCls, 'dot', 'dot-active') : className;
elements[i] = (
<span className={className} style={style} ref={'step' + i} key={'step' + i}></span>
);
}
elements[i] = (
<span className={className} style={style} ref={'step' + i} key={'step' + i}></span>
return (
<div className={stepClassName}>
{elements}
</div>
);
}
return (
<div className={stepClassName}>
{elements}
</div>
);
return null;
},
renderMark(i) {
+8 -2
View File
@@ -39,8 +39,14 @@ describe('rc-slider', function () {
expect(node.find('.rc-slider').length).to.be(1);
expect(node.find('.rc-slider-handle').length).to.be(1);
expect(node.find('.rc-slider-track').length).to.be(1);
expect(node.find('.rc-slider-dot').length).to.be(6);
expect(slider.state.value).to.be(0);
var sliderWithDots = React.render(
<Slider className='rc-slider' step={20} withDots/>,
div
);
var node1 = $(div);
expect(node1.find('.rc-slider-dot').length).to.be(6);
});
it('should render a slider with marks correctly!', function () {
@@ -64,7 +70,7 @@ describe('rc-slider', function () {
// div
// );
// var selectedStep = slider.refs.step3.getDOMNode();
// Simulate.mouseDown(selectedStep);
// setTimeout( function() {