diff --git a/ColorPickerPOC/ColorPickerGrid.module.less b/ColorPickerPOC/ColorPickerGrid.module.less index f1631128d5..c9dde7c624 100644 --- a/ColorPickerPOC/ColorPickerGrid.module.less +++ b/ColorPickerPOC/ColorPickerGrid.module.less @@ -1,8 +1,8 @@ // ColorPicker.module.less // -@import '../styles/colors.less'; -@import '../styles/mixins.less'; -@import '../styles/variables.less'; +@import "../styles/colors.less"; +@import "../styles/mixins.less"; +@import "../styles/variables.less"; .colorPicker { .colorsColumn { diff --git a/ColorPickerPOC/ColorPickerPOC.js b/ColorPickerPOC/ColorPickerPOC.js index ce7c26ee1c..5e6b799055 100644 --- a/ColorPickerPOC/ColorPickerPOC.js +++ b/ColorPickerPOC/ColorPickerPOC.js @@ -12,7 +12,7 @@ import Skinnable from '../Skinnable'; import TabLayout, {Tab} from '../TabLayout'; import ColorPickerGrid from './ColorPickerGrid'; -import ColorPickerSlider, {ColorPickerSliderHSL} from './ColorPickerSlider'; // eslint-disable-line no-unused-vars +import ColorPickerSlider from './ColorPickerSlider'; import ColorPickerSpectrum from './ColorPickerSpectrum'; import {generateOppositeColor} from './utils'; @@ -184,29 +184,28 @@ const ColorPickerPOCBase = ({color = '#eb4034', colors = [], css, onChangeColor, }, [favoriteColors, onChangeColor, selectedColor]); return ( - + - - - + + +
- +
- +
- {/* */}
- + { hsla(${hue}, ${saturation}%, 100%, 1))`; }; -const ColorPickerSlider = ({selectedColor, selectedColorHandler, ...props}) => { +const ColorPickerSliderRGB = ({selectedColor, selectedColorHandler, ...props}) => { const {red, green, blue} = hexToRGB(selectedColor); const [localRed, setLocalRed] = useState(red); const [localGreen, setLocalGreen] = useState(green); const [localBlue, setLocalBlue] = useState(blue); + useEffect(() => { + setLocalRed(red); + setLocalGreen(green); + setLocalBlue(blue); + }, [blue, green, red]); + const changeValueRed = useCallback((ev) => { setLocalRed(ev.value); }, []); @@ -82,22 +89,24 @@ const ColorPickerSlider = ({selectedColor, selectedColorHandler, ...props}) => { }, [localBlue, localGreen, localRed, selectedColorHandler]); return ( -
+ Red { value={localRed} /> - {localRed} + {localRed} - - Green { value={localGreen} /> - {localGreen} + {localGreen} - - Blue { value={localBlue} /> - {localBlue} + {localBlue} -
+ ); }; @@ -177,6 +184,12 @@ const ColorPickerSliderHSL = ({selectedColor, selectedColorHandler, ...props}) = const [saturation, setSaturation] = useState(s); const [lightness, setLightness] = useState(l); + useEffect(() => { + setHue(h); + setSaturation(s); + setLightness(l); + }, [h, l, s]); + const changeValueHue = useCallback((ev) => { setHue(ev.value); }, []); @@ -194,91 +207,121 @@ const ColorPickerSliderHSL = ({selectedColor, selectedColorHandler, ...props}) = }, [hue, saturation, lightness, selectedColorHandler]); return ( -
+ - Hue - - - - - {hue} - + + Hue + + + + + {hue}% + + + + Saturation + + + + + {saturation}% + + + + Lightness + + + + + {lightness}% + + - - Saturation - - - - - {saturation}% - - - - Lightness - - - - - {lightness}% - - -
+ + ); +}; + +const ColorPickerSlider = ({selectedColor, selectedColorHandler, ...props}) => { + const [pickerType, setPickerType] = useState(false); + + const handleSwitch = useCallback(() => { + setPickerType(type => !type); + }, [setPickerType]); + + return ( + + + {pickerType ? 'HSL Picker' : 'RGB picker'} + + {pickerType ? + : + + } + ); }; @@ -292,8 +335,14 @@ ColorPickerSliderHSL.propTypes = { selectedColorHandler: PropTypes.func }; +ColorPickerSliderRGB.propTypes = { + selectedColor: PropTypes.string, + selectedColorHandler: PropTypes.func +}; + export { ColorPickerSlider, - ColorPickerSliderHSL + ColorPickerSliderHSL, + ColorPickerSliderRGB }; export default ColorPickerSlider; diff --git a/ColorPickerPOC/ColorPickerSlider.module.less b/ColorPickerPOC/ColorPickerSlider.module.less index 2ba045213b..6c74cd8175 100644 --- a/ColorPickerPOC/ColorPickerSlider.module.less +++ b/ColorPickerPOC/ColorPickerSlider.module.less @@ -1,53 +1,46 @@ -.cellElement { - margin-top: 21px; +@import "../styles/mixins.less"; + +.switchCell { + margin-top: -63px; + padding: 0 30px; } .labelText { - font-size: 42px; - margin-bottom: 12px; + font-size: 42px; + margin: 9px 0; } .outputText { - align-content: center; - background-color: #eeeeee; - border-radius: 12px; - color: #444444; - display: grid; - justify-content: end; - margin-left: 30px; - padding-right: 21px; -} - -.outputTextPercent { - align-content: center; - background-color: #eeeeee; - border-radius: 12px; - color: #444444; - display: grid; - justify-content: end; - margin-left: 30px; + display: flex; + justify-content: center; + align-items: center; + background-color: #eeeeee; + border-radius: 12px; + margin-left: 30px; } .slider { - --sand-progress-bg-color-rgb: transparent; - border-radius: 99px; - height: 42px; - margin-left: 18px; - margin-right: 18px; + --sand-progress-bg-color-rgb: transparent; + border-radius: 99px; + height: 33px; + margin-left: 18px; + margin-right: 18px; - .knob { - &::before { - border-radius: 99px; - height: 120px; - width: 120px; - } - } -} + .focus({ + .knob { + transform: scale(1.1); + } + }); -.sliderCell { - border-radius: 99px; + .knob { + &::before { + border-radius: 99px; + height: 102px; + width: 102px; + } + } } -.sliderContainer { - width: 900px; +.sliderCell { + border-radius: 99px; } diff --git a/ColorPickerPOC/ColorPickerSpectrum.module.less b/ColorPickerPOC/ColorPickerSpectrum.module.less index 6dca72af1a..47fddea143 100644 --- a/ColorPickerPOC/ColorPickerSpectrum.module.less +++ b/ColorPickerPOC/ColorPickerSpectrum.module.less @@ -1,8 +1,8 @@ // ColorPickerSpectrum.module.less // -@import '../styles/colors.less'; -@import '../styles/mixins.less'; -@import '../styles/variables.less'; +@import "../styles/colors.less"; +@import "../styles/mixins.less"; +@import "../styles/variables.less"; .colorPicker { position: relative; diff --git a/ColorPickerPOC/utils.js b/ColorPickerPOC/utils.js index 97163dfb1b..c21780a9de 100644 --- a/ColorPickerPOC/utils.js +++ b/ColorPickerPOC/utils.js @@ -107,7 +107,7 @@ const hslToHex = ({h, s, l}) => { r = 0; g = x; b = c; } else if (240 <= h && h < 300) { r = x; g = 0; b = c; - } else if (300 <= h && h < 360) { + } else if (300 <= h && h <= 360) { r = c; g = 0; b = x; } // Having obtained RGB, convert channels to hex @@ -152,7 +152,7 @@ const hslToRGBString = ({h, s, l}) => { r = 0; g = x; b = c; } else if (240 <= h && h < 300) { r = x; g = 0; b = c; - } else if (300 <= h && h < 360) { + } else if (300 <= h && h <= 360) { r = c; g = 0; b = x; }