mirror of
https://github.com/wassname/slider.git
synced 2026-09-11 12:42:49 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f850dab6c4 | ||
|
|
f3c1d4bd3d | ||
|
|
4d795b01cc | ||
|
|
959007ed30 | ||
|
|
079469b765 | ||
|
|
ddb2bf670b | ||
|
|
4c57f3ecca | ||
|
|
24f3b755b2 | ||
|
|
867e252631 | ||
|
|
39de81dfa9 |
@@ -144,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>
|
||||||
|
|||||||
+2
-1
@@ -10,6 +10,7 @@ const marks = {
|
|||||||
0: '0°C',
|
0: '0°C',
|
||||||
26: '26°C',
|
26: '26°C',
|
||||||
37: '37°C',
|
37: '37°C',
|
||||||
|
50: '50°C',
|
||||||
100: '100°C',
|
100: '100°C',
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -25,7 +26,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}>
|
||||||
|
|||||||
@@ -86,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} />
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "rc-slider",
|
"name": "rc-slider",
|
||||||
"version": "3.2.0",
|
"version": "3.3.1",
|
||||||
"description": "slider ui component for react",
|
"description": "slider ui component for react",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"react",
|
"react",
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+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}
|
||||||
|
|||||||
+2
-1
@@ -339,7 +339,7 @@ class Slider extends React.Component {
|
|||||||
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}
|
||||||
@@ -417,6 +417,7 @@ 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,
|
||||||
|
|||||||
+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