analytica-frontend-lib 1.1.72 → 1.1.74

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.js CHANGED
@@ -2457,20 +2457,19 @@ var DropdownMenu = ({
2457
2457
  };
2458
2458
  (0, import_react13.useEffect)(() => {
2459
2459
  if (open) {
2460
- document.addEventListener("mousedown", handleClickOutside);
2460
+ document.addEventListener("pointerdown", handleClickOutside);
2461
2461
  document.addEventListener("keydown", handleDownkey);
2462
2462
  }
2463
2463
  return () => {
2464
- document.removeEventListener("mousedown", handleClickOutside);
2464
+ document.removeEventListener("pointerdown", handleClickOutside);
2465
2465
  document.removeEventListener("keydown", handleDownkey);
2466
2466
  };
2467
2467
  }, [open]);
2468
2468
  (0, import_react13.useEffect)(() => {
2469
- setOpen(open);
2470
2469
  onOpenChange?.(open);
2471
2470
  }, [open, onOpenChange]);
2472
2471
  (0, import_react13.useEffect)(() => {
2473
- if (propOpen) {
2472
+ if (propOpen !== void 0) {
2474
2473
  setOpen(propOpen);
2475
2474
  }
2476
2475
  }, [propOpen]);
@@ -2597,6 +2596,7 @@ var DropdownMenuItem = (0, import_react13.forwardRef)(
2597
2596
  onClick,
2598
2597
  variant = "menu",
2599
2598
  store: externalStore,
2599
+ preventClose = false,
2600
2600
  ...props
2601
2601
  }, ref) => {
2602
2602
  const store = useDropdownStore(externalStore);
@@ -2608,8 +2608,17 @@ var DropdownMenuItem = (0, import_react13.forwardRef)(
2608
2608
  e.stopPropagation();
2609
2609
  return;
2610
2610
  }
2611
- onClick?.(e);
2612
- setOpen(false);
2611
+ if (e.type === "click") {
2612
+ onClick?.(e);
2613
+ } else if (e.type === "keydown") {
2614
+ if (e.key === "Enter" || e.key === " ") {
2615
+ onClick?.(e);
2616
+ }
2617
+ props.onKeyDown?.(e);
2618
+ }
2619
+ if (!preventClose) {
2620
+ setOpen(false);
2621
+ }
2613
2622
  };
2614
2623
  const getVariantClasses = () => {
2615
2624
  if (variant === "profile") {
@@ -2636,7 +2645,11 @@ var DropdownMenuItem = (0, import_react13.forwardRef)(
2636
2645
  `,
2637
2646
  onClick: handleClick,
2638
2647
  onKeyDown: (e) => {
2639
- if (e.key === "Enter" || e.key === " ") handleClick(e);
2648
+ if (e.key === "Enter" || e.key === " ") {
2649
+ e.preventDefault();
2650
+ e.stopPropagation();
2651
+ handleClick(e);
2652
+ }
2640
2653
  },
2641
2654
  tabIndex: disabled ? -1 : 0,
2642
2655
  ...props,
@@ -2702,10 +2715,17 @@ var ProfileMenuHeader = (0, import_react13.forwardRef)(({ className, name, email
2702
2715
  );
2703
2716
  });
2704
2717
  ProfileMenuHeader.displayName = "ProfileMenuHeader";
2705
- var ProfileToggleTheme = ({ ...props }) => {
2718
+ var ProfileToggleTheme = ({
2719
+ store: externalStore,
2720
+ ...props
2721
+ }) => {
2706
2722
  const { themeMode, setTheme } = useTheme();
2707
2723
  const [modalThemeToggle, setModalThemeToggle] = (0, import_react13.useState)(false);
2708
2724
  const [selectedTheme, setSelectedTheme] = (0, import_react13.useState)(themeMode);
2725
+ const internalStoreRef = (0, import_react13.useRef)(null);
2726
+ internalStoreRef.current ??= createDropdownStore();
2727
+ const store = externalStore ?? internalStoreRef.current;
2728
+ const setOpen = (0, import_zustand5.useStore)(store, (s) => s.setOpen);
2709
2729
  const handleClick = (e) => {
2710
2730
  e.preventDefault();
2711
2731
  e.stopPropagation();
@@ -2714,12 +2734,20 @@ var ProfileToggleTheme = ({ ...props }) => {
2714
2734
  const handleSave = () => {
2715
2735
  setTheme(selectedTheme);
2716
2736
  setModalThemeToggle(false);
2737
+ setOpen(false);
2738
+ };
2739
+ const handleCancel = () => {
2740
+ setSelectedTheme(themeMode);
2741
+ setModalThemeToggle(false);
2742
+ setOpen(false);
2717
2743
  };
2718
2744
  return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(import_jsx_runtime20.Fragment, { children: [
2719
2745
  /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
2720
2746
  DropdownMenuItem,
2721
2747
  {
2722
2748
  variant: "profile",
2749
+ preventClose: true,
2750
+ store,
2723
2751
  iconLeft: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
2724
2752
  "svg",
2725
2753
  {
@@ -2754,19 +2782,12 @@ var ProfileToggleTheme = ({ ...props }) => {
2754
2782
  Modal_default,
2755
2783
  {
2756
2784
  isOpen: modalThemeToggle,
2757
- onClose: () => setModalThemeToggle(false),
2785
+ onClose: handleCancel,
2758
2786
  title: "Apar\xEAncia",
2759
2787
  size: "md",
2760
2788
  footer: /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { className: "flex gap-3", children: [
2761
- /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
2762
- Button_default,
2763
- {
2764
- variant: "outline",
2765
- onClick: () => setModalThemeToggle(false),
2766
- children: "Cancelar"
2767
- }
2768
- ),
2769
- /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(Button_default, { variant: "solid", onClick: () => handleSave(), children: "Salvar" })
2789
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(Button_default, { variant: "outline", onClick: handleCancel, children: "Cancelar" }),
2790
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(Button_default, { variant: "solid", onClick: handleSave, children: "Salvar" })
2770
2791
  ] }),
2771
2792
  children: /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { className: "flex flex-col", children: [
2772
2793
  /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("p", { className: "text-sm text-text-500", children: "Escolha o tema:" }),
@@ -2855,11 +2876,15 @@ var Search = (0, import_react14.forwardRef)(
2855
2876
  value,
2856
2877
  onChange,
2857
2878
  placeholder = "Buscar...",
2879
+ onKeyDown: userOnKeyDown,
2858
2880
  ...props
2859
2881
  }, ref) => {
2860
2882
  const [dropdownOpen, setDropdownOpen] = (0, import_react14.useState)(false);
2883
+ const [forceClose, setForceClose] = (0, import_react14.useState)(false);
2884
+ const justSelectedRef = (0, import_react14.useRef)(false);
2861
2885
  const dropdownStore = (0, import_react14.useRef)(createDropdownStore()).current;
2862
2886
  const dropdownRef = (0, import_react14.useRef)(null);
2887
+ const inputElRef = (0, import_react14.useRef)(null);
2863
2888
  const filteredOptions = (0, import_react14.useMemo)(() => {
2864
2889
  if (!options.length) {
2865
2890
  return [];
@@ -2867,24 +2892,35 @@ var Search = (0, import_react14.forwardRef)(
2867
2892
  const filtered = filterOptions(options, value || "");
2868
2893
  return filtered;
2869
2894
  }, [options, value]);
2870
- const showDropdown = controlledShowDropdown ?? (dropdownOpen && value && String(value).length > 0);
2895
+ const showDropdown = !forceClose && (controlledShowDropdown ?? (dropdownOpen && value && String(value).length > 0));
2896
+ const setOpenAndNotify = (open) => {
2897
+ setDropdownOpen(open);
2898
+ dropdownStore.setState({ open });
2899
+ onDropdownChange?.(open);
2900
+ };
2871
2901
  (0, import_react14.useEffect)(() => {
2902
+ if (justSelectedRef.current) {
2903
+ justSelectedRef.current = false;
2904
+ return;
2905
+ }
2906
+ if (forceClose) {
2907
+ setOpenAndNotify(false);
2908
+ return;
2909
+ }
2872
2910
  const shouldShow = Boolean(value && String(value).length > 0);
2873
- setDropdownOpen(shouldShow);
2874
- dropdownStore.setState({ open: shouldShow });
2875
- onDropdownChange?.(shouldShow);
2876
- }, [value, onDropdownChange, dropdownStore]);
2911
+ setOpenAndNotify(shouldShow);
2912
+ }, [value, forceClose, onDropdownChange, dropdownStore]);
2877
2913
  const handleSelectOption = (option) => {
2914
+ justSelectedRef.current = true;
2915
+ setForceClose(true);
2878
2916
  onSelect?.(option);
2879
- setDropdownOpen(false);
2880
- dropdownStore.setState({ open: false });
2917
+ setOpenAndNotify(false);
2881
2918
  updateInputValue(option, ref, onChange);
2882
2919
  };
2883
2920
  (0, import_react14.useEffect)(() => {
2884
2921
  const handleClickOutside = (event) => {
2885
2922
  if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
2886
- setDropdownOpen(false);
2887
- dropdownStore.setState({ open: false });
2923
+ setOpenAndNotify(false);
2888
2924
  }
2889
2925
  };
2890
2926
  if (showDropdown) {
@@ -2893,9 +2929,10 @@ var Search = (0, import_react14.forwardRef)(
2893
2929
  return () => {
2894
2930
  document.removeEventListener("mousedown", handleClickOutside);
2895
2931
  };
2896
- }, [showDropdown, dropdownStore]);
2932
+ }, [showDropdown, dropdownStore, onDropdownChange]);
2897
2933
  const generatedId = (0, import_react14.useId)();
2898
2934
  const inputId = id ?? `search-${generatedId}`;
2935
+ const dropdownId = `${inputId}-dropdown`;
2899
2936
  const handleClear = () => {
2900
2937
  if (onClear) {
2901
2938
  onClear();
@@ -2908,21 +2945,40 @@ var Search = (0, import_react14.forwardRef)(
2908
2945
  e.stopPropagation();
2909
2946
  handleClear();
2910
2947
  };
2911
- const handleLeftIconClick = () => {
2912
- if (ref && "current" in ref && ref.current) {
2913
- ref.current.blur();
2914
- }
2948
+ const handleSearchIconClick = (e) => {
2949
+ e.preventDefault();
2950
+ e.stopPropagation();
2951
+ setTimeout(() => {
2952
+ inputElRef.current?.focus();
2953
+ }, 0);
2915
2954
  };
2916
2955
  const handleInputChange = (e) => {
2956
+ setForceClose(false);
2917
2957
  onChange?.(e);
2918
2958
  onSearch?.(e.target.value);
2919
2959
  };
2960
+ const handleKeyDown = (e) => {
2961
+ userOnKeyDown?.(e);
2962
+ if (e.defaultPrevented) return;
2963
+ if (e.key === "Enter") {
2964
+ e.preventDefault();
2965
+ if (showDropdown && filteredOptions.length > 0) {
2966
+ handleSelectOption(filteredOptions[0]);
2967
+ } else if (value) {
2968
+ onSearch?.(String(value));
2969
+ setForceClose(true);
2970
+ setOpenAndNotify(false);
2971
+ }
2972
+ }
2973
+ };
2920
2974
  const getInputStateClasses = (disabled2, readOnly2) => {
2921
2975
  if (disabled2) return "cursor-not-allowed opacity-40";
2922
2976
  if (readOnly2) return "cursor-default focus:outline-none !text-text-900";
2923
2977
  return "hover:border-border-400";
2924
2978
  };
2925
- const showClearButton = value && !disabled && !readOnly;
2979
+ const hasValue = String(value ?? "").length > 0;
2980
+ const showClearButton = hasValue && !disabled && !readOnly;
2981
+ const showSearchIcon = !hasValue && !disabled && !readOnly;
2926
2982
  return /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(
2927
2983
  "div",
2928
2984
  {
@@ -2930,30 +2986,30 @@ var Search = (0, import_react14.forwardRef)(
2930
2986
  className: `w-full max-w-lg md:w-[488px] ${containerClassName}`,
2931
2987
  children: [
2932
2988
  /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "relative flex items-center", children: [
2933
- /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: "absolute left-3 top-1/2 transform -translate-y-1/2", children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
2934
- "button",
2935
- {
2936
- type: "button",
2937
- className: "w-6 h-6 text-text-800 flex items-center justify-center bg-transparent border-0 p-0 cursor-pointer hover:text-text-600 transition-colors",
2938
- onClick: handleLeftIconClick,
2939
- "aria-label": "Voltar",
2940
- children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_phosphor_react10.CaretLeft, {})
2941
- }
2942
- ) }),
2943
2989
  /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
2944
2990
  "input",
2945
2991
  {
2946
- ref,
2992
+ ref: (node) => {
2993
+ if (ref) {
2994
+ if (typeof ref === "function") ref(node);
2995
+ else
2996
+ ref.current = node;
2997
+ }
2998
+ inputElRef.current = node;
2999
+ },
2947
3000
  id: inputId,
2948
3001
  type: "text",
2949
- className: `w-full py-0 px-4 pl-10 ${showClearButton ? "pr-10" : "pr-4"} font-normal text-text-900 focus:outline-primary-950 border rounded-full bg-background focus:bg-primary-50 border-border-300 focus:border-2 focus:border-primary-950 h-10 placeholder:text-text-600 ${getInputStateClasses(disabled, readOnly)} ${className}`,
3002
+ className: `w-full py-0 px-4 pr-10 font-normal text-text-900 focus:outline-primary-950 border rounded-full bg-background focus:bg-primary-50 border-border-300 focus:border-2 focus:border-primary-950 h-10 placeholder:text-text-600 ${getInputStateClasses(disabled, readOnly)} ${className}`,
2950
3003
  value,
2951
3004
  onChange: handleInputChange,
3005
+ onKeyDown: handleKeyDown,
2952
3006
  disabled,
2953
3007
  readOnly,
2954
3008
  placeholder,
2955
3009
  "aria-expanded": showDropdown ? "true" : void 0,
2956
3010
  "aria-haspopup": options.length > 0 ? "listbox" : void 0,
3011
+ "aria-controls": showDropdown ? dropdownId : void 0,
3012
+ "aria-autocomplete": "list",
2957
3013
  role: options.length > 0 ? "combobox" : void 0,
2958
3014
  ...props
2959
3015
  }
@@ -2967,11 +3023,22 @@ var Search = (0, import_react14.forwardRef)(
2967
3023
  "aria-label": "Limpar busca",
2968
3024
  children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("span", { className: "w-6 h-6 text-text-800 flex items-center justify-center hover:text-text-600 transition-colors", children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_phosphor_react10.X, {}) })
2969
3025
  }
3026
+ ) }),
3027
+ showSearchIcon && /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: "absolute right-3 top-1/2 transform -translate-y-1/2", children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
3028
+ "button",
3029
+ {
3030
+ type: "button",
3031
+ className: "p-0 border-0 bg-transparent cursor-pointer",
3032
+ onMouseDown: handleSearchIconClick,
3033
+ "aria-label": "Buscar",
3034
+ children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("span", { className: "w-6 h-6 text-text-800 flex items-center justify-center hover:text-text-600 transition-colors", children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_phosphor_react10.MagnifyingGlass, {}) })
3035
+ }
2970
3036
  ) })
2971
3037
  ] }),
2972
3038
  showDropdown && /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(DropdownMenu_default, { open: showDropdown, onOpenChange: setDropdownOpen, children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
2973
3039
  DropdownMenuContent,
2974
3040
  {
3041
+ id: dropdownId,
2975
3042
  className: "w-full mt-1",
2976
3043
  style: { maxHeight: dropdownMaxHeight },
2977
3044
  align: "start",