feat: support set style of specific mark point

This commit is contained in:
Benjy Cui
2016-03-17 09:45:55 +08:00
parent 0512ee6ee0
commit d6e81a692c
3 changed files with 15 additions and 5 deletions
+2 -2
View File
@@ -90,9 +90,9 @@ ReactDOM.render(<Rcslider />, container);
</tr>
<tr>
<td>marks</td>
<td>object {number: string}</td>
<td>object{number: string} or object{number: object{ style, label }}</td>
<td>{}</td>
<td>Mark on the slider. The key determines the position, and the value determines what will show.</td>
<td>Mark on the slider. The key determines the position, and the value determines what will show. If you want to set the style of a specific mark point, the value should be an object which contains `style` and `label` properties.</td>
</tr>
<tr>
<td>step</td>
+6 -1
View File
@@ -11,7 +11,12 @@ const marks = {
26: '26°C',
37: '37°C',
50: '50°C',
100: '100°C',
100: {
style: {
color: 'red',
},
label: '100°C',
},
};
function log(value) {
+7 -2
View File
@@ -19,8 +19,13 @@ const Marks = ({className, marks, included, upperBound, lowerBound, max, min}) =
const style = { width: markWidth + '%' };
style.left = (point - min) / range * 100 - markWidth / 2 + '%';
return (<span className={markClassName} style={style} key={point}>
{marks[point]}
const markPoint = marks[point];
const markPointIsObject = typeof markPoint === 'object';
const markLabel = markPointIsObject ? markPoint.label : markPoint;
const markStyle = markPointIsObject ?
{ ...style, ...markPoint.style } : style;
return (<span className={markClassName} style={markStyle} key={point}>
{markLabel}
</span>);
});