diff --git a/README.md b/README.md
index 0b7791c..a2bc5c3 100644
--- a/README.md
+++ b/README.md
@@ -130,6 +130,12 @@ ReactDOM.render(, container);
|
Set current positions of handles. If range is `false`, the type of `defaultValue` should be `number`. Otherwise, `[number, number]` |
+
+ | handle |
+ Component |
+ |
+ 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. |
+
| included |
boolean |
diff --git a/examples/custom-handles.html b/examples/custom-handles.html
new file mode 100644
index 0000000..b3a4252
--- /dev/null
+++ b/examples/custom-handles.html
@@ -0,0 +1 @@
+placeholder
\ No newline at end of file
diff --git a/examples/custom-handles.js b/examples/custom-handles.js
new file mode 100644
index 0000000..136fefb
--- /dev/null
+++ b/examples/custom-handles.js
@@ -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 (
+ val: {props.value}
+ );
+};
+CustomHandle.propTypes = {
+ value: React.PropTypes.any,
+ offset: React.PropTypes.number,
+};
+
+ReactDOM.render(
+
+
+
+
Slider with custom handle
+
} />
+
+
+ , document.getElementById('__react-content'));
diff --git a/src/Slider.jsx b/src/Slider.jsx
index 22919bc..d6a2c64 100644
--- a/src/Slider.jsx
+++ b/src/Slider.jsx
@@ -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';
@@ -330,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 = ();
+ 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 = ();
+ lower = cloneElement(customHandle, { className: handleClassName,
+ noTip: isNoTip, tipTransitionName: tipTransitionName, tipFormatter: tipFormatter,
+ vertical: vertical, offset: lowerOffset, value: lowerBound, dragging: handle === 'lowerBound' });
}
const sliderClassName = classNames({
@@ -395,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,
@@ -411,6 +414,7 @@ Slider.defaultProps = {
max: 100,
step: 1,
marks: {},
+ handle: ,
onBeforeChange: noop,
onChange: noop,
onAfterChange: noop,