@graphcommerce/magento-search 9.0.0-canary.116 → 9.0.0-canary.117
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 +6 -0
- package/components/ProductFiltersPro/ProductFiltersProSearchHeader.tsx +12 -2
- package/components/ProductFiltersPro/{ProductFiltersProSearchField.tsx → SearchField.tsx} +7 -5
- package/components/SearchFab/SearchFab.tsx +24 -0
- package/hooks/useProductList.ts +8 -6
- package/index.ts +3 -1
- package/package.json +13 -11
- package/tsconfig.json +1 -1
- package/utils/productListApplySearchDefaults.ts +6 -2
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## 9.0.0-canary.117
|
4
|
+
|
5
|
+
### Minor Changes
|
6
|
+
|
7
|
+
- [#2361](https://github.com/graphcommerce-org/graphcommerce/pull/2361) [`9c3149c`](https://github.com/graphcommerce-org/graphcommerce/commit/9c3149cb7550c6bf7de4b8e3bcaabe2f6a70d5c7) - Search overlay package this is compatible with Magento's default search as well as any other implementation like Algolia and Adobe Sensei. ([@paales](https://github.com/paales))
|
8
|
+
|
3
9
|
## 9.0.0-canary.116
|
4
10
|
|
5
11
|
### Patch Changes
|
@@ -12,8 +12,7 @@ export type ProductFiltersProSearchHeaderProps = {
|
|
12
12
|
children: React.ReactNode
|
13
13
|
}
|
14
14
|
|
15
|
-
export function
|
16
|
-
const { params, children } = props
|
15
|
+
export function useSearchResultRemaining(params: ProductListParams) {
|
17
16
|
const { form } = useProductFiltersPro()
|
18
17
|
const resultSearch = params.search ?? ''
|
19
18
|
const targetSearch = useWatch({ control: form.control, name: 'search' }) ?? ''
|
@@ -22,6 +21,17 @@ export function ProductFiltersProSearchTerm(props: ProductFiltersProSearchHeader
|
|
22
21
|
? targetSearch.slice(resultSearch.length)
|
23
22
|
: ''
|
24
23
|
|
24
|
+
return {
|
25
|
+
resultSearch,
|
26
|
+
targetSearch,
|
27
|
+
remaining,
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
31
|
+
export function ProductFiltersProSearchTerm(props: ProductFiltersProSearchHeaderProps) {
|
32
|
+
const { params, children } = props
|
33
|
+
|
34
|
+
const { remaining, resultSearch, targetSearch } = useSearchResultRemaining(params)
|
25
35
|
if (!resultSearch && !targetSearch) return children
|
26
36
|
|
27
37
|
const search = (
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { iconSearch, IconSvg, showPageLoadIndicator } from '@graphcommerce/next-ui'
|
2
2
|
import type { FabProps } from '@mui/material'
|
3
3
|
import { Fab } from '@mui/material'
|
4
4
|
import dynamic from 'next/dynamic'
|
@@ -6,16 +6,18 @@ import { useMemo, useState } from 'react'
|
|
6
6
|
import type { ProductFiltersProSearchInputProps } from './ProductFiltersProSearchInput'
|
7
7
|
import { useSearchPageAndParam } from './useSearchPageAndParam'
|
8
8
|
|
9
|
-
export type
|
9
|
+
export type SearchFieldProps = ProductFiltersProSearchInputProps & {
|
10
10
|
fab?: FabProps
|
11
|
+
visible?: boolean
|
12
|
+
searchField?: Record<string, unknown>
|
11
13
|
}
|
12
14
|
|
13
15
|
const ProductFiltersProSearchInputLazy = dynamic(
|
14
16
|
async () => (await import('./ProductFiltersProSearchInput')).ProductFiltersProSearchOutlinedInput,
|
15
17
|
)
|
16
18
|
|
17
|
-
export function
|
18
|
-
const { fab, formControl } = props
|
19
|
+
export function SearchField(props: SearchFieldProps) {
|
20
|
+
const { fab, formControl, visible: incomingVisible } = props
|
19
21
|
|
20
22
|
const [searchPage] = useSearchPageAndParam()
|
21
23
|
const [expanded, setExpanded] = useState(searchPage)
|
@@ -23,7 +25,7 @@ export function ProductFiltersProSearchField(props: ProductFiltersProSearchField
|
|
23
25
|
if (!searchPage) setExpanded(searchPage)
|
24
26
|
}, [searchPage])
|
25
27
|
|
26
|
-
const visible = expanded || searchPage
|
28
|
+
const visible = incomingVisible || expanded || searchPage
|
27
29
|
|
28
30
|
return (
|
29
31
|
<>
|
@@ -0,0 +1,24 @@
|
|
1
|
+
import type { FabProps } from '@graphcommerce/next-ui'
|
2
|
+
import { Fab, iconSearch } from '@graphcommerce/next-ui'
|
3
|
+
import { useRouter } from 'next/router'
|
4
|
+
import type { SetOptional } from 'type-fest'
|
5
|
+
|
6
|
+
export type SearchFabProps = SetOptional<FabProps, 'icon'>
|
7
|
+
|
8
|
+
export function SearchFab(props: SearchFabProps) {
|
9
|
+
const { sx, ...fabProps } = props
|
10
|
+
const router = useRouter()
|
11
|
+
return (
|
12
|
+
<Fab
|
13
|
+
color='inherit'
|
14
|
+
size='medium'
|
15
|
+
sx={sx}
|
16
|
+
icon={iconSearch}
|
17
|
+
onClick={async () => {
|
18
|
+
await router.push('/search')
|
19
|
+
globalThis.document.body.querySelector<HTMLInputElement>('[name="search"]')?.focus()
|
20
|
+
}}
|
21
|
+
{...fabProps}
|
22
|
+
/>
|
23
|
+
)
|
24
|
+
}
|
package/hooks/useProductList.ts
CHANGED
@@ -6,9 +6,9 @@ import type {
|
|
6
6
|
ProductListQuery,
|
7
7
|
} from '@graphcommerce/magento-product'
|
8
8
|
import {
|
9
|
+
prefetchProductList,
|
9
10
|
ProductFiltersDocument,
|
10
11
|
ProductListDocument,
|
11
|
-
prefetchProductList,
|
12
12
|
toProductListParams,
|
13
13
|
useRouterFilterParams,
|
14
14
|
} from '@graphcommerce/magento-product'
|
@@ -26,14 +26,16 @@ import {
|
|
26
26
|
* - Creates a prefetch function to preload the product list
|
27
27
|
*/
|
28
28
|
export function useProductList<
|
29
|
-
T extends ProductListQuery &
|
30
|
-
ProductFiltersQuery & {
|
31
|
-
params?: ProductListParams
|
32
|
-
},
|
29
|
+
T extends ProductListQuery & ProductFiltersQuery & { params?: ProductListParams },
|
33
30
|
>(props: T) {
|
34
31
|
const { params, shallow } = useRouterFilterParams(props)
|
35
32
|
const variables = useProductListApplySearchDefaults(params)
|
36
|
-
const result = usePrivateQuery(
|
33
|
+
const result = usePrivateQuery(
|
34
|
+
ProductListDocument,
|
35
|
+
{ variables: { ...variables }, skip: !shallow },
|
36
|
+
props,
|
37
|
+
)
|
38
|
+
|
37
39
|
const filters = usePrivateQuery(
|
38
40
|
ProductFiltersDocument,
|
39
41
|
{ variables: searchDefaultsToProductListFilters(variables), skip: !shallow },
|
package/index.ts
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
export * from './CategorySearch.gql'
|
2
2
|
export * from './components/CategorySearchResult/CategorySearchResult'
|
3
3
|
export * from './components/CategorySearchResult/CategorySearchResults'
|
4
|
+
export * from './components/CategorySearchResult/CategorySearchResult.gql'
|
4
5
|
export * from './components/NoSearchResults/NoSearchResults'
|
5
6
|
export * from './components/SearchButton/SearchButton'
|
6
7
|
export * from './components/SearchContext/SearchContext'
|
7
8
|
export * from './components/SearchDivider/SearchDivider'
|
8
9
|
export * from './components/SearchForm/SearchForm'
|
9
10
|
export * from './components/SearchLink/SearchLink'
|
11
|
+
export * from './components/SearchFab/SearchFab'
|
10
12
|
export * from './hooks/useProductList'
|
11
13
|
export * from './components/ProductFiltersPro/ProductFiltersProCategorySectionSearch'
|
12
14
|
export * from './components/ProductFiltersPro/ProductFiltersProSearchHeader'
|
@@ -23,4 +25,4 @@ export {
|
|
23
25
|
|
24
26
|
export * from '@graphcommerce/magento-product/components/ProductFiltersPro'
|
25
27
|
export * from './utils/productListApplySearchDefaults'
|
26
|
-
export * from './components/ProductFiltersPro/
|
28
|
+
export * from './components/ProductFiltersPro/SearchField'
|
package/package.json
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
"name": "@graphcommerce/magento-search",
|
3
3
|
"homepage": "https://www.graphcommerce.org/",
|
4
4
|
"repository": "github:graphcommerce-org/graphcommerce",
|
5
|
-
"version": "9.0.0-canary.
|
5
|
+
"version": "9.0.0-canary.117",
|
6
6
|
"sideEffects": false,
|
7
7
|
"prettier": "@graphcommerce/prettier-config-pwa",
|
8
8
|
"eslintConfig": {
|
@@ -12,20 +12,22 @@
|
|
12
12
|
}
|
13
13
|
},
|
14
14
|
"peerDependencies": {
|
15
|
-
"@graphcommerce/ecommerce-ui": "^9.0.0-canary.
|
16
|
-
"@graphcommerce/eslint-config-pwa": "^9.0.0-canary.
|
17
|
-
"@graphcommerce/
|
18
|
-
"@graphcommerce/
|
19
|
-
"@graphcommerce/
|
20
|
-
"@graphcommerce/magento-
|
21
|
-
"@graphcommerce/
|
22
|
-
"@graphcommerce/
|
23
|
-
"@graphcommerce/
|
24
|
-
"@graphcommerce/
|
15
|
+
"@graphcommerce/ecommerce-ui": "^9.0.0-canary.117",
|
16
|
+
"@graphcommerce/eslint-config-pwa": "^9.0.0-canary.117",
|
17
|
+
"@graphcommerce/framer-utils": "^9.0.0-canary.117",
|
18
|
+
"@graphcommerce/graphql": "^9.0.0-canary.117",
|
19
|
+
"@graphcommerce/image": "^9.0.0-canary.117",
|
20
|
+
"@graphcommerce/magento-product": "^9.0.0-canary.117",
|
21
|
+
"@graphcommerce/magento-store": "^9.0.0-canary.117",
|
22
|
+
"@graphcommerce/next-ui": "^9.0.0-canary.117",
|
23
|
+
"@graphcommerce/prettier-config-pwa": "^9.0.0-canary.117",
|
24
|
+
"@graphcommerce/react-hook-form": "^9.0.0-canary.117",
|
25
|
+
"@graphcommerce/typescript-config-pwa": "^9.0.0-canary.117",
|
25
26
|
"@lingui/core": "^4.2.1",
|
26
27
|
"@lingui/macro": "^4.2.1",
|
27
28
|
"@lingui/react": "^4.2.1",
|
28
29
|
"@mui/material": "^5.10.16",
|
30
|
+
"framer-motion": "*",
|
29
31
|
"next": "*",
|
30
32
|
"react": "^18.2.0",
|
31
33
|
"react-dom": "^18.2.0"
|
package/tsconfig.json
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
import { cloneDeep, useQuery } from '@graphcommerce/graphql'
|
2
|
-
import type {
|
2
|
+
import type {
|
3
|
+
ProductFiltersQueryVariables,
|
4
|
+
ProductListParams,
|
5
|
+
ProductListQueryVariables,
|
6
|
+
} from '@graphcommerce/magento-product'
|
3
7
|
import type { StoreConfigQuery } from '@graphcommerce/magento-store'
|
4
8
|
import { StoreConfigDocument } from '@graphcommerce/magento-store'
|
5
9
|
|
@@ -43,7 +47,7 @@ export function productListApplySearchDefaults(
|
|
43
47
|
|
44
48
|
export function searchDefaultsToProductListFilters(
|
45
49
|
variables: ProductListQueryVariables | undefined,
|
46
|
-
):
|
50
|
+
): ProductFiltersQueryVariables {
|
47
51
|
return {
|
48
52
|
...variables,
|
49
53
|
filters: {},
|