Skip to content

Commit d5efd35

Browse files
authored
Feat/ColorPicker - preview text style prop (#804)
* Added preview text style prop * Added style override to preview's input * previewInputStyle
1 parent eecc7c0 commit d5efd35

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

src/components/colorPicker/index.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ export default class ColorPicker extends PureBaseComponent {
6262
* Props to pass the Dialog component
6363
*/
6464
dialogProps: PropTypes.object,
65+
/**
66+
* Additional styling for the color preview text.
67+
*/
68+
previewInputStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.number, PropTypes.array]),
6569
/**
6670
* Accessibility labels as an object of strings, ex. {addButton: 'add custom color using hex code', dismissButton: 'dismiss', doneButton: 'done', input: 'custom hex color code'}
6771
*/
@@ -109,7 +113,7 @@ export default class ColorPicker extends PureBaseComponent {
109113
const text = this.getColorValue(nextProps.initialColor || this.props.initialColor);
110114
const color = Colors.getHSL(nextProps.initialColor);
111115
const {valid} = this.getValidColorString(text);
112-
116+
113117
this.setState({color, text, valid});
114118
}
115119
}
@@ -185,7 +189,7 @@ export default class ColorPicker extends PureBaseComponent {
185189

186190
getValidColorString(text) {
187191
const hex = this.getHexColor(text);
188-
192+
189193
if (Colors.isValidHex(hex)) {
190194
return {hex, valid: true};
191195
}
@@ -212,7 +216,7 @@ export default class ColorPicker extends PureBaseComponent {
212216
const color = Colors.getHSL(this.props.initialColor);
213217
const text = this.getColorValue(this.props.initialColor);
214218
const {valid} = this.getValidColorString(text);
215-
219+
216220
this.setState({
217221
show: false,
218222
color,
@@ -275,8 +279,8 @@ export default class ColorPicker extends PureBaseComponent {
275279
const colorValue = color.a === 0 ? Colors.black : Colors.getHexString(color);
276280

277281
return (
278-
<ColorSliderGroup
279-
initialColor={colorValue}
282+
<ColorSliderGroup
283+
initialColor={colorValue}
280284
containerStyle={[this.styles.sliderGroup, {height: keyboardHeight}]}
281285
sliderContainerStyle={this.styles.slider}
282286
showLabels
@@ -288,7 +292,7 @@ export default class ColorPicker extends PureBaseComponent {
288292
}
289293

290294
renderPreview() {
291-
const {accessibilityLabels} = this.getThemeProps();
295+
const {accessibilityLabels, previewInputStyle} = this.getThemeProps();
292296
const {color, text} = this.state;
293297
const hex = this.getHexString(color);
294298
const textColor = this.getTextColor(hex);
@@ -299,11 +303,11 @@ export default class ColorPicker extends PureBaseComponent {
299303
<View style={[this.styles.preview, {backgroundColor: hex}]}>
300304
<TouchableOpacity center onPress={this.setFocus} activeOpacity={1} accessible={false}>
301305
<View style={this.styles.inputContainer}>
302-
<Text
303-
text60
304-
white
305-
marginL-13
306-
marginR-5={Constants.isIOS}
306+
<Text
307+
text60
308+
white
309+
marginL-13
310+
marginR-5={Constants.isIOS}
307311
style={{
308312
color: textColor,
309313
transform: [{scaleX: I18nManager.isRTL ? -1 : 1}]
@@ -321,7 +325,8 @@ export default class ColorPicker extends PureBaseComponent {
321325
style={[
322326
this.styles.input,
323327
{color: textColor, width: (value.length + 1) * 16.5 * fontScale},
324-
Constants.isAndroid && {padding: 0}
328+
Constants.isAndroid && {padding: 0},
329+
previewInputStyle
325330
]}
326331
selectionColor={textColor}
327332
underlineColorAndroid="transparent"
@@ -410,7 +415,7 @@ function createStyles(props) {
410415
const iconSize = SWATCH_SIZE;
411416
const plusButtonContainerWidth = iconSize + 20 + 12;
412417
const plusButtonContainerHeight = 92 - 2 * SWATCH_MARGIN;
413-
418+
414419
const styles = StyleSheet.create({
415420
palette: {
416421
paddingLeft: plusButtonContainerWidth

0 commit comments

Comments
 (0)