Skip to content

Commit

Permalink
WRQ-32437: Fixed deletion of favorite colors for ColorPicker (#1676)
Browse files Browse the repository at this point in the history
* fixed deletion of favorite colors for ColorPicker

* save component state when props change

* removed unnecessary code

* added back useEffect

* changed outputText color to be more visible

* added handler for Enter key to edit favorite colors

* code review fix

---------

Co-authored-by: Stanca <stanca.pop@lgepartner.com>
  • Loading branch information
daniel-stoian-lgp and stanca-pop-lgp authored Aug 26, 2024
1 parent 900440a commit 2abd154
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
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 FavoriteColors = ({favoriteColors = [], favoriteColorsHandler, selectedCol

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);
}, 300);

timerRef.current = setTimeout(() => {
setEditEnabled(true);
setClickEnabled(false);
target.classList.remove(componentsCss.shakeFavoriteColor);
}, 1000);
}
}, [editEnabled]);

const onReleaseHandler = useCallback((ev) => {
Expand All @@ -102,8 +104,8 @@ const FavoriteColors = ({favoriteColors = [], favoriteColorsHandler, selectedCol
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 @@ const FavoriteColors = ({favoriteColors = [], favoriteColorsHandler, selectedCol
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 ColorPickerPOCBase = ({color = '#eb4034', colors = [], css, onChangeColor,
const [favoriteColors, setFavoriteColors] = useState(colors);
const [selectedColor, setSelectedColor] = useState(color);

useEffect(() => {
setFavoriteColors(colors);
setSelectedColor(color);
}, [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

0 comments on commit 2abd154

Please sign in to comment.