@envive-ai/react-widgets 0.1.0 → 0.1.2-arthur-1
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/SearchResults/index-D52sX_I2.d.cts +6 -0
- package/dist/SearchResults/index-D8nrHueo.d.ts +6 -0
- package/dist/SearchResults/index.cjs +123 -0
- package/dist/SearchResults/index.js +121 -0
- package/dist/SearchZeroState/index-19CiYvee.d.cts +27 -0
- package/dist/SearchZeroState/index-6EaGWYP4.d.ts +27 -0
- package/dist/SearchZeroState/index.cjs +3047 -0
- package/dist/SearchZeroState/index.js +3043 -0
- package/dist/SuggestionBar/index-DZU9kbWS.d.cts +39 -0
- package/dist/SuggestionBar/index-DyXd4-b7.d.ts +39 -0
- package/dist/SuggestionBar/index.cjs +5 -0
- package/dist/SuggestionBar/index.js +4 -0
- package/dist/SuggestionBar-BOThXJvJ.cjs +453 -0
- package/dist/SuggestionBar-DeMmAK4M.js +131 -0
- package/dist/SuggestionButtonContainer/index-B_X537jw.d.cts +20 -0
- package/dist/SuggestionButtonContainer/index-vwelzDzM.d.ts +20 -0
- package/dist/SuggestionButtonContainer/index.cjs +3 -0
- package/dist/SuggestionButtonContainer/index.js +3 -0
- package/dist/SuggestionButtonContainer-BeWPpeQk.cjs +173 -0
- package/dist/SuggestionButtonContainer-CZhOkZaJ.js +167 -0
- package/dist/chunk-DWy1uDak.cjs +39 -0
- package/package.json +21 -8
- package/src/SearchZeroState/SearchIcon.tsx +57 -0
- package/src/SearchZeroState/SearchOverlay.tsx +81 -0
- package/src/SearchZeroState/SearchZeroState.tsx +264 -0
- package/src/SearchZeroState/SearchZeroStateWidget.tsx +33 -0
- package/src/SearchZeroState/components/RecommendedProducts.tsx +118 -0
- package/src/SearchZeroState/index.ts +8 -0
- package/src/SearchZeroState/overlay/overlayHostLocator.ts +17 -0
- package/src/SearchZeroState/types.ts +9 -0
- package/src/SearchZeroState/zeroStateSearchVariants.ts +24 -0
- package/src/SuggestionBar/SuggestionBar.tsx +139 -0
- package/src/SuggestionBar/index.ts +2 -0
- package/src/SuggestionBar/types.ts +4 -0
- package/src/SuggestionButtonContainer/SuggestionButtonContainer.tsx +141 -0
- package/src/SuggestionButtonContainer/index.ts +2 -0
- package/src/SuggestionButtonContainer/types.ts +16 -0
- package/src/stories/SearchZeroState.stories.tsx +44 -0
- package/src/stories/SuggestionBar.stories.tsx +46 -0
- package/src/util/useHorizontalScrollAnimation.ts +121 -0
- package/src/util/useReducedMotionWithOverride.ts +24 -0
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
const require_chunk = require('../chunk-DWy1uDak.cjs');
|
|
2
|
+
let react = require("react");
|
|
3
|
+
let jotai = require("jotai");
|
|
4
|
+
let __envive_ai_react_hooks_atoms_globalSearch = require("@envive-ai/react-hooks/atoms/globalSearch");
|
|
5
|
+
let __envive_ai_react_hooks_atoms_search = require("@envive-ai/react-hooks/atoms/search");
|
|
6
|
+
let __envive_ai_react_hooks_hooks_NewOrgConfig = require("@envive-ai/react-hooks/hooks/NewOrgConfig");
|
|
7
|
+
let classnames = require("classnames");
|
|
8
|
+
classnames = require_chunk.__toESM(classnames);
|
|
9
|
+
let __envive_ai_react_toolkit_SearchResultsContent = require("@envive-ai/react-toolkit/SearchResultsContent");
|
|
10
|
+
let __envive_ai_react_toolkit_SearchResultsFilterModal = require("@envive-ai/react-toolkit/SearchResultsFilterModal");
|
|
11
|
+
let __envive_ai_react_toolkit_SearchResultsToolbar = require("@envive-ai/react-toolkit/SearchResultsToolbar");
|
|
12
|
+
let __envive_ai_react_toolkit_util = require("@envive-ai/react-toolkit/util");
|
|
13
|
+
let __envive_ai_react_hooks_hooks_Search = require("@envive-ai/react-hooks/hooks/Search");
|
|
14
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
15
|
+
|
|
16
|
+
//#region src/SearchResults/withSearchResults.tsx
|
|
17
|
+
function withSearchResults(Component) {
|
|
18
|
+
return function SearchResultsHoc(props) {
|
|
19
|
+
const searchHookResult = (0, __envive_ai_react_hooks_hooks_Search.useSearch)();
|
|
20
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Component, {
|
|
21
|
+
...props,
|
|
22
|
+
...searchHookResult,
|
|
23
|
+
productList: searchHookResult.searchData?.products || []
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/SearchResults/SearchResults.tsx
|
|
30
|
+
const SearchResultsComponent = ({ widgetConfig, productCardConfig, merchantShortName, productList, autocompleteResults, searchFilters, availableDynamicFilters, selectedFilterOptions, searchText, query, searchResultsState, isFilterOpen, shouldShowAutocomplete, focusedIndex, focusedOptionId, recommendedProducts, filterButtonText, onSearchInputChange, onSubmitSearch, onAutocompleteSelect, onKeyDown, onSearchInputFocus, onSearchInputBlur, onToggleDynamicFilter, onSelectFilterItem, onRemoveFilter, onClearAllFilters, setIsFilterOpen, searchResultsRef }) => {
|
|
31
|
+
const { searchInputVariant, searchFilterSidebarVariant, productGridVariant, searchBoxPlaceholder, noResultsFoundText, isSearchInputSticky = false } = widgetConfig;
|
|
32
|
+
const { toolbarRef: ref, isVisible, toolbarHeight: height } = (0, __envive_ai_react_toolkit_util.useStickyVisibility)();
|
|
33
|
+
const toolbarRef = isSearchInputSticky ? ref : null;
|
|
34
|
+
const finalIsVisible = isSearchInputSticky ? isVisible : true;
|
|
35
|
+
const toolbarHeight = isSearchInputSticky ? height : 0;
|
|
36
|
+
const stickyToolbarClasses = (0, classnames.default)("spiffy-tw-fixed", "spiffy-tw-top-0", "spiffy-tw-left-0", "spiffy-tw-right-0", "spiffy-tw-transition-transform", "spiffy-tw-duration-300", "spiffy-tw-py-[8px]");
|
|
37
|
+
const containerXPaddingClasses = (0, classnames.default)("spiffy-tw-px-[16px]", "sm:spiffy-tw-px-[46px]");
|
|
38
|
+
(0, react.useEffect)(() => {
|
|
39
|
+
window.scrollTo({
|
|
40
|
+
top: 0,
|
|
41
|
+
behavior: "smooth"
|
|
42
|
+
});
|
|
43
|
+
}, [productList]);
|
|
44
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [
|
|
45
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(__envive_ai_react_toolkit_SearchResultsFilterModal.SearchResultsFilterModal, {
|
|
46
|
+
isOpen: isFilterOpen,
|
|
47
|
+
setIsOpen: setIsFilterOpen,
|
|
48
|
+
searchFilters,
|
|
49
|
+
productCount: productList.length,
|
|
50
|
+
onSelectFilterItem,
|
|
51
|
+
onClearAllFilters,
|
|
52
|
+
searchFilterSidebarVariant,
|
|
53
|
+
filterButtonText
|
|
54
|
+
}),
|
|
55
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(__envive_ai_react_toolkit_SearchResultsToolbar.SearchResultsToolbar, {
|
|
56
|
+
className: isSearchInputSticky ? stickyToolbarClasses : "spiffy-tw-py-[8px]",
|
|
57
|
+
toolbarRef,
|
|
58
|
+
searchInputVariant,
|
|
59
|
+
searchBoxPlaceholder,
|
|
60
|
+
searchText,
|
|
61
|
+
focusedIndex,
|
|
62
|
+
focusedOptionId,
|
|
63
|
+
autocompleteResults,
|
|
64
|
+
filterButtonText,
|
|
65
|
+
onKeyDown,
|
|
66
|
+
onSearchInputChange,
|
|
67
|
+
onSubmitSearch,
|
|
68
|
+
onAutocompleteSelect,
|
|
69
|
+
onSearchInputFocus,
|
|
70
|
+
onSearchInputBlur,
|
|
71
|
+
shouldShowAutocomplete,
|
|
72
|
+
setIsFilterOpen,
|
|
73
|
+
containerXPaddingClasses,
|
|
74
|
+
isVisible: finalIsVisible
|
|
75
|
+
}),
|
|
76
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(__envive_ai_react_toolkit_SearchResultsContent.SearchResultsContent, {
|
|
77
|
+
searchResultsState,
|
|
78
|
+
productList,
|
|
79
|
+
recommendedProducts,
|
|
80
|
+
productCardConfig,
|
|
81
|
+
merchantShortName,
|
|
82
|
+
searchFilterSidebarVariant,
|
|
83
|
+
noResultsFoundText,
|
|
84
|
+
productGridVariant,
|
|
85
|
+
containerXPaddingClasses,
|
|
86
|
+
selectedFilterOptions,
|
|
87
|
+
availableDynamicFilters,
|
|
88
|
+
onRemoveFilter,
|
|
89
|
+
onToggleDynamicFilter,
|
|
90
|
+
searchResultsRef,
|
|
91
|
+
toolbarHeight,
|
|
92
|
+
query
|
|
93
|
+
})
|
|
94
|
+
] });
|
|
95
|
+
};
|
|
96
|
+
const SearchResults = withSearchResults(SearchResultsComponent);
|
|
97
|
+
|
|
98
|
+
//#endregion
|
|
99
|
+
//#region src/SearchResults/SearchResultsWidget.tsx
|
|
100
|
+
const SearchResultsWidget = () => {
|
|
101
|
+
const setIsSearchResultsOpen = (0, jotai.useSetAtom)(__envive_ai_react_hooks_atoms_globalSearch.isSearchResultsOpenAtom);
|
|
102
|
+
const setSearchSystem = (0, jotai.useSetAtom)(__envive_ai_react_hooks_atoms_search.searchSystemAtom);
|
|
103
|
+
const newConfig = (0, __envive_ai_react_hooks_hooks_NewOrgConfig.useNewOrgConfig)();
|
|
104
|
+
(0, react.useEffect)(() => {
|
|
105
|
+
setSearchSystem(true);
|
|
106
|
+
return () => setSearchSystem(false);
|
|
107
|
+
}, [setSearchSystem]);
|
|
108
|
+
(0, react.useEffect)(() => {
|
|
109
|
+
setIsSearchResultsOpen(true);
|
|
110
|
+
return () => {
|
|
111
|
+
setIsSearchResultsOpen(false);
|
|
112
|
+
};
|
|
113
|
+
}, [setIsSearchResultsOpen]);
|
|
114
|
+
const widgetConfig = (0, react.useMemo)(() => {
|
|
115
|
+
if (newConfig && newConfig.frontendConfig?.widgetConfigs) return { ...(newConfig.frontendConfig?.widgetConfigs).find((widget) => widget.key === "searchResultsEntryPoint").config };
|
|
116
|
+
return null;
|
|
117
|
+
}, [newConfig]);
|
|
118
|
+
if (!widgetConfig) return null;
|
|
119
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SearchResults, { widgetConfig });
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
//#endregion
|
|
123
|
+
exports.SearchResultsWidget = SearchResultsWidget;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { useEffect, useMemo } from "react";
|
|
2
|
+
import { useSetAtom } from "jotai";
|
|
3
|
+
import { isSearchResultsOpenAtom } from "@envive-ai/react-hooks/atoms/globalSearch";
|
|
4
|
+
import { searchSystemAtom } from "@envive-ai/react-hooks/atoms/search";
|
|
5
|
+
import { useNewOrgConfig } from "@envive-ai/react-hooks/hooks/NewOrgConfig";
|
|
6
|
+
import classNames from "classnames";
|
|
7
|
+
import { SearchResultsContent } from "@envive-ai/react-toolkit/SearchResultsContent";
|
|
8
|
+
import { SearchResultsFilterModal } from "@envive-ai/react-toolkit/SearchResultsFilterModal";
|
|
9
|
+
import { SearchResultsToolbar } from "@envive-ai/react-toolkit/SearchResultsToolbar";
|
|
10
|
+
import { useStickyVisibility } from "@envive-ai/react-toolkit/util";
|
|
11
|
+
import { useSearch } from "@envive-ai/react-hooks/hooks/Search";
|
|
12
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
13
|
+
|
|
14
|
+
//#region src/SearchResults/withSearchResults.tsx
|
|
15
|
+
function withSearchResults(Component) {
|
|
16
|
+
return function SearchResultsHoc(props) {
|
|
17
|
+
const searchHookResult = useSearch();
|
|
18
|
+
return /* @__PURE__ */ jsx(Component, {
|
|
19
|
+
...props,
|
|
20
|
+
...searchHookResult,
|
|
21
|
+
productList: searchHookResult.searchData?.products || []
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/SearchResults/SearchResults.tsx
|
|
28
|
+
const SearchResultsComponent = ({ widgetConfig, productCardConfig, merchantShortName, productList, autocompleteResults, searchFilters, availableDynamicFilters, selectedFilterOptions, searchText, query, searchResultsState, isFilterOpen, shouldShowAutocomplete, focusedIndex, focusedOptionId, recommendedProducts, filterButtonText, onSearchInputChange, onSubmitSearch, onAutocompleteSelect, onKeyDown, onSearchInputFocus, onSearchInputBlur, onToggleDynamicFilter, onSelectFilterItem, onRemoveFilter, onClearAllFilters, setIsFilterOpen, searchResultsRef }) => {
|
|
29
|
+
const { searchInputVariant, searchFilterSidebarVariant, productGridVariant, searchBoxPlaceholder, noResultsFoundText, isSearchInputSticky = false } = widgetConfig;
|
|
30
|
+
const { toolbarRef: ref, isVisible, toolbarHeight: height } = useStickyVisibility();
|
|
31
|
+
const toolbarRef = isSearchInputSticky ? ref : null;
|
|
32
|
+
const finalIsVisible = isSearchInputSticky ? isVisible : true;
|
|
33
|
+
const toolbarHeight = isSearchInputSticky ? height : 0;
|
|
34
|
+
const stickyToolbarClasses = classNames("spiffy-tw-fixed", "spiffy-tw-top-0", "spiffy-tw-left-0", "spiffy-tw-right-0", "spiffy-tw-transition-transform", "spiffy-tw-duration-300", "spiffy-tw-py-[8px]");
|
|
35
|
+
const containerXPaddingClasses = classNames("spiffy-tw-px-[16px]", "sm:spiffy-tw-px-[46px]");
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
window.scrollTo({
|
|
38
|
+
top: 0,
|
|
39
|
+
behavior: "smooth"
|
|
40
|
+
});
|
|
41
|
+
}, [productList]);
|
|
42
|
+
return /* @__PURE__ */ jsxs("div", { children: [
|
|
43
|
+
/* @__PURE__ */ jsx(SearchResultsFilterModal, {
|
|
44
|
+
isOpen: isFilterOpen,
|
|
45
|
+
setIsOpen: setIsFilterOpen,
|
|
46
|
+
searchFilters,
|
|
47
|
+
productCount: productList.length,
|
|
48
|
+
onSelectFilterItem,
|
|
49
|
+
onClearAllFilters,
|
|
50
|
+
searchFilterSidebarVariant,
|
|
51
|
+
filterButtonText
|
|
52
|
+
}),
|
|
53
|
+
/* @__PURE__ */ jsx(SearchResultsToolbar, {
|
|
54
|
+
className: isSearchInputSticky ? stickyToolbarClasses : "spiffy-tw-py-[8px]",
|
|
55
|
+
toolbarRef,
|
|
56
|
+
searchInputVariant,
|
|
57
|
+
searchBoxPlaceholder,
|
|
58
|
+
searchText,
|
|
59
|
+
focusedIndex,
|
|
60
|
+
focusedOptionId,
|
|
61
|
+
autocompleteResults,
|
|
62
|
+
filterButtonText,
|
|
63
|
+
onKeyDown,
|
|
64
|
+
onSearchInputChange,
|
|
65
|
+
onSubmitSearch,
|
|
66
|
+
onAutocompleteSelect,
|
|
67
|
+
onSearchInputFocus,
|
|
68
|
+
onSearchInputBlur,
|
|
69
|
+
shouldShowAutocomplete,
|
|
70
|
+
setIsFilterOpen,
|
|
71
|
+
containerXPaddingClasses,
|
|
72
|
+
isVisible: finalIsVisible
|
|
73
|
+
}),
|
|
74
|
+
/* @__PURE__ */ jsx(SearchResultsContent, {
|
|
75
|
+
searchResultsState,
|
|
76
|
+
productList,
|
|
77
|
+
recommendedProducts,
|
|
78
|
+
productCardConfig,
|
|
79
|
+
merchantShortName,
|
|
80
|
+
searchFilterSidebarVariant,
|
|
81
|
+
noResultsFoundText,
|
|
82
|
+
productGridVariant,
|
|
83
|
+
containerXPaddingClasses,
|
|
84
|
+
selectedFilterOptions,
|
|
85
|
+
availableDynamicFilters,
|
|
86
|
+
onRemoveFilter,
|
|
87
|
+
onToggleDynamicFilter,
|
|
88
|
+
searchResultsRef,
|
|
89
|
+
toolbarHeight,
|
|
90
|
+
query
|
|
91
|
+
})
|
|
92
|
+
] });
|
|
93
|
+
};
|
|
94
|
+
const SearchResults = withSearchResults(SearchResultsComponent);
|
|
95
|
+
|
|
96
|
+
//#endregion
|
|
97
|
+
//#region src/SearchResults/SearchResultsWidget.tsx
|
|
98
|
+
const SearchResultsWidget = () => {
|
|
99
|
+
const setIsSearchResultsOpen = useSetAtom(isSearchResultsOpenAtom);
|
|
100
|
+
const setSearchSystem = useSetAtom(searchSystemAtom);
|
|
101
|
+
const newConfig = useNewOrgConfig();
|
|
102
|
+
useEffect(() => {
|
|
103
|
+
setSearchSystem(true);
|
|
104
|
+
return () => setSearchSystem(false);
|
|
105
|
+
}, [setSearchSystem]);
|
|
106
|
+
useEffect(() => {
|
|
107
|
+
setIsSearchResultsOpen(true);
|
|
108
|
+
return () => {
|
|
109
|
+
setIsSearchResultsOpen(false);
|
|
110
|
+
};
|
|
111
|
+
}, [setIsSearchResultsOpen]);
|
|
112
|
+
const widgetConfig = useMemo(() => {
|
|
113
|
+
if (newConfig && newConfig.frontendConfig?.widgetConfigs) return { ...(newConfig.frontendConfig?.widgetConfigs).find((widget) => widget.key === "searchResultsEntryPoint").config };
|
|
114
|
+
return null;
|
|
115
|
+
}, [newConfig]);
|
|
116
|
+
if (!widgetConfig) return null;
|
|
117
|
+
return /* @__PURE__ */ jsx(SearchResults, { widgetConfig });
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
//#endregion
|
|
121
|
+
export { SearchResultsWidget };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as react_jsx_runtime1 from "react/jsx-runtime";
|
|
2
|
+
import { SearchEntryPointWidgetConfig, SearchInputVariant } from "@envive-ai/react-hooks/contexts/types";
|
|
3
|
+
import React$1 from "react";
|
|
4
|
+
|
|
5
|
+
//#region src/SearchZeroState/types.d.ts
|
|
6
|
+
interface SearchZeroStateProps {
|
|
7
|
+
widgetConfig: SearchEntryPointWidgetConfig;
|
|
8
|
+
initialIsOpen?: boolean;
|
|
9
|
+
entryPointRef?: React.Ref<HTMLButtonElement>;
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/SearchZeroState/SearchZeroState.d.ts
|
|
13
|
+
declare const SearchZeroState: React$1.FC<SearchZeroStateProps>;
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/SearchZeroState/SearchZeroStateWidget.d.ts
|
|
16
|
+
type SearchZeroStateWidgetProps = {
|
|
17
|
+
initialIsOpen: boolean;
|
|
18
|
+
widgetConfigId?: string;
|
|
19
|
+
entryPointRef: React.Ref<HTMLButtonElement>;
|
|
20
|
+
};
|
|
21
|
+
declare const SearchZeroStateWidget: ({
|
|
22
|
+
initialIsOpen,
|
|
23
|
+
widgetConfigId,
|
|
24
|
+
entryPointRef
|
|
25
|
+
}: SearchZeroStateWidgetProps) => react_jsx_runtime1.JSX.Element;
|
|
26
|
+
//#endregion
|
|
27
|
+
export { type SearchEntryPointWidgetConfig, type SearchInputVariant, SearchZeroState, SearchZeroStateProps, SearchZeroStateWidget };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React$1 from "react";
|
|
2
|
+
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
3
|
+
import { SearchEntryPointWidgetConfig, SearchInputVariant } from "@envive-ai/react-hooks/contexts/types";
|
|
4
|
+
|
|
5
|
+
//#region src/SearchZeroState/types.d.ts
|
|
6
|
+
interface SearchZeroStateProps {
|
|
7
|
+
widgetConfig: SearchEntryPointWidgetConfig;
|
|
8
|
+
initialIsOpen?: boolean;
|
|
9
|
+
entryPointRef?: React.Ref<HTMLButtonElement>;
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/SearchZeroState/SearchZeroState.d.ts
|
|
13
|
+
declare const SearchZeroState: React$1.FC<SearchZeroStateProps>;
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/SearchZeroState/SearchZeroStateWidget.d.ts
|
|
16
|
+
type SearchZeroStateWidgetProps = {
|
|
17
|
+
initialIsOpen: boolean;
|
|
18
|
+
widgetConfigId?: string;
|
|
19
|
+
entryPointRef: React.Ref<HTMLButtonElement>;
|
|
20
|
+
};
|
|
21
|
+
declare const SearchZeroStateWidget: ({
|
|
22
|
+
initialIsOpen,
|
|
23
|
+
widgetConfigId,
|
|
24
|
+
entryPointRef
|
|
25
|
+
}: SearchZeroStateWidgetProps) => react_jsx_runtime0.JSX.Element;
|
|
26
|
+
//#endregion
|
|
27
|
+
export { type SearchEntryPointWidgetConfig, type SearchInputVariant, SearchZeroState, SearchZeroStateProps, SearchZeroStateWidget };
|