@@ -32,15 +32,24 @@ export default class ColorSliderGroup extends PureBaseComponent {
32
32
*/
33
33
sliderContainerStyle : PropTypes . oneOfType ( [ PropTypes . object , PropTypes . number , PropTypes . array ] ) ,
34
34
/**
35
- * Show the sliders labels (Hue, Lightness, Saturation)
35
+ * Show the sliders labels (defaults are: Hue, Lightness, Saturation)
36
36
*/
37
37
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 ,
38
43
/**
39
44
* The labels style
40
45
*/
41
46
labelsStyle : PropTypes . oneOfType ( [ PropTypes . object , PropTypes . number , PropTypes . array ] )
42
47
}
43
48
49
+ static defaultProps = {
50
+ labels : { hue : 'Hue' , lightness : 'Lightness' , saturation : 'Saturation' }
51
+ }
52
+
44
53
state = {
45
54
initialColor : this . props . initialColor
46
55
}
@@ -62,18 +71,29 @@ export default class ColorSliderGroup extends PureBaseComponent {
62
71
_ . invoke ( this . props , 'onValueChange' , value ) ;
63
72
}
64
73
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
+
65
88
render ( ) {
66
- const { containerStyle, sliderContainerStyle , showLabels , labelsStyle , accessible } = this . props ;
89
+ const { containerStyle} = this . props ;
67
90
const { initialColor} = this . state ;
68
91
69
92
return (
70
93
< 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 ) }
77
97
</ SliderGroup >
78
98
) ;
79
99
}
0 commit comments