@seekora-ai/ui-sdk-react 1.0.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.
- package/dist/components/Breadcrumb.d.ts +43 -0
- package/dist/components/Breadcrumb.d.ts.map +1 -0
- package/dist/components/Breadcrumb.js +119 -0
- package/dist/components/ClearRefinements.d.ts +42 -0
- package/dist/components/ClearRefinements.d.ts.map +1 -0
- package/dist/components/ClearRefinements.js +80 -0
- package/dist/components/CurrentRefinements.d.ts +41 -0
- package/dist/components/CurrentRefinements.d.ts.map +1 -0
- package/dist/components/CurrentRefinements.js +83 -0
- package/dist/components/Facets.d.ts +53 -0
- package/dist/components/Facets.d.ts.map +1 -0
- package/dist/components/Facets.js +195 -0
- package/dist/components/FederatedDropdown.d.ts +92 -0
- package/dist/components/FederatedDropdown.d.ts.map +1 -0
- package/dist/components/FederatedDropdown.js +510 -0
- package/dist/components/HierarchicalMenu.d.ts +55 -0
- package/dist/components/HierarchicalMenu.d.ts.map +1 -0
- package/dist/components/HierarchicalMenu.js +168 -0
- package/dist/components/Highlight.d.ts +51 -0
- package/dist/components/Highlight.d.ts.map +1 -0
- package/dist/components/Highlight.js +155 -0
- package/dist/components/HitsPerPage.d.ts +41 -0
- package/dist/components/HitsPerPage.d.ts.map +1 -0
- package/dist/components/HitsPerPage.js +72 -0
- package/dist/components/InfiniteHits.d.ts +56 -0
- package/dist/components/InfiniteHits.d.ts.map +1 -0
- package/dist/components/InfiniteHits.js +181 -0
- package/dist/components/MobileFilters.d.ts +71 -0
- package/dist/components/MobileFilters.d.ts.map +1 -0
- package/dist/components/MobileFilters.js +242 -0
- package/dist/components/Pagination.d.ts +44 -0
- package/dist/components/Pagination.d.ts.map +1 -0
- package/dist/components/Pagination.js +142 -0
- package/dist/components/QuerySuggestions.d.ts +38 -0
- package/dist/components/QuerySuggestions.d.ts.map +1 -0
- package/dist/components/QuerySuggestions.js +86 -0
- package/dist/components/QuerySuggestionsDropdown.d.ts +86 -0
- package/dist/components/QuerySuggestionsDropdown.d.ts.map +1 -0
- package/dist/components/QuerySuggestionsDropdown.js +395 -0
- package/dist/components/RangeInput.d.ts +58 -0
- package/dist/components/RangeInput.d.ts.map +1 -0
- package/dist/components/RangeInput.js +203 -0
- package/dist/components/RangeSlider.d.ts +51 -0
- package/dist/components/RangeSlider.d.ts.map +1 -0
- package/dist/components/RangeSlider.js +193 -0
- package/dist/components/Recommendations.d.ts +90 -0
- package/dist/components/Recommendations.d.ts.map +1 -0
- package/dist/components/Recommendations.js +270 -0
- package/dist/components/RichQuerySuggestions.d.ts +77 -0
- package/dist/components/RichQuerySuggestions.d.ts.map +1 -0
- package/dist/components/RichQuerySuggestions.js +492 -0
- package/dist/components/SearchBar.d.ts +40 -0
- package/dist/components/SearchBar.d.ts.map +1 -0
- package/dist/components/SearchBar.js +217 -0
- package/dist/components/SearchBarWithSuggestions.d.ts +99 -0
- package/dist/components/SearchBarWithSuggestions.d.ts.map +1 -0
- package/dist/components/SearchBarWithSuggestions.js +275 -0
- package/dist/components/SearchLayout.d.ts +35 -0
- package/dist/components/SearchLayout.d.ts.map +1 -0
- package/dist/components/SearchLayout.js +56 -0
- package/dist/components/SearchProvider.d.ts +28 -0
- package/dist/components/SearchProvider.d.ts.map +1 -0
- package/dist/components/SearchProvider.js +43 -0
- package/dist/components/SearchResults.d.ts +51 -0
- package/dist/components/SearchResults.d.ts.map +1 -0
- package/dist/components/SearchResults.js +485 -0
- package/dist/components/SortBy.d.ts +44 -0
- package/dist/components/SortBy.d.ts.map +1 -0
- package/dist/components/SortBy.js +61 -0
- package/dist/components/Stats.d.ts +37 -0
- package/dist/components/Stats.d.ts.map +1 -0
- package/dist/components/Stats.js +52 -0
- package/dist/components/suggestions/AmazonDropdown.d.ts +30 -0
- package/dist/components/suggestions/AmazonDropdown.d.ts.map +1 -0
- package/dist/components/suggestions/AmazonDropdown.js +529 -0
- package/dist/components/suggestions/GoogleDropdown.d.ts +31 -0
- package/dist/components/suggestions/GoogleDropdown.d.ts.map +1 -0
- package/dist/components/suggestions/GoogleDropdown.js +370 -0
- package/dist/components/suggestions/MinimalDropdown.d.ts +24 -0
- package/dist/components/suggestions/MinimalDropdown.d.ts.map +1 -0
- package/dist/components/suggestions/MinimalDropdown.js +314 -0
- package/dist/components/suggestions/MobileSheetDropdown.d.ts +31 -0
- package/dist/components/suggestions/MobileSheetDropdown.d.ts.map +1 -0
- package/dist/components/suggestions/MobileSheetDropdown.js +485 -0
- package/dist/components/suggestions/PinterestDropdown.d.ts +29 -0
- package/dist/components/suggestions/PinterestDropdown.d.ts.map +1 -0
- package/dist/components/suggestions/PinterestDropdown.js +450 -0
- package/dist/components/suggestions/ShopifyDropdown.d.ts +27 -0
- package/dist/components/suggestions/ShopifyDropdown.d.ts.map +1 -0
- package/dist/components/suggestions/ShopifyDropdown.js +451 -0
- package/dist/components/suggestions/SpotlightDropdown.d.ts +33 -0
- package/dist/components/suggestions/SpotlightDropdown.d.ts.map +1 -0
- package/dist/components/suggestions/SpotlightDropdown.js +547 -0
- package/dist/components/suggestions/SuggestionSearchBar.d.ts +123 -0
- package/dist/components/suggestions/SuggestionSearchBar.d.ts.map +1 -0
- package/dist/components/suggestions/SuggestionSearchBar.js +652 -0
- package/dist/components/suggestions/index.d.ts +37 -0
- package/dist/components/suggestions/index.d.ts.map +1 -0
- package/dist/components/suggestions/index.js +59 -0
- package/dist/components/suggestions/styles/index.d.ts +11 -0
- package/dist/components/suggestions/styles/index.d.ts.map +1 -0
- package/dist/components/suggestions/styles/index.js +289 -0
- package/dist/components/suggestions/styles/responsive.d.ts +107 -0
- package/dist/components/suggestions/styles/responsive.d.ts.map +1 -0
- package/dist/components/suggestions/styles/responsive.js +237 -0
- package/dist/components/suggestions/types.d.ts +489 -0
- package/dist/components/suggestions/types.d.ts.map +1 -0
- package/dist/components/suggestions/types.js +6 -0
- package/dist/components/suggestions/utils.d.ts +213 -0
- package/dist/components/suggestions/utils.d.ts.map +1 -0
- package/dist/components/suggestions/utils.js +514 -0
- package/dist/hooks/useAnalytics.d.ts +20 -0
- package/dist/hooks/useAnalytics.d.ts.map +1 -0
- package/dist/hooks/useAnalytics.js +62 -0
- package/dist/hooks/useNaturalLanguageFilters.d.ts +48 -0
- package/dist/hooks/useNaturalLanguageFilters.d.ts.map +1 -0
- package/dist/hooks/useNaturalLanguageFilters.js +221 -0
- package/dist/hooks/useQuerySuggestions.d.ts +21 -0
- package/dist/hooks/useQuerySuggestions.d.ts.map +1 -0
- package/dist/hooks/useQuerySuggestions.js +68 -0
- package/dist/hooks/useQuerySuggestionsEnhanced.d.ts +114 -0
- package/dist/hooks/useQuerySuggestionsEnhanced.d.ts.map +1 -0
- package/dist/hooks/useQuerySuggestionsEnhanced.js +376 -0
- package/dist/hooks/useSearchState.d.ts +35 -0
- package/dist/hooks/useSearchState.d.ts.map +1 -0
- package/dist/hooks/useSearchState.js +68 -0
- package/dist/hooks/useSeekoraSearch.d.ts +20 -0
- package/dist/hooks/useSeekoraSearch.d.ts.map +1 -0
- package/dist/hooks/useSeekoraSearch.js +63 -0
- package/dist/hooks/useSmartSuggestions.d.ts +55 -0
- package/dist/hooks/useSmartSuggestions.d.ts.map +1 -0
- package/dist/hooks/useSmartSuggestions.js +236 -0
- package/dist/hooks/useSuggestionsAnalytics.d.ts +91 -0
- package/dist/hooks/useSuggestionsAnalytics.d.ts.map +1 -0
- package/dist/hooks/useSuggestionsAnalytics.js +226 -0
- package/dist/index.d.ts +80 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +86 -0
- package/dist/index.umd.js +1 -0
- package/dist/src/index.d.ts +2849 -0
- package/dist/src/index.esm.js +11679 -0
- package/dist/src/index.esm.js.map +1 -0
- package/dist/src/index.js +11761 -0
- package/dist/src/index.js.map +1 -0
- package/dist/themes/createTheme.d.ts +8 -0
- package/dist/themes/createTheme.d.ts.map +1 -0
- package/dist/themes/createTheme.js +10 -0
- package/dist/themes/dark.d.ts +6 -0
- package/dist/themes/dark.d.ts.map +1 -0
- package/dist/themes/dark.js +34 -0
- package/dist/themes/default.d.ts +6 -0
- package/dist/themes/default.d.ts.map +1 -0
- package/dist/themes/default.js +71 -0
- package/dist/themes/mergeThemes.d.ts +7 -0
- package/dist/themes/mergeThemes.d.ts.map +1 -0
- package/dist/themes/mergeThemes.js +6 -0
- package/dist/themes/minimal.d.ts +6 -0
- package/dist/themes/minimal.d.ts.map +1 -0
- package/dist/themes/minimal.js +34 -0
- package/dist/themes/suggestions.d.ts +216 -0
- package/dist/themes/suggestions.d.ts.map +1 -0
- package/dist/themes/suggestions.js +546 -0
- package/dist/themes/types.d.ts +7 -0
- package/dist/themes/types.d.ts.map +1 -0
- package/dist/themes/types.js +6 -0
- package/dist/types/index.d.ts +33 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +4 -0
- package/package.json +65 -0
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pagination Component
|
|
3
|
+
*
|
|
4
|
+
* Displays pagination controls for search results
|
|
5
|
+
*/
|
|
6
|
+
import React from 'react';
|
|
7
|
+
import { useSearchContext } from './SearchProvider';
|
|
8
|
+
import { useSearchState } from '../hooks/useSearchState';
|
|
9
|
+
import { clsx } from 'clsx';
|
|
10
|
+
export const Pagination = ({ results: resultsProp, currentPage: currentPageProp, itemsPerPage: itemsPerPageProp, totalPages: totalPagesProp, onPageChange, maxPages = 7, showFirstLast = true, showPrevNext = true, renderPageButton, className, style, theme: customTheme, }) => {
|
|
11
|
+
const { theme } = useSearchContext();
|
|
12
|
+
const { results: stateResults, currentPage: stateCurrentPage, setPage } = useSearchState();
|
|
13
|
+
const paginationTheme = customTheme || {};
|
|
14
|
+
// Use results from prop if provided, otherwise from state manager
|
|
15
|
+
const results = resultsProp || stateResults;
|
|
16
|
+
// Use currentPage from prop if provided, otherwise from state manager
|
|
17
|
+
const currentPage = currentPageProp || stateCurrentPage;
|
|
18
|
+
const res = results;
|
|
19
|
+
const itemsPerPage = itemsPerPageProp
|
|
20
|
+
|| res?.perPage
|
|
21
|
+
|| res?.data?.per_page
|
|
22
|
+
|| res?.data?.data?.per_page
|
|
23
|
+
|| 20;
|
|
24
|
+
const totalResults = res?.totalResults
|
|
25
|
+
|| res?.data?.total_results
|
|
26
|
+
|| res?.data?.data?.total_results
|
|
27
|
+
|| 0;
|
|
28
|
+
const totalPages = totalPagesProp
|
|
29
|
+
|| res?.totalPages
|
|
30
|
+
|| res?.data?.total_pages
|
|
31
|
+
|| res?.data?.data?.total_pages
|
|
32
|
+
|| Math.ceil(totalResults / itemsPerPage);
|
|
33
|
+
const handlePageChange = (page) => {
|
|
34
|
+
if (page < 1 || page > totalPages || page === currentPage)
|
|
35
|
+
return;
|
|
36
|
+
// Update state manager (automatically triggers search)
|
|
37
|
+
setPage(page);
|
|
38
|
+
// Call callback for backwards compatibility
|
|
39
|
+
if (onPageChange) {
|
|
40
|
+
onPageChange(page);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const defaultRenderPageButton = (page, isActive, isDisabled) => (React.createElement("button", { type: "button", disabled: isDisabled, onClick: () => !isDisabled && handlePageChange(page), className: clsx(paginationTheme.item, isActive && paginationTheme.itemActive, isDisabled && paginationTheme.itemDisabled), style: {
|
|
44
|
+
padding: theme.spacing.small,
|
|
45
|
+
margin: `0 ${theme.spacing.small}`,
|
|
46
|
+
border: `1px solid ${theme.colors.border}`,
|
|
47
|
+
borderRadius: typeof theme.borderRadius === 'string' ? theme.borderRadius : theme.borderRadius.medium,
|
|
48
|
+
backgroundColor: isActive ? theme.colors.primary : theme.colors.background,
|
|
49
|
+
color: isActive ? '#fff' : theme.colors.text,
|
|
50
|
+
cursor: isDisabled ? 'not-allowed' : 'pointer',
|
|
51
|
+
opacity: isDisabled ? 0.5 : 1,
|
|
52
|
+
fontSize: theme.typography.fontSize.medium,
|
|
53
|
+
minWidth: '40px',
|
|
54
|
+
...(isActive && {
|
|
55
|
+
fontWeight: 'bold',
|
|
56
|
+
}),
|
|
57
|
+
} }, page));
|
|
58
|
+
if (totalPages <= 1) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
// Calculate page range to display
|
|
62
|
+
const getPageNumbers = () => {
|
|
63
|
+
const pages = [];
|
|
64
|
+
const halfRange = Math.floor(maxPages / 2);
|
|
65
|
+
let startPage = Math.max(1, currentPage - halfRange);
|
|
66
|
+
let endPage = Math.min(totalPages, currentPage + halfRange);
|
|
67
|
+
// Adjust if we're near the beginning or end
|
|
68
|
+
if (currentPage <= halfRange) {
|
|
69
|
+
endPage = Math.min(maxPages, totalPages);
|
|
70
|
+
}
|
|
71
|
+
if (currentPage >= totalPages - halfRange) {
|
|
72
|
+
startPage = Math.max(1, totalPages - maxPages + 1);
|
|
73
|
+
}
|
|
74
|
+
if (showFirstLast && startPage > 1) {
|
|
75
|
+
pages.push(1);
|
|
76
|
+
if (startPage > 2) {
|
|
77
|
+
pages.push('ellipsis');
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
for (let i = startPage; i <= endPage; i++) {
|
|
81
|
+
pages.push(i);
|
|
82
|
+
}
|
|
83
|
+
if (showFirstLast && endPage < totalPages) {
|
|
84
|
+
if (endPage < totalPages - 1) {
|
|
85
|
+
pages.push('ellipsis');
|
|
86
|
+
}
|
|
87
|
+
pages.push(totalPages);
|
|
88
|
+
}
|
|
89
|
+
return pages;
|
|
90
|
+
};
|
|
91
|
+
const pageNumbers = getPageNumbers();
|
|
92
|
+
return (React.createElement("nav", { className: clsx(paginationTheme.container, className), style: style, "aria-label": "Pagination" },
|
|
93
|
+
React.createElement("ul", { className: paginationTheme.list, style: {
|
|
94
|
+
listStyle: 'none',
|
|
95
|
+
display: 'flex',
|
|
96
|
+
alignItems: 'center',
|
|
97
|
+
justifyContent: 'center',
|
|
98
|
+
padding: 0,
|
|
99
|
+
margin: 0,
|
|
100
|
+
flexWrap: 'wrap',
|
|
101
|
+
} },
|
|
102
|
+
showPrevNext && (React.createElement("li", null,
|
|
103
|
+
React.createElement("button", { type: "button", disabled: currentPage === 1, onClick: () => handlePageChange(currentPage - 1), className: clsx(paginationTheme.item, currentPage === 1 && paginationTheme.itemDisabled), style: {
|
|
104
|
+
padding: theme.spacing.small,
|
|
105
|
+
margin: `0 ${theme.spacing.small}`,
|
|
106
|
+
border: `1px solid ${theme.colors.border}`,
|
|
107
|
+
borderRadius: typeof theme.borderRadius === 'string' ? theme.borderRadius : theme.borderRadius.medium,
|
|
108
|
+
backgroundColor: theme.colors.background,
|
|
109
|
+
color: theme.colors.text,
|
|
110
|
+
cursor: currentPage === 1 ? 'not-allowed' : 'pointer',
|
|
111
|
+
opacity: currentPage === 1 ? 0.5 : 1,
|
|
112
|
+
fontSize: theme.typography.fontSize.medium,
|
|
113
|
+
}, "aria-label": "Previous page" }, "Previous"))),
|
|
114
|
+
pageNumbers.map((page, index) => {
|
|
115
|
+
if (page === 'ellipsis') {
|
|
116
|
+
return (React.createElement("li", { key: `ellipsis-${index}` },
|
|
117
|
+
React.createElement("span", { className: paginationTheme.ellipsis, style: {
|
|
118
|
+
padding: theme.spacing.small,
|
|
119
|
+
margin: `0 ${theme.spacing.small}`,
|
|
120
|
+
color: theme.colors.text,
|
|
121
|
+
fontSize: theme.typography.fontSize.medium,
|
|
122
|
+
} }, "...")));
|
|
123
|
+
}
|
|
124
|
+
const isActive = page === currentPage;
|
|
125
|
+
const isDisabled = false;
|
|
126
|
+
return (React.createElement("li", { key: page }, renderPageButton
|
|
127
|
+
? renderPageButton(page, isActive, isDisabled)
|
|
128
|
+
: defaultRenderPageButton(page, isActive, isDisabled)));
|
|
129
|
+
}),
|
|
130
|
+
showPrevNext && (React.createElement("li", null,
|
|
131
|
+
React.createElement("button", { type: "button", disabled: currentPage === totalPages, onClick: () => handlePageChange(currentPage + 1), className: clsx(paginationTheme.item, currentPage === totalPages && paginationTheme.itemDisabled), style: {
|
|
132
|
+
padding: theme.spacing.small,
|
|
133
|
+
margin: `0 ${theme.spacing.small}`,
|
|
134
|
+
border: `1px solid ${theme.colors.border}`,
|
|
135
|
+
borderRadius: typeof theme.borderRadius === 'string' ? theme.borderRadius : theme.borderRadius.medium,
|
|
136
|
+
backgroundColor: theme.colors.background,
|
|
137
|
+
color: theme.colors.text,
|
|
138
|
+
cursor: currentPage === totalPages ? 'not-allowed' : 'pointer',
|
|
139
|
+
opacity: currentPage === totalPages ? 0.5 : 1,
|
|
140
|
+
fontSize: theme.typography.fontSize.medium,
|
|
141
|
+
}, "aria-label": "Next page" }, "Next"))))));
|
|
142
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* QuerySuggestions Component
|
|
3
|
+
*
|
|
4
|
+
* Standalone component for displaying query suggestions
|
|
5
|
+
*/
|
|
6
|
+
import React from 'react';
|
|
7
|
+
export interface SuggestionItem {
|
|
8
|
+
query: string;
|
|
9
|
+
count?: number;
|
|
10
|
+
metadata?: Record<string, any>;
|
|
11
|
+
}
|
|
12
|
+
export interface QuerySuggestionsTheme {
|
|
13
|
+
container?: string;
|
|
14
|
+
title?: string;
|
|
15
|
+
suggestionsList?: string;
|
|
16
|
+
suggestionItem?: string;
|
|
17
|
+
suggestionItemHover?: string;
|
|
18
|
+
suggestionItemActive?: string;
|
|
19
|
+
loadingState?: string;
|
|
20
|
+
emptyState?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface QuerySuggestionsProps {
|
|
23
|
+
query?: string;
|
|
24
|
+
maxSuggestions?: number;
|
|
25
|
+
debounceMs?: number;
|
|
26
|
+
minQueryLength?: number;
|
|
27
|
+
onSuggestionClick?: (suggestion: string) => void;
|
|
28
|
+
renderSuggestion?: (suggestion: SuggestionItem, index: number) => React.ReactNode;
|
|
29
|
+
renderLoading?: () => React.ReactNode;
|
|
30
|
+
renderEmpty?: () => React.ReactNode;
|
|
31
|
+
showTitle?: boolean;
|
|
32
|
+
title?: string;
|
|
33
|
+
className?: string;
|
|
34
|
+
style?: React.CSSProperties;
|
|
35
|
+
theme?: QuerySuggestionsTheme;
|
|
36
|
+
}
|
|
37
|
+
export declare const QuerySuggestions: React.FC<QuerySuggestionsProps>;
|
|
38
|
+
//# sourceMappingURL=QuerySuggestions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QuerySuggestions.d.ts","sourceRoot":"","sources":["../../src/components/QuerySuggestions.tsx"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAmB,MAAM,OAAO,CAAC;AAMxC,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAChC;AAED,MAAM,WAAW,qBAAqB;IACpC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,qBAAqB;IACpC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,iBAAiB,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;IACjD,gBAAgB,CAAC,EAAE,CAAC,UAAU,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,KAAK,KAAK,CAAC,SAAS,CAAC;IAClF,aAAa,CAAC,EAAE,MAAM,KAAK,CAAC,SAAS,CAAC;IACtC,WAAW,CAAC,EAAE,MAAM,KAAK,CAAC,SAAS,CAAC;IACpC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;IAC5B,KAAK,CAAC,EAAE,qBAAqB,CAAC;CAC/B;AAED,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAAE,CAAC,qBAAqB,CAwK5D,CAAC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* QuerySuggestions Component
|
|
3
|
+
*
|
|
4
|
+
* Standalone component for displaying query suggestions
|
|
5
|
+
*/
|
|
6
|
+
import React, { useState } from 'react';
|
|
7
|
+
import { useSearchContext } from './SearchProvider';
|
|
8
|
+
import { useQuerySuggestions } from '../hooks/useQuerySuggestions';
|
|
9
|
+
import { clsx } from 'clsx';
|
|
10
|
+
export const QuerySuggestions = ({ query = '', maxSuggestions = 10, debounceMs = 300, minQueryLength = 2, onSuggestionClick, renderSuggestion, renderLoading, renderEmpty, showTitle = false, title = 'Suggestions', className, style, theme: customTheme, }) => {
|
|
11
|
+
const { client, theme } = useSearchContext();
|
|
12
|
+
const [selectedIndex, setSelectedIndex] = useState(-1);
|
|
13
|
+
const { suggestions, loading, error } = useQuerySuggestions({
|
|
14
|
+
client,
|
|
15
|
+
query,
|
|
16
|
+
enabled: query.length >= minQueryLength,
|
|
17
|
+
debounceMs,
|
|
18
|
+
maxSuggestions,
|
|
19
|
+
});
|
|
20
|
+
const displayedSuggestions = suggestions.slice(0, maxSuggestions);
|
|
21
|
+
const suggestionsTheme = customTheme || {};
|
|
22
|
+
const defaultRenderSuggestion = (suggestion, index) => (React.createElement("div", { key: index },
|
|
23
|
+
React.createElement("span", null, suggestion.query),
|
|
24
|
+
suggestion.count !== undefined && (React.createElement("span", { style: { opacity: 0.6, marginLeft: theme.spacing.small } },
|
|
25
|
+
"(",
|
|
26
|
+
suggestion.count,
|
|
27
|
+
")"))));
|
|
28
|
+
const defaultRenderLoading = () => (React.createElement("div", { style: {
|
|
29
|
+
padding: theme.spacing.medium,
|
|
30
|
+
textAlign: 'center',
|
|
31
|
+
color: theme.colors.text,
|
|
32
|
+
} }, "Loading suggestions..."));
|
|
33
|
+
const defaultRenderEmpty = () => (React.createElement("div", { style: {
|
|
34
|
+
padding: theme.spacing.medium,
|
|
35
|
+
textAlign: 'center',
|
|
36
|
+
color: theme.colors.text,
|
|
37
|
+
opacity: 0.6,
|
|
38
|
+
} }, "No suggestions available"));
|
|
39
|
+
const handleSuggestionClick = (suggestion) => {
|
|
40
|
+
if (onSuggestionClick) {
|
|
41
|
+
onSuggestionClick(suggestion.query);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
if (query.length < minQueryLength) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
if (loading) {
|
|
48
|
+
return (React.createElement("div", { className: clsx(suggestionsTheme.container, className), style: style },
|
|
49
|
+
showTitle && (React.createElement("div", { className: suggestionsTheme.title, style: {
|
|
50
|
+
fontSize: theme.typography.fontSize.large,
|
|
51
|
+
fontWeight: 'bold',
|
|
52
|
+
marginBottom: theme.spacing.medium,
|
|
53
|
+
color: theme.colors.text,
|
|
54
|
+
} }, title)),
|
|
55
|
+
renderLoading ? renderLoading() : defaultRenderLoading()));
|
|
56
|
+
}
|
|
57
|
+
if (error || displayedSuggestions.length === 0) {
|
|
58
|
+
return (React.createElement("div", { className: clsx(suggestionsTheme.container, className), style: style },
|
|
59
|
+
showTitle && (React.createElement("div", { className: suggestionsTheme.title, style: {
|
|
60
|
+
fontSize: theme.typography.fontSize.large,
|
|
61
|
+
fontWeight: 'bold',
|
|
62
|
+
marginBottom: theme.spacing.medium,
|
|
63
|
+
color: theme.colors.text,
|
|
64
|
+
} }, title)),
|
|
65
|
+
renderEmpty ? renderEmpty() : defaultRenderEmpty()));
|
|
66
|
+
}
|
|
67
|
+
const renderFn = renderSuggestion || defaultRenderSuggestion;
|
|
68
|
+
return (React.createElement("div", { className: clsx(suggestionsTheme.container, className), style: style },
|
|
69
|
+
showTitle && (React.createElement("div", { className: suggestionsTheme.title, style: {
|
|
70
|
+
fontSize: theme.typography.fontSize.large,
|
|
71
|
+
fontWeight: 'bold',
|
|
72
|
+
marginBottom: theme.spacing.medium,
|
|
73
|
+
color: theme.colors.text,
|
|
74
|
+
} }, title)),
|
|
75
|
+
React.createElement("div", { className: suggestionsTheme.suggestionsList }, displayedSuggestions.map((suggestion, index) => {
|
|
76
|
+
const isSelected = index === selectedIndex;
|
|
77
|
+
return (React.createElement("div", { key: index, className: clsx(suggestionsTheme.suggestionItem, isSelected && suggestionsTheme.suggestionItemActive), onClick: () => handleSuggestionClick(suggestion), onMouseEnter: () => setSelectedIndex(index), onMouseLeave: () => setSelectedIndex(-1), style: {
|
|
78
|
+
padding: theme.spacing.medium,
|
|
79
|
+
cursor: 'pointer',
|
|
80
|
+
borderRadius: typeof theme.borderRadius === 'string' ? theme.borderRadius : theme.borderRadius.medium,
|
|
81
|
+
transition: 'background-color 0.2s ease',
|
|
82
|
+
backgroundColor: isSelected ? theme.colors.hover : 'transparent',
|
|
83
|
+
marginBottom: index < displayedSuggestions.length - 1 ? theme.spacing.small : 0,
|
|
84
|
+
} }, renderFn(suggestion, index)));
|
|
85
|
+
}))));
|
|
86
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* QuerySuggestionsDropdown Component
|
|
3
|
+
*
|
|
4
|
+
* Classic dropdown variant with:
|
|
5
|
+
* - Highlighted matches
|
|
6
|
+
* - Keyboard navigation
|
|
7
|
+
* - Recent searches
|
|
8
|
+
* - Customizable styling
|
|
9
|
+
* - Analytics tracking
|
|
10
|
+
* - Accessibility support
|
|
11
|
+
*/
|
|
12
|
+
import React from 'react';
|
|
13
|
+
import type { SuggestionItem, RecentSearch, QuerySuggestionsClassNames, HighlightConfig, KeyboardNavConfig, AnimationConfig, QuerySuggestionsEventHandlers } from '@seekora-ai/ui-sdk-types';
|
|
14
|
+
export interface QuerySuggestionsDropdownProps extends QuerySuggestionsEventHandlers {
|
|
15
|
+
/** Current query string */
|
|
16
|
+
query: string;
|
|
17
|
+
/** Whether the dropdown is visible */
|
|
18
|
+
isOpen?: boolean;
|
|
19
|
+
/** Maximum suggestions to display */
|
|
20
|
+
maxSuggestions?: number;
|
|
21
|
+
/** Minimum query length to trigger suggestions */
|
|
22
|
+
minQueryLength?: number;
|
|
23
|
+
/** Debounce delay in ms */
|
|
24
|
+
debounceMs?: number;
|
|
25
|
+
/** Show recent searches section */
|
|
26
|
+
showRecentSearches?: boolean;
|
|
27
|
+
/** Maximum recent searches to display */
|
|
28
|
+
maxRecentSearches?: number;
|
|
29
|
+
/** Show suggestion counts */
|
|
30
|
+
showCounts?: boolean;
|
|
31
|
+
/** Show loading state */
|
|
32
|
+
showLoading?: boolean;
|
|
33
|
+
/** Show empty state when no results */
|
|
34
|
+
showEmptyState?: boolean;
|
|
35
|
+
/** Highlight configuration */
|
|
36
|
+
highlight?: HighlightConfig;
|
|
37
|
+
/** Keyboard navigation configuration */
|
|
38
|
+
keyboardNav?: KeyboardNavConfig;
|
|
39
|
+
/** Animation configuration */
|
|
40
|
+
animation?: AnimationConfig;
|
|
41
|
+
/** Custom class names */
|
|
42
|
+
classNames?: QuerySuggestionsClassNames;
|
|
43
|
+
/** Custom CSS styles */
|
|
44
|
+
style?: React.CSSProperties;
|
|
45
|
+
/** Custom render for suggestion item */
|
|
46
|
+
renderSuggestion?: (suggestion: SuggestionItem, index: number, isActive: boolean, highlight: (text: string) => React.ReactNode) => React.ReactNode;
|
|
47
|
+
/** Custom render for recent search item */
|
|
48
|
+
renderRecentSearch?: (search: RecentSearch, index: number, isActive: boolean) => React.ReactNode;
|
|
49
|
+
/** Custom render for loading state */
|
|
50
|
+
renderLoading?: () => React.ReactNode;
|
|
51
|
+
/** Custom render for empty state */
|
|
52
|
+
renderEmpty?: () => React.ReactNode;
|
|
53
|
+
/** Custom footer content */
|
|
54
|
+
footer?: React.ReactNode;
|
|
55
|
+
/** Position of dropdown */
|
|
56
|
+
position?: 'absolute' | 'fixed';
|
|
57
|
+
/** Dropdown width */
|
|
58
|
+
width?: string | number;
|
|
59
|
+
/** Z-index for dropdown */
|
|
60
|
+
zIndex?: number;
|
|
61
|
+
/** Input element ref for positioning */
|
|
62
|
+
inputRef?: React.RefObject<HTMLInputElement>;
|
|
63
|
+
/** Close on click outside */
|
|
64
|
+
closeOnClickOutside?: boolean;
|
|
65
|
+
/** Close on escape key */
|
|
66
|
+
closeOnEscape?: boolean;
|
|
67
|
+
/** ARIA label */
|
|
68
|
+
ariaLabel?: string;
|
|
69
|
+
}
|
|
70
|
+
export interface QuerySuggestionsDropdownRef {
|
|
71
|
+
/** Select the currently active item */
|
|
72
|
+
selectActive: () => void;
|
|
73
|
+
/** Navigate to next item */
|
|
74
|
+
navigateNext: () => void;
|
|
75
|
+
/** Navigate to previous item */
|
|
76
|
+
navigatePrevious: () => void;
|
|
77
|
+
/** Reset selection */
|
|
78
|
+
resetSelection: () => void;
|
|
79
|
+
/** Get active index */
|
|
80
|
+
getActiveIndex: () => number;
|
|
81
|
+
/** Get total items count */
|
|
82
|
+
getTotalItems: () => number;
|
|
83
|
+
}
|
|
84
|
+
export declare const QuerySuggestionsDropdown: React.ForwardRefExoticComponent<QuerySuggestionsDropdownProps & React.RefAttributes<QuerySuggestionsDropdownRef>>;
|
|
85
|
+
export default QuerySuggestionsDropdown;
|
|
86
|
+
//# sourceMappingURL=QuerySuggestionsDropdown.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QuerySuggestionsDropdown.d.ts","sourceRoot":"","sources":["../../src/components/QuerySuggestionsDropdown.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAQN,MAAM,OAAO,CAAC;AAIf,OAAO,KAAK,EACV,cAAc,EACd,YAAY,EACZ,0BAA0B,EAC1B,eAAe,EACf,iBAAiB,EACjB,eAA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