@chayns-components/color-picker 5.5.30 → 5.5.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +6 -0
- package/lib/cjs/components/color-picker/ColorPicker.js +4 -2
- package/lib/cjs/components/color-picker/ColorPicker.js.map +1 -1
- package/lib/cjs/components/color-picker/color-picker-wrapper/ColorPickerWrapper.js +7 -6
- package/lib/cjs/components/color-picker/color-picker-wrapper/ColorPickerWrapper.js.map +1 -1
- package/lib/cjs/components/color-picker-popup/ColorPickerPopup.js +46 -15
- package/lib/cjs/components/color-picker-popup/ColorPickerPopup.js.map +1 -1
- package/lib/cjs/components/color-picker-popup/color-area/ColorArea.js +24 -2
- package/lib/cjs/components/color-picker-popup/color-area/ColorArea.js.map +1 -1
- package/lib/cjs/components/color-picker-popup/color-area/ColorArea.styles.js +1 -0
- package/lib/cjs/components/color-picker-popup/color-area/ColorArea.styles.js.map +1 -1
- package/lib/cjs/components/color-picker-popup/more-options/MoreOptions.js +29 -1
- package/lib/cjs/components/color-picker-popup/more-options/MoreOptions.js.map +1 -1
- package/lib/cjs/components/color-picker-popup/more-options/MoreOptions.styles.js +1 -0
- package/lib/cjs/components/color-picker-popup/more-options/MoreOptions.styles.js.map +1 -1
- package/lib/cjs/components/color-picker-popup/preset-colors/PresetColors.js +22 -6
- package/lib/cjs/components/color-picker-popup/preset-colors/PresetColors.js.map +1 -1
- package/lib/cjs/components/color-picker-popup/preset-colors/preset-button/PresetButton.js +23 -6
- package/lib/cjs/components/color-picker-popup/preset-colors/preset-button/PresetButton.js.map +1 -1
- package/lib/cjs/components/color-picker-popup/preset-colors/preset-button/PresetButton.styles.js +2 -1
- package/lib/cjs/components/color-picker-popup/preset-colors/preset-button/PresetButton.styles.js.map +1 -1
- package/lib/cjs/components/color-picker-popup/preset-colors/preset-color/PresetColor.js +26 -2
- package/lib/cjs/components/color-picker-popup/preset-colors/preset-color/PresetColor.js.map +1 -1
- package/lib/cjs/components/color-picker-popup/sliders/Sliders.js +9 -3
- package/lib/cjs/components/color-picker-popup/sliders/Sliders.js.map +1 -1
- package/lib/cjs/components/hue-slider/HueSlider.js +10 -1
- package/lib/cjs/components/hue-slider/HueSlider.js.map +1 -1
- package/lib/cjs/components/transparency-slider/TransparencySlider.js +10 -1
- package/lib/cjs/components/transparency-slider/TransparencySlider.js.map +1 -1
- package/lib/cjs/hooks/useColorAreaKeyboardNavigation.js +27 -0
- package/lib/cjs/hooks/useColorAreaKeyboardNavigation.js.map +1 -0
- package/lib/cjs/hooks/usePresetColorKeyboardNavigation.js +47 -0
- package/lib/cjs/hooks/usePresetColorKeyboardNavigation.js.map +1 -0
- package/lib/esm/components/color-picker/ColorPicker.js +4 -2
- package/lib/esm/components/color-picker/ColorPicker.js.map +1 -1
- package/lib/esm/components/color-picker/color-picker-wrapper/ColorPickerWrapper.js +7 -5
- package/lib/esm/components/color-picker/color-picker-wrapper/ColorPickerWrapper.js.map +1 -1
- package/lib/esm/components/color-picker-popup/ColorPickerPopup.js +42 -14
- package/lib/esm/components/color-picker-popup/ColorPickerPopup.js.map +1 -1
- package/lib/esm/components/color-picker-popup/color-area/ColorArea.js +25 -3
- package/lib/esm/components/color-picker-popup/color-area/ColorArea.js.map +1 -1
- package/lib/esm/components/color-picker-popup/color-area/ColorArea.styles.js +1 -0
- package/lib/esm/components/color-picker-popup/color-area/ColorArea.styles.js.map +1 -1
- package/lib/esm/components/color-picker-popup/more-options/MoreOptions.js +31 -3
- package/lib/esm/components/color-picker-popup/more-options/MoreOptions.js.map +1 -1
- package/lib/esm/components/color-picker-popup/more-options/MoreOptions.styles.js +1 -0
- package/lib/esm/components/color-picker-popup/more-options/MoreOptions.styles.js.map +1 -1
- package/lib/esm/components/color-picker-popup/preset-colors/PresetColors.js +22 -6
- package/lib/esm/components/color-picker-popup/preset-colors/PresetColors.js.map +1 -1
- package/lib/esm/components/color-picker-popup/preset-colors/preset-button/PresetButton.js +25 -8
- package/lib/esm/components/color-picker-popup/preset-colors/preset-button/PresetButton.js.map +1 -1
- package/lib/esm/components/color-picker-popup/preset-colors/preset-button/PresetButton.styles.js +2 -1
- package/lib/esm/components/color-picker-popup/preset-colors/preset-button/PresetButton.styles.js.map +1 -1
- package/lib/esm/components/color-picker-popup/preset-colors/preset-color/PresetColor.js +27 -3
- package/lib/esm/components/color-picker-popup/preset-colors/preset-color/PresetColor.js.map +1 -1
- package/lib/esm/components/color-picker-popup/sliders/Sliders.js +9 -3
- package/lib/esm/components/color-picker-popup/sliders/Sliders.js.map +1 -1
- package/lib/esm/components/hue-slider/HueSlider.js +10 -1
- package/lib/esm/components/hue-slider/HueSlider.js.map +1 -1
- package/lib/esm/components/transparency-slider/TransparencySlider.js +10 -1
- package/lib/esm/components/transparency-slider/TransparencySlider.js.map +1 -1
- package/lib/esm/hooks/useColorAreaKeyboardNavigation.js +20 -0
- package/lib/esm/hooks/useColorAreaKeyboardNavigation.js.map +1 -0
- package/lib/esm/hooks/usePresetColorKeyboardNavigation.js +39 -0
- package/lib/esm/hooks/usePresetColorKeyboardNavigation.js.map +1 -0
- package/lib/types/components/color-picker/ColorPicker.d.ts +5 -1
- package/lib/types/components/color-picker/color-picker-wrapper/ColorPickerWrapper.d.ts +2 -1
- package/lib/types/components/color-picker/color-picker-wrapper/ColorPickerWrapper.styles.d.ts +2 -2
- package/lib/types/components/color-picker-popup/ColorPickerPopup.d.ts +10 -2
- package/lib/types/components/color-picker-popup/color-area/ColorArea.d.ts +4 -1
- package/lib/types/components/color-picker-popup/more-options/MoreOptions.d.ts +4 -1
- package/lib/types/components/color-picker-popup/preset-colors/PresetColors.d.ts +2 -1
- package/lib/types/components/color-picker-popup/preset-colors/preset-button/PresetButton.d.ts +6 -2
- package/lib/types/components/color-picker-popup/preset-colors/preset-button/PresetButton.styles.d.ts +2 -2
- package/lib/types/components/color-picker-popup/preset-colors/preset-color/PresetColor.d.ts +6 -2
- package/lib/types/components/color-picker-popup/sliders/Sliders.d.ts +2 -1
- package/lib/types/components/color-picker-popup/sliders/color-preview/ColorPreview.styles.d.ts +2 -2
- package/lib/types/components/hue-slider/HueSlider.d.ts +4 -0
- package/lib/types/components/hue-slider/HueSlider.styles.d.ts +2 -2
- package/lib/types/components/transparency-slider/TransparencySlider.d.ts +5 -1
- package/lib/types/components/transparency-slider/TransparencySlider.styles.d.ts +6 -6
- package/lib/types/hooks/useColorAreaKeyboardNavigation.d.ts +14 -0
- package/lib/types/hooks/usePresetColorKeyboardNavigation.d.ts +6 -0
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ColorArea.styles.js","names":["motion","styled","StyledColorArea","div","StyledColorAreaCanvas","canvas","StyledColorAreaPseudo","StyledMotionColorAreaPointer"],"sources":["../../../../../src/components/color-picker-popup/color-area/ColorArea.styles.ts"],"sourcesContent":["import { motion } from 'motion/react';\nimport styled from 'styled-components';\n\nexport const StyledColorArea = styled.div`\n height: 150px;\n width: 300px;\n position: relative;\n user-select: none;\n overflow: hidden;\n cursor: crosshair;\n`;\n\nexport const StyledColorAreaCanvas = styled.canvas`\n user-select: none;\n`;\n\nexport const StyledColorAreaPseudo = styled.div`\n position: absolute;\n top: -10px;\n left: -10px;\n touch-action: none;\n user-select: none;\n\n height: 170px;\n width: 320px;\n`;\n\nexport const StyledMotionColorAreaPointer = styled(motion.div)`\n position: absolute;\n border-radius: 100%;\n border: 2px solid white;\n width: 20px;\n height: 20px;\n box-shadow:\n 0 0 5px 0 rgba(0, 0, 0, 0.5),\n 0 0 3px 0 rgba(0, 0, 0, 0.5) inset;\n pointer-events: none;\n user-select: none;\n top: 0;\n left: 0;\n`;\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,cAAc;AACrC,OAAOC,MAAM,MAAM,mBAAmB;AAEtC,OAAO,MAAMC,eAAe,GAAGD,MAAM,CAACE,GAAG;AACzC;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AAED,OAAO,MAAMC,qBAAqB,GAAGH,MAAM,CAACI,MAAM;AAClD;AACA,CAAC;AAED,OAAO,MAAMC,qBAAqB,GAAGL,MAAM,CAACE,GAAG;AAC/C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AAED,OAAO,MAAMI,4BAA4B,GAAGN,MAAM,CAACD,MAAM,CAACG,GAAG,CAAC;AAC9D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"ColorArea.styles.js","names":["motion","styled","StyledColorArea","div","StyledColorAreaCanvas","canvas","StyledColorAreaPseudo","StyledMotionColorAreaPointer"],"sources":["../../../../../src/components/color-picker-popup/color-area/ColorArea.styles.ts"],"sourcesContent":["import { motion } from 'motion/react';\nimport styled from 'styled-components';\n\nexport const StyledColorArea = styled.div`\n height: 150px;\n width: 300px;\n position: relative;\n user-select: none;\n overflow: hidden;\n cursor: crosshair;\n`;\n\nexport const StyledColorAreaCanvas = styled.canvas`\n user-select: none;\n`;\n\nexport const StyledColorAreaPseudo = styled.div`\n outline: none;\n position: absolute;\n top: -10px;\n left: -10px;\n touch-action: none;\n user-select: none;\n\n height: 170px;\n width: 320px;\n`;\n\nexport const StyledMotionColorAreaPointer = styled(motion.div)`\n position: absolute;\n border-radius: 100%;\n border: 2px solid white;\n width: 20px;\n height: 20px;\n box-shadow:\n 0 0 5px 0 rgba(0, 0, 0, 0.5),\n 0 0 3px 0 rgba(0, 0, 0, 0.5) inset;\n pointer-events: none;\n user-select: none;\n top: 0;\n left: 0;\n`;\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,cAAc;AACrC,OAAOC,MAAM,MAAM,mBAAmB;AAEtC,OAAO,MAAMC,eAAe,GAAGD,MAAM,CAACE,GAAG;AACzC;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AAED,OAAO,MAAMC,qBAAqB,GAAGH,MAAM,CAACI,MAAM;AAClD;AACA,CAAC;AAED,OAAO,MAAMC,qBAAqB,GAAGL,MAAM,CAACE,GAAG;AAC/C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AAED,OAAO,MAAMI,4BAA4B,GAAGN,MAAM,CAACD,MAAM,CAACG,GAAG,CAAC;AAC9D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC","ignoreList":[]}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import { Accordion, AccordionGroup, AreaContext } from '@chayns-components/core';
|
|
1
|
+
import { Accordion, AccordionGroup, AreaContext, useFocusRingPortal, useKeyboardFocusHighlighting } from '@chayns-components/core';
|
|
2
2
|
import { isHex } from '@chayns/colors';
|
|
3
|
-
import React, { useContext, useEffect, useMemo, useState } from 'react';
|
|
3
|
+
import React, { useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
4
4
|
import { extractRgbValues, hexToRgb, isValidRGBA, rgbToHex } from '../../../utils/color';
|
|
5
5
|
import { ColorPickerContext } from '../../ColorPickerProvider';
|
|
6
6
|
import { StyledMoreOptions, StyledMoreOptionsInput, StyledMoreOptionsInputWrapper } from './MoreOptions.styles';
|
|
7
7
|
import { ttsToITextString, useTextstringValue } from '@chayns-components/textstring';
|
|
8
8
|
import textStrings from '../../../constants/textStrings';
|
|
9
|
-
const MoreOptions = (
|
|
9
|
+
const MoreOptions = ({
|
|
10
|
+
shouldEnableKeyboardHighlighting
|
|
11
|
+
}) => {
|
|
10
12
|
const {
|
|
11
13
|
selectedColor,
|
|
12
14
|
updateSelectedColor,
|
|
@@ -17,6 +19,30 @@ const MoreOptions = () => {
|
|
|
17
19
|
const [tmpRgbValue, setTmpRgbValue] = useState('');
|
|
18
20
|
const [isHexInvalid, setIsHexInvalid] = useState(false);
|
|
19
21
|
const [isRgbInvalid, setIsRgbInvalid] = useState(false);
|
|
22
|
+
const [areInputsMounted, setAreInputsMounted] = useState(false);
|
|
23
|
+
const hexInputRef = useRef(null);
|
|
24
|
+
const rgbInputRef = useRef(null);
|
|
25
|
+
const shouldShowKeyboardHighlighting = useKeyboardFocusHighlighting(shouldEnableKeyboardHighlighting);
|
|
26
|
+
useFocusRingPortal(hexInputRef, {
|
|
27
|
+
isEnabled: shouldShowKeyboardHighlighting,
|
|
28
|
+
updateKey: areInputsMounted
|
|
29
|
+
});
|
|
30
|
+
useFocusRingPortal(rgbInputRef, {
|
|
31
|
+
isEnabled: shouldShowKeyboardHighlighting,
|
|
32
|
+
updateKey: areInputsMounted
|
|
33
|
+
});
|
|
34
|
+
const setHexInputRef = useCallback(element => {
|
|
35
|
+
hexInputRef.current = element;
|
|
36
|
+
if (element) {
|
|
37
|
+
setAreInputsMounted(true);
|
|
38
|
+
}
|
|
39
|
+
}, []);
|
|
40
|
+
const setRgbInputRef = useCallback(element => {
|
|
41
|
+
rgbInputRef.current = element;
|
|
42
|
+
if (element) {
|
|
43
|
+
setAreInputsMounted(true);
|
|
44
|
+
}
|
|
45
|
+
}, []);
|
|
20
46
|
const shouldChangeColor = useMemo(() => areaProvider.shouldChangeColor ?? false, [areaProvider.shouldChangeColor]);
|
|
21
47
|
const handleHexChange = event => {
|
|
22
48
|
setTmpHexValue(event.target.value);
|
|
@@ -71,11 +97,13 @@ const MoreOptions = () => {
|
|
|
71
97
|
}, /*#__PURE__*/React.createElement(Accordion, {
|
|
72
98
|
title: title
|
|
73
99
|
}, /*#__PURE__*/React.createElement(StyledMoreOptionsInputWrapper, null, /*#__PURE__*/React.createElement(StyledMoreOptionsInput, {
|
|
100
|
+
ref: setHexInputRef,
|
|
74
101
|
$shouldChangeColor: shouldChangeColor,
|
|
75
102
|
value: tmpHexValue,
|
|
76
103
|
onChange: handleHexChange,
|
|
77
104
|
$isInvalid: isHexInvalid
|
|
78
105
|
}), /*#__PURE__*/React.createElement(StyledMoreOptionsInput, {
|
|
106
|
+
ref: setRgbInputRef,
|
|
79
107
|
$shouldChangeColor: shouldChangeColor,
|
|
80
108
|
value: tmpRgbValue,
|
|
81
109
|
onChange: handleRgbChange,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MoreOptions.js","names":["Accordion","AccordionGroup","AreaContext","isHex","React","useContext","useEffect","useMemo","useState","extractRgbValues","hexToRgb","isValidRGBA","rgbToHex","ColorPickerContext","StyledMoreOptions","StyledMoreOptionsInput","StyledMoreOptionsInputWrapper","ttsToITextString","useTextstringValue","textStrings","MoreOptions","selectedColor","updateSelectedColor","updateShouldCallOnSelect","areaProvider","tmpHexValue","setTmpHexValue","tmpRgbValue","setTmpRgbValue","isHexInvalid","setIsHexInvalid","isRgbInvalid","setIsRgbInvalid","shouldChangeColor","handleHexChange","event","target","value","isValid","r","g","b","a","handleRgbChange","title","textstring","components","colorPickerPopup","moreOptions","accordionTitle","createElement","isWrapped","$shouldChangeColor","onChange","$isInvalid","displayName"],"sources":["../../../../../src/components/color-picker-popup/more-options/MoreOptions.tsx"],"sourcesContent":["import { Accordion, AccordionGroup, AreaContext } from '@chayns-components/core';\nimport { isHex } from '@chayns/colors';\nimport React, { type ChangeEvent, useContext, useEffect, useMemo, useState } from 'react';\n\nimport { extractRgbValues, hexToRgb, isValidRGBA, rgbToHex } from '../../../utils/color';\nimport { ColorPickerContext } from '../../ColorPickerProvider';\nimport {\n StyledMoreOptions,\n StyledMoreOptionsInput,\n StyledMoreOptionsInputWrapper,\n} from './MoreOptions.styles';\nimport { ttsToITextString, useTextstringValue } from '@chayns-components/textstring';\nimport textStrings from '../../../constants/textStrings';\n\nconst MoreOptions = () => {\n const { selectedColor, updateSelectedColor, updateShouldCallOnSelect } =\n useContext(ColorPickerContext);\n const areaProvider = useContext(AreaContext);\n\n const [tmpHexValue, setTmpHexValue] = useState('');\n const [tmpRgbValue, setTmpRgbValue] = useState('');\n const [isHexInvalid, setIsHexInvalid] = useState(false);\n const [isRgbInvalid, setIsRgbInvalid] = useState(false);\n\n const shouldChangeColor = useMemo(\n () => areaProvider.shouldChangeColor ?? false,\n [areaProvider.shouldChangeColor],\n );\n\n const handleHexChange = (event: ChangeEvent<HTMLInputElement>) => {\n setTmpHexValue(event.target.value);\n\n const isValid = isHex(event.target.value);\n\n setIsHexInvalid(!isValid);\n\n if (typeof updateSelectedColor === 'function' && isValid) {\n const { r, g, b, a } = hexToRgb(event.target.value);\n\n updateSelectedColor(`rgba(${r},${g},${b},${a})`);\n }\n\n if (typeof updateShouldCallOnSelect === 'function' && isValid) {\n updateShouldCallOnSelect(true);\n }\n };\n\n const handleRgbChange = (event: ChangeEvent<HTMLInputElement>) => {\n setTmpRgbValue(event.target.value);\n\n const isValid = isValidRGBA(event.target.value);\n\n setIsRgbInvalid(!isValid);\n\n if (typeof updateSelectedColor === 'function' && isValid) {\n updateSelectedColor(event.target.value);\n }\n\n if (typeof updateShouldCallOnSelect === 'function' && isValid) {\n updateShouldCallOnSelect(true);\n }\n };\n\n useEffect(() => {\n if (selectedColor) {\n if (isValidRGBA(selectedColor)) {\n setTmpRgbValue(selectedColor);\n setTmpHexValue(rgbToHex(extractRgbValues(selectedColor ?? '')));\n } else {\n const { r, g, b, a } = hexToRgb(selectedColor);\n\n setTmpRgbValue(`rgba(${r},${g},${b},${a})`);\n setTmpHexValue(selectedColor);\n }\n }\n }, [selectedColor]);\n\n const title = useTextstringValue({\n textstring: ttsToITextString(\n textStrings.components.colorPickerPopup.moreOptions.accordionTitle,\n ),\n });\n\n return (\n <StyledMoreOptions>\n <AccordionGroup isWrapped>\n <Accordion title={title}>\n <StyledMoreOptionsInputWrapper>\n <StyledMoreOptionsInput\n $shouldChangeColor={shouldChangeColor}\n value={tmpHexValue}\n onChange={handleHexChange}\n $isInvalid={isHexInvalid}\n />\n <StyledMoreOptionsInput\n $shouldChangeColor={shouldChangeColor}\n value={tmpRgbValue}\n onChange={handleRgbChange}\n $isInvalid={isRgbInvalid}\n />\n </StyledMoreOptionsInputWrapper>\n </Accordion>\n </AccordionGroup>\n </StyledMoreOptions>\n );\n};\n\nMoreOptions.displayName = 'MoreOptions';\n\nexport default MoreOptions;\n"],"mappings":"AAAA,S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aAAa,CAAC;QAE9CO,cAAc,CAAC,QAAQW,CAAC,IAAIC,CAAC,IAAIC,CAAC,IAAIC,CAAC,GAAG,CAAC;QAC3ChB,cAAc,CAACL,aAAa,CAAC;MACjC;IACJ;EACJ,CAAC,EAAE,CAACA,aAAa,CAAC,CAAC;EAEnB,MAAMuB,KAAK,GAAG1B,kBAAkB,CAAC;IAC7B2B,UAAU,EAAE5B,gBAAgB,CACxBE,WAAW,CAAC2B,UAAU,CAACC,gBAAgB,CAACC,WAAW,CAACC,cACxD;EACJ,CAAC,CAAC;EAEF,oBACI7C,KAAA,CAAA8C,aAAA,CAACpC,iBAAiB,qBACdV,KAAA,CAAA8C,aAAA,CAACjD,cAAc;IAACkD,SAAS;EAAA,gBACrB/C,KAAA,CAAA8C,aAAA,CAAClD,SAAS;IAAC4C,KAAK,EAAEA;EAAM,gBACpBxC,KAAA,CAAA8C,aAAA,CAAClC,6BAA6B,qBAC1BZ,KAAA,CAAA8C,aAAA,CAACnC,sBAAsB;IACnBqC,kBAAkB,EAAEnB,iBAAkB;IACtCI,KAAK,EAAEZ,WAAY;IACnB4B,QAAQ,EAAEnB,eAAgB;IAC1BoB,UAAU,EAAEzB;EAAa,CAC5B,CAAC,eACFzB,KAAA,CAAA8C,aAAA,CAACnC,sBAAsB;IACnBqC,kBAAkB,EAAEnB,iBAAkB;IACtCI,KAAK,EAAEV,WAAY;IACnB0B,QAAQ,EAAEV,eAAgB;IAC1BW,UAAU,EAAEvB;EAAa,CAC5B,CAC0B,CACxB,CACC,CACD,CAAC;AAE5B,CAAC;AAEDX,WAAW,CAACmC,WAAW,GAAG,aAAa;AAEvC,eAAenC,WAAW","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"MoreOptions.js","names":["Accordion","AccordionGroup","AreaContext","useFocusRingPortal","useKeyboardFocusHighlighting","isHex","React","useCallback","useContext","useEffect","useMemo","useRef","useState","extractRgbValues","hexToRgb","isValidRGBA","rgbToHex","ColorPickerContext","StyledMoreOptions","StyledMoreOptionsInput","StyledMoreOptionsInputWrapper","ttsToITextString","useTextstringValue","textStrings","MoreOptions","shouldEnableKeyboardHighlighting","selectedColor","updateSelectedColor","updateShouldCallOnSelect","areaProvider","tmpHexValue","setTmpHexValue","tmpRgbValue","setTmpRgbValue","isHexInvalid","setIsHexInvalid","isRgbInvalid","setIsRgbInvalid","areInputsMounted","setAreInputsMounted","hexInputRef","rgbInputRef","shouldShowKeyboardHighlighting","isEnabled","updateKey","setHexInputRef","element","current","setRgbInputRef","shouldChangeColor","handleHexChange","event","target","value","isValid","r","g","b","a","handleRgbChange","title","textstring","components","colorPickerPopup","moreOptions","accordionTitle","createElement","isWrapped","ref","$shouldChangeColor","onChange","$isInvalid","displayName"],"sources":["../../../../../src/components/color-picker-popup/more-options/MoreOptions.tsx"],"sourcesContent":["import {\n Accordion,\n AccordionGroup,\n AreaContext,\n useFocusRingPortal,\n useKeyboardFocusHighlighting,\n} from '@chayns-components/core';\nimport { isHex } from '@chayns/colors';\nimport React, {\n type ChangeEvent,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\n\nimport { extractRgbValues, hexToRgb, isValidRGBA, rgbToHex } from '../../../utils/color';\nimport { ColorPickerContext } from '../../ColorPickerProvider';\nimport {\n StyledMoreOptions,\n StyledMoreOptionsInput,\n StyledMoreOptionsInputWrapper,\n} from './MoreOptions.styles';\nimport { ttsToITextString, useTextstringValue } from '@chayns-components/textstring';\nimport textStrings from '../../../constants/textStrings';\n\ntype MoreOptionsProps = {\n shouldEnableKeyboardHighlighting?: boolean;\n};\n\nconst MoreOptions = ({ shouldEnableKeyboardHighlighting }: MoreOptionsProps) => {\n const { selectedColor, updateSelectedColor, updateShouldCallOnSelect } =\n useContext(ColorPickerContext);\n const areaProvider = useContext(AreaContext);\n\n const [tmpHexValue, setTmpHexValue] = useState('');\n const [tmpRgbValue, setTmpRgbValue] = useState('');\n const [isHexInvalid, setIsHexInvalid] = useState(false);\n const [isRgbInvalid, setIsRgbInvalid] = useState(false);\n const [areInputsMounted, setAreInputsMounted] = useState(false);\n const hexInputRef = useRef<HTMLInputElement | null>(null);\n const rgbInputRef = useRef<HTMLInputElement | null>(null);\n const shouldShowKeyboardHighlighting = useKeyboardFocusHighlighting(\n shouldEnableKeyboardHighlighting,\n );\n\n useFocusRingPortal(hexInputRef, {\n isEnabled: shouldShowKeyboardHighlighting,\n updateKey: areInputsMounted,\n });\n useFocusRingPortal(rgbInputRef, {\n isEnabled: shouldShowKeyboardHighlighting,\n updateKey: areInputsMounted,\n });\n\n const setHexInputRef = useCallback((element: HTMLInputElement | null) => {\n hexInputRef.current = element;\n\n if (element) {\n setAreInputsMounted(true);\n }\n }, []);\n\n const setRgbInputRef = useCallback((element: HTMLInputElement | null) => {\n rgbInputRef.current = element;\n\n if (element) {\n setAreInputsMounted(true);\n }\n }, []);\n\n const shouldChangeColor = useMemo(\n () => areaProvider.shouldChangeColor ?? false,\n [areaProvider.shouldChangeColor],\n );\n\n const handleHexChange = (event: ChangeEvent<HTMLInputElement>) => {\n setTmpHexValue(event.target.value);\n\n const isValid = isHex(event.target.value);\n\n setIsHexInvalid(!isValid);\n\n if (typeof updateSelectedColor === 'function' && isValid) {\n const { r, g, b, a } = hexToRgb(event.target.value);\n\n updateSelectedColor(`rgba(${r},${g},${b},${a})`);\n }\n\n if (typeof updateShouldCallOnSelect === 'function' && isValid) {\n updateShouldCallOnSelect(true);\n }\n };\n\n const handleRgbChange = (event: ChangeEvent<HTMLInputElement>) => {\n setTmpRgbValue(event.target.value);\n\n const isValid = isValidRGBA(event.target.value);\n\n setIsRgbInvalid(!isValid);\n\n if (typeof updateSelectedColor === 'function' && isValid) {\n updateSelectedColor(event.target.value);\n }\n\n if (typeof updateShouldCallOnSelect === 'function' && isValid) {\n updateShouldCallOnSelect(true);\n }\n };\n\n useEffect(() => {\n if (selectedColor) {\n if (isValidRGBA(selectedColor)) {\n setTmpRgbValue(selectedColor);\n setTmpHexValue(rgbToHex(extractRgbValues(selectedColor ?? '')));\n } else {\n const { r, g, b, a } = hexToRgb(selectedColor);\n\n setTmpRgbValue(`rgba(${r},${g},${b},${a})`);\n setTmpHexValue(selectedColor);\n }\n }\n }, [selectedColor]);\n\n const title = useTextstringValue({\n textstring: ttsToITextString(\n textStrings.components.colorPickerPopup.moreOptions.accordionTitle,\n ),\n });\n\n return (\n <StyledMoreOptions>\n <AccordionGroup isWrapped>\n <Accordion title={title}>\n <StyledMoreOptionsInputWrapper>\n <StyledMoreOptionsInput\n ref={setHexInputRef}\n $shouldChangeColor={shouldChangeColor}\n value={tmpHexValue}\n onChange={handleHexChange}\n $isInvalid={isHexInvalid}\n />\n <StyledMoreOptionsInput\n ref={setRgbInputRef}\n $shouldChangeColor={shouldChangeColor}\n value={tmpRgbValue}\n onChange={handleRgbChange}\n $isInvalid={isRgbInvalid}\n />\n </StyledMoreOptionsInputWrapper>\n </Accordion>\n </AccordionGroup>\n </StyledMoreOptions>\n );\n};\n\nMoreOptions.displayName = 'MoreOptions';\n\nexport default MoreOptions;\n"],"mappings":"AAAA,SACIA,SAAS,EACTC,cAAc,EACdC,WAAW,EACXC,kBAAkB,EAClBC,4BAA4B,QACzB,yBAAyB;AAChC,SAASC,KAAK,QAAQ,gBAAgB;AACtC,OAAOC,KAAK,IAERC,WAAW,EACXC,UAAU,EACVC,SAAS,EACTC,OAAO,EACPC,MAAM,EACNC,QAAQ,QACL,OAAO;AAEd,SAASC,gBAAgB,EAAEC,QAAQ,EAAEC,WAAW,EAAEC,QAAQ,QAAQ,sBAAsB;AACxF,SAASC,kBAAkB,QAAQ,2BAA2B;AAC9D,SACIC,iBAAiB,EACjBC,sBAAsB,EACtBC,6BAA6B,QAC1B,sBAAsB;AAC7B,SAASC,gBAAgB,EAAEC,kBAAkB,QAAQ,+BAA+B;AACpF,OAAOC,WAAW,MAAM,gCAAgC;AAMxD,MAAMC,WAAW,GAAGA,CAAC;EAAEC;AAAmD,CAAC,KAAK;EAC5E,MAAM;IAAEC,aAAa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AAEpB,iBAAkB;IACtCI,KAAK,EAAErB,WAAY;IACnBsC,QAAQ,EAAEX,eAAgB;IAC1BY,UAAU,EAAEnC;EAAa,CAC5B,CAC0B,CACxB,CACC,CACD,CAAC;AAE5B,CAAC;AAEDZ,WAAW,CAACgD,WAAW,GAAG,aAAa;AAEvC,eAAehD,WAAW","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MoreOptions.styles.js","names":["styled","StyledMoreOptions","div","StyledMoreOptionsInputWrapper","StyledMoreOptionsInput","input","theme","$isInvalid","wrong","$shouldChangeColor","colorMode","text"],"sources":["../../../../../src/components/color-picker-popup/more-options/MoreOptions.styles.ts"],"sourcesContent":["import type { WithTheme } from '@chayns-components/core';\nimport styled from 'styled-components';\n\nexport const StyledMoreOptions = styled.div``;\nexport const StyledMoreOptionsInputWrapper = styled.div`\n display: flex;\n justify-content: space-between;\n gap: 8px;\n align-items: center;\n`;\n\ntype StyledMoreOptionsInputProps = WithTheme<{ $isInvalid: boolean; $shouldChangeColor: boolean }>;\n\nexport const StyledMoreOptionsInput = styled.input<StyledMoreOptionsInputProps>`\n width: 100%;\n border-radius: 3px;\n border: 1px solid\n ${({ theme, $isInvalid }: StyledMoreOptionsInputProps) =>\n $isInvalid ? theme.wrong : 'rgba(160, 160, 160, 0.3)'};\n background-color: ${({ theme, $shouldChangeColor }: StyledMoreOptionsInputProps) =>\n theme.colorMode === 'classic' || $shouldChangeColor ? theme['000'] : theme['100']};\n color: ${({ theme, $isInvalid }: StyledMoreOptionsInputProps) =>\n $isInvalid ? theme.wrong : theme.text};\n padding: 8px 10px;\n font-size: 11px;\n`;\n"],"mappings":"AACA,OAAOA,MAAM,MAAM,mBAAmB;AAEtC,OAAO,MAAMC,iBAAiB,GAAGD,MAAM,CAACE,GAAG,EAAE;AAC7C,OAAO,MAAMC,6BAA6B,GAAGH,MAAM,CAACE,GAAG;AACvD;AACA;AACA;AACA;AACA,CAAC;AAID,OAAO,MAAME,sBAAsB,GAAGJ,MAAM,CAACK,KAAkC;AAC/E;AACA;AACA;AACA,UAAU,CAAC;EAAEC,KAAK;EAAEC;AAAwC,CAAC,KACjDA,UAAU,GAAGD,KAAK,CAACE,KAAK,GAAG,0BAA0B;AACjE,wBAAwB,CAAC;EAAEF,KAAK;EAAEG;AAAgD,CAAC,KAC3EH,KAAK,CAACI,SAAS,KAAK,SAAS,IAAID,kBAAkB,GAAGH,KAAK,CAAC,KAAK,CAAC,GAAGA,KAAK,CAAC,KAAK,CAAC;AACzF,aAAa,CAAC;EAAEA,KAAK;EAAEC;AAAwC,CAAC,KACxDA,UAAU,GAAGD,KAAK,CAACE,KAAK,GAAGF,KAAK,CAACK,IAAI;AAC7C;AACA;AACA,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"MoreOptions.styles.js","names":["styled","StyledMoreOptions","div","StyledMoreOptionsInputWrapper","StyledMoreOptionsInput","input","theme","$isInvalid","wrong","$shouldChangeColor","colorMode","text"],"sources":["../../../../../src/components/color-picker-popup/more-options/MoreOptions.styles.ts"],"sourcesContent":["import type { WithTheme } from '@chayns-components/core';\nimport styled from 'styled-components';\n\nexport const StyledMoreOptions = styled.div``;\nexport const StyledMoreOptionsInputWrapper = styled.div`\n display: flex;\n justify-content: space-between;\n gap: 8px;\n align-items: center;\n`;\n\ntype StyledMoreOptionsInputProps = WithTheme<{ $isInvalid: boolean; $shouldChangeColor: boolean }>;\n\nexport const StyledMoreOptionsInput = styled.input<StyledMoreOptionsInputProps>`\n width: 100%;\n border-radius: 3px;\n border: 1px solid\n ${({ theme, $isInvalid }: StyledMoreOptionsInputProps) =>\n $isInvalid ? theme.wrong : 'rgba(160, 160, 160, 0.3)'};\n background-color: ${({ theme, $shouldChangeColor }: StyledMoreOptionsInputProps) =>\n theme.colorMode === 'classic' || $shouldChangeColor ? theme['000'] : theme['100']};\n color: ${({ theme, $isInvalid }: StyledMoreOptionsInputProps) =>\n $isInvalid ? theme.wrong : theme.text};\n padding: 8px 10px;\n font-size: 11px;\n outline: none;\n`;\n"],"mappings":"AACA,OAAOA,MAAM,MAAM,mBAAmB;AAEtC,OAAO,MAAMC,iBAAiB,GAAGD,MAAM,CAACE,GAAG,EAAE;AAC7C,OAAO,MAAMC,6BAA6B,GAAGH,MAAM,CAACE,GAAG;AACvD;AACA;AACA;AACA;AACA,CAAC;AAID,OAAO,MAAME,sBAAsB,GAAGJ,MAAM,CAACK,KAAkC;AAC/E;AACA;AACA;AACA,UAAU,CAAC;EAAEC,KAAK;EAAEC;AAAwC,CAAC,KACjDA,UAAU,GAAGD,KAAK,CAACE,KAAK,GAAG,0BAA0B;AACjE,wBAAwB,CAAC;EAAEF,KAAK;EAAEG;AAAgD,CAAC,KAC3EH,KAAK,CAACI,SAAS,KAAK,SAAS,IAAID,kBAAkB,GAAGH,KAAK,CAAC,KAAK,CAAC,GAAGA,KAAK,CAAC,KAAK,CAAC;AACzF,aAAa,CAAC;EAAEA,KAAK;EAAEC;AAAwC,CAAC,KACxDA,UAAU,GAAGD,KAAK,CAACE,KAAK,GAAGF,KAAK,CAACK,IAAI;AAC7C;AACA;AACA;AACA,CAAC","ignoreList":[]}
|
|
@@ -8,17 +8,20 @@ import { ColorPickerContext } from '../../ColorPickerProvider';
|
|
|
8
8
|
import PresetButton from './preset-button/PresetButton';
|
|
9
9
|
import PresetColor from './preset-color/PresetColor';
|
|
10
10
|
import { StyledPresetColors } from './PresetColors.styles';
|
|
11
|
+
import { usePresetColorKeyboardNavigation } from '../../../hooks/usePresetColorKeyboardNavigation';
|
|
11
12
|
const PresetColors = ({
|
|
12
13
|
presetColors,
|
|
13
14
|
onPresetColorRemove,
|
|
14
15
|
onPresetColorAdd,
|
|
15
16
|
shouldUseSiteColors,
|
|
16
|
-
shouldHideDefaultPresetColors
|
|
17
|
+
shouldHideDefaultPresetColors,
|
|
18
|
+
shouldEnableKeyboardHighlighting
|
|
17
19
|
}) => {
|
|
18
20
|
const {
|
|
19
21
|
selectedColor
|
|
20
22
|
} = useContext(ColorPickerContext);
|
|
21
23
|
const [siteColors, setSiteColors] = useState(undefined);
|
|
24
|
+
const [focusedPresetIndex, setFocusedPresetIndex] = useState(0);
|
|
22
25
|
const loadSiteColors = async presetColorId => {
|
|
23
26
|
const colors = await getSiteColors();
|
|
24
27
|
setSiteColors(prevColors => {
|
|
@@ -97,14 +100,21 @@ const PresetColors = ({
|
|
|
97
100
|
combinedColors.forEach(({
|
|
98
101
|
color,
|
|
99
102
|
id
|
|
100
|
-
}) => {
|
|
103
|
+
}, index) => {
|
|
101
104
|
items.push(/*#__PURE__*/React.createElement(PresetColor, {
|
|
102
105
|
key: `preset-color__${id}`,
|
|
103
|
-
color: color
|
|
106
|
+
color: color,
|
|
107
|
+
isKeyboardFocusable: index === focusedPresetIndex,
|
|
108
|
+
onFocus: () => setFocusedPresetIndex(index),
|
|
109
|
+
presetIndex: index,
|
|
110
|
+
shouldEnableKeyboardHighlighting: shouldEnableKeyboardHighlighting
|
|
104
111
|
}));
|
|
105
112
|
});
|
|
106
113
|
return items;
|
|
107
|
-
}, [combinedColors]);
|
|
114
|
+
}, [combinedColors, focusedPresetIndex, shouldEnableKeyboardHighlighting]);
|
|
115
|
+
const handlePresetColorsKeyDown = usePresetColorKeyboardNavigation({
|
|
116
|
+
onFocusChange: setFocusedPresetIndex
|
|
117
|
+
});
|
|
108
118
|
const currentPresetColor = useMemo(() => combinedColors.find(({
|
|
109
119
|
color
|
|
110
120
|
}) => color === selectedColor), [combinedColors, selectedColor]);
|
|
@@ -130,11 +140,17 @@ const PresetColors = ({
|
|
|
130
140
|
onPresetColorRemove(presetColorId);
|
|
131
141
|
}
|
|
132
142
|
};
|
|
133
|
-
return /*#__PURE__*/React.createElement(StyledPresetColors,
|
|
143
|
+
return /*#__PURE__*/React.createElement(StyledPresetColors, {
|
|
144
|
+
onKeyDown: handlePresetColorsKeyDown
|
|
145
|
+
}, content, !shouldHideDefaultPresetColors && /*#__PURE__*/React.createElement(PresetButton, {
|
|
134
146
|
id: currentPresetColor?.id,
|
|
135
147
|
isCustom: currentPresetColor?.isCustom,
|
|
148
|
+
isKeyboardFocusable: focusedPresetIndex === combinedColors.length,
|
|
136
149
|
onAdd: handleAddColor,
|
|
137
|
-
|
|
150
|
+
onFocus: () => setFocusedPresetIndex(combinedColors.length),
|
|
151
|
+
onRemove: handleRemoveColor,
|
|
152
|
+
presetIndex: combinedColors.length,
|
|
153
|
+
shouldEnableKeyboardHighlighting: shouldEnableKeyboardHighlighting
|
|
138
154
|
}));
|
|
139
155
|
};
|
|
140
156
|
PresetColors.displayName = 'PresetColors';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PresetColors.js","names":["isHex","React","useContext","useEffect","useMemo","useState","putSiteColors","getSiteColors","PRESETCOLORS","extractRgbValues","hexToRgb","rgbToHex","ColorPickerContext","PresetButton","PresetColor","StyledPresetColors","PresetColors","presetColors","onPresetColorRemove","onPresetColorAdd","shouldUseSiteColors","shouldHideDefaultPresetColors","selectedColor","siteColors","setSiteColors","undefined","loadSiteColors","presetColorId","colors","prevColors","newColors","value","map","color","r","g","b","a","newColor","id","Math","random","toString","isCustom","deletedColor","find","filteredColors","filter","formattedColors","rgbValues","combinedColors","tmp","content","items","forEach","push","createElement","key","currentPresetColor","handleAddColor","presetColor","handleRemoveColor","onAdd","onRemove","displayName"],"sources":["../../../../../src/components/color-picker-popup/preset-colors/PresetColors.tsx"],"sourcesContent":["import { isHex } from '@chayns/colors';\nimport React, { useContext, useEffect, useMemo, useState, type ReactElement } from 'react';\n\nimport { putSiteColors } from '../../../api/color/get';\nimport { getSiteColors } from '../../../api/color/put';\nimport { PRESETCOLORS } from '../../../constants/color';\nimport type { IPresetColor } from '../../../types/colorPicker';\nimport { extractRgbValues, hexToRgb, rgbToHex } from '../../../utils/color';\nimport { ColorPickerContext } from '../../ColorPickerProvider';\nimport PresetButton from './preset-button/PresetButton';\nimport PresetColor from './preset-color/PresetColor';\nimport { StyledPresetColors } from './PresetColors.styles';\n\ninterface PresetColorsProps {\n presetColors?: IPresetColor[];\n onPresetColorAdd?: (presetColor: IPresetColor) => void;\n onPresetColorRemove?: (presetColorId: IPresetColor['id']) => void;\n shouldUseSiteColors: boolean;\n shouldHideDefaultPresetColors: boolean;\n}\n\nconst PresetColors = ({\n presetColors,\n onPresetColorRemove,\n onPresetColorAdd,\n shouldUseSiteColors,\n shouldHideDefaultPresetColors,\n}: PresetColorsProps) => {\n const { selectedColor } = useContext(ColorPickerContext);\n\n const [siteColors, setSiteColors] = useState<IPresetColor[] | undefined>(undefined);\n\n const loadSiteColors = async (presetColorId?: IPresetColor['id']) => {\n const colors = await getSiteColors();\n\n setSiteColors((prevColors) => {\n const newColors = colors.value.map((color) => {\n const { r, g, b, a } = hexToRgb(color);\n\n const newColor = `rgba(${r},${g},${b},${a})`;\n\n return {\n color: newColor,\n id: Math.random().toString(),\n isCustom: true,\n };\n });\n\n if (!presetColorId) {\n return newColors;\n }\n\n const deletedColor = prevColors?.find(({ id }) => id === presetColorId)?.color;\n\n if (!deletedColor) {\n return newColors;\n }\n\n const filteredColors = newColors?.filter(({ color }) => color !== deletedColor);\n\n const formattedColors = filteredColors?.map(({ color }) => {\n const rgbValues = extractRgbValues(color);\n\n return rgbToHex(rgbValues);\n });\n\n void putSiteColors(formattedColors ?? []);\n\n return filteredColors;\n });\n };\n\n useEffect(() => {\n if (!shouldUseSiteColors) {\n setSiteColors(undefined);\n\n return;\n }\n\n void loadSiteColors();\n }, [shouldUseSiteColors]);\n\n const combinedColors = useMemo(() => {\n const tmp = (presetColors ?? []).map(({ color, isCustom, id }) => {\n let newColor = color;\n\n if (isHex(color)) {\n const { r, g, b, a } = hexToRgb(color);\n\n newColor = `rgba(${r},${g},${b},${a})`;\n }\n\n return {\n id,\n isCustom,\n color: newColor,\n };\n });\n\n if (shouldHideDefaultPresetColors) {\n return tmp;\n }\n\n return [...PRESETCOLORS, ...(siteColors ?? []), ...tmp];\n }, [presetColors, shouldHideDefaultPresetColors, siteColors]);\n\n const content = useMemo(() => {\n const items: ReactElement[] = [];\n\n combinedColors.forEach(({ color, id }) => {\n items.push(<PresetColor key={`preset-color__${id}`} color={color} />);\n });\n\n return items;\n }, [combinedColors]);\n\n const currentPresetColor = useMemo(\n () => combinedColors.find(({ color }) => color === selectedColor),\n [combinedColors, selectedColor],\n );\n\n const handleAddColor = (presetColor: IPresetColor) => {\n if (typeof onPresetColorAdd === 'function') {\n onPresetColorAdd(presetColor);\n }\n\n setSiteColors((prevColors) => {\n const colors = [...(prevColors ?? []), presetColor];\n\n const newColors = colors?.map(({ color }) => {\n const rgbValues = extractRgbValues(color);\n\n return rgbToHex(rgbValues);\n });\n\n void putSiteColors(newColors);\n\n return colors;\n });\n };\n\n const handleRemoveColor = (presetColorId: IPresetColor['id']) => {\n void loadSiteColors(presetColorId);\n\n if (typeof onPresetColorRemove === 'function') {\n onPresetColorRemove(presetColorId);\n }\n };\n\n return (\n <StyledPresetColors>\n {content}\n {!shouldHideDefaultPresetColors && (\n <PresetButton\n id={currentPresetColor?.id}\n isCustom={currentPresetColor?.isCustom}\n onAdd={handleAddColor}\n onRemove={handleRemoveColor}\n />\n )}\n </StyledPresetColors>\n );\n};\n\nPresetColors.displayName = 'PresetColors';\n\nexport default PresetColors;\n"],"mappings":"AAAA,SAASA,KAAK,QAAQ,gBAAgB;AACtC,OAAOC,KAAK,IAAIC,UAAU,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAA2B,OAAO;AAE1F,SAASC,aAAa,QAAQ,wBAAwB;AACtD,SAASC,aAAa,QAAQ,wBAAwB;AACtD,SAASC,YAAY,QAAQ,0BAA0B;AAEvD,SAASC,gBAAgB,EAAEC,QAAQ,EAAEC,QAAQ,QAAQ,sBAAsB;AAC3E,SAASC,kBAAkB,QAAQ,2BAA2B;AAC9D,OAAOC,YAAY,MAAM,8BAA8B;AACvD,OAAOC,WAAW,MAAM,4BAA4B;AACpD,SAASC,kBAAkB,QAAQ,uBAAuB;AAU1D,MAAM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ACtC;EACJ,CAAC;EAED,oBACI1B,KAAA,CAAAuD,aAAA,CAACzC,kBAAkB,QACdqC,OAAO,EACP,CAAC/B,6BAA6B,iBAC3BpB,KAAA,CAAAuD,aAAA,CAAC3C,YAAY;IACT0B,EAAE,EAAEmB,kBAAkB,EAAEnB,EAAG;IAC3BI,QAAQ,EAAEe,kBAAkB,EAAEf,QAAS;IACvCmB,KAAK,EAAEH,cAAe;IACtBI,QAAQ,EAAEF;EAAkB,CAC/B,CAEW,CAAC;AAE7B,CAAC;AAED7C,YAAY,CAACgD,WAAW,GAAG,cAAc;AAEzC,eAAehD,YAAY","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"PresetColors.js","names":["isHex","React","useContext","useEffect","useMemo","useState","putSiteColors","getSiteColors","PRESETCOLORS","extractRgbValues","hexToRgb","rgbToHex","ColorPickerContext","PresetButton","PresetColor","StyledPresetColors","usePresetColorKeyboardNavigation","PresetColors","presetColors","onPresetColorRemove","onPresetColorAdd","shouldUseSiteColors","shouldHideDefaultPresetColors","shouldEnableKeyboardHighlighting","selectedColor","siteColors","setSiteColors","undefined","focusedPresetIndex","setFocusedPresetIndex","loadSiteColors","presetColorId","colors","prevColors","newColors","value","map","color","r","g","b","a","newColor","id","Math","random","toString","isCustom","deletedColor","find","filteredColors","filter","formattedColors","rgbValues","combinedColors","tmp","content","items","forEach","index","push","createElement","key","isKeyboardFocusable","onFocus","presetIndex","handlePresetColorsKeyDown","onFocusChange","currentPresetColor","handleAddColor","presetColor","handleRemoveColor","onKeyDown","length","onAdd","onRemove","displayName"],"sources":["../../../../../src/components/color-picker-popup/preset-colors/PresetColors.tsx"],"sourcesContent":["import { isHex } from '@chayns/colors';\nimport React, { useContext, useEffect, useMemo, useState, type ReactElement } from 'react';\n\nimport { putSiteColors } from '../../../api/color/get';\nimport { getSiteColors } from '../../../api/color/put';\nimport { PRESETCOLORS } from '../../../constants/color';\nimport type { IPresetColor } from '../../../types/colorPicker';\nimport { extractRgbValues, hexToRgb, rgbToHex } from '../../../utils/color';\nimport { ColorPickerContext } from '../../ColorPickerProvider';\nimport PresetButton from './preset-button/PresetButton';\nimport PresetColor from './preset-color/PresetColor';\nimport { StyledPresetColors } from './PresetColors.styles';\nimport { usePresetColorKeyboardNavigation } from '../../../hooks/usePresetColorKeyboardNavigation';\n\ninterface PresetColorsProps {\n presetColors?: IPresetColor[];\n onPresetColorAdd?: (presetColor: IPresetColor) => void;\n onPresetColorRemove?: (presetColorId: IPresetColor['id']) => void;\n shouldUseSiteColors: boolean;\n shouldHideDefaultPresetColors: boolean;\n shouldEnableKeyboardHighlighting?: boolean;\n}\n\nconst PresetColors = ({\n presetColors,\n onPresetColorRemove,\n onPresetColorAdd,\n shouldUseSiteColors,\n shouldHideDefaultPresetColors,\n shouldEnableKeyboardHighlighting,\n}: PresetColorsProps) => {\n const { selectedColor } = useContext(ColorPickerContext);\n\n const [siteColors, setSiteColors] = useState<IPresetColor[] | undefined>(undefined);\n const [focusedPresetIndex, setFocusedPresetIndex] = useState(0);\n\n const loadSiteColors = async (presetColorId?: IPresetColor['id']) => {\n const colors = await getSiteColors();\n\n setSiteColors((prevColors) => {\n const newColors = colors.value.map((color) => {\n const { r, g, b, a } = hexToRgb(color);\n\n const newColor = `rgba(${r},${g},${b},${a})`;\n\n return {\n color: newColor,\n id: Math.random().toString(),\n isCustom: true,\n };\n });\n\n if (!presetColorId) {\n return newColors;\n }\n\n const deletedColor = prevColors?.find(({ id }) => id === presetColorId)?.color;\n\n if (!deletedColor) {\n return newColors;\n }\n\n const filteredColors = newColors?.filter(({ color }) => color !== deletedColor);\n\n const formattedColors = filteredColors?.map(({ color }) => {\n const rgbValues = extractRgbValues(color);\n\n return rgbToHex(rgbValues);\n });\n\n void putSiteColors(formattedColors ?? []);\n\n return filteredColors;\n });\n };\n\n useEffect(() => {\n if (!shouldUseSiteColors) {\n setSiteColors(undefined);\n\n return;\n }\n\n void loadSiteColors();\n }, [shouldUseSiteColors]);\n\n const combinedColors = useMemo(() => {\n const tmp = (presetColors ?? []).map(({ color, isCustom, id }) => {\n let newColor = color;\n\n if (isHex(color)) {\n const { r, g, b, a } = hexToRgb(color);\n\n newColor = `rgba(${r},${g},${b},${a})`;\n }\n\n return {\n id,\n isCustom,\n color: newColor,\n };\n });\n\n if (shouldHideDefaultPresetColors) {\n return tmp;\n }\n\n return [...PRESETCOLORS, ...(siteColors ?? []), ...tmp];\n }, [presetColors, shouldHideDefaultPresetColors, siteColors]);\n\n const content = useMemo(() => {\n const items: ReactElement[] = [];\n\n combinedColors.forEach(({ color, id }, index) => {\n items.push(\n <PresetColor\n key={`preset-color__${id}`}\n color={color}\n isKeyboardFocusable={index === focusedPresetIndex}\n onFocus={() => setFocusedPresetIndex(index)}\n presetIndex={index}\n shouldEnableKeyboardHighlighting={shouldEnableKeyboardHighlighting}\n />,\n );\n });\n\n return items;\n }, [combinedColors, focusedPresetIndex, shouldEnableKeyboardHighlighting]);\n\n const handlePresetColorsKeyDown = usePresetColorKeyboardNavigation({\n onFocusChange: setFocusedPresetIndex,\n });\n\n const currentPresetColor = useMemo(\n () => combinedColors.find(({ color }) => color === selectedColor),\n [combinedColors, selectedColor],\n );\n\n const handleAddColor = (presetColor: IPresetColor) => {\n if (typeof onPresetColorAdd === 'function') {\n onPresetColorAdd(presetColor);\n }\n\n setSiteColors((prevColors) => {\n const colors = [...(prevColors ?? []), presetColor];\n\n const newColors = colors?.map(({ color }) => {\n const rgbValues = extractRgbValues(color);\n\n return rgbToHex(rgbValues);\n });\n\n void putSiteColors(newColors);\n\n return colors;\n });\n };\n\n const handleRemoveColor = (presetColorId: IPresetColor['id']) => {\n void loadSiteColors(presetColorId);\n\n if (typeof onPresetColorRemove === 'function') {\n onPresetColorRemove(presetColorId);\n }\n };\n\n return (\n <StyledPresetColors onKeyDown={handlePresetColorsKeyDown}>\n {content}\n {!shouldHideDefaultPresetColors && (\n <PresetButton\n id={currentPresetColor?.id}\n isCustom={currentPresetColor?.isCustom}\n isKeyboardFocusable={focusedPresetIndex === combinedColors.length}\n onAdd={handleAddColor}\n onFocus={() => setFocusedPresetIndex(combinedColors.length)}\n onRemove={handleRemoveColor}\n presetIndex={combinedColors.length}\n shouldEnableKeyboardHighlighting={shouldEnableKeyboardHighlighting}\n />\n )}\n </StyledPresetColors>\n );\n};\n\nPresetColors.displayName = 'PresetColors';\n\nexport default PresetColors;\n"],"mappings":"AAAA,SAASA,KAAK,QAAQ,gBAAgB;AACtC,OAAOC,KAAK,IAAIC,UAAU,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAA2B,OAAO;AAE1F,SAASC,aAAa,QAAQ,wBAAwB;AACtD,SAASC,aAAa,QAAQ,wBAAwB;AACtD,SAASC,YAAY,QAAQ,0BAA0B;AAEvD,SAASC,gBAAgB,EAAEC,QAAQ,EAAEC,QAAQ,QAAQ,sBAAsB;AAC3E,SAASC,kBAAkB,QAAQ,2BAA2B;AAC9D,OAAOC,YAAY,MAAM,8BAA8B;AACvD,OAAOC,WAAW,MAAM,4BAA4B;AACpD,SAASC,kBAAkB,QAAQ,uBAAuB;AAC1D,SAASC,gCAAgC,QAAQ,iDAAiD;AAWlG,MAAMC,YAAY,GAAGA,CAAC;EAClBC,YAAY;EACZC,mBAAmB;EACnBC,gBAAgB;EAChBC,mBAAmB;EACnBC,6BAA6B;EAC7BC;AACe,CAAC,KAAK;EACrB,MAAM;IAAEC;EAAc,CAAC,GAAGtB,UAAU,CAACU,kBAAkB,CAAC;EAExD,MAAM,CAACa,UAAU,EAAEC,aAAa,CAAC,GAAGrB,QAAQ,CAA6BsB,SAAS,CAAC;EACnF,MAAM,CAACC,kBAAkB,EAAEC,qBAAqB,CAAC,GAAGxB,QAAQ,CAAC,CAAC,CAAC;EAE/D,MAAMyB,cAAc,GAAG,MAAOC,aAAkC,IAAK;IACjE,MAAMC,MAAM,GAAG,MAAMzB,aAAa,CAAC,CAAC;IAEpCmB,aAAa,CAAEO,UAAU,IAAK;MAC1B,MAAMC,SAAS,GAAGF,MA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ACpDV,OAAO,EACP,CAAClC,6BAA6B,iBAC3BrB,KAAA,CAAA4D,aAAA,CAAChD,YAAY;IACT8B,EAAE,EAAEyB,kBAAkB,EAAEzB,EAAG;IAC3BI,QAAQ,EAAEqB,kBAAkB,EAAErB,QAAS;IACvCgB,mBAAmB,EAAEnC,kBAAkB,KAAK0B,cAAc,CAACmB,MAAO;IAClEC,KAAK,EAAEL,cAAe;IACtBL,OAAO,EAAEA,CAAA,KAAMnC,qBAAqB,CAACyB,cAAc,CAACmB,MAAM,CAAE;IAC5DE,QAAQ,EAAEJ,iBAAkB;IAC5BN,WAAW,EAAEX,cAAc,CAACmB,MAAO;IACnClD,gCAAgC,EAAEA;EAAiC,CACtE,CAEW,CAAC;AAE7B,CAAC;AAEDN,YAAY,CAAC2D,WAAW,GAAG,cAAc;AAEzC,eAAe3D,YAAY","ignoreList":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Icon } from '@chayns-components/core';
|
|
2
|
-
import React, { useContext } from 'react';
|
|
1
|
+
import { Icon, useFocusRingPortal, useKeyboardFocusHighlighting } from '@chayns-components/core';
|
|
2
|
+
import React, { useContext, useRef } from 'react';
|
|
3
3
|
import { v4 as uuidv4 } from 'uuid';
|
|
4
4
|
import { ColorPickerContext } from '../../../ColorPickerProvider';
|
|
5
5
|
import { StyledPresetButton } from './PresetButton.styles';
|
|
@@ -7,15 +7,27 @@ const PresetButton = ({
|
|
|
7
7
|
id,
|
|
8
8
|
isCustom,
|
|
9
9
|
onRemove,
|
|
10
|
-
onAdd
|
|
10
|
+
onAdd,
|
|
11
|
+
shouldEnableKeyboardHighlighting,
|
|
12
|
+
isKeyboardFocusable = false,
|
|
13
|
+
onFocus,
|
|
14
|
+
presetIndex
|
|
11
15
|
}) => {
|
|
12
16
|
const {
|
|
13
17
|
selectedColor
|
|
14
18
|
} = useContext(ColorPickerContext);
|
|
15
|
-
const
|
|
19
|
+
const buttonRef = useRef(null);
|
|
20
|
+
const canRemove = Boolean(id && isCustom);
|
|
21
|
+
const shouldShowKeyboardHighlighting = useKeyboardFocusHighlighting(shouldEnableKeyboardHighlighting);
|
|
22
|
+
useFocusRingPortal(buttonRef, {
|
|
23
|
+
isEnabled: shouldShowKeyboardHighlighting,
|
|
24
|
+
shape: 'circle',
|
|
25
|
+
padding: 3
|
|
26
|
+
});
|
|
27
|
+
const icon = canRemove ? ['fa-solid fa-trash'] : ['fa-solid fa-plus'];
|
|
16
28
|
const handleClick = () => {
|
|
17
|
-
if (
|
|
18
|
-
if (typeof onRemove === 'function') {
|
|
29
|
+
if (canRemove) {
|
|
30
|
+
if (id && typeof onRemove === 'function') {
|
|
19
31
|
onRemove(id);
|
|
20
32
|
}
|
|
21
33
|
} else if (typeof onAdd === 'function' && selectedColor) {
|
|
@@ -28,10 +40,15 @@ const PresetButton = ({
|
|
|
28
40
|
};
|
|
29
41
|
return /*#__PURE__*/React.createElement(StyledPresetButton, {
|
|
30
42
|
onClick: handleClick,
|
|
31
|
-
|
|
43
|
+
onFocus: onFocus,
|
|
44
|
+
ref: buttonRef,
|
|
45
|
+
"data-preset-color-index": presetIndex,
|
|
46
|
+
tabIndex: isKeyboardFocusable ? 0 : -1,
|
|
47
|
+
type: "button",
|
|
48
|
+
$isDisabled: false
|
|
32
49
|
}, /*#__PURE__*/React.createElement(Icon, {
|
|
33
50
|
icons: icon,
|
|
34
|
-
size:
|
|
51
|
+
size: canRemove ? 10 : 15
|
|
35
52
|
}));
|
|
36
53
|
};
|
|
37
54
|
PresetButton.displayName = 'PresetButton';
|
package/lib/esm/components/color-picker-popup/preset-colors/preset-button/PresetButton.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PresetButton.js","names":["Icon","React","useContext","v4","uuidv4","ColorPickerContext","StyledPresetButton","PresetButton","id","isCustom","onRemove","onAdd","selectedColor","icon","handleClick","color","createElement","onClick","$isDisabled","icons","size","displayName"],"sources":["../../../../../../src/components/color-picker-popup/preset-colors/preset-button/PresetButton.tsx"],"sourcesContent":["import { Icon } from '@chayns-components/core';\nimport React, { useContext } from 'react';\nimport { v4 as uuidv4 } from 'uuid';\nimport type { IPresetColor } from '../../../../types/colorPicker';\nimport { ColorPickerContext } from '../../../ColorPickerProvider';\nimport { StyledPresetButton } from './PresetButton.styles';\n\ninterface PresetButtonProps {\n id?: IPresetColor['id'];\n isCustom?: IPresetColor['isCustom'];\n onAdd?: (color: IPresetColor) => void;\n onRemove?: (id: IPresetColor['id']) => void;\n}\n\nconst PresetButton = ({
|
|
1
|
+
{"version":3,"file":"PresetButton.js","names":["Icon","useFocusRingPortal","useKeyboardFocusHighlighting","React","useContext","useRef","v4","uuidv4","ColorPickerContext","StyledPresetButton","PresetButton","id","isCustom","onRemove","onAdd","shouldEnableKeyboardHighlighting","isKeyboardFocusable","onFocus","presetIndex","selectedColor","buttonRef","canRemove","Boolean","shouldShowKeyboardHighlighting","isEnabled","shape","padding","icon","handleClick","color","createElement","onClick","ref","tabIndex","type","$isDisabled","icons","size","displayName"],"sources":["../../../../../../src/components/color-picker-popup/preset-colors/preset-button/PresetButton.tsx"],"sourcesContent":["import { Icon, useFocusRingPortal, useKeyboardFocusHighlighting } from '@chayns-components/core';\nimport React, { FocusEventHandler, useContext, useRef } from 'react';\nimport { v4 as uuidv4 } from 'uuid';\nimport type { IPresetColor } from '../../../../types/colorPicker';\nimport { ColorPickerContext } from '../../../ColorPickerProvider';\nimport { StyledPresetButton } from './PresetButton.styles';\n\ninterface PresetButtonProps {\n id?: IPresetColor['id'];\n isCustom?: IPresetColor['isCustom'];\n onAdd?: (color: IPresetColor) => void;\n onRemove?: (id: IPresetColor['id']) => void;\n shouldEnableKeyboardHighlighting?: boolean;\n isKeyboardFocusable?: boolean;\n onFocus?: FocusEventHandler<HTMLButtonElement>;\n presetIndex?: number;\n}\n\nconst PresetButton = ({\n id,\n isCustom,\n onRemove,\n onAdd,\n shouldEnableKeyboardHighlighting,\n isKeyboardFocusable = false,\n onFocus,\n presetIndex,\n}: PresetButtonProps) => {\n const { selectedColor } = useContext(ColorPickerContext);\n const buttonRef = useRef<HTMLButtonElement>(null);\n const canRemove = Boolean(id && isCustom);\n const shouldShowKeyboardHighlighting = useKeyboardFocusHighlighting(\n shouldEnableKeyboardHighlighting,\n );\n\n useFocusRingPortal(buttonRef, {\n isEnabled: shouldShowKeyboardHighlighting,\n shape: 'circle',\n padding: 3,\n });\n\n const icon = canRemove ? ['fa-solid fa-trash'] : ['fa-solid fa-plus'];\n\n const handleClick = () => {\n if (canRemove) {\n if (id && typeof onRemove === 'function') {\n onRemove(id);\n }\n } else if (typeof onAdd === 'function' && selectedColor) {\n onAdd({ color: selectedColor, isCustom: true, id: uuidv4() });\n }\n };\n\n return (\n <StyledPresetButton\n onClick={handleClick}\n onFocus={onFocus}\n ref={buttonRef}\n data-preset-color-index={presetIndex}\n tabIndex={isKeyboardFocusable ? 0 : -1}\n type=\"button\"\n $isDisabled={false}\n >\n <Icon icons={icon} size={canRemove ? 10 : 15} />\n </StyledPresetButton>\n );\n};\n\nPresetButton.displayName = 'PresetButton';\n\nexport default PresetButton;\n"],"mappings":"AAAA,SAASA,IAAI,EAAEC,kBAAkB,EAAEC,4BAA4B,QAAQ,yBAAyB;AAChG,OAAOC,KAAK,IAAuBC,UAAU,EAAEC,MAAM,QAAQ,OAAO;AACpE,SAASC,EAAE,IAAIC,MAAM,QAAQ,MAAM;AAEnC,SAASC,kBAAkB,QAAQ,8BAA8B;AACjE,SAASC,kBAAkB,QAAQ,uBAAuB;AAa1D,MAAMC,YAAY,GAAGA,CAAC;EAClBC,EAAE;EACFC,QAAQ;EACRC,QAAQ;EACRC,KAAK;EACLC,gCAAgC;EAChCC,mBAAmB,GAAG,KAAK;EAC3BC,OAAO;EACPC;AACe,CAAC,KAAK;EACrB,MAAM;IAAEC;EAAc,CAAC,GAAGf,UAAU,CAACI,kBAAkB,CAAC;EACxD,MAAMY,SAAS,GAAGf,MAAM,CAAoB,IAAI,CAAC;EACjD,MAAMgB,SAA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ANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import styled from 'styled-components';
|
|
2
|
-
export const StyledPresetButton = styled.
|
|
2
|
+
export const StyledPresetButton = styled.button`
|
|
3
3
|
display: flex;
|
|
4
4
|
align-items: center;
|
|
5
5
|
justify-content: center;
|
|
6
6
|
|
|
7
7
|
background-color: transparent;
|
|
8
|
+
padding: 0;
|
|
8
9
|
width: 22px;
|
|
9
10
|
aspect-ratio: 1;
|
|
10
11
|
cursor: ${({
|
package/lib/esm/components/color-picker-popup/preset-colors/preset-button/PresetButton.styles.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PresetButton.styles.js","names":["styled","StyledPresetButton","
|
|
1
|
+
{"version":3,"file":"PresetButton.styles.js","names":["styled","StyledPresetButton","button","$isDisabled"],"sources":["../../../../../../src/components/color-picker-popup/preset-colors/preset-button/PresetButton.styles.ts"],"sourcesContent":["import type { WithTheme } from '@chayns-components/core';\nimport styled from 'styled-components';\n\ntype StyledPresetButtonProps = WithTheme<{ $isDisabled: boolean }>;\n\nexport const StyledPresetButton = styled.button<StyledPresetButtonProps>`\n display: flex;\n align-items: center;\n justify-content: center;\n\n background-color: transparent;\n padding: 0;\n width: 22px;\n aspect-ratio: 1;\n cursor: ${({ $isDisabled }) => ($isDisabled ? 'normal' : 'pointer')};\n\n opacity: ${({ $isDisabled }) => ($isDisabled ? 0.5 : 1)};\n\n border-radius: 50px;\n border: 1px solid rgba(160, 160, 160, 0.3);\n`;\n"],"mappings":"AACA,OAAOA,MAAM,MAAM,mBAAmB;AAItC,OAAO,MAAMC,kBAAkB,GAAGD,MAAM,CAACE,MAA+B;AACxE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,cAAc,CAAC;EAAEC;AAAY,CAAC,KAAMA,WAAW,GAAG,QAAQ,GAAG,SAAU;AACvE;AACA,eAAe,CAAC;EAAEA;AAAY,CAAC,KAAMA,WAAW,GAAG,GAAG,GAAG,CAAE;AAC3D;AACA;AACA;AACA,CAAC","ignoreList":[]}
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useFocusRingPortal, useKeyboardFocusHighlighting } from '@chayns-components/core';
|
|
2
|
+
import React, { useContext, useMemo, useRef } from 'react';
|
|
2
3
|
import { ColorPickerContext } from '../../../ColorPickerProvider';
|
|
3
4
|
import { StyledPresetColor, StyledPresetColorBackground, StyledPresetColorColor } from './PresetColor.styles';
|
|
4
5
|
const PresetColor = ({
|
|
5
|
-
color
|
|
6
|
+
color,
|
|
7
|
+
shouldEnableKeyboardHighlighting,
|
|
8
|
+
isKeyboardFocusable = false,
|
|
9
|
+
presetIndex,
|
|
10
|
+
onFocus
|
|
6
11
|
}) => {
|
|
7
12
|
const {
|
|
8
13
|
selectedColor,
|
|
@@ -13,6 +18,13 @@ const PresetColor = ({
|
|
|
13
18
|
updateIsPresetColor
|
|
14
19
|
} = useContext(ColorPickerContext);
|
|
15
20
|
const isSelected = useMemo(() => selectedColor === color, [color, selectedColor]);
|
|
21
|
+
const presetColorRef = useRef(null);
|
|
22
|
+
const shouldShowKeyboardHighlighting = useKeyboardFocusHighlighting(shouldEnableKeyboardHighlighting);
|
|
23
|
+
useFocusRingPortal(presetColorRef, {
|
|
24
|
+
isEnabled: shouldShowKeyboardHighlighting,
|
|
25
|
+
shape: 'circle',
|
|
26
|
+
padding: 3
|
|
27
|
+
});
|
|
16
28
|
const handleClick = () => {
|
|
17
29
|
if (typeof updateSelectedColor === 'function') {
|
|
18
30
|
updateSelectedColor(color);
|
|
@@ -30,9 +42,21 @@ const PresetColor = ({
|
|
|
30
42
|
updateShouldGetCoordinates(true);
|
|
31
43
|
}
|
|
32
44
|
};
|
|
45
|
+
const handleKeyDown = event => {
|
|
46
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
47
|
+
event.preventDefault();
|
|
48
|
+
handleClick();
|
|
49
|
+
}
|
|
50
|
+
};
|
|
33
51
|
return /*#__PURE__*/React.createElement(StyledPresetColor, {
|
|
52
|
+
ref: presetColorRef,
|
|
34
53
|
onClick: handleClick,
|
|
35
|
-
|
|
54
|
+
onKeyDown: handleKeyDown,
|
|
55
|
+
onFocus: onFocus,
|
|
56
|
+
$isSelected: isSelected,
|
|
57
|
+
"data-preset-color-index": presetIndex,
|
|
58
|
+
role: "button",
|
|
59
|
+
tabIndex: isKeyboardFocusable ? 0 : -1
|
|
36
60
|
}, /*#__PURE__*/React.createElement(StyledPresetColorBackground, null), /*#__PURE__*/React.createElement(StyledPresetColorColor, {
|
|
37
61
|
$color: color
|
|
38
62
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PresetColor.js","names":["React","useContext","useMemo","ColorPickerContext","StyledPresetColor","StyledPresetColorBackground","StyledPresetColorColor","PresetColor","color","selectedColor","updateSelectedColor","updateHueColor","updateShouldCallOnSelect","updateShouldGetCoordinates","updateIsPresetColor","isSelected","handleClick","createElement","onClick","$isSelected","$color","displayName"],"sources":["../../../../../../src/components/color-picker-popup/preset-colors/preset-color/PresetColor.tsx"],"sourcesContent":["import React, { useContext, useMemo } from 'react';\n\nimport type { IPresetColor } from '../../../../types/colorPicker';\nimport { ColorPickerContext } from '../../../ColorPickerProvider';\nimport {\n StyledPresetColor,\n StyledPresetColorBackground,\n StyledPresetColorColor,\n} from './PresetColor.styles';\n\ninterface PresetColorProps {\n color: IPresetColor['color'];\n}\n\nconst PresetColor = ({
|
|
1
|
+
{"version":3,"file":"PresetColor.js","names":["useFocusRingPortal","useKeyboardFocusHighlighting","React","useContext","useMemo","useRef","ColorPickerContext","StyledPresetColor","StyledPresetColorBackground","StyledPresetColorColor","PresetColor","color","shouldEnableKeyboardHighlighting","isKeyboardFocusable","presetIndex","onFocus","selectedColor","updateSelectedColor","updateHueColor","updateShouldCallOnSelect","updateShouldGetCoordinates","updateIsPresetColor","isSelected","presetColorRef","shouldShowKeyboardHighlighting","isEnabled","shape","padding","handleClick","handleKeyDown","event","key","preventDefault","createElement","ref","onClick","onKeyDown","$isSelected","role","tabIndex","$color","displayName"],"sources":["../../../../../../src/components/color-picker-popup/preset-colors/preset-color/PresetColor.tsx"],"sourcesContent":["import { useFocusRingPortal, useKeyboardFocusHighlighting } from '@chayns-components/core';\nimport React, { FocusEventHandler, KeyboardEvent, useContext, useMemo, useRef } from 'react';\n\nimport type { IPresetColor } from '../../../../types/colorPicker';\nimport { ColorPickerContext } from '../../../ColorPickerProvider';\nimport {\n StyledPresetColor,\n StyledPresetColorBackground,\n StyledPresetColorColor,\n} from './PresetColor.styles';\n\ninterface PresetColorProps {\n color: IPresetColor['color'];\n shouldEnableKeyboardHighlighting?: boolean;\n isKeyboardFocusable?: boolean;\n presetIndex?: number;\n onFocus?: FocusEventHandler<HTMLDivElement>;\n}\n\nconst PresetColor = ({\n color,\n shouldEnableKeyboardHighlighting,\n isKeyboardFocusable = false,\n presetIndex,\n onFocus,\n}: PresetColorProps) => {\n const {\n selectedColor,\n updateSelectedColor,\n updateHueColor,\n updateShouldCallOnSelect,\n updateShouldGetCoordinates,\n updateIsPresetColor,\n } = useContext(ColorPickerContext);\n\n const isSelected = useMemo(() => selectedColor === color, [color, selectedColor]);\n const presetColorRef = useRef<HTMLDivElement>(null);\n const shouldShowKeyboardHighlighting = useKeyboardFocusHighlighting(\n shouldEnableKeyboardHighlighting,\n );\n\n useFocusRingPortal(presetColorRef, {\n isEnabled: shouldShowKeyboardHighlighting,\n shape: 'circle',\n padding: 3,\n });\n\n const handleClick = () => {\n if (typeof updateSelectedColor === 'function') {\n updateSelectedColor(color);\n }\n\n if (typeof updateHueColor === 'function') {\n updateHueColor(color);\n }\n\n if (typeof updateIsPresetColor === 'function') {\n updateIsPresetColor(true);\n }\n\n if (typeof updateShouldCallOnSelect === 'function') {\n updateShouldCallOnSelect(true);\n }\n\n if (typeof updateShouldGetCoordinates === 'function') {\n updateShouldGetCoordinates(true);\n }\n };\n\n const handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {\n if (event.key === 'Enter' || event.key === ' ') {\n event.preventDefault();\n handleClick();\n }\n };\n\n return (\n <StyledPresetColor\n ref={presetColorRef}\n onClick={handleClick}\n onKeyDown={handleKeyDown}\n onFocus={onFocus}\n $isSelected={isSelected}\n data-preset-color-index={presetIndex}\n role=\"button\"\n tabIndex={isKeyboardFocusable ? 0 : -1}\n >\n <StyledPresetColorBackground />\n <StyledPresetColorColor $color={color} />\n </StyledPresetColor>\n );\n};\n\nPresetColor.displayName = 'PresetColor';\n\nexport default PresetColor;\n"],"mappings":"AAAA,SAASA,kBAAkB,EAAEC,4BAA4B,QAAQ,yBAAyB;AAC1F,OAAOC,KAAK,IAAsCC,UAAU,EAAEC,OAAO,EAAEC,MAAM,QAAQ,OAAO;AAG5F,SAASC,kBAAkB,QAAQ,8BAA8B;AACjE,SACIC,iBAAiB,EACjBC,2BAA2B,EAC3BC,sBAAsB,QACnB,sBAAsB;AAU7B,MAAMC,WAAW,GAAGA,CAAC;EACjBC,KAAK;EACLC,gCAAgC;EAChCC,mBAAmB,GAAG,KAAK;EAC3BC,WAAW;EACXC;AACc,CAAC,KAAK;EACpB,MAAM;IACFC,aAAa;IACbC,mBAAmB;IACnBC,cAAc;IACdC,wBAAwB;IACxBC,0BAA0B;IAC1BC;EACJ,CAAC,GAAGlB,UAAU,CAACG,kBAAkB,CAAC;EAElC,MAAMgB,UAAU,GAAGlB,OAAO,CAAC,MAAMY,aAAa,KAAKL,KAAK,EAAE,CAACA,KAAK,EAAEK,aAAa,CAAC,CAAC;EACjF,MAAMO,cAAc,GAAGlB,MAAM,CAAiB,IAAI,CAAC;EACnD,MAAMmB,8BAA8B,GAAGvB,4BAA4B,CAC/DW,gCACJ,CAAC;EAEDZ,kBAAkB,CAACuB,cAAc,EAAE;IAC/BE,SAAS,EAAED,8BAA8B;IACzCE,KAAK,EAAE,QAAQ;IACfC,OAAO,EAAE;EACb,CAAC,CAAC;EAEF,MAAMC,WAAW,GAAGA,CAAA,KAAM;IACtB,IAAI,OAAOX,mBAAmB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view from './color-preview/ColorPreview';
|
|
7
7
|
import { StyledSliders, StyledSlidersWrapper } from './Sliders.styles';
|
|
8
8
|
const Sliders = ({
|
|
9
|
-
shouldShowTransparencySlider
|
|
9
|
+
shouldShowTransparencySlider,
|
|
10
|
+
shouldEnableKeyboardHighlighting
|
|
10
11
|
}) => {
|
|
11
12
|
const {
|
|
12
13
|
selectedColor,
|
|
@@ -26,6 +27,9 @@ const Sliders = ({
|
|
|
26
27
|
if (typeof updateHueColor === 'function' && color) {
|
|
27
28
|
updateHueColor(color);
|
|
28
29
|
}
|
|
30
|
+
if (typeof updateSelectedColor === 'function' && color) {
|
|
31
|
+
updateSelectedColor(color);
|
|
32
|
+
}
|
|
29
33
|
};
|
|
30
34
|
const handleStart = () => {
|
|
31
35
|
if (typeof updateShouldGetCoordinates === 'function') {
|
|
@@ -53,12 +57,14 @@ const Sliders = ({
|
|
|
53
57
|
opacity: opacity,
|
|
54
58
|
onEnd: handleEnd,
|
|
55
59
|
onStart: handleHueStart,
|
|
56
|
-
onChange: handleHueColorChange
|
|
60
|
+
onChange: handleHueColorChange,
|
|
61
|
+
shouldEnableKeyboardHighlighting: shouldEnableKeyboardHighlighting
|
|
57
62
|
}), shouldShowTransparencySlider && /*#__PURE__*/React.createElement(TransparencySlider, {
|
|
58
63
|
color: selectedColor,
|
|
59
64
|
onEnd: handleEnd,
|
|
60
65
|
onStart: handleStart,
|
|
61
|
-
onChange: handleColorChange
|
|
66
|
+
onChange: handleColorChange,
|
|
67
|
+
shouldEnableKeyboardHighlighting: shouldEnableKeyboardHighlighting
|
|
62
68
|
})), /*#__PURE__*/React.createElement(ColorPreview, null));
|
|
63
69
|
};
|
|
64
70
|
Sliders.displayName = 'Sliders';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Sliders.js","names":["React","useContext","useMemo","extractRgbValues","ColorPickerContext","HueSlider","TransparencySlider","ColorPreview","StyledSliders","StyledSlidersWrapper","Sliders","shouldShowTransparencySlider","selectedColor","updateSelectedColor","updateHueColor","updateShouldGetCoordinates","updateShouldCallOnSelect","updateCanGetColorFromArea","hueColor","handleColorChange","color","handleHueColorChange","handleStart","handleHueStart","handleEnd","opacity","a","createElement","onEnd","onStart","onChange","displayName"],"sources":["../../../../../src/components/color-picker-popup/sliders/Sliders.tsx"],"sourcesContent":["import React, { useContext, useMemo, type CSSProperties } from 'react';\nimport { extractRgbValues } from '../../../utils/color';\nimport { ColorPickerContext } from '../../ColorPickerProvider';\nimport HueSlider from '../../hue-slider/HueSlider';\nimport TransparencySlider from '../../transparency-slider/TransparencySlider';\nimport ColorPreview from './color-preview/ColorPreview';\nimport { StyledSliders, StyledSlidersWrapper } from './Sliders.styles';\n\ninterface SlidersProps {\n shouldShowTransparencySlider: boolean;\n}\n\nconst Sliders = ({
|
|
1
|
+
{"version":3,"file":"Sliders.js","names":["React","useContext","useMemo","extractRgbValues","ColorPickerContext","HueSlider","TransparencySlider","ColorPreview","StyledSliders","StyledSlidersWrapper","Sliders","shouldShowTransparencySlider","shouldEnableKeyboardHighlighting","selectedColor","updateSelectedColor","updateHueColor","updateShouldGetCoordinates","updateShouldCallOnSelect","updateCanGetColorFromArea","hueColor","handleColorChange","color","handleHueColorChange","handleStart","handleHueStart","handleEnd","opacity","a","createElement","onEnd","onStart","onChange","displayName"],"sources":["../../../../../src/components/color-picker-popup/sliders/Sliders.tsx"],"sourcesContent":["import React, { useContext, useMemo, type CSSProperties } from 'react';\nimport { extractRgbValues } from '../../../utils/color';\nimport { ColorPickerContext } from '../../ColorPickerProvider';\nimport HueSlider from '../../hue-slider/HueSlider';\nimport TransparencySlider from '../../transparency-slider/TransparencySlider';\nimport ColorPreview from './color-preview/ColorPreview';\nimport { StyledSliders, StyledSlidersWrapper } from './Sliders.styles';\n\ninterface SlidersProps {\n shouldShowTransparencySlider: boolean;\n shouldEnableKeyboardHighlighting?: boolean;\n}\n\nconst Sliders = ({\n shouldShowTransparencySlider,\n shouldEnableKeyboardHighlighting,\n}: SlidersProps) => {\n const {\n selectedColor,\n updateSelectedColor,\n updateHueColor,\n updateShouldGetCoordinates,\n updateShouldCallOnSelect,\n updateCanGetColorFromArea,\n hueColor,\n } = useContext(ColorPickerContext);\n\n const handleColorChange = (color: CSSProperties['color']) => {\n if (typeof updateSelectedColor === 'function' && color) {\n updateSelectedColor(color);\n }\n };\n\n const handleHueColorChange = (color: CSSProperties['color']) => {\n if (typeof updateHueColor === 'function' && color) {\n updateHueColor(color);\n }\n\n if (typeof updateSelectedColor === 'function' && color) {\n updateSelectedColor(color);\n }\n };\n\n const handleStart = () => {\n if (typeof updateShouldGetCoordinates === 'function') {\n updateShouldGetCoordinates(false);\n }\n };\n\n const handleHueStart = () => {\n handleStart();\n\n if (typeof updateCanGetColorFromArea === 'function') {\n updateCanGetColorFromArea(true);\n }\n };\n\n const handleEnd = () => {\n if (\n typeof updateShouldGetCoordinates === 'function' &&\n typeof updateShouldCallOnSelect === 'function'\n ) {\n updateShouldGetCoordinates(true);\n updateShouldCallOnSelect(true);\n }\n\n if (typeof updateCanGetColorFromArea === 'function') {\n updateCanGetColorFromArea(false);\n }\n };\n\n const opacity = useMemo(() => extractRgbValues(selectedColor ?? '').a, [selectedColor]);\n\n return (\n <StyledSliders>\n <StyledSlidersWrapper>\n <HueSlider\n color={hueColor}\n opacity={opacity}\n onEnd={handleEnd}\n onStart={handleHueStart}\n onChange={handleHueColorChange}\n shouldEnableKeyboardHighlighting={shouldEnableKeyboardHighlighting}\n />\n {shouldShowTransparencySlider && (\n <TransparencySlider\n color={selectedColor}\n onEnd={handleEnd}\n onStart={handleStart}\n onChange={handleColorChange}\n shouldEnableKeyboardHighlighting={shouldEnableKeyboardHighlighting}\n />\n )}\n </StyledSlidersWrapper>\n <ColorPreview />\n </StyledSliders>\n );\n};\n\nSliders.displayName = 'Sliders';\n\nexport default Sliders;\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,UAAU,EAAEC,OAAO,QAA4B,OAAO;AACtE,SAASC,gBAAgB,QAAQ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U,EAChD;MACED,0BAA0B,CAAC,IAAI,CAAC;MAChCC,wBAAwB,CAAC,IAAI,CAAC;IAClC;IAEA,IAAI,OAAOC,yBAAyB,KAAK,UAAU,EAAE;MACjDA,yBAAyB,CAAC,KAAK,CAAC;IACpC;EACJ,CAAC;EAED,MAAMQ,OAAO,GAAGxB,OAAO,CAAC,MAAMC,gBAAgB,CAACU,aAAa,IAAI,EAAE,CAAC,CAACc,CAAC,EAAE,CAACd,aAAa,CAAC,CAAC;EAEvF,oBACIb,KAAA,CAAA4B,aAAA,CAACpB,aAAa,qBACVR,KAAA,CAAA4B,aAAA,CAACnB,oBAAoB,qBACjBT,KAAA,CAAA4B,aAAA,CAACvB,SAAS;IACNgB,KAAK,EAAEF,QAAS;IAChBO,OAAO,EAAEA,OAAQ;IACjBG,KAAK,EAAEJ,SAAU;IACjBK,OAAO,EAAEN,cAAe;IACxBO,QAAQ,EAAET,oBAAqB;IAC/BV,gCAAgC,EAAEA;EAAiC,CACtE,CAAC,EACDD,4BAA4B,iBACzBX,KAAA,CAAA4B,aAAA,CAACtB,kBAAkB;IACfe,KAAK,EAAER,aAAc;IACrBgB,KAAK,EAAEJ,SAAU;IACjBK,OAAO,EAAEP,WAAY;IACrBQ,QAAQ,EAAEX,iBAAkB;IAC5BR,gCAAgC,EAAEA;EAAiC,CACtE,CAEa,CAAC,eACvBZ,KAAA,CAAA4B,aAAA,CAACrB,YAAY,MAAE,CACJ,CAAC;AAExB,CAAC;AAEDG,OAAO,CAACsB,WAAW,GAAG,SAAS;AAE/B,eAAetB,OAAO","ignoreList":[]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { hslToRgb255 } from '@chayns/colors';
|
|
2
|
+
import { useFocusRingPortal, useKeyboardFocusHighlighting } from '@chayns-components/core';
|
|
2
3
|
import { setRefreshScrollEnabled } from 'chayns-api';
|
|
3
4
|
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
4
5
|
import { convertColorToHsl, extractHsl, hexToRgb, isValidRGBA, splitRgb } from '../../utils/color';
|
|
@@ -8,13 +9,21 @@ const HueSlider = ({
|
|
|
8
9
|
onStart,
|
|
9
10
|
onEnd,
|
|
10
11
|
opacity,
|
|
11
|
-
color = 'rgba(255, 0, 0, 1)'
|
|
12
|
+
color = 'rgba(255, 0, 0, 1)',
|
|
13
|
+
shouldEnableKeyboardHighlighting
|
|
12
14
|
}) => {
|
|
13
15
|
const [editedValue, setEditedValue] = useState(0);
|
|
14
16
|
const [hslColor, setHslColor] = useState('hsl(0, 0, 100)');
|
|
15
17
|
const [internalOpacity, setInternalOpacity] = useState(1);
|
|
16
18
|
const sliderThumbRef = useRef(null);
|
|
17
19
|
const sliderRef = useRef(null);
|
|
20
|
+
const shouldShowKeyboardHighlighting = useKeyboardFocusHighlighting(shouldEnableKeyboardHighlighting);
|
|
21
|
+
useFocusRingPortal(sliderRef, {
|
|
22
|
+
isEnabled: shouldShowKeyboardHighlighting,
|
|
23
|
+
overlayRef: sliderThumbRef,
|
|
24
|
+
shape: 'circle',
|
|
25
|
+
padding: 3
|
|
26
|
+
});
|
|
18
27
|
useEffect(() => {
|
|
19
28
|
if (color) {
|
|
20
29
|
let rgb;
|