@nickaux/form-configurator 1.1.220 → 1.1.221

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.
@@ -136628,9 +136628,6 @@ class TypeFile extends TypeDefault {
136628
136628
  }
136629
136629
  }
136630
136630
  class TypeColorPicker extends TypeDefault {
136631
- // initValue(p_field) {
136632
- // return "";
136633
- // }
136634
136631
  getComponent() {
136635
136632
  return ({
136636
136633
  getValue: getValue2 = () => "",
@@ -136638,15 +136635,12 @@ class TypeColorPicker extends TypeDefault {
136638
136635
  onChange: onChange3 = false,
136639
136636
  initComponent = false
136640
136637
  }, ...props) => {
136641
- const [fieldValue2, setFieldValue] = useState(
136642
- getValue2() ? getValue2() : ""
136643
- );
136638
+ const [fieldValue2, setFieldValue] = useState(getValue2() || "");
136644
136639
  const [colorPickerColorValue, setColorPickerColorValue] = useState(
136645
- getValue2() ? getValue2() : ""
136640
+ getValue2() || ""
136646
136641
  );
136647
136642
  const [displayColorPicker, setDisplayColorPicker] = useState(false);
136648
- const popoverRef = useRef(false);
136649
- const inputRef = useRef(false);
136643
+ const popoverRef = useRef(null);
136650
136644
  const changeValue = () => {
136651
136645
  setFieldValue(colorPickerColorValue);
136652
136646
  if (onChange3) {
@@ -136665,31 +136659,98 @@ class TypeColorPicker extends TypeDefault {
136665
136659
  setDisplayColorPicker(false);
136666
136660
  };
136667
136661
  const handleOutsideClick = (e2) => {
136668
- if (!popoverRef.current.contains(e2.target)) {
136662
+ if (popoverRef.current && !popoverRef.current.contains(e2.target)) {
136669
136663
  handleClose();
136670
136664
  }
136671
136665
  };
136672
- const displayLabel = !param.displayLabel || param.displayLabel !== "notDisplay";
136673
- displayLabel && param.label ? /* @__PURE__ */ jsx$2("label", { children: param.label }) : "";
136674
- if (this.userAllow === "read-only") {
136675
- return /* @__PURE__ */ jsx$2(
136676
- "div",
136677
- {
136678
- style: {
136679
- width: "36px",
136680
- height: "14px",
136681
- borderRadius: "2px",
136682
- background: `${fieldValue2}`
136683
- }
136666
+ const selectTransparent = () => {
136667
+ setColorPickerColorValue("transparent");
136668
+ setFieldValue("transparent");
136669
+ if (onChange3) {
136670
+ onChange3("transparent");
136671
+ }
136672
+ handleClose();
136673
+ };
136674
+ const copyToClipboard = (text2, format2) => {
136675
+ navigator.clipboard.writeText(text2).then(
136676
+ () => {
136677
+ alert(`Valeur ${format2} copiée : ${text2}`);
136678
+ },
136679
+ () => {
136680
+ alert("Échec de la copie dans le presse-papiers !");
136684
136681
  }
136685
136682
  );
136686
- } else {
136687
- const cssColor = {
136688
- width: "36px",
136689
- height: "14px",
136690
- borderRadius: "2px",
136691
- background: `${fieldValue2}`
136683
+ };
136684
+ useEffect(() => {
136685
+ if (displayColorPicker) {
136686
+ document.addEventListener("mousedown", handleOutsideClick);
136687
+ } else {
136688
+ document.removeEventListener("mousedown", handleOutsideClick);
136689
+ }
136690
+ return () => {
136691
+ document.removeEventListener("mousedown", handleOutsideClick);
136692
+ };
136693
+ }, [displayColorPicker]);
136694
+ const displayLabel = !param.displayLabel || param.displayLabel !== "notDisplay";
136695
+ const label = displayLabel && param.label ? /* @__PURE__ */ jsx$2("label", { children: param.label }) : "";
136696
+ const getColorLabel = () => {
136697
+ if (fieldValue2 === "transparent" || !fieldValue2) {
136698
+ return {
136699
+ rgba: "0, 0, 0, 0",
136700
+ hex: "transparent"
136701
+ };
136702
+ }
136703
+ const rgb = fieldValue2.startsWith("#") ? {
136704
+ r: parseInt(fieldValue2.substring(1, 3), 16),
136705
+ g: parseInt(fieldValue2.substring(3, 5), 16),
136706
+ b: parseInt(fieldValue2.substring(5, 7), 16)
136707
+ } : null;
136708
+ if (rgb) {
136709
+ return {
136710
+ rgba: `${rgb.r}, ${rgb.g}, ${rgb.b}, 1`,
136711
+ hex: fieldValue2
136712
+ };
136713
+ }
136714
+ return {
136715
+ rgba: "Invalid color",
136716
+ hex: ""
136692
136717
  };
136718
+ };
136719
+ const colorInfo = getColorLabel();
136720
+ const cssWrapper = {
136721
+ display: "flex",
136722
+ alignItems: "center",
136723
+ gap: "10px"
136724
+ };
136725
+ const cssColor = {
136726
+ width: "36px",
136727
+ height: "14px",
136728
+ borderRadius: "2px",
136729
+ background: fieldValue2 === "transparent" ? "repeating-linear-gradient(45deg, #fff, #fff 10px, #ccc 10px, #ccc 20px)" : `${fieldValue2}`,
136730
+ border: "1px solid #ccc"
136731
+ };
136732
+ const cssColorInfo = {
136733
+ fontSize: "12px",
136734
+ fontStyle: "italic",
136735
+ lineHeight: "1.4",
136736
+ cursor: "pointer"
136737
+ // Curseur interactif
136738
+ };
136739
+ if (this.userAllow === "read-only") {
136740
+ return /* @__PURE__ */ jsxs("div", { style: cssWrapper, children: [
136741
+ /* @__PURE__ */ jsx$2("div", { style: cssColor }),
136742
+ /* @__PURE__ */ jsxs("div", { style: cssColorInfo, children: [
136743
+ /* @__PURE__ */ jsxs("div", { onClick: () => copyToClipboard(colorInfo.rgba, "RGBA"), children: [
136744
+ "RGBA: ",
136745
+ colorInfo.rgba
136746
+ ] }),
136747
+ /* @__PURE__ */ jsxs("div", { onClick: () => copyToClipboard(colorInfo.hex, "HEX"), children: [
136748
+ "HEX: ",
136749
+ colorInfo.hex
136750
+ ] })
136751
+ ] })
136752
+ ] });
136753
+ } else {
136693
136754
  const cssSwatch = {
136694
136755
  padding: "5px",
136695
136756
  background: "#fff",
@@ -136703,34 +136764,82 @@ class TypeColorPicker extends TypeDefault {
136703
136764
  zIndex: "30",
136704
136765
  padding: "8px",
136705
136766
  backgroundColor: "#FFFFFF",
136706
- border: "solid 1px #cccc",
136767
+ border: "solid 1px #ccc",
136707
136768
  borderRadius: "5px",
136708
136769
  boxShadow: "0 0 5px rgba(0,0,0,0.2)"
136709
136770
  };
136710
- React__default.useEffect(() => {
136711
- if (displayColorPicker) {
136712
- document.addEventListener("mousedown", handleOutsideClick);
136713
- } else {
136714
- document.removeEventListener("mousedown", handleOutsideClick);
136715
- }
136716
- return () => {
136717
- document.removeEventListener("mousedown", handleOutsideClick);
136718
- };
136719
- }, [displayColorPicker]);
136720
136771
  return /* @__PURE__ */ jsxs("div", { children: [
136721
- /* @__PURE__ */ jsx$2("div", { style: cssSwatch, onClick: handleClick, children: /* @__PURE__ */ jsx$2("div", { style: cssColor }) }),
136772
+ label,
136773
+ /* @__PURE__ */ jsxs("div", { style: cssWrapper, children: [
136774
+ /* @__PURE__ */ jsx$2("div", { style: cssSwatch, onClick: handleClick, children: /* @__PURE__ */ jsx$2("div", { style: cssColor }) }),
136775
+ /* @__PURE__ */ jsxs("div", { style: cssColorInfo, children: [
136776
+ /* @__PURE__ */ jsxs("div", { onClick: () => copyToClipboard(colorInfo.rgba, "RGBA"), children: [
136777
+ "RGBA: ",
136778
+ colorInfo.rgba
136779
+ ] }),
136780
+ /* @__PURE__ */ jsxs("div", { onClick: () => copyToClipboard(colorInfo.hex, "HEX"), children: [
136781
+ "HEX: ",
136782
+ colorInfo.hex
136783
+ ] })
136784
+ ] })
136785
+ ] }),
136722
136786
  displayColorPicker ? /* @__PURE__ */ jsxs("div", { ref: popoverRef, style: cssPopover, children: [
136723
136787
  /* @__PURE__ */ jsx$2(
136724
136788
  ChromePicker,
136725
136789
  {
136726
- ref: inputRef,
136727
136790
  color: colorPickerColorValue,
136728
136791
  onChange: pickValue
136729
136792
  }
136730
136793
  ),
136731
- /* @__PURE__ */ jsxs("div", { children: [
136732
- /* @__PURE__ */ jsx$2("button", { type: "btn btn-type1", onClick: handleClose, style: { width: "100%" }, children: "annuler" }),
136733
- /* @__PURE__ */ jsx$2("button", { type: "btn btn-type2", onClick: changeValue, style: { width: "100%" }, children: "Choisir" })
136794
+ /* @__PURE__ */ jsxs("div", { style: { marginTop: "10px" }, children: [
136795
+ /* @__PURE__ */ jsx$2(
136796
+ "button",
136797
+ {
136798
+ type: "button",
136799
+ onClick: selectTransparent,
136800
+ style: {
136801
+ width: "100%",
136802
+ marginBottom: "5px",
136803
+ background: "#eee",
136804
+ border: "1px solid #ccc",
136805
+ padding: "5px",
136806
+ cursor: "pointer"
136807
+ },
136808
+ children: "Aucune couleur"
136809
+ }
136810
+ ),
136811
+ /* @__PURE__ */ jsx$2(
136812
+ "button",
136813
+ {
136814
+ type: "button",
136815
+ onClick: handleClose,
136816
+ style: {
136817
+ width: "48%",
136818
+ marginRight: "4%",
136819
+ background: "#f5f5f5",
136820
+ border: "1px solid #ccc",
136821
+ padding: "5px",
136822
+ cursor: "pointer"
136823
+ },
136824
+ children: "Annuler"
136825
+ }
136826
+ ),
136827
+ /* @__PURE__ */ jsx$2(
136828
+ "button",
136829
+ {
136830
+ type: "button",
136831
+ onClick: changeValue,
136832
+ style: {
136833
+ width: "48%",
136834
+ background: "#007BFF",
136835
+ border: "1px solid #007BFF",
136836
+ color: "white",
136837
+ padding: "5px",
136838
+ cursor: "pointer"
136839
+ },
136840
+ children: "Choisir"
136841
+ }
136842
+ )
136734
136843
  ] })
136735
136844
  ] }) : null
136736
136845
  ] });