From 81061b4be1dd535c86a8861288c56df5c5452fe7 Mon Sep 17 00:00:00 2001 From: ion-andrusciac-lgp <122601449+ion-andrusciac-lgp@users.noreply.github.com> Date: Thu, 1 Aug 2024 14:51:49 +0300 Subject: [PATCH 01/24] WRQ-30515: Created component skeleton (#1650) * Created component skeleton for ColorPickerPOC * Added propTypes * Fixed lint warnings --- ColorPickerPOC/ColorPickerPOC.js | 158 ++++++++++++++++++ ColorPickerPOC/ColorPickerPOC.module.less | 32 ++++ ColorPickerPOC/package.json | 3 + .../sampler/stories/default/ColorPickerPOC.js | 22 +++ 4 files changed, 215 insertions(+) create mode 100644 ColorPickerPOC/ColorPickerPOC.js create mode 100644 ColorPickerPOC/ColorPickerPOC.module.less create mode 100644 ColorPickerPOC/package.json create mode 100644 samples/sampler/stories/default/ColorPickerPOC.js diff --git a/ColorPickerPOC/ColorPickerPOC.js b/ColorPickerPOC/ColorPickerPOC.js new file mode 100644 index 0000000000..183ad35337 --- /dev/null +++ b/ColorPickerPOC/ColorPickerPOC.js @@ -0,0 +1,158 @@ +import kind from '@enact/core/kind'; +import Spottable from '@enact/spotlight/Spottable'; +import {Cell, Row} from '@enact/ui/Layout'; +import Toggleable from '@enact/ui/Toggleable'; +import ri from '@enact/ui/resolution'; +import PropTypes from 'prop-types'; +import compose from 'ramda/src/compose'; +import {useCallback, useState} from 'react'; + +import {Button, ButtonBase} from '../Button'; +import Popup from '../Popup'; +import Skinnable from '../Skinnable'; +import TabLayout, {Tab} from '../TabLayout'; + +import componentsCss from './ColorPickerPOC.module.less'; + +const SpottableButton = Spottable(ButtonBase); + +const FavoriteColors = ({colorHandler, colors = [], css, selectedColor = '#3455eb'}) => { + const [currentColor, setCurrentColor] = useState(selectedColor); + const [favoriteColors, setFavoriteColors] = useState(colors); + + const onSelectFavoriteColor = useCallback((ev) => { + const color = ev.target.offsetParent.id; + setCurrentColor(color); + + colorHandler({currentColor: color, favoriteColors}); + }, [colorHandler, favoriteColors]); + + const addNewFavoriteColor = useCallback(() => { + if (favoriteColors.length > 6) favoriteColors.shift(); + + setFavoriteColors(prevState => { + const colorsState = [...prevState, selectedColor]; + colorHandler({currentColor, favoriteColors: colorsState}); + + return colorsState; + }); + }, [colorHandler, currentColor, favoriteColors, selectedColor]); + + const onAddNewFavoriteColor = useCallback(() => { + if (!document.startViewTransition) { + addNewFavoriteColor(); + return; + } + + document.startViewTransition(() => { + addNewFavoriteColor(); + }); + }, [addNewFavoriteColor]); + + return ( +