componentes-sinco 1.1.41 → 1.1.42

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/dist/index.cjs CHANGED
@@ -2514,7 +2514,8 @@ function SCAutocomplete({
2514
2514
  state,
2515
2515
  inputChange,
2516
2516
  maxCheck,
2517
- width = "100%"
2517
+ width = "100%",
2518
+ chipOutside
2518
2519
  }) {
2519
2520
  const labelContent = `<span style="color: red;">* </span>` + label;
2520
2521
  let group = "";
@@ -2550,6 +2551,16 @@ function SCAutocomplete({
2550
2551
  setIsUserTyping(false);
2551
2552
  }
2552
2553
  }, [inputValue]);
2554
+ const handleDeleteChip = (optionToDelete) => {
2555
+ const newSelected = selectedOptions.filter(
2556
+ (opt) => getItemValue(opt).value !== getItemValue(optionToDelete).value
2557
+ );
2558
+ setSelectedOptions(newSelected);
2559
+ setState({
2560
+ hiddenValue: newSelected.length > 0 ? newSelected.map((item) => getItemValue(item).value) : "-1",
2561
+ textValue: newSelected.length > 0 ? newSelected.map((item) => getItemValue(item).text) : ""
2562
+ });
2563
+ };
2553
2564
  const normalizedData = (0, import_react19.useMemo)(() => {
2554
2565
  return data.map((option) => {
2555
2566
  if ((option == null ? void 0 : option.icon) && option.icon.type === void 0) {
@@ -2608,6 +2619,10 @@ function SCAutocomplete({
2608
2619
  const componentClickActiveRef = import_react19.default.useRef(false);
2609
2620
  const containerRef = import_react19.default.useRef(null);
2610
2621
  const [chipLimit, setChipLimit] = import_react19.default.useState(2);
2622
+ const outsideChipsMeasureRef = import_react19.default.useRef(null);
2623
+ const [visibleChipCount, setVisibleChipCount] = import_react19.default.useState(Number.MAX_SAFE_INTEGER);
2624
+ const [popoverAnchor, setPopoverAnchor] = import_react19.default.useState(null);
2625
+ const popoverTimerRef = import_react19.default.useRef(null);
2611
2626
  (0, import_react19.useEffect)(() => {
2612
2627
  const el = containerRef.current;
2613
2628
  if (!el) return;
@@ -2619,6 +2634,50 @@ function SCAutocomplete({
2619
2634
  observer.observe(el);
2620
2635
  return () => observer.disconnect();
2621
2636
  }, []);
2637
+ (0, import_react19.useEffect)(() => {
2638
+ if (!chipOutside || typeFormat !== "multiselect") return;
2639
+ const box = outsideChipsMeasureRef.current;
2640
+ if (!box) return;
2641
+ const measure = () => {
2642
+ const chips = Array.from(box.querySelectorAll("[data-outside-chip]"));
2643
+ let count = selectedOptions.length;
2644
+ for (let i = 0; i < chips.length; i++) {
2645
+ if (chips[i].offsetTop + chips[i].offsetHeight > 36) {
2646
+ count = i;
2647
+ break;
2648
+ }
2649
+ }
2650
+ setVisibleChipCount(count);
2651
+ };
2652
+ measure();
2653
+ const observer = new ResizeObserver(measure);
2654
+ observer.observe(box);
2655
+ return () => observer.disconnect();
2656
+ }, [selectedOptions, chipOutside, typeFormat]);
2657
+ (0, import_react19.useEffect)(() => {
2658
+ const displayCount = Math.min(visibleChipCount, selectedOptions.length);
2659
+ if (selectedOptions.length - displayCount === 0) {
2660
+ setPopoverAnchor(null);
2661
+ }
2662
+ }, [selectedOptions, visibleChipCount]);
2663
+ const handlePlusEnter = (event2) => {
2664
+ if (popoverTimerRef.current) clearTimeout(popoverTimerRef.current);
2665
+ setPopoverAnchor(event2.currentTarget);
2666
+ };
2667
+ const handlePlusLeave = () => {
2668
+ popoverTimerRef.current = setTimeout(() => setPopoverAnchor(null), 150);
2669
+ };
2670
+ const handlePopperEnter = () => {
2671
+ if (popoverTimerRef.current) clearTimeout(popoverTimerRef.current);
2672
+ };
2673
+ const handlePopperLeave = () => {
2674
+ popoverTimerRef.current = setTimeout(() => setPopoverAnchor(null), 150);
2675
+ };
2676
+ const resolveAvatarText = (option) => {
2677
+ const optionText = getItemValue(option).text;
2678
+ if (!(chipOutside == null ? void 0 : chipOutside.textSeccion)) return optionText.charAt(0).toUpperCase();
2679
+ return chipOutside.textSeccion.split(",").map((p) => optionText.charAt(Number(p.trim())).toUpperCase()).join("");
2680
+ };
2622
2681
  const hayOnComponentClickGlobal = (0, import_react19.useMemo)(() => {
2623
2682
  return data.some((opt) => {
2624
2683
  const item = getItemValue(opt);
@@ -2656,7 +2715,7 @@ function SCAutocomplete({
2656
2715
  maxWidth: "100%"
2657
2716
  },
2658
2717
  limitTags: chipLimit,
2659
- renderTags: (value, getTagProps) => {
2718
+ renderTags: chipOutside ? () => null : (value, getTagProps) => {
2660
2719
  const limit = chipLimit;
2661
2720
  return /* @__PURE__ */ import_react19.default.createElement(import_react19.default.Fragment, null, value.slice(0, limit).map((option, index) => {
2662
2721
  const _a = getTagProps({ index }), { key } = _a, chipProps = __objRest(_a, ["key"]);
@@ -2741,12 +2800,14 @@ function SCAutocomplete({
2741
2800
  renderInput: (params) => /* @__PURE__ */ import_react19.default.createElement(import_react19.default.Fragment, null, /* @__PURE__ */ import_react19.default.createElement(
2742
2801
  import_material13.TextField,
2743
2802
  __spreadProps(__spreadValues({
2744
- sx: { "& .MuiOutlinedInput-input": {
2745
- padding: "2.5px 2px 2.5px 2px !important",
2746
- // ajusta aquí
2747
- width: "10px !important",
2748
- minWidth: "10px !important"
2749
- } }
2803
+ sx: {
2804
+ "& .MuiOutlinedInput-input": {
2805
+ padding: "2.5px 2px 2.5px 2px !important",
2806
+ // ajusta aquí
2807
+ width: "10px !important",
2808
+ minWidth: "10px !important"
2809
+ }
2810
+ }
2750
2811
  }, params), {
2751
2812
  label: required ? /* @__PURE__ */ import_react19.default.createElement("span", { dangerouslySetInnerHTML: { __html: labelContent } }) : label,
2752
2813
  placeholder: selectedOptions.length == 0 ? "B\xFAsqueda" : "",
@@ -2822,7 +2883,90 @@ function SCAutocomplete({
2822
2883
  }
2823
2884
  }
2824
2885
  })
2825
- )));
2886
+ ), chipOutside && typeFormat === "multiselect" && selectedOptions.length > 0 && (() => {
2887
+ const displayCount = Math.min(visibleChipCount, selectedOptions.length);
2888
+ const hiddenCount = selectedOptions.length - displayCount;
2889
+ return /* @__PURE__ */ import_react19.default.createElement(import_material13.Box, { sx: { position: "relative", mt: 0.5 } }, /* @__PURE__ */ import_react19.default.createElement(
2890
+ import_material13.Box,
2891
+ {
2892
+ ref: outsideChipsMeasureRef,
2893
+ "aria-hidden": "true",
2894
+ sx: {
2895
+ display: "flex",
2896
+ flexWrap: "wrap",
2897
+ gap: 0.5,
2898
+ position: "absolute",
2899
+ top: 0,
2900
+ left: 0,
2901
+ right: 0,
2902
+ visibility: "hidden",
2903
+ pointerEvents: "none"
2904
+ }
2905
+ },
2906
+ selectedOptions.map((option) => {
2907
+ const avatarText = resolveAvatarText(option);
2908
+ return /* @__PURE__ */ import_react19.default.createElement("div", { key: getItemValue(option).value, "data-outside-chip": true, style: { display: "inline-flex" } }, /* @__PURE__ */ import_react19.default.createElement(
2909
+ import_material13.Chip,
2910
+ __spreadValues({
2911
+ size: "small",
2912
+ label: getItemValue(option).text
2913
+ }, chipOutside.type === "avatar" ? { avatar: /* @__PURE__ */ import_react19.default.createElement(import_material13.Avatar, null, avatarText) } : {})
2914
+ ));
2915
+ })
2916
+ ), /* @__PURE__ */ import_react19.default.createElement(import_material13.Box, { sx: { display: "flex", flexWrap: "wrap", gap: 0.5, maxHeight: 36, overflow: "hidden" } }, selectedOptions.slice(0, displayCount).map((option) => {
2917
+ const avatarText = resolveAvatarText(option);
2918
+ return /* @__PURE__ */ import_react19.default.createElement(
2919
+ import_material13.Chip,
2920
+ __spreadValues({
2921
+ key: getItemValue(option).value,
2922
+ color: "default",
2923
+ size: "small",
2924
+ variant: "filled",
2925
+ label: getItemValue(option).text,
2926
+ onDelete: () => handleDeleteChip(option)
2927
+ }, chipOutside.type === "avatar" ? { avatar: /* @__PURE__ */ import_react19.default.createElement(import_material13.Avatar, null, avatarText) } : {})
2928
+ );
2929
+ }), hiddenCount > 0 && /* @__PURE__ */ import_react19.default.createElement(
2930
+ import_material13.Box,
2931
+ {
2932
+ onMouseEnter: handlePlusEnter,
2933
+ onMouseLeave: handlePlusLeave,
2934
+ sx: { ml: 0.5, fontSize: 13, color: "#666", display: "flex", alignItems: "center", cursor: "default" }
2935
+ },
2936
+ `+${hiddenCount}`
2937
+ )), /* @__PURE__ */ import_react19.default.createElement(
2938
+ import_material13.Popper,
2939
+ {
2940
+ open: Boolean(popoverAnchor),
2941
+ anchorEl: popoverAnchor,
2942
+ placement: "bottom-start",
2943
+ sx: { zIndex: 1500 }
2944
+ },
2945
+ /* @__PURE__ */ import_react19.default.createElement(
2946
+ import_material13.Paper,
2947
+ {
2948
+ elevation: 3,
2949
+ onMouseEnter: handlePopperEnter,
2950
+ onMouseLeave: handlePopperLeave,
2951
+ sx: { p: 1, display: "flex", flexWrap: "wrap", gap: 0.5, maxWidth: 300 }
2952
+ },
2953
+ selectedOptions.slice(displayCount).map((option) => {
2954
+ const avatarText = resolveAvatarText(option);
2955
+ return /* @__PURE__ */ import_react19.default.createElement(
2956
+ import_material13.Chip,
2957
+ __spreadValues({
2958
+ key: getItemValue(option).value,
2959
+ color: "default",
2960
+ size: "small",
2961
+ variant: "filled",
2962
+ label: getItemValue(option).text,
2963
+ onDelete: () => handleDeleteChip(option)
2964
+ }, chipOutside.type === "avatar" ? { avatar: /* @__PURE__ */ import_react19.default.createElement(import_material13.Avatar, { sx: { fontSize: avatarText.length > 1 ? "0.55rem" : "0.75rem" } }, avatarText) } : {})
2965
+ );
2966
+ })
2967
+ )
2968
+ ));
2969
+ })()));
2826
2970
  }
2827
2971
 
2828
2972
  // src/Components/SCDateRange.tsx