mirror of
https://github.com/wassname/slider.git
synced 2026-09-10 12:38:09 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
80d4ee4794 | ||
|
|
e2504d99fe | ||
|
|
d4ae5a5298 | ||
|
|
ce755ecb4b | ||
|
|
9bc56e993d | ||
|
|
1e34b94d86 | ||
|
|
a678437462 | ||
|
|
a4c06c2509 | ||
|
|
ff9e68cd36 | ||
|
|
1adc68504a | ||
|
|
01174f3cb0 | ||
|
|
1ae39dd995 | ||
|
|
0b4b546e03 | ||
|
|
bc3883304d | ||
|
|
e2f9c508f3 | ||
|
|
ef5d136b14 | ||
|
|
f1637da046 | ||
|
|
ddcf32b094 | ||
|
|
025a9e7ea6 | ||
|
|
e4396ae4bd | ||
|
|
37b7f508da | ||
|
|
ecbb253986 | ||
|
|
f4a82e3fd1 | ||
|
|
0b1a421a71 |
@@ -0,0 +1,20 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
Copyright (c) 2015-present Alipay.com, https://www.alipay.com/
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||||
|
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
|
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||||
|
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||||
|
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||||
|
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
@@ -130,6 +130,12 @@ ReactDOM.render(<Rcslider />, container);
|
|||||||
<td></td>
|
<td></td>
|
||||||
<td>Set current positions of handles. If range is `false`, the type of `defaultValue` should be `number`. Otherwise, `[number, number]`</td>
|
<td>Set current positions of handles. If range is `false`, the type of `defaultValue` should be `number`. Otherwise, `[number, number]`</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>handle</td>
|
||||||
|
<td>Component</td>
|
||||||
|
<td></td>
|
||||||
|
<td>Provide a custom Handle to use in the slider by passing a component. This component will have a `value` and `offset` props used to define custom styling/content.</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>included</td>
|
<td>included</td>
|
||||||
<td>boolean</td>
|
<td>boolean</td>
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
placeholder
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
require('rc-slider/assets/index.less');
|
||||||
|
|
||||||
|
const React = require('react');
|
||||||
|
const ReactDOM = require('react-dom');
|
||||||
|
const Slider = require('rc-slider');
|
||||||
|
|
||||||
|
const wrapperStyle = {width: 400, margin: 50};
|
||||||
|
|
||||||
|
const handleStyle = {
|
||||||
|
position: 'absolute',
|
||||||
|
transform: 'translate(-50%, -50%)',
|
||||||
|
cursor: 'pointer',
|
||||||
|
padding: '2px',
|
||||||
|
border: '2px solid #abe2fb',
|
||||||
|
borderRadius: '3px',
|
||||||
|
background: '#fff',
|
||||||
|
fontSize: '14px',
|
||||||
|
textAlign: 'center',
|
||||||
|
zIndex: 3,
|
||||||
|
};
|
||||||
|
|
||||||
|
const CustomHandle = props => {
|
||||||
|
const style = Object.assign({left: props.offset + '%'}, handleStyle);
|
||||||
|
return (
|
||||||
|
<div style={style}>val: {props.value}</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
CustomHandle.propTypes = {
|
||||||
|
value: React.PropTypes.any,
|
||||||
|
offset: React.PropTypes.number,
|
||||||
|
};
|
||||||
|
|
||||||
|
ReactDOM.render(
|
||||||
|
<div>
|
||||||
|
<div style={wrapperStyle}>
|
||||||
|
<p>Default slider</p>
|
||||||
|
<Slider min={0} max={20} defaultValue={3} />
|
||||||
|
</div>
|
||||||
|
<div style={wrapperStyle}>
|
||||||
|
<p>Slider with custom handle</p>
|
||||||
|
<Slider min={0} max={20} defaultValue={3} handle={<CustomHandle />} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
, document.getElementById('__react-content'));
|
||||||
+1
-1
@@ -95,7 +95,7 @@ ReactDOM.render(
|
|||||||
</div>
|
</div>
|
||||||
<div style={style}>
|
<div style={style}>
|
||||||
<p>Basic Range,`step=20` </p>
|
<p>Basic Range,`step=20` </p>
|
||||||
<Slider range step={20} defaultValue={[20, 40]} onBeforeChange={log} />
|
<Slider range step={20} defaultValue={[20, 20]} onBeforeChange={log} />
|
||||||
</div>
|
</div>
|
||||||
<div style={style}>
|
<div style={style}>
|
||||||
<p>Basic Range,`step=20, dots` </p>
|
<p>Basic Range,`step=20, dots` </p>
|
||||||
|
|||||||
+4
-1
@@ -28,8 +28,11 @@ const CustomizedSlider = React.createClass({
|
|||||||
value: value,
|
value: value,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
onAfterChange: function(value) {
|
||||||
|
console.log(value);
|
||||||
|
},
|
||||||
render: function() {
|
render: function() {
|
||||||
return <Slider value={this.state.value} onChange={this.onSliderChange} />;
|
return <Slider value={this.state.value} onChange={this.onSliderChange} onAfterChange={this.onAfterChange} />;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+8
-7
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "rc-slider",
|
"name": "rc-slider",
|
||||||
"version": "3.6.0",
|
"version": "3.7.4",
|
||||||
"description": "slider ui component for react",
|
"description": "slider ui component for react",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"react",
|
"react",
|
||||||
@@ -42,16 +42,17 @@
|
|||||||
"pre-commit": "1.x",
|
"pre-commit": "1.x",
|
||||||
"rc-server": "3.x",
|
"rc-server": "3.x",
|
||||||
"rc-tools": "4.x",
|
"rc-tools": "4.x",
|
||||||
"react": "~0.14.0",
|
"react": "^15.2.1",
|
||||||
"react-addons-test-utils": "^0.14.0",
|
"react-addons-test-utils": "^15.2.1",
|
||||||
"react-dom": "~0.14.0"
|
"react-dom": "^15.2.1"
|
||||||
},
|
},
|
||||||
"pre-commit": [
|
"pre-commit": [
|
||||||
"lint"
|
"lint"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"classnames": "^2.2.1",
|
"classnames": "^2.2.5",
|
||||||
"rc-tooltip": "3.x",
|
"rc-tooltip": "^3.4.2",
|
||||||
"rc-util": "3.x"
|
"rc-util": "^3.2.1",
|
||||||
|
"warning": "^3.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+23
-24
@@ -1,8 +1,8 @@
|
|||||||
import React from 'react';
|
import React, { cloneElement } from 'react';
|
||||||
import {Dom as DomUtils} from 'rc-util';
|
import addEventListener from 'rc-util/lib/Dom/addEventListener';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import Track from './Track';
|
import Track from './Track';
|
||||||
import Handle from './Handle';
|
import DefaultHandle from './Handle';
|
||||||
import Steps from './Steps';
|
import Steps from './Steps';
|
||||||
import Marks from './Marks';
|
import Marks from './Marks';
|
||||||
|
|
||||||
@@ -46,12 +46,7 @@ class Slider extends React.Component {
|
|||||||
|
|
||||||
let recent;
|
let recent;
|
||||||
if (props.range && upperBound === lowerBound) {
|
if (props.range && upperBound === lowerBound) {
|
||||||
if (lowerBound === max) {
|
recent = lowerBound === max ? 'lowerBound' : 'upperBound';
|
||||||
recent = 'lowerBound';
|
|
||||||
}
|
|
||||||
if (upperBound === min) {
|
|
||||||
recent = 'upperBound';
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
recent = 'upperBound';
|
recent = 'upperBound';
|
||||||
}
|
}
|
||||||
@@ -172,6 +167,7 @@ class Slider extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onMouseDown(e) {
|
onMouseDown(e) {
|
||||||
|
if (e.button !== 0) { return; }
|
||||||
const position = getMousePosition(this.props.vertical, e);
|
const position = getMousePosition(this.props.vertical, e);
|
||||||
this.onStart(position);
|
this.onStart(position);
|
||||||
this.addDocumentEvents('mouse');
|
this.addDocumentEvents('mouse');
|
||||||
@@ -240,9 +236,8 @@ class Slider extends React.Component {
|
|||||||
return this.props.vertical ? rect.top : rect.left;
|
return this.props.vertical ? rect.top : rect.left;
|
||||||
}
|
}
|
||||||
|
|
||||||
getPrecision() {
|
getPrecision(step) {
|
||||||
const props = this.props;
|
const stepString = step.toString();
|
||||||
const stepString = props.step.toString();
|
|
||||||
let precision = 0;
|
let precision = 0;
|
||||||
if (stepString.indexOf('.') >= 0) {
|
if (stepString.indexOf('.') >= 0) {
|
||||||
precision = stepString.length - stepString.indexOf('.') - 1;
|
precision = stepString.length - stepString.indexOf('.') - 1;
|
||||||
@@ -275,14 +270,14 @@ class Slider extends React.Component {
|
|||||||
|
|
||||||
const points = Object.keys(marks).map(parseFloat);
|
const points = Object.keys(marks).map(parseFloat);
|
||||||
if (step !== null) {
|
if (step !== null) {
|
||||||
const closestStep = Math.round(val / step) * step;
|
const closestStep = (Math.round((val - min) / step) * step) + min;
|
||||||
points.push(closestStep);
|
points.push(closestStep);
|
||||||
}
|
}
|
||||||
|
|
||||||
const diffs = points.map((point) => Math.abs(val - point));
|
const diffs = points.map((point) => Math.abs(val - point));
|
||||||
const closestPoint = points[diffs.indexOf(Math.min.apply(Math, diffs))];
|
const closestPoint = points[diffs.indexOf(Math.min.apply(Math, diffs))];
|
||||||
|
|
||||||
return step !== null ? parseFloat(closestPoint.toFixed(this.getPrecision())) : closestPoint;
|
return step !== null ? parseFloat(closestPoint.toFixed(this.getPrecision(step))) : closestPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
calcOffset(value) {
|
calcOffset(value) {
|
||||||
@@ -307,11 +302,11 @@ class Slider extends React.Component {
|
|||||||
addDocumentEvents(type) {
|
addDocumentEvents(type) {
|
||||||
if (type === 'touch') {
|
if (type === 'touch') {
|
||||||
// just work for chrome iOS Safari and Android Browser
|
// just work for chrome iOS Safari and Android Browser
|
||||||
this.onTouchMoveListener = DomUtils.addEventListener(document, 'touchmove', this.onTouchMove.bind(this));
|
this.onTouchMoveListener = addEventListener(document, 'touchmove', this.onTouchMove.bind(this));
|
||||||
this.onTouchUpListener = DomUtils.addEventListener(document, 'touchend', this.end.bind(this, 'touch'));
|
this.onTouchUpListener = addEventListener(document, 'touchend', this.end.bind(this, 'touch'));
|
||||||
} else if (type === 'mouse') {
|
} else if (type === 'mouse') {
|
||||||
this.onMouseMoveListener = DomUtils.addEventListener(document, 'mousemove', this.onMouseMove.bind(this));
|
this.onMouseMoveListener = addEventListener(document, 'mousemove', this.onMouseMove.bind(this));
|
||||||
this.onMouseUpListener = DomUtils.addEventListener(document, 'mouseup', this.end.bind(this, 'mouse'));
|
this.onMouseUpListener = addEventListener(document, 'mouseup', this.end.bind(this, 'mouse'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -336,21 +331,23 @@ class Slider extends React.Component {
|
|||||||
const {className, prefixCls, disabled, vertical, dots, included, range, step,
|
const {className, prefixCls, disabled, vertical, dots, included, range, step,
|
||||||
marks, max, min, tipTransitionName, tipFormatter, children} = this.props;
|
marks, max, min, tipTransitionName, tipFormatter, children} = this.props;
|
||||||
|
|
||||||
|
const customHandle = this.props.handle;
|
||||||
|
|
||||||
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 === null);
|
const isNoTip = (step === null) || (tipFormatter === null);
|
||||||
|
|
||||||
const upper = (<Handle className={handleClassName}
|
const upper = cloneElement(customHandle, { className: handleClassName,
|
||||||
noTip={isNoTip} tipTransitionName={tipTransitionName} tipFormatter={tipFormatter}
|
noTip: isNoTip, tipTransitionName: tipTransitionName, tipFormatter: tipFormatter,
|
||||||
vertical = {vertical} offset={upperOffset} value={upperBound} dragging={handle === 'upperBound'}/>);
|
vertical: vertical, offset: upperOffset, value: upperBound, dragging: handle === 'upperBound' });
|
||||||
|
|
||||||
let lower = null;
|
let lower = null;
|
||||||
if (range) {
|
if (range) {
|
||||||
lower = (<Handle className={handleClassName}
|
lower = cloneElement(customHandle, { className: handleClassName,
|
||||||
noTip={isNoTip} tipTransitionName={tipTransitionName} tipFormatter={tipFormatter}
|
noTip: isNoTip, tipTransitionName: tipTransitionName, tipFormatter: tipFormatter,
|
||||||
vertical = {vertical} offset={lowerOffset} value={lowerBound} dragging={handle === 'lowerBound'}/>);
|
vertical: vertical, offset: lowerOffset, value: lowerBound, dragging: handle === 'lowerBound' });
|
||||||
}
|
}
|
||||||
|
|
||||||
const sliderClassName = classNames({
|
const sliderClassName = classNames({
|
||||||
@@ -401,6 +398,7 @@ Slider.propTypes = {
|
|||||||
onBeforeChange: React.PropTypes.func,
|
onBeforeChange: React.PropTypes.func,
|
||||||
onChange: React.PropTypes.func,
|
onChange: React.PropTypes.func,
|
||||||
onAfterChange: React.PropTypes.func,
|
onAfterChange: React.PropTypes.func,
|
||||||
|
handle: React.PropTypes.element,
|
||||||
tipTransitionName: React.PropTypes.string,
|
tipTransitionName: React.PropTypes.string,
|
||||||
tipFormatter: React.PropTypes.func,
|
tipFormatter: React.PropTypes.func,
|
||||||
dots: React.PropTypes.bool,
|
dots: React.PropTypes.bool,
|
||||||
@@ -417,6 +415,7 @@ Slider.defaultProps = {
|
|||||||
max: 100,
|
max: 100,
|
||||||
step: 1,
|
step: 1,
|
||||||
marks: {},
|
marks: {},
|
||||||
|
handle: <DefaultHandle />,
|
||||||
onBeforeChange: noop,
|
onBeforeChange: noop,
|
||||||
onChange: noop,
|
onChange: noop,
|
||||||
onAfterChange: noop,
|
onAfterChange: noop,
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
|
import warning from 'warning';
|
||||||
|
|
||||||
function calcPoints(vertical, marks, dots, step, min, max) {
|
function calcPoints(vertical, marks, dots, step, min, max) {
|
||||||
|
warning(dots ? step > 0 : true, '`Slider[step]` should be a positive number in order to make Slider[dots] work.');
|
||||||
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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user