Skip to content

ColorSliderGroup - allow sending translation to the labels #782

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 25, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions src/components/slider/ColorSliderGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,24 @@ export default class ColorSliderGroup extends PureBaseComponent {
*/
sliderContainerStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.number, PropTypes.array]),
/**
* Show the sliders labels (Hue, Lightness, Saturation)
* Show the sliders labels (defaults are: Hue, Lightness, Saturation)
*/
showLabels: PropTypes.bool,
/**
* In case you would like to change the default labels (translations etc.), you can provide
* this prop with a map to the relevant labels ({hue: ..., lightness: ..., saturation: ...}).
*/
labels: PropTypes.object,
/**
* The labels style
*/
labelsStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.number, PropTypes.array])
}

static defaultProps = {
labels: {hue: 'Hue', lightness: 'Lightness', saturation: 'Saturation'}
}

state = {
initialColor: this.props.initialColor
}
Expand All @@ -62,18 +71,29 @@ export default class ColorSliderGroup extends PureBaseComponent {
_.invoke(this.props, 'onValueChange', value);
}

renderSlider = (type) => {
const {sliderContainerStyle, showLabels, labelsStyle, accessible, labels} = this.getThemeProps();
return (
<>
{showLabels && (
<Text dark30 text80 style={labelsStyle} accessible={accessible}>
{labels[type]}
</Text>
)}
<GradientSlider type={type} containerStyle={sliderContainerStyle} accessible={accessible}/>
</>
);
};

render() {
const {containerStyle, sliderContainerStyle, showLabels, labelsStyle, accessible} = this.props;
const {containerStyle} = this.props;
const {initialColor} = this.state;

return (
<SliderGroup style={containerStyle} color={initialColor} onValueChange={this.onValueChange}>
{showLabels && <Text dark30 text80 style={labelsStyle} accessible={accessible}>Hue</Text>}
<GradientSlider type={GradientSlider.types.HUE} containerStyle={sliderContainerStyle} accessible={accessible}/>
{showLabels && <Text dark30 text80 style={labelsStyle} accessible={accessible}>Lightness</Text>}
<GradientSlider type={GradientSlider.types.LIGHTNESS} containerStyle={sliderContainerStyle} accessible={accessible}/>
{showLabels && <Text dark30 text80 style={labelsStyle} accessible={accessible}>Saturation</Text>}
<GradientSlider type={GradientSlider.types.SATURATION} containerStyle={sliderContainerStyle} accessible={accessible}/>
{this.renderSlider(GradientSlider.types.HUE)}
{this.renderSlider(GradientSlider.types.LIGHTNESS)}
{this.renderSlider(GradientSlider.types.SATURATION)}
</SliderGroup>
);
}
Expand Down