@foundrykit/components 1.0.9 → 1.0.12
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 +23 -0
- package/dist/index.d.ts +61 -1
- package/dist/index.js +692 -2
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
- package/src/components/advanced-search-bar/config.ts +200 -0
- package/src/components/advanced-search-bar/index.tsx +739 -0
- package/src/index.ts +15 -0
package/dist/index.js
CHANGED
|
@@ -609,9 +609,694 @@ function CommandShortcut({
|
|
|
609
609
|
);
|
|
610
610
|
}
|
|
611
611
|
|
|
612
|
-
// src/index.
|
|
612
|
+
// src/components/advanced-search-bar/index.tsx
|
|
613
|
+
import * as React6 from "react";
|
|
614
|
+
|
|
615
|
+
// ../../node_modules/@radix-ui/react-slot/dist/index.mjs
|
|
616
|
+
import * as React5 from "react";
|
|
617
|
+
|
|
618
|
+
// ../../node_modules/@radix-ui/react-compose-refs/dist/index.mjs
|
|
619
|
+
import * as React4 from "react";
|
|
620
|
+
function setRef(ref, value) {
|
|
621
|
+
if (typeof ref === "function") {
|
|
622
|
+
return ref(value);
|
|
623
|
+
} else if (ref !== null && ref !== void 0) {
|
|
624
|
+
ref.current = value;
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
function composeRefs(...refs) {
|
|
628
|
+
return (node) => {
|
|
629
|
+
let hasCleanup = false;
|
|
630
|
+
const cleanups = refs.map((ref) => {
|
|
631
|
+
const cleanup = setRef(ref, node);
|
|
632
|
+
if (!hasCleanup && typeof cleanup == "function") {
|
|
633
|
+
hasCleanup = true;
|
|
634
|
+
}
|
|
635
|
+
return cleanup;
|
|
636
|
+
});
|
|
637
|
+
if (hasCleanup) {
|
|
638
|
+
return () => {
|
|
639
|
+
for (let i = 0; i < cleanups.length; i++) {
|
|
640
|
+
const cleanup = cleanups[i];
|
|
641
|
+
if (typeof cleanup == "function") {
|
|
642
|
+
cleanup();
|
|
643
|
+
} else {
|
|
644
|
+
setRef(refs[i], null);
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
};
|
|
648
|
+
}
|
|
649
|
+
};
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
// ../../node_modules/@radix-ui/react-slot/dist/index.mjs
|
|
653
|
+
import { Fragment as Fragment2, jsx as jsx6 } from "react/jsx-runtime";
|
|
654
|
+
// @__NO_SIDE_EFFECTS__
|
|
655
|
+
function createSlot(ownerName) {
|
|
656
|
+
const SlotClone = /* @__PURE__ */ createSlotClone(ownerName);
|
|
657
|
+
const Slot2 = React5.forwardRef((props, forwardedRef) => {
|
|
658
|
+
const { children, ...slotProps } = props;
|
|
659
|
+
const childrenArray = React5.Children.toArray(children);
|
|
660
|
+
const slottable = childrenArray.find(isSlottable);
|
|
661
|
+
if (slottable) {
|
|
662
|
+
const newElement = slottable.props.children;
|
|
663
|
+
const newChildren = childrenArray.map((child) => {
|
|
664
|
+
if (child === slottable) {
|
|
665
|
+
if (React5.Children.count(newElement) > 1) return React5.Children.only(null);
|
|
666
|
+
return React5.isValidElement(newElement) ? newElement.props.children : null;
|
|
667
|
+
} else {
|
|
668
|
+
return child;
|
|
669
|
+
}
|
|
670
|
+
});
|
|
671
|
+
return /* @__PURE__ */ jsx6(SlotClone, { ...slotProps, ref: forwardedRef, children: React5.isValidElement(newElement) ? React5.cloneElement(newElement, void 0, newChildren) : null });
|
|
672
|
+
}
|
|
673
|
+
return /* @__PURE__ */ jsx6(SlotClone, { ...slotProps, ref: forwardedRef, children });
|
|
674
|
+
});
|
|
675
|
+
Slot2.displayName = `${ownerName}.Slot`;
|
|
676
|
+
return Slot2;
|
|
677
|
+
}
|
|
678
|
+
var Slot = /* @__PURE__ */ createSlot("Slot");
|
|
679
|
+
// @__NO_SIDE_EFFECTS__
|
|
680
|
+
function createSlotClone(ownerName) {
|
|
681
|
+
const SlotClone = React5.forwardRef((props, forwardedRef) => {
|
|
682
|
+
const { children, ...slotProps } = props;
|
|
683
|
+
if (React5.isValidElement(children)) {
|
|
684
|
+
const childrenRef = getElementRef(children);
|
|
685
|
+
const props2 = mergeProps(slotProps, children.props);
|
|
686
|
+
if (children.type !== React5.Fragment) {
|
|
687
|
+
props2.ref = forwardedRef ? composeRefs(forwardedRef, childrenRef) : childrenRef;
|
|
688
|
+
}
|
|
689
|
+
return React5.cloneElement(children, props2);
|
|
690
|
+
}
|
|
691
|
+
return React5.Children.count(children) > 1 ? React5.Children.only(null) : null;
|
|
692
|
+
});
|
|
693
|
+
SlotClone.displayName = `${ownerName}.SlotClone`;
|
|
694
|
+
return SlotClone;
|
|
695
|
+
}
|
|
696
|
+
var SLOTTABLE_IDENTIFIER = Symbol("radix.slottable");
|
|
697
|
+
function isSlottable(child) {
|
|
698
|
+
return React5.isValidElement(child) && typeof child.type === "function" && "__radixId" in child.type && child.type.__radixId === SLOTTABLE_IDENTIFIER;
|
|
699
|
+
}
|
|
700
|
+
function mergeProps(slotProps, childProps) {
|
|
701
|
+
const overrideProps = { ...childProps };
|
|
702
|
+
for (const propName in childProps) {
|
|
703
|
+
const slotPropValue = slotProps[propName];
|
|
704
|
+
const childPropValue = childProps[propName];
|
|
705
|
+
const isHandler = /^on[A-Z]/.test(propName);
|
|
706
|
+
if (isHandler) {
|
|
707
|
+
if (slotPropValue && childPropValue) {
|
|
708
|
+
overrideProps[propName] = (...args) => {
|
|
709
|
+
const result = childPropValue(...args);
|
|
710
|
+
slotPropValue(...args);
|
|
711
|
+
return result;
|
|
712
|
+
};
|
|
713
|
+
} else if (slotPropValue) {
|
|
714
|
+
overrideProps[propName] = slotPropValue;
|
|
715
|
+
}
|
|
716
|
+
} else if (propName === "style") {
|
|
717
|
+
overrideProps[propName] = { ...slotPropValue, ...childPropValue };
|
|
718
|
+
} else if (propName === "className") {
|
|
719
|
+
overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(" ");
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
return { ...slotProps, ...overrideProps };
|
|
723
|
+
}
|
|
724
|
+
function getElementRef(element) {
|
|
725
|
+
let getter = Object.getOwnPropertyDescriptor(element.props, "ref")?.get;
|
|
726
|
+
let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
|
|
727
|
+
if (mayWarn) {
|
|
728
|
+
return element.ref;
|
|
729
|
+
}
|
|
730
|
+
getter = Object.getOwnPropertyDescriptor(element, "ref")?.get;
|
|
731
|
+
mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
|
|
732
|
+
if (mayWarn) {
|
|
733
|
+
return element.props.ref;
|
|
734
|
+
}
|
|
735
|
+
return element.props.ref || element.ref;
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
// ../../node_modules/class-variance-authority/dist/index.mjs
|
|
739
|
+
import { clsx } from "clsx";
|
|
740
|
+
var falsyToString = (value) => typeof value === "boolean" ? `${value}` : value === 0 ? "0" : value;
|
|
741
|
+
var cx = clsx;
|
|
742
|
+
var cva = (base, config) => (props) => {
|
|
743
|
+
var _config_compoundVariants;
|
|
744
|
+
if ((config === null || config === void 0 ? void 0 : config.variants) == null) return cx(base, props === null || props === void 0 ? void 0 : props.class, props === null || props === void 0 ? void 0 : props.className);
|
|
745
|
+
const { variants, defaultVariants } = config;
|
|
746
|
+
const getVariantClassNames = Object.keys(variants).map((variant) => {
|
|
747
|
+
const variantProp = props === null || props === void 0 ? void 0 : props[variant];
|
|
748
|
+
const defaultVariantProp = defaultVariants === null || defaultVariants === void 0 ? void 0 : defaultVariants[variant];
|
|
749
|
+
if (variantProp === null) return null;
|
|
750
|
+
const variantKey = falsyToString(variantProp) || falsyToString(defaultVariantProp);
|
|
751
|
+
return variants[variant][variantKey];
|
|
752
|
+
});
|
|
753
|
+
const propsWithoutUndefined = props && Object.entries(props).reduce((acc, param) => {
|
|
754
|
+
let [key, value] = param;
|
|
755
|
+
if (value === void 0) {
|
|
756
|
+
return acc;
|
|
757
|
+
}
|
|
758
|
+
acc[key] = value;
|
|
759
|
+
return acc;
|
|
760
|
+
}, {});
|
|
761
|
+
const getCompoundVariantClassNames = config === null || config === void 0 ? void 0 : (_config_compoundVariants = config.compoundVariants) === null || _config_compoundVariants === void 0 ? void 0 : _config_compoundVariants.reduce((acc, param) => {
|
|
762
|
+
let { class: cvClass, className: cvClassName, ...compoundVariantOptions } = param;
|
|
763
|
+
return Object.entries(compoundVariantOptions).every((param2) => {
|
|
764
|
+
let [key, value] = param2;
|
|
765
|
+
return Array.isArray(value) ? value.includes({
|
|
766
|
+
...defaultVariants,
|
|
767
|
+
...propsWithoutUndefined
|
|
768
|
+
}[key]) : {
|
|
769
|
+
...defaultVariants,
|
|
770
|
+
...propsWithoutUndefined
|
|
771
|
+
}[key] === value;
|
|
772
|
+
}) ? [
|
|
773
|
+
...acc,
|
|
774
|
+
cvClass,
|
|
775
|
+
cvClassName
|
|
776
|
+
] : acc;
|
|
777
|
+
}, []);
|
|
778
|
+
return cx(base, getVariantClassNames, getCompoundVariantClassNames, props === null || props === void 0 ? void 0 : props.class, props === null || props === void 0 ? void 0 : props.className);
|
|
779
|
+
};
|
|
780
|
+
|
|
781
|
+
// src/components/advanced-search-bar/index.tsx
|
|
782
|
+
import { Search as Search2, X, ChevronDown } from "lucide-react";
|
|
613
783
|
import { cn as cn6 } from "@foundrykit/utils";
|
|
784
|
+
import {
|
|
785
|
+
useAdvancedSearch,
|
|
786
|
+
SearchContext
|
|
787
|
+
} from "@foundrykit/hooks";
|
|
788
|
+
import { Input as Input3 } from "@foundrykit/primitives";
|
|
789
|
+
import { Button as Button4 } from "@foundrykit/primitives";
|
|
790
|
+
import { Separator } from "@foundrykit/primitives";
|
|
791
|
+
import { Badge } from "@foundrykit/primitives";
|
|
792
|
+
import { Card, CardContent } from "@foundrykit/primitives";
|
|
793
|
+
import {
|
|
794
|
+
Popover,
|
|
795
|
+
PopoverContent,
|
|
796
|
+
PopoverTrigger
|
|
797
|
+
} from "@foundrykit/primitives";
|
|
798
|
+
import { jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
799
|
+
function AdvancedSearchProvider({
|
|
800
|
+
children,
|
|
801
|
+
onSearch,
|
|
802
|
+
onResultSelect,
|
|
803
|
+
debounceMs = 300,
|
|
804
|
+
minQueryLength = 1,
|
|
805
|
+
emptyStateBehavior = "show-empty-message",
|
|
806
|
+
initialResults = []
|
|
807
|
+
}) {
|
|
808
|
+
const [query, setQuery] = React6.useState("");
|
|
809
|
+
const [isOpen, setIsOpen] = React6.useState(false);
|
|
810
|
+
const [results, setResults] = React6.useState(initialResults);
|
|
811
|
+
const [isLoading, setIsLoading] = React6.useState(false);
|
|
812
|
+
const debouncedSearch = React6.useCallback(
|
|
813
|
+
(searchQuery) => {
|
|
814
|
+
const timeoutId = setTimeout(async () => {
|
|
815
|
+
if (searchQuery.length >= minQueryLength && onSearch) {
|
|
816
|
+
setIsLoading(true);
|
|
817
|
+
try {
|
|
818
|
+
const searchResults = await onSearch(searchQuery);
|
|
819
|
+
setResults(searchResults);
|
|
820
|
+
} catch (error) {
|
|
821
|
+
console.error("Search error:", error);
|
|
822
|
+
setResults([]);
|
|
823
|
+
} finally {
|
|
824
|
+
setIsLoading(false);
|
|
825
|
+
}
|
|
826
|
+
} else {
|
|
827
|
+
if (emptyStateBehavior === "show-all-results" && searchQuery.length === 0) {
|
|
828
|
+
setResults(initialResults);
|
|
829
|
+
} else if (emptyStateBehavior === "show-all-results" && searchQuery.length > 0 && searchQuery.length < minQueryLength) {
|
|
830
|
+
setResults(initialResults);
|
|
831
|
+
} else {
|
|
832
|
+
setResults([]);
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
}, debounceMs);
|
|
836
|
+
return () => clearTimeout(timeoutId);
|
|
837
|
+
},
|
|
838
|
+
[onSearch, debounceMs, minQueryLength, emptyStateBehavior, initialResults]
|
|
839
|
+
);
|
|
840
|
+
const handleSearch = React6.useCallback(
|
|
841
|
+
(searchQuery) => {
|
|
842
|
+
setQuery(searchQuery);
|
|
843
|
+
debouncedSearch(searchQuery);
|
|
844
|
+
},
|
|
845
|
+
[debouncedSearch]
|
|
846
|
+
);
|
|
847
|
+
const handleResultSelect = React6.useCallback(
|
|
848
|
+
(result) => {
|
|
849
|
+
onResultSelect?.(result);
|
|
850
|
+
setIsOpen(false);
|
|
851
|
+
},
|
|
852
|
+
[onResultSelect]
|
|
853
|
+
);
|
|
854
|
+
const value = React6.useMemo(
|
|
855
|
+
() => ({
|
|
856
|
+
query,
|
|
857
|
+
setQuery,
|
|
858
|
+
isOpen,
|
|
859
|
+
setIsOpen,
|
|
860
|
+
results,
|
|
861
|
+
setResults,
|
|
862
|
+
isLoading,
|
|
863
|
+
setIsLoading,
|
|
864
|
+
onSearch: handleSearch,
|
|
865
|
+
onResultSelect: handleResultSelect,
|
|
866
|
+
emptyStateBehavior,
|
|
867
|
+
minQueryLength
|
|
868
|
+
}),
|
|
869
|
+
[
|
|
870
|
+
query,
|
|
871
|
+
isOpen,
|
|
872
|
+
results,
|
|
873
|
+
isLoading,
|
|
874
|
+
handleSearch,
|
|
875
|
+
handleResultSelect,
|
|
876
|
+
emptyStateBehavior,
|
|
877
|
+
minQueryLength
|
|
878
|
+
]
|
|
879
|
+
);
|
|
880
|
+
return /* @__PURE__ */ jsx7(SearchContext.Provider, { value, children });
|
|
881
|
+
}
|
|
882
|
+
var searchInputWrapperVariants = cva("relative flex items-center w-full", {
|
|
883
|
+
variants: {
|
|
884
|
+
size: {
|
|
885
|
+
sm: "h-8",
|
|
886
|
+
md: "h-10",
|
|
887
|
+
lg: "h-12",
|
|
888
|
+
xl: "h-14"
|
|
889
|
+
},
|
|
890
|
+
variant: {
|
|
891
|
+
default: "border border-input bg-background",
|
|
892
|
+
ghost: "bg-transparent",
|
|
893
|
+
filled: "bg-muted"
|
|
894
|
+
}
|
|
895
|
+
},
|
|
896
|
+
defaultVariants: {
|
|
897
|
+
size: "md",
|
|
898
|
+
variant: "default"
|
|
899
|
+
}
|
|
900
|
+
});
|
|
901
|
+
var searchResultsVariants = cva("w-full", {
|
|
902
|
+
variants: {
|
|
903
|
+
size: {
|
|
904
|
+
sm: "max-w-sm",
|
|
905
|
+
md: "max-w-md",
|
|
906
|
+
lg: "max-w-lg",
|
|
907
|
+
xl: "max-w-xl",
|
|
908
|
+
"2xl": "max-w-2xl",
|
|
909
|
+
full: "max-w-full"
|
|
910
|
+
}
|
|
911
|
+
},
|
|
912
|
+
defaultVariants: {
|
|
913
|
+
size: "lg"
|
|
914
|
+
}
|
|
915
|
+
});
|
|
916
|
+
var SearchInput = React6.forwardRef(
|
|
917
|
+
({
|
|
918
|
+
className,
|
|
919
|
+
size,
|
|
920
|
+
variant,
|
|
921
|
+
placeholder = "Search...",
|
|
922
|
+
showSearchIcon = true,
|
|
923
|
+
showClearButton = true,
|
|
924
|
+
onClear,
|
|
925
|
+
asChild = false,
|
|
926
|
+
...props
|
|
927
|
+
}, ref) => {
|
|
928
|
+
const {
|
|
929
|
+
query,
|
|
930
|
+
setQuery,
|
|
931
|
+
onSearch,
|
|
932
|
+
setIsOpen,
|
|
933
|
+
emptyStateBehavior,
|
|
934
|
+
minQueryLength
|
|
935
|
+
} = useAdvancedSearch();
|
|
936
|
+
const Comp = asChild ? Slot : "div";
|
|
937
|
+
const handleChange = (e) => {
|
|
938
|
+
const value = e.target.value;
|
|
939
|
+
setQuery(value);
|
|
940
|
+
onSearch(value);
|
|
941
|
+
if (emptyStateBehavior === "hide-until-min-chars") {
|
|
942
|
+
setIsOpen(value.length >= minQueryLength);
|
|
943
|
+
} else {
|
|
944
|
+
setIsOpen(true);
|
|
945
|
+
}
|
|
946
|
+
props.onChange?.(e);
|
|
947
|
+
};
|
|
948
|
+
const handleFocus = (e) => {
|
|
949
|
+
if (emptyStateBehavior === "hide-until-min-chars") {
|
|
950
|
+
setIsOpen(query.length >= minQueryLength);
|
|
951
|
+
} else {
|
|
952
|
+
setIsOpen(true);
|
|
953
|
+
}
|
|
954
|
+
props.onFocus?.(e);
|
|
955
|
+
};
|
|
956
|
+
const handleClear = () => {
|
|
957
|
+
setQuery("");
|
|
958
|
+
onSearch("");
|
|
959
|
+
onClear?.();
|
|
960
|
+
};
|
|
961
|
+
return /* @__PURE__ */ jsxs5(
|
|
962
|
+
Comp,
|
|
963
|
+
{
|
|
964
|
+
className: cn6(
|
|
965
|
+
searchInputWrapperVariants({ size, variant }),
|
|
966
|
+
"rounded-md",
|
|
967
|
+
className
|
|
968
|
+
),
|
|
969
|
+
children: [
|
|
970
|
+
showSearchIcon && /* @__PURE__ */ jsx7(Search2, { className: "text-muted-foreground absolute left-3 h-4 w-4" }),
|
|
971
|
+
/* @__PURE__ */ jsx7(
|
|
972
|
+
Input3,
|
|
973
|
+
{
|
|
974
|
+
ref,
|
|
975
|
+
type: "search",
|
|
976
|
+
placeholder,
|
|
977
|
+
value: query,
|
|
978
|
+
onChange: handleChange,
|
|
979
|
+
onFocus: handleFocus,
|
|
980
|
+
className: cn6(
|
|
981
|
+
"border-0 bg-transparent focus-visible:ring-0 focus-visible:ring-offset-0",
|
|
982
|
+
showSearchIcon && "pl-10",
|
|
983
|
+
showClearButton && query && "pr-10"
|
|
984
|
+
),
|
|
985
|
+
size: void 0,
|
|
986
|
+
...props
|
|
987
|
+
}
|
|
988
|
+
),
|
|
989
|
+
showClearButton && query && /* @__PURE__ */ jsx7(
|
|
990
|
+
Button4,
|
|
991
|
+
{
|
|
992
|
+
variant: "ghost",
|
|
993
|
+
size: "sm",
|
|
994
|
+
className: "absolute right-1 h-6 w-6 p-0",
|
|
995
|
+
onClick: handleClear,
|
|
996
|
+
children: /* @__PURE__ */ jsx7(X, { className: "h-3 w-3" })
|
|
997
|
+
}
|
|
998
|
+
)
|
|
999
|
+
]
|
|
1000
|
+
}
|
|
1001
|
+
);
|
|
1002
|
+
}
|
|
1003
|
+
);
|
|
1004
|
+
SearchInput.displayName = "SearchInput";
|
|
1005
|
+
var SearchTrigger = React6.forwardRef(({ className, asChild = false, children, ...props }, ref) => {
|
|
1006
|
+
const { isOpen, setIsOpen } = useAdvancedSearch();
|
|
1007
|
+
const Comp = asChild ? Slot : Button4;
|
|
1008
|
+
return /* @__PURE__ */ jsx7(
|
|
1009
|
+
Comp,
|
|
1010
|
+
{
|
|
1011
|
+
ref,
|
|
1012
|
+
className: cn6(className),
|
|
1013
|
+
onClick: () => setIsOpen(!isOpen),
|
|
1014
|
+
...props,
|
|
1015
|
+
children
|
|
1016
|
+
}
|
|
1017
|
+
);
|
|
1018
|
+
});
|
|
1019
|
+
SearchTrigger.displayName = "SearchTrigger";
|
|
1020
|
+
var SearchResults = React6.forwardRef(
|
|
1021
|
+
({
|
|
1022
|
+
className,
|
|
1023
|
+
size,
|
|
1024
|
+
sections,
|
|
1025
|
+
showEmptyState = true,
|
|
1026
|
+
emptyStateMessage = "No results found",
|
|
1027
|
+
showLoadingState = true,
|
|
1028
|
+
loadingMessage = "Searching...",
|
|
1029
|
+
...props
|
|
1030
|
+
}, ref) => {
|
|
1031
|
+
const {
|
|
1032
|
+
results,
|
|
1033
|
+
isLoading,
|
|
1034
|
+
query,
|
|
1035
|
+
onResultSelect,
|
|
1036
|
+
emptyStateBehavior,
|
|
1037
|
+
minQueryLength
|
|
1038
|
+
} = useAdvancedSearch();
|
|
1039
|
+
if (isLoading && showLoadingState) {
|
|
1040
|
+
return /* @__PURE__ */ jsx7(
|
|
1041
|
+
"div",
|
|
1042
|
+
{
|
|
1043
|
+
ref,
|
|
1044
|
+
className: cn6(
|
|
1045
|
+
searchResultsVariants({ size }),
|
|
1046
|
+
"text-muted-foreground p-4 text-center",
|
|
1047
|
+
className
|
|
1048
|
+
),
|
|
1049
|
+
...props,
|
|
1050
|
+
children: loadingMessage
|
|
1051
|
+
}
|
|
1052
|
+
);
|
|
1053
|
+
}
|
|
1054
|
+
if (!query || results.length === 0) {
|
|
1055
|
+
if (!showEmptyState) return null;
|
|
1056
|
+
if (emptyStateBehavior === "hide-until-min-chars" && query.length > 0 && query.length < minQueryLength) {
|
|
1057
|
+
return null;
|
|
1058
|
+
}
|
|
1059
|
+
return /* @__PURE__ */ jsx7(
|
|
1060
|
+
"div",
|
|
1061
|
+
{
|
|
1062
|
+
ref,
|
|
1063
|
+
className: cn6(
|
|
1064
|
+
searchResultsVariants({ size }),
|
|
1065
|
+
"text-muted-foreground p-4 text-center",
|
|
1066
|
+
className
|
|
1067
|
+
),
|
|
1068
|
+
...props,
|
|
1069
|
+
children: emptyStateMessage
|
|
1070
|
+
}
|
|
1071
|
+
);
|
|
1072
|
+
}
|
|
1073
|
+
const displaySections = sections || [
|
|
1074
|
+
{
|
|
1075
|
+
id: "results",
|
|
1076
|
+
title: "Results",
|
|
1077
|
+
results
|
|
1078
|
+
}
|
|
1079
|
+
];
|
|
1080
|
+
return /* @__PURE__ */ jsx7(
|
|
1081
|
+
"div",
|
|
1082
|
+
{
|
|
1083
|
+
ref,
|
|
1084
|
+
className: cn6(
|
|
1085
|
+
searchResultsVariants({ size }),
|
|
1086
|
+
"max-h-96 overflow-hidden",
|
|
1087
|
+
className
|
|
1088
|
+
),
|
|
1089
|
+
...props,
|
|
1090
|
+
children: /* @__PURE__ */ jsx7("div", { className: "h-full overflow-auto", children: /* @__PURE__ */ jsx7("div", { className: "space-y-4 p-4", children: displaySections.map((section, index) => /* @__PURE__ */ jsxs5("div", { children: [
|
|
1091
|
+
index > 0 && /* @__PURE__ */ jsx7(Separator, { className: "my-4" }),
|
|
1092
|
+
/* @__PURE__ */ jsxs5("div", { className: "space-y-2", children: [
|
|
1093
|
+
/* @__PURE__ */ jsx7("h3", { className: "text-muted-foreground text-sm font-semibold uppercase tracking-wide", children: section.title }),
|
|
1094
|
+
/* @__PURE__ */ jsxs5("div", { className: "space-y-1", children: [
|
|
1095
|
+
section.results.map((result) => /* @__PURE__ */ jsx7(
|
|
1096
|
+
SearchResultItem,
|
|
1097
|
+
{
|
|
1098
|
+
result,
|
|
1099
|
+
onClick: () => onResultSelect(result)
|
|
1100
|
+
},
|
|
1101
|
+
result.id
|
|
1102
|
+
)),
|
|
1103
|
+
section.showMore && section.onShowMore && /* @__PURE__ */ jsxs5(
|
|
1104
|
+
Button4,
|
|
1105
|
+
{
|
|
1106
|
+
variant: "ghost",
|
|
1107
|
+
size: "sm",
|
|
1108
|
+
className: "text-muted-foreground w-full justify-start",
|
|
1109
|
+
onClick: section.onShowMore,
|
|
1110
|
+
children: [
|
|
1111
|
+
"Show more",
|
|
1112
|
+
/* @__PURE__ */ jsx7(ChevronDown, { className: "ml-2 h-3 w-3" })
|
|
1113
|
+
]
|
|
1114
|
+
}
|
|
1115
|
+
)
|
|
1116
|
+
] })
|
|
1117
|
+
] })
|
|
1118
|
+
] }, section.id)) }) })
|
|
1119
|
+
}
|
|
1120
|
+
);
|
|
1121
|
+
}
|
|
1122
|
+
);
|
|
1123
|
+
SearchResults.displayName = "SearchResults";
|
|
1124
|
+
var SearchResultItem = ({ result, onClick }) => {
|
|
1125
|
+
if (result.type === "category") {
|
|
1126
|
+
return /* @__PURE__ */ jsx7("div", { className: "text-muted-foreground p-2 text-sm font-medium", children: result.title });
|
|
1127
|
+
}
|
|
1128
|
+
if (result.type === "suggestion") {
|
|
1129
|
+
return /* @__PURE__ */ jsx7(
|
|
1130
|
+
Button4,
|
|
1131
|
+
{
|
|
1132
|
+
variant: "ghost",
|
|
1133
|
+
size: "sm",
|
|
1134
|
+
className: "h-auto w-full justify-start p-2",
|
|
1135
|
+
onClick,
|
|
1136
|
+
children: /* @__PURE__ */ jsx7("span", { className: "text-sm", children: result.title })
|
|
1137
|
+
}
|
|
1138
|
+
);
|
|
1139
|
+
}
|
|
1140
|
+
return /* @__PURE__ */ jsx7(
|
|
1141
|
+
Card,
|
|
1142
|
+
{
|
|
1143
|
+
className: "hover:bg-muted/50 cursor-pointer transition-colors",
|
|
1144
|
+
onClick,
|
|
1145
|
+
children: /* @__PURE__ */ jsx7(CardContent, { className: "p-3", children: /* @__PURE__ */ jsxs5("div", { className: "flex gap-3", children: [
|
|
1146
|
+
result.image && /* @__PURE__ */ jsx7("div", { className: "flex-shrink-0", children: /* @__PURE__ */ jsx7(
|
|
1147
|
+
"img",
|
|
1148
|
+
{
|
|
1149
|
+
src: result.image,
|
|
1150
|
+
alt: result.title,
|
|
1151
|
+
className: "h-12 w-12 rounded-md object-cover"
|
|
1152
|
+
}
|
|
1153
|
+
) }),
|
|
1154
|
+
/* @__PURE__ */ jsxs5("div", { className: "min-w-0 flex-1", children: [
|
|
1155
|
+
/* @__PURE__ */ jsxs5("div", { className: "flex items-start justify-between gap-2", children: [
|
|
1156
|
+
/* @__PURE__ */ jsx7("h4", { className: "truncate text-sm font-semibold", children: result.title }),
|
|
1157
|
+
result.badge && /* @__PURE__ */ jsx7(Badge, { variant: "secondary", className: "text-xs", children: result.badge })
|
|
1158
|
+
] }),
|
|
1159
|
+
result.description && /* @__PURE__ */ jsx7("p", { className: "text-muted-foreground mt-1 line-clamp-2 text-xs", children: result.description })
|
|
1160
|
+
] })
|
|
1161
|
+
] }) })
|
|
1162
|
+
}
|
|
1163
|
+
);
|
|
1164
|
+
};
|
|
1165
|
+
var AdvancedSearchBar = React6.forwardRef(({ className, children, open, onOpenChange, ...props }, ref) => {
|
|
1166
|
+
const { isOpen, setIsOpen } = useAdvancedSearch();
|
|
1167
|
+
const handleOpenChange = (newOpen) => {
|
|
1168
|
+
if (open !== void 0) {
|
|
1169
|
+
onOpenChange?.(newOpen);
|
|
1170
|
+
} else {
|
|
1171
|
+
setIsOpen(newOpen);
|
|
1172
|
+
}
|
|
1173
|
+
};
|
|
1174
|
+
const isControlled = open !== void 0;
|
|
1175
|
+
const isOpenState = isControlled ? open : isOpen;
|
|
1176
|
+
const childrenArray = React6.Children.toArray(children);
|
|
1177
|
+
const inputChild = childrenArray.find(
|
|
1178
|
+
(child) => React6.isValidElement(child) && child.type === SearchInput
|
|
1179
|
+
);
|
|
1180
|
+
const resultsChild = childrenArray.find(
|
|
1181
|
+
(child) => React6.isValidElement(child) && child.type === SearchResults
|
|
1182
|
+
);
|
|
1183
|
+
const triggerElement = inputChild || /* @__PURE__ */ jsx7(SearchInput, {});
|
|
1184
|
+
return /* @__PURE__ */ jsx7("div", { ref, className: cn6("relative", className), ...props, children: /* @__PURE__ */ jsxs5(Popover, { open: isOpenState, onOpenChange: handleOpenChange, children: [
|
|
1185
|
+
/* @__PURE__ */ jsx7(PopoverTrigger, { asChild: true, children: triggerElement }),
|
|
1186
|
+
/* @__PURE__ */ jsx7(PopoverContent, { className: "p-0", align: "start", children: resultsChild || /* @__PURE__ */ jsx7(SearchResults, {}) })
|
|
1187
|
+
] }) });
|
|
1188
|
+
});
|
|
1189
|
+
AdvancedSearchBar.displayName = "AdvancedSearchBar";
|
|
1190
|
+
var SearchSection = React6.forwardRef(({ className, title, showMore, onShowMore, children, ...props }, ref) => {
|
|
1191
|
+
return /* @__PURE__ */ jsxs5("div", { ref, className: cn6("space-y-2", className), ...props, children: [
|
|
1192
|
+
title && /* @__PURE__ */ jsx7("h3", { className: "text-muted-foreground text-sm font-semibold uppercase tracking-wide", children: title }),
|
|
1193
|
+
/* @__PURE__ */ jsxs5("div", { className: "space-y-1", children: [
|
|
1194
|
+
children,
|
|
1195
|
+
showMore && onShowMore && /* @__PURE__ */ jsxs5(
|
|
1196
|
+
Button4,
|
|
1197
|
+
{
|
|
1198
|
+
variant: "ghost",
|
|
1199
|
+
size: "sm",
|
|
1200
|
+
className: "text-muted-foreground w-full justify-start",
|
|
1201
|
+
onClick: onShowMore,
|
|
1202
|
+
children: [
|
|
1203
|
+
"Show more",
|
|
1204
|
+
/* @__PURE__ */ jsx7(ChevronDown, { className: "ml-2 h-3 w-3" })
|
|
1205
|
+
]
|
|
1206
|
+
}
|
|
1207
|
+
)
|
|
1208
|
+
] })
|
|
1209
|
+
] });
|
|
1210
|
+
});
|
|
1211
|
+
SearchSection.displayName = "SearchSection ";
|
|
1212
|
+
var SearchItem = React6.forwardRef(
|
|
1213
|
+
({ className, result, onClick, children, ...props }, ref) => {
|
|
1214
|
+
const { onResultSelect } = useAdvancedSearch();
|
|
1215
|
+
const handleClick = () => {
|
|
1216
|
+
if (result) {
|
|
1217
|
+
onResultSelect(result);
|
|
1218
|
+
}
|
|
1219
|
+
onClick?.();
|
|
1220
|
+
};
|
|
1221
|
+
if (children) {
|
|
1222
|
+
return /* @__PURE__ */ jsx7(
|
|
1223
|
+
"div",
|
|
1224
|
+
{
|
|
1225
|
+
ref,
|
|
1226
|
+
className: cn6("cursor-pointer", className),
|
|
1227
|
+
onClick: handleClick,
|
|
1228
|
+
...props,
|
|
1229
|
+
children
|
|
1230
|
+
}
|
|
1231
|
+
);
|
|
1232
|
+
}
|
|
1233
|
+
if (!result) return null;
|
|
1234
|
+
if (result.type === "category") {
|
|
1235
|
+
return /* @__PURE__ */ jsx7(
|
|
1236
|
+
"div",
|
|
1237
|
+
{
|
|
1238
|
+
ref,
|
|
1239
|
+
className: cn6(
|
|
1240
|
+
"text-muted-foreground p-2 text-sm font-medium",
|
|
1241
|
+
className
|
|
1242
|
+
),
|
|
1243
|
+
...props,
|
|
1244
|
+
children: result.title
|
|
1245
|
+
}
|
|
1246
|
+
);
|
|
1247
|
+
}
|
|
1248
|
+
if (result.type === "suggestion") {
|
|
1249
|
+
return /* @__PURE__ */ jsx7(
|
|
1250
|
+
Button4,
|
|
1251
|
+
{
|
|
1252
|
+
ref,
|
|
1253
|
+
variant: "ghost",
|
|
1254
|
+
size: "sm",
|
|
1255
|
+
className: cn6("h-auto w-full justify-start p-2", className),
|
|
1256
|
+
onClick: handleClick,
|
|
1257
|
+
...props,
|
|
1258
|
+
children: /* @__PURE__ */ jsx7("span", { className: "text-sm", children: result.title })
|
|
1259
|
+
}
|
|
1260
|
+
);
|
|
1261
|
+
}
|
|
1262
|
+
return /* @__PURE__ */ jsx7(
|
|
1263
|
+
Card,
|
|
1264
|
+
{
|
|
1265
|
+
ref,
|
|
1266
|
+
className: cn6(
|
|
1267
|
+
"hover:bg-muted/50 cursor-pointer transition-colors",
|
|
1268
|
+
className
|
|
1269
|
+
),
|
|
1270
|
+
onClick: handleClick,
|
|
1271
|
+
...props,
|
|
1272
|
+
children: /* @__PURE__ */ jsx7(CardContent, { className: "p-3", children: /* @__PURE__ */ jsxs5("div", { className: "flex gap-3", children: [
|
|
1273
|
+
result.image && /* @__PURE__ */ jsx7("div", { className: "flex-shrink-0", children: /* @__PURE__ */ jsx7(
|
|
1274
|
+
"img",
|
|
1275
|
+
{
|
|
1276
|
+
src: result.image,
|
|
1277
|
+
alt: result.title,
|
|
1278
|
+
className: "h-12 w-12 rounded-md object-cover"
|
|
1279
|
+
}
|
|
1280
|
+
) }),
|
|
1281
|
+
/* @__PURE__ */ jsxs5("div", { className: "min-w-0 flex-1", children: [
|
|
1282
|
+
/* @__PURE__ */ jsxs5("div", { className: "flex items-start justify-between gap-2", children: [
|
|
1283
|
+
/* @__PURE__ */ jsx7("h4", { className: "truncate text-sm font-semibold", children: result.title }),
|
|
1284
|
+
result.badge && /* @__PURE__ */ jsx7(Badge, { variant: "secondary", className: "text-xs", children: result.badge })
|
|
1285
|
+
] }),
|
|
1286
|
+
result.description && /* @__PURE__ */ jsx7("p", { className: "text-muted-foreground mt-1 line-clamp-2 text-xs", children: result.description })
|
|
1287
|
+
] })
|
|
1288
|
+
] }) })
|
|
1289
|
+
}
|
|
1290
|
+
);
|
|
1291
|
+
}
|
|
1292
|
+
);
|
|
1293
|
+
SearchItem.displayName = "SearchItem";
|
|
1294
|
+
|
|
1295
|
+
// src/index.ts
|
|
1296
|
+
import { cn as cn7 } from "@foundrykit/utils";
|
|
614
1297
|
export {
|
|
1298
|
+
AdvancedSearchBar,
|
|
1299
|
+
AdvancedSearchProvider,
|
|
615
1300
|
Calendar,
|
|
616
1301
|
Command,
|
|
617
1302
|
CommandDialog,
|
|
@@ -631,6 +1316,11 @@ export {
|
|
|
631
1316
|
PaginationNext,
|
|
632
1317
|
PaginationPrevious,
|
|
633
1318
|
SearchBar,
|
|
634
|
-
|
|
1319
|
+
SearchInput,
|
|
1320
|
+
SearchItem,
|
|
1321
|
+
SearchResults,
|
|
1322
|
+
SearchSection,
|
|
1323
|
+
SearchTrigger,
|
|
1324
|
+
cn7 as cn
|
|
635
1325
|
};
|
|
636
1326
|
//# sourceMappingURL=index.js.map
|