Skip to content

Commit

Permalink
Merge pull request #243 from react-component/support-color
Browse files Browse the repository at this point in the history
feature: support minimumTrackTintColor & maximumTrackTintColor
  • Loading branch information
paranoidjk committed Mar 22, 2017
2 parents 0017ed4 + 786cd86 commit 3c7ce8f
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ The following APIs are shared by Slider and Range.
| onBeforeChange | Function | NOOP | `onBeforeChange` will be triggered when `ontouchstart` or `onmousedown` is triggered. |
| onChange | Function | NOOP | `onChange` will be triggered while the value of Slider changing. |
| onAfterChange | Function | NOOP | `onAfterChange` will be triggered when `ontouchend` or `onmouseup` is triggered. |
| minimumTrackTintColor | String | | The color used for the track to the left of the button. |
| maximumTrackTintColor | String | | The color used for the track to the right of the button. |

### Slider

Expand Down
2 changes: 1 addition & 1 deletion examples/handle.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
placeholder
placeholder
10 changes: 8 additions & 2 deletions src/Handle.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ import React, { PropTypes } from 'react';

export default class Handle extends React.Component {
render() {
const { className, vertical, offset, ...restProps } = this.props;

const {
className, vertical, offset, maximumTrackTintColor, disabled, ...restProps,
} = this.props;
const style = vertical ? { bottom: `${offset}%` } : { left: `${offset}%` };
if (maximumTrackTintColor && !disabled) {
style.borderColor = maximumTrackTintColor;
}
return <div {...restProps} className={className} style={style} />;
}
}
Expand All @@ -13,4 +17,6 @@ Handle.propTypes = {
className: PropTypes.string,
vertical: PropTypes.bool,
offset: PropTypes.number,
maximumTrackTintColor: PropTypes.string,
disabled: PropTypes.bool,
};
4 changes: 4 additions & 0 deletions src/Slider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class Slider extends React.Component {
vertical,
included,
disabled,
maximumTrackTintColor,
handle: handleGenerator,
} = this.props;
const { value, dragging } = this.state;
Expand All @@ -120,6 +121,7 @@ class Slider extends React.Component {
value,
dragging,
disabled,
maximumTrackTintColor,
ref: h => this.saveHandle(0, h),
});
const track = (
Expand All @@ -128,7 +130,9 @@ class Slider extends React.Component {
vertical={vertical}
included={included}
offset={0}
disabled={disabled}
length={offset}
maximumTrackTintColor={maximumTrackTintColor}
/>
);

Expand Down
7 changes: 6 additions & 1 deletion src/common/Track.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';

const Track = ({ className, included, vertical, offset, length }) => {
const Track = ({
className, included, vertical, offset, length, maximumTrackTintColor, disabled,
}) => {
const style = {
visibility: included ? 'visible' : 'hidden',
};
Expand All @@ -11,6 +13,9 @@ const Track = ({ className, included, vertical, offset, length }) => {
style.left = `${offset}%`;
style.width = `${length}%`;
}
if (maximumTrackTintColor && !disabled) {
style.backgroundColor = maximumTrackTintColor;
}
return <div className={className} style={style} />;
};

Expand Down
9 changes: 8 additions & 1 deletion src/common/createSlider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export default function createSlider(Component) {
dots: PropTypes.bool,
vertical: PropTypes.bool,
style: PropTypes.object,
minimumTrackTintColor: PropTypes.string,
};

static defaultProps = {
Expand Down Expand Up @@ -206,6 +207,7 @@ export default function createSlider(Component) {
min,
max,
children,
minimumTrackTintColor,
style,
} = this.props;
const { tracks, handles } = super.render();
Expand All @@ -217,6 +219,11 @@ export default function createSlider(Component) {
[`${prefixCls}-vertical`]: vertical,
[className]: className,
});

const trackStyle = minimumTrackTintColor && !disabled ? {
backgroundColor: minimumTrackTintColor,
} : {};

return (
<div
ref={this.saveSlider}
Expand All @@ -225,7 +232,7 @@ export default function createSlider(Component) {
onMouseDown={disabled ? noop : this.onMouseDown}
style={style}
>
<div className={`${prefixCls}-rail`} />
<div className={`${prefixCls}-rail`} style={trackStyle} />
{tracks}
<Steps
prefixCls={prefixCls}
Expand Down

0 comments on commit 3c7ce8f

Please sign in to comment.