Skip to content

Commit 630cf46

Browse files
authored
ColorPicker - small fixes (#2650)
1 parent 47d2ab1 commit 630cf46

File tree

3 files changed

+15
-25
lines changed

3 files changed

+15
-25
lines changed

demo/src/screens/componentScreens/ColorPickerScreen.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {StyleSheet, ScrollView} from 'react-native';
44
import {Colors, View, Text, ColorPicker, ColorPalette, ColorName} from 'react-native-ui-lib';
55
import {renderMultipleSegmentOptions} from '../ExampleScreenPresenter';
66

7-
interface Props {}
87
interface State {
98
color: string;
109
textColor?: string;
@@ -14,6 +13,7 @@ interface State {
1413
}
1514

1615
const INITIAL_COLOR = Colors.$backgroundPrimaryHeavy;
16+
// prettier-ignore
1717
const colors = [
1818
'#20303C', '#43515C', '#66737C', '#858F96', '#A3ABB0', '#C2C7CB', '#E0E3E5', '#F2F4F5',
1919
'#3182C8', '#4196E0', '#459FED', '#57a8ef', '#8fc5f4', '#b5d9f8', '#daecfb', '#ecf5fd',
@@ -25,7 +25,7 @@ const colors = [
2525
'#8B1079', '#A0138E', '#B13DAC', '#C164BD', '#D08BCD', '#E0B1DE', '#EFD8EE', '#F7EBF7'
2626
];
2727

28-
export default class ColorPickerScreen extends Component<Props, State> {
28+
export default class ColorPickerScreen extends Component<{}, State> {
2929
state: State = {
3030
color: INITIAL_COLOR,
3131
textColor: Colors.$textDefaultLight,

src/components/colorPicker/ColorPickerDialog.tsx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,24 @@ interface Props extends DialogProps {
4545
/**
4646
* Ok (v) button color
4747
*/
48-
doneButtonColor?: string,
48+
doneButtonColor?: string;
4949
accessibilityLabels?: {
50-
dismissButton?: string,
51-
doneButton?: string,
52-
input?: string
50+
dismissButton?: string;
51+
doneButton?: string;
52+
input?: string;
5353
};
54-
/**
54+
/**
5555
* Whether to use the new Slider implementation using Reanimated
5656
*/
5757
migrate?: boolean;
5858
}
5959
export type ColorPickerDialogProps = Props;
6060

6161
interface State {
62-
keyboardHeight: number,
63-
color: any,
64-
text?: string,
65-
valid: boolean
62+
keyboardHeight: number;
63+
color: any;
64+
text?: string;
65+
valid: boolean;
6666
}
6767

6868
const KEYBOARD_HEIGHT = 216;
@@ -357,7 +357,6 @@ class ColorPickerDialog extends PureComponent<Props, State> {
357357

358358
export default asBaseComponent<Props>(ColorPickerDialog);
359359

360-
361360
const BORDER_RADIUS = 12;
362361

363362
const styles = StyleSheet.create({

src/components/colorPicker/index.tsx

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import Assets from '../../assets';
44
import {Colors} from '../../style';
55
import View from '../view';
66
import Button from '../button';
7-
import ColorPalette from '../colorPalette';
7+
import ColorPalette, {ColorPaletteProps} from '../colorPalette';
88
import {SWATCH_MARGIN, SWATCH_SIZE} from '../colorSwatch';
99
import ColorPickerDialog, {ColorPickerDialogProps} from './ColorPickerDialog';
1010

11-
interface Props extends ColorPickerDialogProps {
11+
interface Props extends ColorPickerDialogProps, Pick<ColorPaletteProps, 'onValueChange'> {
1212
/**
1313
* Array of colors for the picker's color palette (hex values)
1414
*/
@@ -21,10 +21,6 @@ interface Props extends ColorPickerDialogProps {
2121
* The index of the item to animate at first render (default is last)
2222
*/
2323
animatedIndex?: number;
24-
/**
25-
* onValueChange callback for the picker's color palette change
26-
*/
27-
onValueChange?: (value: string, options: object) => void;
2824
/**
2925
* Accessibility labels as an object of strings, ex.
3026
* {
@@ -90,7 +86,7 @@ class ColorPicker extends PureComponent<Props> {
9086
};
9187

9288
render() {
93-
const {initialColor, colors, value, testID, accessibilityLabels, backgroundColor} = this.props;
89+
const {initialColor, colors, value, testID, accessibilityLabels, backgroundColor, onValueChange} = this.props;
9490
const {show} = this.state;
9591
return (
9692
<View row testID={testID} style={{backgroundColor}}>
@@ -100,7 +96,7 @@ class ColorPicker extends PureComponent<Props> {
10096
style={styles.palette}
10197
usePagination={false}
10298
animatedIndex={this.animatedIndex}
103-
onValueChange={this.onValueChange}
99+
onValueChange={onValueChange}
104100
testID={`${testID}-palette`}
105101
backgroundColor={backgroundColor}
106102
/>
@@ -131,11 +127,6 @@ class ColorPicker extends PureComponent<Props> {
131127
</View>
132128
);
133129
}
134-
135-
// ColorPalette
136-
onValueChange = (value: string, options: object) => {
137-
this.props.onValueChange?.(value, options);
138-
};
139130
}
140131

141132
export default ColorPicker;

0 commit comments

Comments
 (0)