Skip to content
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

WRQ-32437: Fixed deletion of favorite colors for ColorPicker #1676

Merged
merged 9 commits into from
Aug 26, 2024
37 changes: 22 additions & 15 deletions ColorPickerPOC/ColorPickerPOC.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,19 @@

const onPressHandler = useCallback((ev) => {
if (editEnabled) return;
const target = ev.target.id ? ev.target : ev.target.offsetParent;

shakeEffectRef.current = setTimeout(() => {
target.classList.add(componentsCss.shakeFavoriteColor);
}, 300);

timerRef.current = setTimeout(() => {
setEditEnabled(true);
setClickEnabled(false);
target.classList.remove(componentsCss.shakeFavoriteColor);
}, 1000);
if (ev.type === 'pointerdown' || (ev.type === 'keydown' && ev.keyCode === 13)) {
const target = ev.target.id ? ev.target : ev.target.offsetParent;

shakeEffectRef.current = setTimeout(() => {
target.classList.add(componentsCss.shakeFavoriteColor);

Check warning on line 73 in ColorPickerPOC/ColorPickerPOC.js

View check run for this annotation

Codecov / codecov/patch

ColorPickerPOC/ColorPickerPOC.js#L72-L73

Added lines #L72 - L73 were not covered by tests
}, 300);

timerRef.current = setTimeout(() => {
setEditEnabled(true);
setClickEnabled(false);
target.classList.remove(componentsCss.shakeFavoriteColor);

Check warning on line 79 in ColorPickerPOC/ColorPickerPOC.js

View check run for this annotation

Codecov / codecov/patch

ColorPickerPOC/ColorPickerPOC.js#L76-L79

Added lines #L76 - L79 were not covered by tests
}, 1000);
}
}, [editEnabled]);

const onReleaseHandler = useCallback((ev) => {
Expand All @@ -102,8 +104,8 @@
key={`${color}_${index + 4}`}
minWidth={false}
onClick={onSelectFavoriteColor}
onMouseDown={onPressHandler}
onMouseUp={onReleaseHandler}
onKeyDown={onPressHandler}
onKeyUp={onReleaseHandler}
onPointerDown={onPressHandler}
onPointerUp={onReleaseHandler}
size="small"
Expand All @@ -127,8 +129,8 @@
key={`${color}_${index}`}
minWidth={false}
onClick={onSelectFavoriteColor}
onMouseDown={onPressHandler}
onMouseUp={onReleaseHandler}
onKeyDown={onPressHandler}
onKeyUp={onReleaseHandler}
onPointerDown={onPressHandler}
onPointerUp={onReleaseHandler}
size="small"
Expand Down Expand Up @@ -177,6 +179,11 @@
const [favoriteColors, setFavoriteColors] = useState(colors);
const [selectedColor, setSelectedColor] = useState(color);

useEffect(() => {
setFavoriteColors(colors);
setSelectedColor(color);

Check warning on line 184 in ColorPickerPOC/ColorPickerPOC.js

View check run for this annotation

Codecov / codecov/patch

ColorPickerPOC/ColorPickerPOC.js#L182-L184

Added lines #L182 - L184 were not covered by tests
}, [color, colors]);

useEffect(() => {
if (selectedColor || favoriteColors) {
onChangeColor({selectedColor, favoriteColors});
Expand Down
1 change: 1 addition & 0 deletions ColorPickerPOC/ColorPickerSlider.module.less
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
justify-content: center;
align-items: center;
background-color: #eeeeee;
color: rgb(76, 80, 89);
border-radius: 12px;
margin-left: 30px;
}
Expand Down