Skip to content

Commit 3c7ce8f

Browse files
authored
Merge pull request #243 from react-component/support-color
feature: support minimumTrackTintColor & maximumTrackTintColor
2 parents 0017ed4 + 786cd86 commit 3c7ce8f

File tree

6 files changed

+29
-5
lines changed

6 files changed

+29
-5
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ The following APIs are shared by Slider and Range.
105105
| onBeforeChange | Function | NOOP | `onBeforeChange` will be triggered when `ontouchstart` or `onmousedown` is triggered. |
106106
| onChange | Function | NOOP | `onChange` will be triggered while the value of Slider changing. |
107107
| onAfterChange | Function | NOOP | `onAfterChange` will be triggered when `ontouchend` or `onmouseup` is triggered. |
108+
| minimumTrackTintColor | String | | The color used for the track to the left of the button. |
109+
| maximumTrackTintColor | String | | The color used for the track to the right of the button. |
108110

109111
### Slider
110112

examples/handle.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
placeholder
1+
placeholder

src/Handle.jsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ import React, { PropTypes } from 'react';
22

33
export default class Handle extends React.Component {
44
render() {
5-
const { className, vertical, offset, ...restProps } = this.props;
6-
5+
const {
6+
className, vertical, offset, maximumTrackTintColor, disabled, ...restProps,
7+
} = this.props;
78
const style = vertical ? { bottom: `${offset}%` } : { left: `${offset}%` };
9+
if (maximumTrackTintColor && !disabled) {
10+
style.borderColor = maximumTrackTintColor;
11+
}
812
return <div {...restProps} className={className} style={style} />;
913
}
1014
}
@@ -13,4 +17,6 @@ Handle.propTypes = {
1317
className: PropTypes.string,
1418
vertical: PropTypes.bool,
1519
offset: PropTypes.number,
20+
maximumTrackTintColor: PropTypes.string,
21+
disabled: PropTypes.bool,
1622
};

src/Slider.jsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ class Slider extends React.Component {
109109
vertical,
110110
included,
111111
disabled,
112+
maximumTrackTintColor,
112113
handle: handleGenerator,
113114
} = this.props;
114115
const { value, dragging } = this.state;
@@ -120,6 +121,7 @@ class Slider extends React.Component {
120121
value,
121122
dragging,
122123
disabled,
124+
maximumTrackTintColor,
123125
ref: h => this.saveHandle(0, h),
124126
});
125127
const track = (
@@ -128,7 +130,9 @@ class Slider extends React.Component {
128130
vertical={vertical}
129131
included={included}
130132
offset={0}
133+
disabled={disabled}
131134
length={offset}
135+
maximumTrackTintColor={maximumTrackTintColor}
132136
/>
133137
);
134138

src/common/Track.jsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import React from 'react';
22

3-
const Track = ({ className, included, vertical, offset, length }) => {
3+
const Track = ({
4+
className, included, vertical, offset, length, maximumTrackTintColor, disabled,
5+
}) => {
46
const style = {
57
visibility: included ? 'visible' : 'hidden',
68
};
@@ -11,6 +13,9 @@ const Track = ({ className, included, vertical, offset, length }) => {
1113
style.left = `${offset}%`;
1214
style.width = `${length}%`;
1315
}
16+
if (maximumTrackTintColor && !disabled) {
17+
style.backgroundColor = maximumTrackTintColor;
18+
}
1419
return <div className={className} style={style} />;
1520
};
1621

src/common/createSlider.jsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export default function createSlider(Component) {
3030
dots: PropTypes.bool,
3131
vertical: PropTypes.bool,
3232
style: PropTypes.object,
33+
minimumTrackTintColor: PropTypes.string,
3334
};
3435

3536
static defaultProps = {
@@ -206,6 +207,7 @@ export default function createSlider(Component) {
206207
min,
207208
max,
208209
children,
210+
minimumTrackTintColor,
209211
style,
210212
} = this.props;
211213
const { tracks, handles } = super.render();
@@ -217,6 +219,11 @@ export default function createSlider(Component) {
217219
[`${prefixCls}-vertical`]: vertical,
218220
[className]: className,
219221
});
222+
223+
const trackStyle = minimumTrackTintColor && !disabled ? {
224+
backgroundColor: minimumTrackTintColor,
225+
} : {};
226+
220227
return (
221228
<div
222229
ref={this.saveSlider}
@@ -225,7 +232,7 @@ export default function createSlider(Component) {
225232
onMouseDown={disabled ? noop : this.onMouseDown}
226233
style={style}
227234
>
228-
<div className={`${prefixCls}-rail`} />
235+
<div className={`${prefixCls}-rail`} style={trackStyle} />
229236
{tracks}
230237
<Steps
231238
prefixCls={prefixCls}

0 commit comments

Comments
 (0)