Compare commits

..
15 Commits
Author SHA1 Message Date
Benjy Cui 1adc68504a bump 3.7.0 2016-05-31 14:27:23 +08:00
Benjy Cui 01174f3cb0 Merge pull request #102 from elboman/custom-handle
Allow to pass custom handle components
2016-05-31 14:24:13 +08:00
Marco Botto 1ae39dd995 added custom handle API to docs 2016-05-30 12:16:53 +02:00
Marco Botto 0b4b546e03 changed API to from to 2016-05-30 12:08:52 +02:00
Marco Botto bc3883304d allow to pass custom handle components 2016-05-16 17:38:56 +02:00
Benjy Cui e2f9c508f3 Merge pull request #101 from nathandurand/master
Add license file
2016-05-06 12:05:19 +08:00
Nathan Durand ef5d136b14 Update license file 2016-05-06 06:53:38 +03:00
Nathan Durand f1637da046 Add license file 2016-05-05 16:41:49 +03:00
Benjy Cui ddcf32b094 bump 3.6.2 2016-04-28 09:35:21 +08:00
Boris Serdiuk 025a9e7ea6 Merge pull request #99 from react-component/fix-bugs
Fix #96 and #97
2016-04-27 15:08:48 +04:00
Benjy Cui e4396ae4bd refactor: simplify code 2016-04-27 17:48:17 +08:00
Benjy Cui 37b7f508da fix: use the latest step, close: #96 2016-04-27 14:29:45 +08:00
Benjy Cui ecbb253986 fix: set recent default value correctly, close: #97 2016-04-27 14:17:32 +08:00
Benjy Cui f4a82e3fd1 bump 3.6.1 2016-04-27 12:09:04 +08:00
Benjy Cui 0b1a421a71 chore: add warning for invalid usage, close: #91 2016-04-27 12:07:20 +08:00
8 changed files with 93 additions and 21 deletions
+20
View File
@@ -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.
+6
View File
@@ -130,6 +130,12 @@ ReactDOM.render(<Rcslider />, container);
<td></td>
<td>Set current positions of handles. If range is `false`, the type of `defaultValue` should be `number`. Otherwise, `[number, number]`</td>
</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>
<td>included</td>
<td>boolean</td>
+1
View File
@@ -0,0 +1 @@
placeholder
+44
View File
@@ -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
View File
@@ -95,7 +95,7 @@ ReactDOM.render(
</div>
<div style={style}>
<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 style={style}>
<p>Basic Range`step=20, dots` </p>
+3 -2
View File
@@ -1,6 +1,6 @@
{
"name": "rc-slider",
"version": "3.6.0",
"version": "3.7.0",
"description": "slider ui component for react",
"keywords": [
"react",
@@ -52,6 +52,7 @@
"dependencies": {
"classnames": "^2.2.1",
"rc-tooltip": "3.x",
"rc-util": "3.x"
"rc-util": "3.x",
"warning": "^2.1.0"
}
}
+16 -18
View File
@@ -1,8 +1,8 @@
import React from 'react';
import React, { cloneElement } from 'react';
import {Dom as DomUtils} from 'rc-util';
import classNames from 'classnames';
import Track from './Track';
import Handle from './Handle';
import DefaultHandle from './Handle';
import Steps from './Steps';
import Marks from './Marks';
@@ -46,12 +46,7 @@ class Slider extends React.Component {
let recent;
if (props.range && upperBound === lowerBound) {
if (lowerBound === max) {
recent = 'lowerBound';
}
if (upperBound === min) {
recent = 'upperBound';
}
recent = lowerBound === max ? 'lowerBound' : 'upperBound';
} else {
recent = 'upperBound';
}
@@ -240,9 +235,8 @@ class Slider extends React.Component {
return this.props.vertical ? rect.top : rect.left;
}
getPrecision() {
const props = this.props;
const stepString = props.step.toString();
getPrecision(step) {
const stepString = step.toString();
let precision = 0;
if (stepString.indexOf('.') >= 0) {
precision = stepString.length - stepString.indexOf('.') - 1;
@@ -282,7 +276,7 @@ class Slider extends React.Component {
const diffs = points.map((point) => Math.abs(val - point));
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) {
@@ -336,21 +330,23 @@ class Slider extends React.Component {
const {className, prefixCls, disabled, vertical, dots, included, range, step,
marks, max, min, tipTransitionName, tipFormatter, children} = this.props;
const customHandle = this.props.handle;
const upperOffset = this.calcOffset(upperBound);
const lowerOffset = this.calcOffset(lowerBound);
const handleClassName = prefixCls + '-handle';
const isNoTip = (step === null) || (tipFormatter === null);
const upper = (<Handle className={handleClassName}
noTip={isNoTip} tipTransitionName={tipTransitionName} tipFormatter={tipFormatter}
vertical = {vertical} offset={upperOffset} value={upperBound} dragging={handle === 'upperBound'}/>);
const upper = cloneElement(customHandle, { className: handleClassName,
noTip: isNoTip, tipTransitionName: tipTransitionName, tipFormatter: tipFormatter,
vertical: vertical, offset: upperOffset, value: upperBound, dragging: handle === 'upperBound' });
let lower = null;
if (range) {
lower = (<Handle className={handleClassName}
noTip={isNoTip} tipTransitionName={tipTransitionName} tipFormatter={tipFormatter}
vertical = {vertical} offset={lowerOffset} value={lowerBound} dragging={handle === 'lowerBound'}/>);
lower = cloneElement(customHandle, { className: handleClassName,
noTip: isNoTip, tipTransitionName: tipTransitionName, tipFormatter: tipFormatter,
vertical: vertical, offset: lowerOffset, value: lowerBound, dragging: handle === 'lowerBound' });
}
const sliderClassName = classNames({
@@ -401,6 +397,7 @@ Slider.propTypes = {
onBeforeChange: React.PropTypes.func,
onChange: React.PropTypes.func,
onAfterChange: React.PropTypes.func,
handle: React.PropTypes.element,
tipTransitionName: React.PropTypes.string,
tipFormatter: React.PropTypes.func,
dots: React.PropTypes.bool,
@@ -417,6 +414,7 @@ Slider.defaultProps = {
max: 100,
step: 1,
marks: {},
handle: <DefaultHandle />,
onBeforeChange: noop,
onChange: noop,
onAfterChange: noop,
+2
View File
@@ -1,7 +1,9 @@
import React from 'react';
import classNames from 'classnames';
import warning from 'warning';
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);
if (dots) {
for (let i = min; i <= max; i = i + step) {