Skip to content

Commit 804b06e

Browse files
committed
Reverting changes to ColorSliderGroup
1 parent 035333c commit 804b06e

File tree

1 file changed

+21
-67
lines changed

1 file changed

+21
-67
lines changed
Lines changed: 21 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import _ from 'lodash';
2-
import React, {PureComponent, GetDerivedStateFromProps} from 'react';
1+
import React, {useState, useEffect, useCallback} from 'react';
32
import {StyleProp, ViewStyle, TextStyle} from 'react-native';
43
import {asBaseComponent} from '../../commons/new';
54
import GradientSlider, {GradientSliderTypes} from './GradientSlider';
65
import SliderGroup from './context/SliderGroup';
7-
import Text from '../text';
6+
import ColorSlider from './ColorSlider';
87

98
type SliderOnValueChange = (value: string) => void;
109

@@ -48,76 +47,31 @@ export type ColorSliderGroupProps = {
4847
migrate?: boolean;
4948
};
5049

51-
interface ColorSliderGroupState {
52-
initialColor: string;
53-
}
54-
5550
/**
5651
* @description: A Gradient Slider component
5752
* @example: https://github.com/wix/react-native-ui-lib/blob/master/demo/src/screens/componentScreens/SliderScreen.tsx
5853
* @gif: https://github.com/wix/react-native-ui-lib/blob/master/demo/showcase/ColorSliderGroup/ColorSliderGroup.gif?raw=true
5954
*/
60-
class ColorSliderGroup extends PureComponent<ColorSliderGroupProps, ColorSliderGroupState> {
61-
static displayName = 'ColorSliderGroup';
62-
63-
static defaultProps = {
64-
labels: {hue: 'Hue', lightness: 'Lightness', saturation: 'Saturation'}
65-
};
66-
67-
state = {
68-
initialColor: this.props.initialColor
69-
};
70-
71-
static getDerivedStateFromProps: GetDerivedStateFromProps<ColorSliderGroupProps, ColorSliderGroupState> = (nextProps,
72-
prevState) => {
73-
if (prevState.initialColor !== nextProps.initialColor) {
74-
return {
75-
initialColor: nextProps.initialColor
76-
};
77-
}
78-
return null;
79-
};
55+
const ColorSliderGroup = (props: ColorSliderGroupProps) => {
56+
const {initialColor, containerStyle, ...others} = props;
57+
const [color, setColor] = useState(initialColor);
58+
useEffect(() => {
59+
setColor(initialColor);
60+
}, [initialColor]);
8061

81-
onValueChange = (value: string) => {
82-
_.invoke(this.props, 'onValueChange', value);
83-
};
62+
const onValueChange = useCallback((value: string) => {
63+
props?.onValueChange?.(value);
64+
},
65+
[props]);
8466

85-
renderSlider = (type: GradientSliderTypes) => {
86-
const {sliderContainerStyle, showLabels, labelsStyle, accessible, labels, migrate} = this.props;
87-
88-
return (
89-
<>
90-
{showLabels && labels && (
91-
<Text recorderTag={'unmask'} $textNeutral text80 style={labelsStyle} accessible={accessible}>
92-
{labels[type]}
93-
</Text>
94-
)}
95-
{
96-
// @ts-ignore
97-
<GradientSlider
98-
color={this.props.initialColor}
99-
type={type}
100-
containerStyle={sliderContainerStyle}
101-
accessible={accessible}
102-
migrate={migrate}
103-
/>
104-
}
105-
</>
106-
);
107-
};
108-
109-
render() {
110-
const {containerStyle} = this.props;
111-
const {initialColor} = this.state;
112-
113-
return (
114-
<SliderGroup style={containerStyle} color={initialColor} onValueChange={this.onValueChange}>
115-
{this.renderSlider(GradientSlider.types.HUE)}
116-
{this.renderSlider(GradientSlider.types.LIGHTNESS)}
117-
{this.renderSlider(GradientSlider.types.SATURATION)}
118-
</SliderGroup>
119-
);
120-
}
121-
}
67+
return (
68+
<SliderGroup style={containerStyle} color={color} onValueChange={onValueChange}>
69+
<ColorSlider type={GradientSlider.types.HUE} initialColor={initialColor} {...others}/>
70+
<ColorSlider type={GradientSlider.types.LIGHTNESS} initialColor={initialColor} {...others}/>
71+
<ColorSlider type={GradientSlider.types.SATURATION} initialColor={initialColor} {...others}/>
72+
</SliderGroup>
73+
);
74+
};
12275

76+
ColorSliderGroup.displayName = 'ColorSliderGroup';
12377
export default asBaseComponent<ColorSliderGroupProps, typeof ColorSliderGroup>(ColorSliderGroup);

0 commit comments

Comments
 (0)