mirror of
https://github.com/wassname/slider.git
synced 2026-09-11 12:42:49 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
806cb06d76 | ||
|
|
73b9953084 | ||
|
|
6347b6d0c6 | ||
|
|
6a5573b6ca | ||
|
|
e030ba9f9d | ||
|
|
daaea139b9 | ||
|
|
2641880783 | ||
|
|
d6e81a692c | ||
|
|
0512ee6ee0 | ||
|
|
613a2ae213 | ||
|
|
2cb0dbce6f | ||
|
|
f850dab6c4 | ||
|
|
f3c1d4bd3d | ||
|
|
4d795b01cc | ||
|
|
959007ed30 | ||
|
|
079469b765 | ||
|
|
ddb2bf670b | ||
|
|
4c57f3ecca | ||
|
|
24f3b755b2 | ||
|
|
867e252631 | ||
|
|
39de81dfa9 | ||
|
|
978d877323 | ||
|
|
a1ae3a8374 | ||
|
|
15f568283c | ||
|
|
e85d325542 | ||
|
|
395fa6c201 |
@@ -90,9 +90,9 @@ ReactDOM.render(<Rcslider />, container);
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>marks</td>
|
<td>marks</td>
|
||||||
<td>object {number: string}</td>
|
<td>object{number: string} or object{number: object{ style, label }}</td>
|
||||||
<td>{}</td>
|
<td>{}</td>
|
||||||
<td>Mark on the slider. The key determines the position, and the value determines what will show.</td>
|
<td>Mark on the slider. The key determines the position, and the value determines what will show. If you want to set the style of a specific mark point, the value should be an object which contains `style` and `label` properties.</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>step</td>
|
<td>step</td>
|
||||||
@@ -106,6 +106,12 @@ ReactDOM.render(<Rcslider />, container);
|
|||||||
<td>false</td>
|
<td>false</td>
|
||||||
<td>Determines the type of slider. If range is `true`, two handles will be rendered in order to select a range.</td>
|
<td>Determines the type of slider. If range is `true`, two handles will be rendered in order to select a range.</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>allowCross</td>
|
||||||
|
<td>boolean</td>
|
||||||
|
<td>true</td>
|
||||||
|
<td>When `range` is `true`, `allowCross` could be set as `true` to allow those two handles cross.</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>defaultValue</td>
|
<td>defaultValue</td>
|
||||||
<td>number or [number, number]</td>
|
<td>number or [number, number]</td>
|
||||||
@@ -138,9 +144,9 @@ ReactDOM.render(<Rcslider />, container);
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>tipFormatter</td>
|
<td>tipFormatter</td>
|
||||||
<td>function</td>
|
<td>function or `null`</td>
|
||||||
<td></td>
|
<td></td>
|
||||||
<td>Format the value of the tooltip if it shows.</td>
|
<td>Format the value of the tooltip if it shows. If `null` the tooltip will always be hidden.</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>dots</td>
|
<td>dots</td>
|
||||||
|
|||||||
+9
-3
@@ -7,10 +7,16 @@ const Slider = require('rc-slider');
|
|||||||
const style = {width: 400, margin: 50};
|
const style = {width: 400, margin: 50};
|
||||||
const marks = {
|
const marks = {
|
||||||
'-10': '-10°C',
|
'-10': '-10°C',
|
||||||
0: '0°C',
|
0: <strong>0°C</strong>,
|
||||||
26: '26°C',
|
26: '26°C',
|
||||||
37: '37°C',
|
37: '37°C',
|
||||||
100: '100°C',
|
50: '50°C',
|
||||||
|
100: {
|
||||||
|
style: {
|
||||||
|
color: 'red',
|
||||||
|
},
|
||||||
|
label: <strong>100°C</strong>,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
function log(value) {
|
function log(value) {
|
||||||
@@ -25,7 +31,7 @@ ReactDOM.render(
|
|||||||
</div>
|
</div>
|
||||||
<div style={style}>
|
<div style={style}>
|
||||||
<p>Slider with marks and steps</p>
|
<p>Slider with marks and steps</p>
|
||||||
<Slider min={-10} marks={marks} step={10} onChange={log} defaultValue={20} />
|
<Slider dots min={-10} marks={marks} step={10} onChange={log} defaultValue={20} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div style={style}>
|
<div style={style}>
|
||||||
|
|||||||
+23
-3
@@ -1,3 +1,4 @@
|
|||||||
|
/* eslint react/no-multi-comp: 0 */
|
||||||
require('rc-slider/assets/index.less');
|
require('rc-slider/assets/index.less');
|
||||||
|
|
||||||
const React = require('react');
|
const React = require('react');
|
||||||
@@ -22,6 +23,21 @@ const CustomizedRange = React.createClass({
|
|||||||
value: value,
|
value: value,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
render: function() {
|
||||||
|
return <Slider range value={this.state.value} onChange={this.onSliderChange} />;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const DynamicBounds = React.createClass({
|
||||||
|
getInitialState() {
|
||||||
|
return {
|
||||||
|
min: 0,
|
||||||
|
max: 100,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
onSliderChange: function(value) {
|
||||||
|
log(value);
|
||||||
|
},
|
||||||
onMinChange: function(e) {
|
onMinChange: function(e) {
|
||||||
this.setState({
|
this.setState({
|
||||||
min: +e.target.value || 0,
|
min: +e.target.value || 0,
|
||||||
@@ -41,7 +57,7 @@ const CustomizedRange = React.createClass({
|
|||||||
<label>Max: </label>
|
<label>Max: </label>
|
||||||
<input type="number" value={this.state.max} onChange={this.onMaxChange} />
|
<input type="number" value={this.state.max} onChange={this.onMaxChange} />
|
||||||
<br /><br />
|
<br /><br />
|
||||||
<Slider range value={this.state.value} min={this.state.min} max={this.state.max} onChange={this.onSliderChange} />
|
<Slider range defaultValue={[20, 50]} min={this.state.min} max={this.state.max} onChange={this.onSliderChange} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@@ -50,8 +66,8 @@ const CustomizedRange = React.createClass({
|
|||||||
ReactDOM.render(
|
ReactDOM.render(
|
||||||
<div>
|
<div>
|
||||||
<div style={style}>
|
<div style={style}>
|
||||||
<p>Basic Range</p>
|
<p>Basic Range,`allowCross=false`</p>
|
||||||
<Slider range defaultValue={[0, 20]} onChange={log} />
|
<Slider range allowCross={false} defaultValue={[0, 20]} onChange={log} />
|
||||||
</div>
|
</div>
|
||||||
<div style={style}>
|
<div style={style}>
|
||||||
<p>Basic Range,`step=20` </p>
|
<p>Basic Range,`step=20` </p>
|
||||||
@@ -69,5 +85,9 @@ ReactDOM.render(
|
|||||||
<p>Customized Range</p>
|
<p>Customized Range</p>
|
||||||
<CustomizedRange />
|
<CustomizedRange />
|
||||||
</div>
|
</div>
|
||||||
|
<div style={style}>
|
||||||
|
<p>Range with dynamic `max` `min`</p>
|
||||||
|
<DynamicBounds />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
, document.getElementById('__react-content'));
|
, document.getElementById('__react-content'));
|
||||||
|
|||||||
+25
-3
@@ -1,3 +1,4 @@
|
|||||||
|
/* eslint react/no-multi-comp: 0 */
|
||||||
require('rc-slider/assets/index.less');
|
require('rc-slider/assets/index.less');
|
||||||
|
|
||||||
const React = require('react');
|
const React = require('react');
|
||||||
@@ -19,8 +20,6 @@ const CustomizedSlider = React.createClass({
|
|||||||
getInitialState: function() {
|
getInitialState: function() {
|
||||||
return {
|
return {
|
||||||
value: 50,
|
value: 50,
|
||||||
min: 0,
|
|
||||||
max: 100,
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
onSliderChange: function(value) {
|
onSliderChange: function(value) {
|
||||||
@@ -29,6 +28,21 @@ const CustomizedSlider = React.createClass({
|
|||||||
value: value,
|
value: value,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
render: function() {
|
||||||
|
return <Slider value={this.state.value} onChange={this.onSliderChange} />;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const DynamicBounds = React.createClass({
|
||||||
|
getInitialState: function() {
|
||||||
|
return {
|
||||||
|
min: 0,
|
||||||
|
max: 100,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
onSliderChange: function(value) {
|
||||||
|
log(value);
|
||||||
|
},
|
||||||
onMinChange: function(e) {
|
onMinChange: function(e) {
|
||||||
this.setState({
|
this.setState({
|
||||||
min: +e.target.value || 0,
|
min: +e.target.value || 0,
|
||||||
@@ -48,7 +62,7 @@ const CustomizedSlider = React.createClass({
|
|||||||
<label>Max: </label>
|
<label>Max: </label>
|
||||||
<input type="number" value={this.state.max} onChange={this.onMaxChange} />
|
<input type="number" value={this.state.max} onChange={this.onMaxChange} />
|
||||||
<br /><br />
|
<br /><br />
|
||||||
<Slider value={this.state.value} min={this.state.min} max={this.state.max} onChange={this.onSliderChange} />
|
<Slider defaultValue={50} min={this.state.min} max={this.state.max} onChange={this.onSliderChange} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@@ -72,6 +86,10 @@ ReactDOM.render(
|
|||||||
<p>Basic Slider with `tipFormatter`</p>
|
<p>Basic Slider with `tipFormatter`</p>
|
||||||
<Slider tipFormatter={percentFormatter} tipTransitionName="rc-slider-tooltip-zoom-down" onChange={log} />
|
<Slider tipFormatter={percentFormatter} tipTransitionName="rc-slider-tooltip-zoom-down" onChange={log} />
|
||||||
</div>
|
</div>
|
||||||
|
<div style={style}>
|
||||||
|
<p>Basic Slider without tooltip</p>
|
||||||
|
<Slider tipFormatter={null} onChange={log} />
|
||||||
|
</div>
|
||||||
<div style={style}>
|
<div style={style}>
|
||||||
<p>Controlled Slider</p>
|
<p>Controlled Slider</p>
|
||||||
<Slider value={50} />
|
<Slider value={50} />
|
||||||
@@ -80,5 +98,9 @@ ReactDOM.render(
|
|||||||
<p>Customized Slider</p>
|
<p>Customized Slider</p>
|
||||||
<CustomizedSlider />
|
<CustomizedSlider />
|
||||||
</div>
|
</div>
|
||||||
|
<div style={style}>
|
||||||
|
<p>Slider with dynamic `min` `max`</p>
|
||||||
|
<DynamicBounds />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
, document.getElementById('__react-content'));
|
, document.getElementById('__react-content'));
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "rc-slider",
|
"name": "rc-slider",
|
||||||
"version": "3.1.4",
|
"version": "3.5.1",
|
||||||
"description": "slider ui component for react",
|
"description": "slider ui component for react",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"react",
|
"react",
|
||||||
|
|||||||
+1
-1
@@ -42,7 +42,7 @@ export default class Handle extends React.Component {
|
|||||||
prefixCls={className.replace('slider-handle', 'tooltip')}
|
prefixCls={className.replace('slider-handle', 'tooltip')}
|
||||||
placement="top"
|
placement="top"
|
||||||
visible={isTooltipVisible}
|
visible={isTooltipVisible}
|
||||||
overlay={<span>{tipFormatter ? tipFormatter(value) : value}</span>}
|
overlay={<span>{tipFormatter(value)}</span>}
|
||||||
delay={0}
|
delay={0}
|
||||||
transitionName={tipTransitionName}>
|
transitionName={tipTransitionName}>
|
||||||
{handle}
|
{handle}
|
||||||
|
|||||||
+14
-5
@@ -8,7 +8,7 @@ const Marks = ({className, marks, included, upperBound, lowerBound, max, min}) =
|
|||||||
const markWidth = unit * 0.9;
|
const markWidth = unit * 0.9;
|
||||||
|
|
||||||
const range = max - min;
|
const range = max - min;
|
||||||
const elements = marksKeys.map(parseFloat).map((point) => {
|
const elements = marksKeys.map(parseFloat).sort((a, b) => a - b).map((point) => {
|
||||||
const isActived = (!included && point === upperBound) ||
|
const isActived = (!included && point === upperBound) ||
|
||||||
(included && point <= upperBound && point >= lowerBound);
|
(included && point <= upperBound && point >= lowerBound);
|
||||||
const markClassName = classNames({
|
const markClassName = classNames({
|
||||||
@@ -16,11 +16,20 @@ const Marks = ({className, marks, included, upperBound, lowerBound, max, min}) =
|
|||||||
[className + '-text-active']: isActived,
|
[className + '-text-active']: isActived,
|
||||||
});
|
});
|
||||||
|
|
||||||
const style = { width: markWidth + '%' };
|
const style = {
|
||||||
style.left = (point - min) / range * 100 - markWidth / 2 + '%';
|
width: markWidth + '%',
|
||||||
|
marginLeft: -markWidth / 2 + '%',
|
||||||
|
};
|
||||||
|
style.left = (point - min) / range * 100 + '%';
|
||||||
|
|
||||||
return (<span className={markClassName} style={style} key={point}>
|
const markPoint = marks[point];
|
||||||
{marks[point]}
|
const markPointIsObject = typeof markPoint === 'object' &&
|
||||||
|
!React.isValidElement(markPoint);
|
||||||
|
const markLabel = markPointIsObject ? markPoint.label : markPoint;
|
||||||
|
const markStyle = markPointIsObject ?
|
||||||
|
{ ...style, ...markPoint.style } : style;
|
||||||
|
return (<span className={markClassName} style={markStyle} key={point}>
|
||||||
|
{markLabel}
|
||||||
</span>);
|
</span>);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+47
-25
@@ -4,7 +4,7 @@ import classNames from 'classnames';
|
|||||||
import objectAssign from 'object-assign';
|
import objectAssign from 'object-assign';
|
||||||
import Track from './Track';
|
import Track from './Track';
|
||||||
import Handle from './Handle';
|
import Handle from './Handle';
|
||||||
import Dots from './Dots';
|
import Steps from './Steps';
|
||||||
import Marks from './Marks';
|
import Marks from './Marks';
|
||||||
|
|
||||||
function noop() {
|
function noop() {
|
||||||
@@ -34,7 +34,7 @@ class Slider extends React.Component {
|
|||||||
const {range, min, max} = props;
|
const {range, min, max} = props;
|
||||||
const initialValue = range ? [min, min] : min;
|
const initialValue = range ? [min, min] : min;
|
||||||
const defaultValue = ('defaultValue' in props ? props.defaultValue : initialValue);
|
const defaultValue = ('defaultValue' in props ? props.defaultValue : initialValue);
|
||||||
const value = ('value' in props ? props.value : defaultValue);
|
const value = (props.value !== undefined ? props.value : defaultValue);
|
||||||
|
|
||||||
let upperBound;
|
let upperBound;
|
||||||
let lowerBound;
|
let lowerBound;
|
||||||
@@ -71,7 +71,7 @@ class Slider extends React.Component {
|
|||||||
|
|
||||||
const {lowerBound, upperBound} = this.state;
|
const {lowerBound, upperBound} = this.state;
|
||||||
if (nextProps.range) {
|
if (nextProps.range) {
|
||||||
const value = nextProps.value;
|
const value = nextProps.value || [lowerBound, upperBound];
|
||||||
const nextUpperBound = this.trimAlignValue(value[1], nextProps);
|
const nextUpperBound = this.trimAlignValue(value[1], nextProps);
|
||||||
const nextLowerBound = this.trimAlignValue(value[0], nextProps);
|
const nextLowerBound = this.trimAlignValue(value[0], nextProps);
|
||||||
if (nextLowerBound === lowerBound && nextUpperBound === upperBound) return;
|
if (nextLowerBound === lowerBound && nextUpperBound === upperBound) return;
|
||||||
@@ -81,11 +81,12 @@ class Slider extends React.Component {
|
|||||||
lowerBound: nextLowerBound,
|
lowerBound: nextLowerBound,
|
||||||
});
|
});
|
||||||
if (this.isValueOutOfBounds(upperBound, nextProps) ||
|
if (this.isValueOutOfBounds(upperBound, nextProps) ||
|
||||||
this.isValueOutOfBounds(lowerBound, nextProps)) {
|
this.isValueOutOfBounds(lowerBound, nextProps)) {
|
||||||
this.props.onChange([nextLowerBound, nextUpperBound]);
|
this.props.onChange([nextLowerBound, nextUpperBound]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const nextValue = this.trimAlignValue(nextProps.value, nextProps);
|
const value = nextProps.value !== undefined ? nextProps.value : upperBound;
|
||||||
|
const nextValue = this.trimAlignValue(value, nextProps);
|
||||||
if (nextValue === upperBound && lowerBound === nextProps.min) return;
|
if (nextValue === upperBound && lowerBound === nextProps.min) return;
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
@@ -98,19 +99,16 @@ class Slider extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onChange(handle, value) {
|
onChange(state) {
|
||||||
const props = this.props;
|
const props = this.props;
|
||||||
const isNotControlled = !('value' in props);
|
const isNotControlled = !('value' in props);
|
||||||
if (isNotControlled) {
|
if (isNotControlled) {
|
||||||
this.setState({[handle]: value});
|
this.setState(state);
|
||||||
|
} else if (state.handle) {
|
||||||
|
this.setState({handle: state.handle});
|
||||||
}
|
}
|
||||||
|
|
||||||
const state = this.state;
|
const data = objectAssign({}, this.state, state);
|
||||||
const data = {
|
|
||||||
upperBound: state.upperBound,
|
|
||||||
lowerBound: state.lowerBound,
|
|
||||||
};
|
|
||||||
data[handle] = value;
|
|
||||||
const changedValue = props.range ? [data.lowerBound, data.upperBound] : data.upperBound;
|
const changedValue = props.range ? [data.lowerBound, data.upperBound] : data.upperBound;
|
||||||
props.onChange(changedValue);
|
props.onChange(changedValue);
|
||||||
}
|
}
|
||||||
@@ -142,7 +140,26 @@ class Slider extends React.Component {
|
|||||||
const oldValue = state[state.handle];
|
const oldValue = state[state.handle];
|
||||||
if (value === oldValue) return;
|
if (value === oldValue) return;
|
||||||
|
|
||||||
this.onChange(state.handle, value);
|
if (props.allowCross && value < state.lowerBound && state.handle === 'upperBound') {
|
||||||
|
this.onChange({
|
||||||
|
handle: 'lowerBound',
|
||||||
|
lowerBound: value,
|
||||||
|
upperBound: this.state.lowerBound,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (props.allowCross && value > state.upperBound && state.handle === 'lowerBound') {
|
||||||
|
this.onChange({
|
||||||
|
handle: 'upperBound',
|
||||||
|
upperBound: value,
|
||||||
|
lowerBound: this.state.upperBound,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.onChange({
|
||||||
|
[state.handle]: value,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onTouchStart(e) {
|
onTouchStart(e) {
|
||||||
@@ -197,7 +214,9 @@ class Slider extends React.Component {
|
|||||||
const oldValue = state[valueNeedChanging];
|
const oldValue = state[valueNeedChanging];
|
||||||
if (value === oldValue) return;
|
if (value === oldValue) return;
|
||||||
|
|
||||||
this.onChange(valueNeedChanging, value);
|
this.onChange({
|
||||||
|
[valueNeedChanging]: value,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getValue() {
|
getValue() {
|
||||||
@@ -238,7 +257,7 @@ class Slider extends React.Component {
|
|||||||
trimAlignValue(v, nextProps) {
|
trimAlignValue(v, nextProps) {
|
||||||
const state = this.state || {};
|
const state = this.state || {};
|
||||||
const {handle, lowerBound, upperBound} = state;
|
const {handle, lowerBound, upperBound} = state;
|
||||||
const {marks, step, min, max} = objectAssign({}, this.props, nextProps || {});
|
const {marks, step, min, max, allowCross} = objectAssign({}, this.props, nextProps || {});
|
||||||
|
|
||||||
let val = v;
|
let val = v;
|
||||||
if (val <= min) {
|
if (val <= min) {
|
||||||
@@ -247,10 +266,10 @@ class Slider extends React.Component {
|
|||||||
if (val >= max) {
|
if (val >= max) {
|
||||||
val = max;
|
val = max;
|
||||||
}
|
}
|
||||||
if (handle === 'upperBound' && val <= lowerBound) {
|
if (!allowCross && handle === 'upperBound' && val <= lowerBound) {
|
||||||
val = lowerBound;
|
val = lowerBound;
|
||||||
}
|
}
|
||||||
if (handle === 'lowerBound' && val >= upperBound) {
|
if (!allowCross && handle === 'lowerBound' && val >= upperBound) {
|
||||||
val = upperBound;
|
val = upperBound;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -314,23 +333,23 @@ class Slider extends React.Component {
|
|||||||
render() {
|
render() {
|
||||||
const {handle, upperBound, lowerBound} = this.state;
|
const {handle, upperBound, lowerBound} = this.state;
|
||||||
const {className, prefixCls, disabled, dots, included, range, step,
|
const {className, prefixCls, disabled, dots, included, range, step,
|
||||||
marks, max, min, tipTransitionName, tipFormatter, children} = this.props;
|
marks, max, min, tipTransitionName, tipFormatter, children} = this.props;
|
||||||
|
|
||||||
const upperOffset = this.calcOffset(upperBound);
|
const upperOffset = this.calcOffset(upperBound);
|
||||||
const lowerOffset = this.calcOffset(lowerBound);
|
const lowerOffset = this.calcOffset(lowerBound);
|
||||||
|
|
||||||
const handleClassName = prefixCls + '-handle';
|
const handleClassName = prefixCls + '-handle';
|
||||||
const isNoTip = (step === null) && !tipFormatter;
|
const isNoTip = (step === null) || (tipFormatter === null);
|
||||||
|
|
||||||
const upper = (<Handle className={handleClassName}
|
const upper = (<Handle className={handleClassName}
|
||||||
noTip={isNoTip} tipTransitionName={tipTransitionName} tipFormatter={tipFormatter}
|
noTip={isNoTip} tipTransitionName={tipTransitionName} tipFormatter={tipFormatter}
|
||||||
offset={upperOffset} value={upperBound} dragging={handle === 'upperBound'} />);
|
offset={upperOffset} value={upperBound} dragging={handle === 'upperBound'}/>);
|
||||||
|
|
||||||
let lower = null;
|
let lower = null;
|
||||||
if (range) {
|
if (range) {
|
||||||
lower = (<Handle className={handleClassName}
|
lower = (<Handle className={handleClassName}
|
||||||
noTip={isNoTip} tipTransitionName={tipTransitionName} tipFormatter={tipFormatter}
|
noTip={isNoTip} tipTransitionName={tipTransitionName} tipFormatter={tipFormatter}
|
||||||
offset={lowerOffset} value={lowerBound} dragging={handle === 'lowerBound'} />);
|
offset={lowerOffset} value={lowerBound} dragging={handle === 'lowerBound'}/>);
|
||||||
}
|
}
|
||||||
|
|
||||||
const sliderClassName = classNames({
|
const sliderClassName = classNames({
|
||||||
@@ -347,12 +366,12 @@ class Slider extends React.Component {
|
|||||||
{lower}
|
{lower}
|
||||||
<Track className={prefixCls + '-track'} included={isIncluded}
|
<Track className={prefixCls + '-track'} included={isIncluded}
|
||||||
offset={lowerOffset} length={upperOffset - lowerOffset}/>
|
offset={lowerOffset} length={upperOffset - lowerOffset}/>
|
||||||
<Dots prefixCls={prefixCls} marks={marks} dots={dots} step={step}
|
<Steps prefixCls={prefixCls} marks={marks} dots={dots} step={step}
|
||||||
included={isIncluded} lowerBound={lowerBound}
|
included={isIncluded} lowerBound={lowerBound}
|
||||||
upperBound={upperBound} max={max} min={min} />
|
upperBound={upperBound} max={max} min={min}/>
|
||||||
<Marks className={prefixCls + '-mark'} marks={marks}
|
<Marks className={prefixCls + '-mark'} marks={marks}
|
||||||
included={isIncluded} lowerBound={lowerBound}
|
included={isIncluded} lowerBound={lowerBound}
|
||||||
upperBound={upperBound} max={max} min={min} />
|
upperBound={upperBound} max={max} min={min}/>
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@@ -384,6 +403,7 @@ Slider.propTypes = {
|
|||||||
tipFormatter: React.PropTypes.func,
|
tipFormatter: React.PropTypes.func,
|
||||||
dots: React.PropTypes.bool,
|
dots: React.PropTypes.bool,
|
||||||
range: React.PropTypes.bool,
|
range: React.PropTypes.bool,
|
||||||
|
allowCross: React.PropTypes.bool,
|
||||||
};
|
};
|
||||||
|
|
||||||
Slider.defaultProps = {
|
Slider.defaultProps = {
|
||||||
@@ -397,10 +417,12 @@ Slider.defaultProps = {
|
|||||||
onBeforeChange: noop,
|
onBeforeChange: noop,
|
||||||
onChange: noop,
|
onChange: noop,
|
||||||
onAfterChange: noop,
|
onAfterChange: noop,
|
||||||
|
tipFormatter: value => value,
|
||||||
included: true,
|
included: true,
|
||||||
disabled: false,
|
disabled: false,
|
||||||
dots: false,
|
dots: false,
|
||||||
range: false,
|
range: false,
|
||||||
|
allowCross: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Slider;
|
export default Slider;
|
||||||
|
|||||||
@@ -5,13 +5,15 @@ function calcPoints(marks, dots, step, min, max) {
|
|||||||
const points = Object.keys(marks).map(parseFloat);
|
const points = Object.keys(marks).map(parseFloat);
|
||||||
if (dots) {
|
if (dots) {
|
||||||
for (let i = min; i <= max; i = i + step) {
|
for (let i = min; i <= max; i = i + step) {
|
||||||
|
if (points.indexOf(i) >= 0) continue;
|
||||||
points.push(i);
|
points.push(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return points;
|
return points;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Dots = ({prefixCls, marks, dots, step, included, lowerBound, upperBound, max, min}) => {
|
const Steps = ({prefixCls, marks, dots, step, included,
|
||||||
|
lowerBound, upperBound, max, min}) => {
|
||||||
const range = max - min;
|
const range = max - min;
|
||||||
const elements = calcPoints(marks, dots, step, min, max).map((point) => {
|
const elements = calcPoints(marks, dots, step, min, max).map((point) => {
|
||||||
const offset = (point - min) / range * 100 + '%';
|
const offset = (point - min) / range * 100 + '%';
|
||||||
@@ -30,4 +32,4 @@ const Dots = ({prefixCls, marks, dots, step, included, lowerBound, upperBound, m
|
|||||||
return <div className={prefixCls + '-step'}>{elements}</div>;
|
return <div className={prefixCls + '-step'}>{elements}</div>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Dots;
|
export default Steps;
|
||||||
+51
-35
@@ -22,28 +22,36 @@ describe('rc-slider', function() {
|
|||||||
expect(ReactTestUtils.scryRenderedDOMComponentsWithClass(slider, 'rc-slider-track').length).to.be(1);
|
expect(ReactTestUtils.scryRenderedDOMComponentsWithClass(slider, 'rc-slider-track').length).to.be(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should render a Slider with correct value and CSS style', () => {
|
it('should render a Slider with default value correctly', () => {
|
||||||
const sliderWithDefaultValue = ReactDOM.render(<Slider defaultValue={50} />, div);
|
const sliderWithDefaultValue = ReactDOM.render(<Slider defaultValue={50} />, div);
|
||||||
expect(sliderWithDefaultValue.state.upperBound).to.be(50);
|
expect(sliderWithDefaultValue.state.upperBound).to.be(50);
|
||||||
expect(ReactTestUtils
|
expect(ReactTestUtils
|
||||||
.scryRenderedDOMComponentsWithClass(sliderWithDefaultValue, 'rc-slider-handle')[0]
|
.scryRenderedDOMComponentsWithClass(sliderWithDefaultValue, 'rc-slider-handle')[0]
|
||||||
.style.cssText)
|
.style.cssText)
|
||||||
.to.be('left: 50%; ');
|
.to.match(/left: 50%;/);
|
||||||
expect(ReactTestUtils
|
|
||||||
.scryRenderedDOMComponentsWithClass(sliderWithDefaultValue, 'rc-slider-track')[0]
|
|
||||||
.style.cssText)
|
|
||||||
.to.be('left: 0%; width: 50%; visibility: visible; ');
|
|
||||||
|
|
||||||
|
const trackStyle = ReactTestUtils
|
||||||
|
.scryRenderedDOMComponentsWithClass(sliderWithDefaultValue, 'rc-slider-track')[0]
|
||||||
|
.style.cssText;
|
||||||
|
expect(trackStyle).to.match(/left: 0%;/);
|
||||||
|
expect(trackStyle).to.match(/width: 50%;/);
|
||||||
|
expect(trackStyle).to.match(/visibility: visible;/);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should render a Slider with value corrently', () => {
|
||||||
const sliderWithValue = ReactDOM.render(<Slider value={50} />, div);
|
const sliderWithValue = ReactDOM.render(<Slider value={50} />, div);
|
||||||
expect(sliderWithValue.state.upperBound).to.be(50);
|
expect(sliderWithValue.state.upperBound).to.be(50);
|
||||||
expect(ReactTestUtils
|
expect(ReactTestUtils
|
||||||
.scryRenderedDOMComponentsWithClass(sliderWithDefaultValue, 'rc-slider-handle')[0]
|
.scryRenderedDOMComponentsWithClass(sliderWithValue, 'rc-slider-handle')[0]
|
||||||
.style.cssText)
|
.style.cssText)
|
||||||
.to.be('left: 50%; ');
|
.to.match(/left: 50%;/);
|
||||||
expect(ReactTestUtils
|
|
||||||
.scryRenderedDOMComponentsWithClass(sliderWithDefaultValue, 'rc-slider-track')[0]
|
const trackStyle = ReactTestUtils
|
||||||
.style.cssText)
|
.scryRenderedDOMComponentsWithClass(sliderWithValue, 'rc-slider-track')[0]
|
||||||
.to.be('left: 0%; width: 50%; visibility: visible; ');
|
.style.cssText;
|
||||||
|
expect(trackStyle).to.match(/left: 0%;/);
|
||||||
|
expect(trackStyle).to.match(/width: 50%;/);
|
||||||
|
expect(trackStyle).to.match(/visibility: visible;/);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should render a Range with correct DOM structure', () => {
|
it('should render a Range with correct DOM structure', () => {
|
||||||
@@ -53,38 +61,46 @@ describe('rc-slider', function() {
|
|||||||
expect(ReactTestUtils.scryRenderedDOMComponentsWithClass(range, 'rc-slider-track').length).to.be(1);
|
expect(ReactTestUtils.scryRenderedDOMComponentsWithClass(range, 'rc-slider-track').length).to.be(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should render a Range with correct value and CSS style', () => {
|
it('should render a Range with default value correctly', () => {
|
||||||
const sliderWithDefaultValue = ReactDOM.render(<Slider range defaultValue={[0, 50]} />, div);
|
const rangeWithDefaultValue = ReactDOM.render(<Slider range defaultValue={[0, 50]} />, div);
|
||||||
expect(sliderWithDefaultValue.state.lowerBound).to.be(0);
|
expect(rangeWithDefaultValue.state.lowerBound).to.be(0);
|
||||||
expect(sliderWithDefaultValue.state.upperBound).to.be(50);
|
expect(rangeWithDefaultValue.state.upperBound).to.be(50);
|
||||||
expect(ReactTestUtils
|
expect(ReactTestUtils
|
||||||
.scryRenderedDOMComponentsWithClass(sliderWithDefaultValue, 'rc-slider-handle')[0]
|
.scryRenderedDOMComponentsWithClass(rangeWithDefaultValue, 'rc-slider-handle')[0]
|
||||||
.style.cssText)
|
.style.cssText)
|
||||||
.to.be('left: 50%; ');
|
.to.match(/left: 50%;/);
|
||||||
expect(ReactTestUtils
|
expect(ReactTestUtils
|
||||||
.scryRenderedDOMComponentsWithClass(sliderWithDefaultValue, 'rc-slider-handle')[1]
|
.scryRenderedDOMComponentsWithClass(rangeWithDefaultValue, 'rc-slider-handle')[1]
|
||||||
.style.cssText)
|
.style.cssText)
|
||||||
.to.be('left: 0%; ');
|
.to.match(/left: 0%;/);
|
||||||
expect(ReactTestUtils
|
|
||||||
.scryRenderedDOMComponentsWithClass(sliderWithDefaultValue, 'rc-slider-track')[0]
|
|
||||||
.style.cssText)
|
|
||||||
.to.be('left: 0%; width: 50%; visibility: visible; ');
|
|
||||||
|
|
||||||
const sliderWithValue = ReactDOM.render(<Slider range value={[50, 100]} />, div);
|
const trackStyle = ReactTestUtils
|
||||||
expect(sliderWithValue.state.lowerBound).to.be(50);
|
.scryRenderedDOMComponentsWithClass(rangeWithDefaultValue, 'rc-slider-track')[0]
|
||||||
expect(sliderWithValue.state.upperBound).to.be(100);
|
.style.cssText;
|
||||||
|
expect(trackStyle).to.match(/left: 0%;/);
|
||||||
|
expect(trackStyle).to.match(/width: 50%;/);
|
||||||
|
expect(trackStyle).to.match(/visibility: visible;/);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should render a Range with value correctly', () => {
|
||||||
|
const rangeWithValue = ReactDOM.render(<Slider range value={[50, 100]} />, div);
|
||||||
|
expect(rangeWithValue.state.lowerBound).to.be(50);
|
||||||
|
expect(rangeWithValue.state.upperBound).to.be(100);
|
||||||
expect(ReactTestUtils
|
expect(ReactTestUtils
|
||||||
.scryRenderedDOMComponentsWithClass(sliderWithDefaultValue, 'rc-slider-handle')[0]
|
.scryRenderedDOMComponentsWithClass(rangeWithValue, 'rc-slider-handle')[0]
|
||||||
.style.cssText)
|
.style.cssText)
|
||||||
.to.be('left: 100%; ');
|
.to.match(/left: 100%;/);
|
||||||
expect(ReactTestUtils
|
expect(ReactTestUtils
|
||||||
.scryRenderedDOMComponentsWithClass(sliderWithDefaultValue, 'rc-slider-handle')[1]
|
.scryRenderedDOMComponentsWithClass(rangeWithValue, 'rc-slider-handle')[1]
|
||||||
.style.cssText)
|
.style.cssText)
|
||||||
.to.be('left: 50%; ');
|
.to.match(/left: 50%;/);
|
||||||
expect(ReactTestUtils
|
|
||||||
.scryRenderedDOMComponentsWithClass(sliderWithDefaultValue, 'rc-slider-track')[0]
|
const trackStyle = ReactTestUtils
|
||||||
.style.cssText)
|
.scryRenderedDOMComponentsWithClass(rangeWithValue, 'rc-slider-track')[0]
|
||||||
.to.be('width: 50%; visibility: visible; left: 50%; ');
|
.style.cssText;
|
||||||
|
expect(trackStyle).to.match(/left: 50%;/);
|
||||||
|
expect(trackStyle).to.match(/width: 50%;/);
|
||||||
|
expect(trackStyle).to.match(/visibility: visible;/);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should render dots correctly when `dots=true`', () => {
|
it('should render dots correctly when `dots=true`', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user