@connectif/ui-components 5.1.0 → 5.1.1
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/CHANGELOG.md
CHANGED
|
@@ -47,6 +47,12 @@ export type ColorPickerProps = {
|
|
|
47
47
|
* (optional) The width of the input field
|
|
48
48
|
*/
|
|
49
49
|
inputWidthStyle?: string;
|
|
50
|
+
/**
|
|
51
|
+
* (optional) The color format mode, 'hex' to force hex format in the "onChange" call. 'auto' to switch between hex and rgba depending on user input.
|
|
52
|
+
* rgba will be used when alpha is allowed and the color has transparency even in hex mode.
|
|
53
|
+
* @default 'auto'
|
|
54
|
+
*/
|
|
55
|
+
mode?: 'hex' | 'auto';
|
|
50
56
|
/**
|
|
51
57
|
* A function to update color value
|
|
52
58
|
*/
|
package/dist/index.js
CHANGED
|
@@ -21651,6 +21651,7 @@ var ColorPicker = React62.forwardRef(function ColorPickerWrapper({
|
|
|
21651
21651
|
allowAlpha = false,
|
|
21652
21652
|
popoverZIndex,
|
|
21653
21653
|
inputWidthStyle = "150px",
|
|
21654
|
+
mode = "auto",
|
|
21654
21655
|
onChange
|
|
21655
21656
|
}, ref) {
|
|
21656
21657
|
const { t } = useTranslation();
|
|
@@ -21675,20 +21676,9 @@ var ColorPicker = React62.forwardRef(function ColorPickerWrapper({
|
|
|
21675
21676
|
setTextFieldValue(newValue);
|
|
21676
21677
|
if (isValidColor(newValue) || allowEmpty && newValue === "") {
|
|
21677
21678
|
setInternalPickerValue(newValue);
|
|
21678
|
-
onChange(newValue);
|
|
21679
|
+
onChange(mode === "hex" ? rgbToHex(newValue) : newValue);
|
|
21679
21680
|
}
|
|
21680
21681
|
};
|
|
21681
|
-
const normalizeBlack = (color2) => {
|
|
21682
|
-
const rgb = color2.match(/\d+/g);
|
|
21683
|
-
if (!rgb) {
|
|
21684
|
-
return color2;
|
|
21685
|
-
}
|
|
21686
|
-
const [r2, g, b] = rgb.map(Number);
|
|
21687
|
-
if (r2 <= 1 && g <= 1 && b <= 1) {
|
|
21688
|
-
return "rgb(0,0,0)";
|
|
21689
|
-
}
|
|
21690
|
-
return color2;
|
|
21691
|
-
};
|
|
21692
21682
|
const iconColor = /* @__PURE__ */ jsx117(
|
|
21693
21683
|
IconButton_default,
|
|
21694
21684
|
{
|
|
@@ -21703,8 +21693,8 @@ var ColorPicker = React62.forwardRef(function ColorPickerWrapper({
|
|
|
21703
21693
|
React62.useEffect(() => {
|
|
21704
21694
|
const handleInternalColorChange = (color2) => {
|
|
21705
21695
|
setPreviousColors((prev) => [color2, ...prev.slice(0, 17)]);
|
|
21706
|
-
setTextFieldValue(rgbToHex(color2));
|
|
21707
|
-
onChange(color2);
|
|
21696
|
+
setTextFieldValue(mode === "hex" ? rgbToHex(color2) : color2);
|
|
21697
|
+
onChange(mode === "hex" ? rgbToHex(color2) : color2);
|
|
21708
21698
|
setValidPickerChange(false);
|
|
21709
21699
|
setColorChangeOccurred(false);
|
|
21710
21700
|
};
|
|
@@ -21717,7 +21707,8 @@ var ColorPicker = React62.forwardRef(function ColorPickerWrapper({
|
|
|
21717
21707
|
onChange,
|
|
21718
21708
|
isValidPickerChange,
|
|
21719
21709
|
colorChangeOccurred,
|
|
21720
|
-
isPopoverInputFocused
|
|
21710
|
+
isPopoverInputFocused,
|
|
21711
|
+
mode
|
|
21721
21712
|
]);
|
|
21722
21713
|
React62.useEffect(() => {
|
|
21723
21714
|
const handleExternalColorChange = (color2) => {
|
|
@@ -21862,7 +21853,19 @@ var ColorPicker = React62.forwardRef(function ColorPickerWrapper({
|
|
|
21862
21853
|
});
|
|
21863
21854
|
var ColorPicker_default = ColorPicker;
|
|
21864
21855
|
var rgbToHex = (rgb) => {
|
|
21865
|
-
|
|
21856
|
+
if (/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(rgb) || !rgb.startsWith("rgb")) {
|
|
21857
|
+
return rgb;
|
|
21858
|
+
}
|
|
21859
|
+
if (rgb.includes("rgba")) {
|
|
21860
|
+
const alphaMatch = rgb.match(
|
|
21861
|
+
/rgba\(\d{1,3}, {0,1}\d{1,3}, {0,1}\d{1,3}, {0,1}([01]|0?\.\d+)\)/
|
|
21862
|
+
);
|
|
21863
|
+
if (alphaMatch && alphaMatch[1] === "0") {
|
|
21864
|
+
return "transparent";
|
|
21865
|
+
}
|
|
21866
|
+
}
|
|
21867
|
+
const normalized = normalizeBlack(rgb);
|
|
21868
|
+
const rgbValues = normalized.match(/\d+/g);
|
|
21866
21869
|
if (!rgbValues || rgbValues.length !== 3 && rgbValues.length !== 4) {
|
|
21867
21870
|
return rgb;
|
|
21868
21871
|
}
|
|
@@ -21871,6 +21874,17 @@ var rgbToHex = (rgb) => {
|
|
|
21871
21874
|
return hex.length === 1 ? "0" + hex : hex;
|
|
21872
21875
|
}).join("");
|
|
21873
21876
|
};
|
|
21877
|
+
var normalizeBlack = (color2) => {
|
|
21878
|
+
const rgb = color2.match(/\d+/g);
|
|
21879
|
+
if (!rgb) {
|
|
21880
|
+
return color2;
|
|
21881
|
+
}
|
|
21882
|
+
const [r2, g, b] = rgb.map(Number);
|
|
21883
|
+
if (r2 <= 1 && g <= 1 && b <= 1) {
|
|
21884
|
+
return "rgb(0,0,0)";
|
|
21885
|
+
}
|
|
21886
|
+
return color2;
|
|
21887
|
+
};
|
|
21874
21888
|
|
|
21875
21889
|
// src/components/input/UploadClickableArea.tsx
|
|
21876
21890
|
import { Box as Box3 } from "@mui/material";
|