@agroshine/ags-web-ui-kit 1.0.0 → 1.2.0

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.
@@ -720,114 +720,249 @@ var QueryState = React.forwardRef(function QueryState2({
720
720
  return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
721
721
  });
722
722
  QueryState.displayName = "QueryState";
723
- function SearchFilterBar({
723
+ var SearchCategoryMenu = ({
724
724
  options,
725
- selectedOption,
726
- onOptionChange,
727
- searchValue,
728
- onSearchChange,
729
- searchPlaceholder = "Buscar...",
730
- className = ""
731
- }) {
732
- const [isOpen, setIsOpen] = React.useState(false);
733
- const dropdownRef = React.useRef(null);
734
- const selectedLabel = React.useMemo(
735
- () => options.find((option) => String(option.value) === selectedOption)?.label ?? selectedOption,
736
- [options, selectedOption]
737
- );
738
- React.useEffect(() => {
739
- const onClickOutside = (event) => {
740
- if (!dropdownRef.current) return;
741
- if (!dropdownRef.current.contains(event.target)) {
742
- setIsOpen(false);
743
- }
744
- };
745
- document.addEventListener("mousedown", onClickOutside);
746
- return () => document.removeEventListener("mousedown", onClickOutside);
747
- }, []);
725
+ isActive,
726
+ onSelect,
727
+ multi
728
+ }) => /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: options.map((opt) => {
729
+ const v = String(opt.value);
730
+ const active = isActive(v);
748
731
  return /* @__PURE__ */ jsxRuntime.jsxs(
749
- "div",
732
+ "button",
750
733
  {
751
- className: `flex w-full flex-col gap-3 sm:flex-row sm:items-stretch sm:gap-0 ${className}`,
734
+ type: "button",
735
+ onClick: () => onSelect(v),
736
+ disabled: opt.disabled,
737
+ className: chunkA3A7PJWG_cjs.cn(
738
+ "flex w-full items-center gap-3 rounded-md px-3 py-2.5 text-left text-sm transition-colors",
739
+ "disabled:cursor-not-allowed disabled:opacity-50",
740
+ active ? "bg-primary-50 text-primary" : "text-foreground hover:bg-primary-50 hover:text-primary"
741
+ ),
752
742
  children: [
753
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative w-full sm:w-[180px] sm:min-w-[180px]", ref: dropdownRef, children: [
754
- /* @__PURE__ */ jsxRuntime.jsxs(
755
- "button",
756
- {
757
- type: "button",
758
- onClick: () => setIsOpen((prev) => !prev),
759
- className: "flex h-10 w-full items-center justify-between rounded-md border border-primary-500 bg-white px-4 text-left text-sm font-semibold text-primary-500 sm:rounded-r-none sm:border-r-0",
760
- "aria-haspopup": "listbox",
761
- "aria-expanded": isOpen,
762
- children: [
763
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm leading-tight", children: selectedLabel }),
764
- /* @__PURE__ */ jsxRuntime.jsx(
765
- "svg",
766
- {
767
- className: "h-4 w-4 flex-shrink-0 text-primary-500",
768
- viewBox: "0 0 20 20",
769
- fill: "currentColor",
770
- "aria-hidden": "true",
771
- children: /* @__PURE__ */ jsxRuntime.jsx(
772
- "path",
743
+ multi && /* @__PURE__ */ jsxRuntime.jsx(
744
+ "input",
745
+ {
746
+ type: "checkbox",
747
+ readOnly: true,
748
+ checked: active,
749
+ tabIndex: -1,
750
+ className: "h-4 w-4 shrink-0 accent-primary"
751
+ }
752
+ ),
753
+ opt.leadingIcon && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "shrink-0 text-primary [&_svg]:h-[18px] [&_svg]:w-[18px]", children: opt.leadingIcon }),
754
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "flex-1 truncate", children: opt.label })
755
+ ]
756
+ },
757
+ v
758
+ );
759
+ }) });
760
+ var SearchFilterBar = React.forwardRef(
761
+ function SearchFilterBar2(props, ref) {
762
+ const {
763
+ options,
764
+ searchValue,
765
+ onSearchChange,
766
+ searchPlaceholder = "Busca en la categor\xEDa seleccionada",
767
+ onSearch,
768
+ onClear,
769
+ showClear = true,
770
+ suggestions,
771
+ suggestionsOpen,
772
+ categoryMenuWidth = 280,
773
+ className
774
+ } = props;
775
+ const [catOpen, setCatOpen] = React.useState(false);
776
+ const [focused, setFocused] = React.useState(false);
777
+ const inputRef = React.useRef(null);
778
+ const isMulti = props.categoryMultiSelect === true;
779
+ const categoryLabel = React.useMemo(() => {
780
+ if (isMulti) {
781
+ const selected = props.selectedOptions;
782
+ if (selected.length === 0) {
783
+ return props.categoryEmptyLabel ?? "Categor\xEDas";
784
+ }
785
+ const labelFn = props.categoryMultiLabel;
786
+ return labelFn?.(selected.length) ?? `${selected.length} elementos...`;
787
+ }
788
+ const v = props.selectedOption;
789
+ return options.find((o) => String(o.value) === v)?.label ?? v;
790
+ }, [isMulti, props, options]);
791
+ const isOptionActive = React.useCallback(
792
+ (v) => {
793
+ if (isMulti) return props.selectedOptions.includes(v);
794
+ return props.selectedOption === v;
795
+ },
796
+ [isMulti, props]
797
+ );
798
+ const handleSelect = React.useCallback(
799
+ (v) => {
800
+ if (isMulti) {
801
+ const selected = props.selectedOptions;
802
+ const next = selected.includes(v) ? selected.filter((x) => x !== v) : [...selected, v];
803
+ props.onOptionsChange(next);
804
+ } else {
805
+ props.onOptionChange(v);
806
+ setCatOpen(false);
807
+ }
808
+ },
809
+ [isMulti, props]
810
+ );
811
+ const showSuggestions = suggestionsOpen ?? (focused && searchValue.length > 0 && suggestions !== void 0);
812
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { ref, className: chunkA3A7PJWG_cjs.cn("relative", className), children: [
813
+ /* @__PURE__ */ jsxRuntime.jsxs(chunk2KRMLIJQ_cjs.Popover, { open: catOpen, onOpenChange: setCatOpen, children: [
814
+ /* @__PURE__ */ jsxRuntime.jsx(chunk2KRMLIJQ_cjs.PopoverAnchor, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsxs(
815
+ "div",
816
+ {
817
+ className: chunkA3A7PJWG_cjs.cn(
818
+ "flex h-12 items-center rounded-lg border-[1.5px] bg-background transition-colors",
819
+ catOpen || focused ? "border-primary" : "border-primary-200 hover:border-primary-400"
820
+ ),
821
+ children: [
822
+ /* @__PURE__ */ jsxRuntime.jsx(chunk2KRMLIJQ_cjs.PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsxs(
823
+ "button",
824
+ {
825
+ type: "button",
826
+ className: "flex h-full w-[190px] shrink-0 cursor-pointer items-center gap-3 border-0 bg-transparent px-4 text-left text-sm font-semibold text-primary focus:outline-none",
827
+ "aria-haspopup": "listbox",
828
+ "aria-expanded": catOpen,
829
+ children: [
830
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "flex-1 truncate", children: categoryLabel }),
831
+ /* @__PURE__ */ jsxRuntime.jsx(
832
+ lucideReact.ChevronDown,
773
833
  {
774
- fillRule: "evenodd",
775
- d: "M5.23 7.21a.75.75 0 0 1 1.06.02L10 11.168l3.71-3.938a.75.75 0 1 1 1.08 1.04l-4.25 4.5a.75.75 0 0 1-1.08 0l-4.25-4.5a.75.75 0 0 1 .02-1.06Z",
776
- clipRule: "evenodd"
834
+ "aria-hidden": "true",
835
+ className: chunkA3A7PJWG_cjs.cn(
836
+ "h-3 w-3 shrink-0 transition-transform duration-200",
837
+ catOpen && "rotate-180"
838
+ )
777
839
  }
778
840
  )
779
- }
780
- )
781
- ]
782
- }
783
- ),
784
- isOpen && /* @__PURE__ */ jsxRuntime.jsx(
785
- "ul",
786
- {
787
- role: "listbox",
788
- className: "absolute z-20 mt-1 max-h-60 w-full overflow-y-auto rounded-md border border-[#d1d5db] bg-white py-1 shadow-lg",
789
- children: options.map((option) => {
790
- const value = String(option.value);
791
- const isSelected = value === selectedOption;
792
- return /* @__PURE__ */ jsxRuntime.jsx("li", { children: /* @__PURE__ */ jsxRuntime.jsx(
841
+ ]
842
+ }
843
+ ) }),
844
+ /* @__PURE__ */ jsxRuntime.jsx("div", { "aria-hidden": "true", className: "h-6 w-px shrink-0 bg-primary-200" }),
845
+ /* @__PURE__ */ jsxRuntime.jsx(
846
+ "input",
847
+ {
848
+ ref: inputRef,
849
+ type: "text",
850
+ value: searchValue,
851
+ onChange: (e) => onSearchChange(e.target.value),
852
+ onFocus: () => setFocused(true),
853
+ onBlur: () => {
854
+ window.setTimeout(() => setFocused(false), 120);
855
+ },
856
+ onKeyDown: (e) => {
857
+ if (e.key === "Enter") onSearch?.(searchValue);
858
+ },
859
+ placeholder: searchPlaceholder,
860
+ className: "h-full min-w-0 flex-1 border-0 bg-transparent pl-4 pr-3 text-sm text-foreground outline-none placeholder:text-muted-foreground"
861
+ }
862
+ ),
863
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex shrink-0 items-center gap-3 pr-4", children: [
864
+ showClear && searchValue && /* @__PURE__ */ jsxRuntime.jsx(
793
865
  "button",
794
866
  {
795
867
  type: "button",
868
+ "aria-label": "Limpiar",
796
869
  onClick: () => {
797
- onOptionChange(value);
798
- setIsOpen(false);
870
+ onSearchChange("");
871
+ onClear?.();
872
+ inputRef.current?.focus();
799
873
  },
800
- className: `w-full px-4 py-2 text-left text-sm hover:bg-blue-50 ${isSelected ? "bg-blue-50 font-medium text-primary-500" : "text-[#374151]"}`,
801
- children: option.label
874
+ className: "grid h-6 w-6 cursor-pointer place-items-center border-0 bg-transparent p-0 text-muted-foreground hover:text-foreground",
875
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.X, { "aria-hidden": "true", className: "h-5 w-5" })
802
876
  }
803
- ) }, value);
804
- })
805
- }
806
- )
807
- ] }),
808
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full sm:max-w-[360px] sm:flex-1", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative flex h-10 w-full items-center rounded-md border border-[#d1d5db] bg-white px-4 sm:rounded-l-none", children: [
809
- /* @__PURE__ */ jsxRuntime.jsx(
810
- "input",
811
- {
812
- type: "text",
813
- value: searchValue,
814
- onChange: (event) => onSearchChange(event.target.value),
815
- placeholder: searchPlaceholder,
816
- className: "w-full bg-transparent pr-8 text-sm text-gray-500-500 placeholder:text-[#9ca3af] focus:outline-none"
817
- }
818
- ),
819
- /* @__PURE__ */ jsxRuntime.jsx(
820
- reactFontawesome.FontAwesomeIcon,
821
- {
822
- icon: freeSolidSvgIcons.faSearch,
823
- className: "pointer-events-none absolute right-3 text-[#c4c8d0]"
824
- }
825
- )
826
- ] }) })
827
- ]
828
- }
829
- );
830
- }
877
+ ),
878
+ /* @__PURE__ */ jsxRuntime.jsx(
879
+ "button",
880
+ {
881
+ type: "button",
882
+ "aria-label": "Buscar",
883
+ onClick: () => onSearch?.(searchValue),
884
+ className: "grid h-6 w-6 cursor-pointer place-items-center border-0 bg-transparent p-0 text-primary hover:text-primary-600",
885
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Search, { "aria-hidden": "true", className: "h-5 w-5" })
886
+ }
887
+ )
888
+ ] })
889
+ ]
890
+ }
891
+ ) }),
892
+ /* @__PURE__ */ jsxRuntime.jsx(
893
+ chunk2KRMLIJQ_cjs.PopoverContent,
894
+ {
895
+ align: "start",
896
+ sideOffset: 6,
897
+ style: { width: categoryMenuWidth },
898
+ className: "p-1.5",
899
+ children: /* @__PURE__ */ jsxRuntime.jsx(
900
+ SearchCategoryMenu,
901
+ {
902
+ options,
903
+ isActive: isOptionActive,
904
+ onSelect: handleSelect,
905
+ multi: isMulti
906
+ }
907
+ )
908
+ }
909
+ )
910
+ ] }),
911
+ showSuggestions && /* @__PURE__ */ jsxRuntime.jsx(
912
+ "div",
913
+ {
914
+ className: "absolute inset-x-0 top-full z-20 mt-1.5 overflow-hidden rounded-lg border border-border bg-popover shadow-md",
915
+ onMouseDown: (e) => e.preventDefault(),
916
+ children: suggestions
917
+ }
918
+ )
919
+ ] });
920
+ }
921
+ );
922
+ SearchFilterBar.displayName = "SearchFilterBar";
923
+ var SearchSuggestRow = ({
924
+ children,
925
+ className
926
+ }) => /* @__PURE__ */ jsxRuntime.jsx("div", { className: chunkA3A7PJWG_cjs.cn("border-b border-border px-[18px] py-3 text-sm last:border-0", className), children });
927
+ var SearchSuggestQuery = ({ children }) => /* @__PURE__ */ jsxRuntime.jsx(SearchSuggestRow, { className: "font-medium text-foreground", children });
928
+ var SearchSuggestHeader = ({
929
+ title,
930
+ action
931
+ }) => /* @__PURE__ */ jsxRuntime.jsxs(SearchSuggestRow, { className: "flex items-center justify-between font-semibold text-foreground", children: [
932
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: title }),
933
+ action && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cursor-pointer text-[13.5px] font-medium text-primary underline underline-offset-[3px]", children: action })
934
+ ] });
935
+ var SearchSuggestItem = ({
936
+ active,
937
+ withLinkIcon,
938
+ onClick,
939
+ children,
940
+ className
941
+ }) => /* @__PURE__ */ jsxRuntime.jsxs(
942
+ "div",
943
+ {
944
+ role: "option",
945
+ "aria-selected": active,
946
+ onClick,
947
+ className: chunkA3A7PJWG_cjs.cn(
948
+ "flex cursor-pointer items-center gap-3 border-b border-border px-[18px] py-3 text-sm text-foreground transition-colors last:border-0 hover:bg-primary-50",
949
+ active && "bg-primary-50",
950
+ className
951
+ ),
952
+ children: [
953
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "flex-1", children }),
954
+ withLinkIcon && /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ArrowUpRight, { "aria-hidden": "true", className: "h-4 w-4 shrink-0 text-foreground" })
955
+ ]
956
+ }
957
+ );
958
+ var SearchSuggestFooter = ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("div", { className: "border-t border-border px-[18px] py-3 text-xs text-muted-foreground", children });
959
+ var SearchSuggestEmpty = ({
960
+ title,
961
+ description
962
+ }) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-[18px] py-7 text-center", children: [
963
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm font-semibold text-foreground", children: title }),
964
+ description && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mx-auto mt-1.5 max-w-[36ch] text-xs text-muted-foreground", children: description })
965
+ ] });
831
966
  var sidebarItemVariants = classVarianceAuthority.cva(
832
967
  [
833
968
  "group/sb-item relative flex items-center gap-2.5 text-[13px] cursor-pointer select-none outline-none",
@@ -1179,9 +1314,15 @@ exports.RangePicker = RangePicker;
1179
1314
  exports.Result = Result;
1180
1315
  exports.SearchBox = SearchBox;
1181
1316
  exports.SearchFilterBar = SearchFilterBar;
1317
+ exports.SearchSuggestEmpty = SearchSuggestEmpty;
1318
+ exports.SearchSuggestFooter = SearchSuggestFooter;
1319
+ exports.SearchSuggestHeader = SearchSuggestHeader;
1320
+ exports.SearchSuggestItem = SearchSuggestItem;
1321
+ exports.SearchSuggestQuery = SearchSuggestQuery;
1322
+ exports.SearchSuggestRow = SearchSuggestRow;
1182
1323
  exports.Sidebar = Sidebar;
1183
1324
  exports.Toaster = Toaster;
1184
1325
  exports.Tree = Tree;
1185
1326
  exports.UserAvatar = UserAvatar;
1186
- //# sourceMappingURL=chunk-C4LX3XTN.cjs.map
1187
- //# sourceMappingURL=chunk-C4LX3XTN.cjs.map
1327
+ //# sourceMappingURL=chunk-NDHF6M7F.cjs.map
1328
+ //# sourceMappingURL=chunk-NDHF6M7F.cjs.map