Skip to content

Commit 92e321a

Browse files
authored
ColorSliderGroup - allow sending translation to the labels (#782)
* ColorSliderGroup - allow sending translation to the labels * Change to defaultProps * Fix name from getSlider to renderSlider
1 parent af1d1bd commit 92e321a

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

src/components/slider/ColorSliderGroup.js

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,24 @@ export default class ColorSliderGroup extends PureBaseComponent {
3232
*/
3333
sliderContainerStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.number, PropTypes.array]),
3434
/**
35-
* Show the sliders labels (Hue, Lightness, Saturation)
35+
* Show the sliders labels (defaults are: Hue, Lightness, Saturation)
3636
*/
3737
showLabels: PropTypes.bool,
38+
/**
39+
* In case you would like to change the default labels (translations etc.), you can provide
40+
* this prop with a map to the relevant labels ({hue: ..., lightness: ..., saturation: ...}).
41+
*/
42+
labels: PropTypes.object,
3843
/**
3944
* The labels style
4045
*/
4146
labelsStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.number, PropTypes.array])
4247
}
4348

49+
static defaultProps = {
50+
labels: {hue: 'Hue', lightness: 'Lightness', saturation: 'Saturation'}
51+
}
52+
4453
state = {
4554
initialColor: this.props.initialColor
4655
}
@@ -62,18 +71,29 @@ export default class ColorSliderGroup extends PureBaseComponent {
6271
_.invoke(this.props, 'onValueChange', value);
6372
}
6473

74+
renderSlider = (type) => {
75+
const {sliderContainerStyle, showLabels, labelsStyle, accessible, labels} = this.getThemeProps();
76+
return (
77+
<>
78+
{showLabels && (
79+
<Text dark30 text80 style={labelsStyle} accessible={accessible}>
80+
{labels[type]}
81+
</Text>
82+
)}
83+
<GradientSlider type={type} containerStyle={sliderContainerStyle} accessible={accessible}/>
84+
</>
85+
);
86+
};
87+
6588
render() {
66-
const {containerStyle, sliderContainerStyle, showLabels, labelsStyle, accessible} = this.props;
89+
const {containerStyle} = this.props;
6790
const {initialColor} = this.state;
6891

6992
return (
7093
<SliderGroup style={containerStyle} color={initialColor} onValueChange={this.onValueChange}>
71-
{showLabels && <Text dark30 text80 style={labelsStyle} accessible={accessible}>Hue</Text>}
72-
<GradientSlider type={GradientSlider.types.HUE} containerStyle={sliderContainerStyle} accessible={accessible}/>
73-
{showLabels && <Text dark30 text80 style={labelsStyle} accessible={accessible}>Lightness</Text>}
74-
<GradientSlider type={GradientSlider.types.LIGHTNESS} containerStyle={sliderContainerStyle} accessible={accessible}/>
75-
{showLabels && <Text dark30 text80 style={labelsStyle} accessible={accessible}>Saturation</Text>}
76-
<GradientSlider type={GradientSlider.types.SATURATION} containerStyle={sliderContainerStyle} accessible={accessible}/>
94+
{this.renderSlider(GradientSlider.types.HUE)}
95+
{this.renderSlider(GradientSlider.types.LIGHTNESS)}
96+
{this.renderSlider(GradientSlider.types.SATURATION)}
7797
</SliderGroup>
7898
);
7999
}

0 commit comments

Comments
 (0)