@ecomid/modules 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +334 -2
- package/dist/chunks/cs-Dqb_rREp.js +97 -0
- package/dist/chunks/da-WYTDtjgg.js +97 -0
- package/dist/chunks/de-D6tbcZ82.js +97 -0
- package/dist/chunks/en-BJsf6vvY.js +97 -0
- package/dist/chunks/es-UCU6bjwJ.js +97 -0
- package/dist/chunks/fi-BZ1TBPKK.js +97 -0
- package/dist/chunks/fr-Bh4svI2n.js +97 -0
- package/dist/chunks/it-S3zZ2XyN.js +97 -0
- package/dist/chunks/nl-BskWxJtL.js +97 -0
- package/dist/chunks/no-fPEJ7LXi.js +97 -0
- package/dist/chunks/pl-DgFibWpI.js +97 -0
- package/dist/chunks/pt-CZ1aBAcy.js +97 -0
- package/dist/chunks/resultsStore-DuG3wQlt.js +1729 -0
- package/dist/chunks/searchPage-CwY8JW57.d.ts +107 -0
- package/dist/chunks/sk-BVkd-dpe.js +97 -0
- package/dist/chunks/sv-CoiCABF8.js +97 -0
- package/dist/react.d.ts +55 -0
- package/dist/react.js +4532 -0
- package/dist/search/styles.css +2 -0
- package/dist/search.d.ts +227 -0
- package/dist/search.js +39 -0
- package/package.json +56 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 eComID AB
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,335 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @ecomid/modules
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Components and a framework-free search client for ecomid.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install @ecomid/modules
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
The `react` entry point requires `react` and `react-dom` 18 or newer. The `search` entry point works without React.
|
|
12
|
+
|
|
13
|
+
The eComID loader script must be on the page for the React components too. Personalize and sign-in, signed-in search and usage events all depend on it; without it the components render and search as a guest, but those features do nothing.
|
|
14
|
+
|
|
15
|
+
## Entry points
|
|
16
|
+
|
|
17
|
+
| Import | Contents |
|
|
18
|
+
|--------|----------|
|
|
19
|
+
| `@ecomid/modules/react` | `EcomidProvider`, `SearchModal`, `SearchResults` and their types |
|
|
20
|
+
| `@ecomid/modules/search` | Framework-free store and API functions |
|
|
21
|
+
| `@ecomid/modules/search/styles.css` | Search styles |
|
|
22
|
+
|
|
23
|
+
## Provider
|
|
24
|
+
|
|
25
|
+
```tsx
|
|
26
|
+
import { EcomidProvider } from '@ecomid/modules/react'
|
|
27
|
+
|
|
28
|
+
<EcomidProvider clientId="YOUR_CLIENT_ID" locale="sv-se" environment="production">
|
|
29
|
+
<App />
|
|
30
|
+
</EcomidProvider>
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
| Prop | Type | Description |
|
|
34
|
+
|------|------|-------------|
|
|
35
|
+
| `clientId` | `string` | Your ecomid client id |
|
|
36
|
+
| `locale` | `string` | Language and market, e.g. `sv-se`. The market is required |
|
|
37
|
+
| `environment` | `'production' \| 'staging' \| 'sandbox'` | Backend used for requests and error reports. Defaults to `'production'` |
|
|
38
|
+
|
|
39
|
+
Components also work without a provider when given the same values as props.
|
|
40
|
+
|
|
41
|
+
## Search
|
|
42
|
+
|
|
43
|
+
Import the stylesheet once, for example in `pages/_app.tsx`:
|
|
44
|
+
|
|
45
|
+
```tsx
|
|
46
|
+
import '@ecomid/modules/search/styles.css'
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
```tsx
|
|
50
|
+
import { SearchModal } from '@ecomid/modules/react'
|
|
51
|
+
import { useState } from 'react'
|
|
52
|
+
|
|
53
|
+
export function SearchButton() {
|
|
54
|
+
const [open, setOpen] = useState(false)
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<>
|
|
58
|
+
<button type="button" onClick={() => setOpen(true)}>
|
|
59
|
+
Search
|
|
60
|
+
</button>
|
|
61
|
+
<SearchModal
|
|
62
|
+
open={open}
|
|
63
|
+
onClose={() => setOpen(false)}
|
|
64
|
+
resultsUrl="/search"
|
|
65
|
+
/>
|
|
66
|
+
</>
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
| Prop | Type | Description |
|
|
72
|
+
|------|------|-------------|
|
|
73
|
+
| `open` | `boolean` | Whether the modal is open |
|
|
74
|
+
| `onClose` | `() => void` | Called when the modal asks to close |
|
|
75
|
+
| `clientId` | `string` | Overrides the provider |
|
|
76
|
+
| `locale` | `string` | Overrides the provider |
|
|
77
|
+
| `environment` | `'production' \| 'staging' \| 'sandbox'` | Overrides the provider |
|
|
78
|
+
| `onSubmit` | `(query: string) => void` | Called on submit. Takes precedence over `resultsUrl` |
|
|
79
|
+
| `resultsUrl` | `string` | Path or URL navigated to on submit, with the submitted text added as the `request` param (see [Results page](#results-page)). Params already in it are kept |
|
|
80
|
+
| `onProductClick` | `(product, event: MouseEvent<HTMLElement>) => void` | Called when a product is clicked |
|
|
81
|
+
| `renderProduct` | `(product, { position, menuButton }) => ReactNode` | Renders your own product card in place of the default one, in the recommended carousel and in the instant and result grids. `position` is the zero-based index of the product in the list. `menuButton` is our product menu button, ready to place anywhere in your card. Returning `null` or `undefined` uses the default card. Clicks on links inside it track, call `onProductClick` and close the modal after your own handlers have run |
|
|
82
|
+
| `onOpen` | `() => void` | Called when the modal opens |
|
|
83
|
+
|
|
84
|
+
Errors thrown by your callbacks are reported and do not escape. Invalid or missing `clientId`, `locale` or market are reported and nothing is rendered.
|
|
85
|
+
|
|
86
|
+
### Custom product card
|
|
87
|
+
|
|
88
|
+
```tsx
|
|
89
|
+
<SearchModal
|
|
90
|
+
open={open}
|
|
91
|
+
onClose={() => setOpen(false)}
|
|
92
|
+
renderProduct={(product) => <MerchantProductCard product={product} />}
|
|
93
|
+
/>
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
`menuButton` is an icon button that opens a menu with "More like this", which sends a new search for products similar to the one in the card. It works inside a link: clicking it doesn't follow the link or call `onProductClick`. It has no position of its own, so place it where you want it, for example over the product image:
|
|
97
|
+
|
|
98
|
+
```tsx
|
|
99
|
+
<SearchModal
|
|
100
|
+
open={open}
|
|
101
|
+
onClose={() => setOpen(false)}
|
|
102
|
+
renderProduct={(product, { menuButton }) => (
|
|
103
|
+
<MerchantProductCard product={product}>{menuButton}</MerchantProductCard>
|
|
104
|
+
)}
|
|
105
|
+
/>
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
`renderProduct` may be called more than once for the same product, for example when results refresh, so don't attach listeners that are never removed. If the card throws, the default card is rendered for that product.
|
|
109
|
+
|
|
110
|
+
## Results page
|
|
111
|
+
|
|
112
|
+
`SearchResults` renders the results for a page you own. Your route decides the URL; the component never reads `location`. It renders on the server when given `initialResults`.
|
|
113
|
+
|
|
114
|
+
A results page is described by URL params, the same ones the shopper sees: a search page carries `term`, `exclude_term`, `filter=key:value`, `exclude=key:value` (keys: `category`, `gender`, `size`, `color`, `material`, `price_min`, `price_max`, `on_sale`) and `sort` (omitted for relevance), and a page composed from a request carries `request=<text>`. The component reports each new page through `onPageChange` and shows the page you pass in `page`, so your router owns the URL and the browser's back button works.
|
|
115
|
+
|
|
116
|
+
```tsx
|
|
117
|
+
import { useRouter } from 'next/router'
|
|
118
|
+
import { SearchResults } from '@ecomid/modules/react'
|
|
119
|
+
|
|
120
|
+
export default function Search() {
|
|
121
|
+
const router = useRouter()
|
|
122
|
+
return (
|
|
123
|
+
<SearchResults
|
|
124
|
+
page={router.asPath.split('?')[1]}
|
|
125
|
+
onPageChange={(next) =>
|
|
126
|
+
router.replace({ query: next.toString() }, undefined, { shallow: true })
|
|
127
|
+
}
|
|
128
|
+
/>
|
|
129
|
+
)
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
To render on the server, fetch the results in `getServerSideProps` and pass them as `initialResults`:
|
|
134
|
+
|
|
135
|
+
```tsx
|
|
136
|
+
import { useRouter } from 'next/router'
|
|
137
|
+
import { SearchResults } from '@ecomid/modules/react'
|
|
138
|
+
import { fetchSearchResults } from '@ecomid/modules/search'
|
|
139
|
+
|
|
140
|
+
export const getServerSideProps = async ({ query }) => {
|
|
141
|
+
const params = new URLSearchParams()
|
|
142
|
+
for (const [key, value] of Object.entries(query)) {
|
|
143
|
+
for (const item of [value].flat()) params.append(key, String(item))
|
|
144
|
+
}
|
|
145
|
+
let initialResults = null
|
|
146
|
+
try {
|
|
147
|
+
initialResults = await fetchSearchResults(
|
|
148
|
+
'YOUR_CLIENT_ID',
|
|
149
|
+
{ page: params, locale: 'sv-se', limit: 24 },
|
|
150
|
+
AbortSignal.timeout(3000),
|
|
151
|
+
)
|
|
152
|
+
} catch {
|
|
153
|
+
initialResults = null
|
|
154
|
+
}
|
|
155
|
+
return { props: { params: params.toString(), initialResults } }
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export default function Search({ params, initialResults }) {
|
|
159
|
+
const router = useRouter()
|
|
160
|
+
return (
|
|
161
|
+
<SearchResults
|
|
162
|
+
locale="sv-se"
|
|
163
|
+
limit={24}
|
|
164
|
+
page={params}
|
|
165
|
+
onPageChange={(next) =>
|
|
166
|
+
router.replace({ query: next.toString() }, undefined, { shallow: true })
|
|
167
|
+
}
|
|
168
|
+
initialResults={initialResults}
|
|
169
|
+
/>
|
|
170
|
+
)
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
`readSearchPage(params)` and `searchPageParams(page)` from `@ecomid/modules/search` convert between URL params and a page (`{ kind: 'search', state }` or `{ kind: 'compose', text }`), and `withSearchPageParams(search, page)` writes a page into a query string and keeps the other params. Unknown filter keys and sorts are dropped.
|
|
175
|
+
|
|
176
|
+
`SearchResultsData` must come from `fetchSearchResults`, which stamps `query`, `lang`, `market`, `limit` and the requested `page`. The server fetch and the component must use the same `locale`, `limit` and page (or `query` when there is no page); results stamped with another value are ignored and the client fetches instead. With a `page` the fetch sends the page's state, or its request text, as the first turn; the fetch rejects when the turn is not a search. A stable `initialResults` identity is preferred but not required.
|
|
177
|
+
|
|
178
|
+
| Prop | Type | Description |
|
|
179
|
+
|------|------|-------------|
|
|
180
|
+
| `query` | `string` | The query to show results for when there is no `page`. Changing it fetches the new results on the client |
|
|
181
|
+
| `page` | `URLSearchParams \| string` | The page to show, as the params above (other params are ignored). With a page, the first turn sends its state, or its request text, and `query` is ignored. When it changes to a page other than the one shown, the new page is fetched; set it from your router so back and forward work |
|
|
182
|
+
| `onPageChange` | `(params: URLSearchParams) => void` | Called with the params of each new page the shopper reaches: a new search, a refine, a filter or sort change, a removed term. Not called for a `page` you passed in |
|
|
183
|
+
| `initialResults` | `SearchResultsData \| null` | Results fetched on the server. Only used when `results.query`, `results.lang`, `results.market`, `results.limit` and `results.page` match the trimmed `query` (or the `page`'s terms), the component's locale, `limit` and `page`, in which case the client request is skipped. Results that don't match are ignored, the client fetches instead, and a mismatch in the results that seed a new instance is reported once per instance |
|
|
184
|
+
| `limit` | `number` | Products per page. Defaults to 24 on the client. Use the same value as the server fetch |
|
|
185
|
+
| `headingLevel` | `1 \| 2 \| 3 \| 4 \| 5` | Heading level of the results title. Section headings are one level below it; without a title they use this level. Defaults to `1` |
|
|
186
|
+
| `clientId` | `string` | Overrides the provider |
|
|
187
|
+
| `locale` | `string` | Overrides the provider |
|
|
188
|
+
| `environment` | `'production' \| 'staging' \| 'sandbox'` | Overrides the provider |
|
|
189
|
+
| `renderProduct` | `(product, { position, menuButton }) => ReactNode` | Same as on `SearchModal`. `position` counts across all sections |
|
|
190
|
+
| `onProductClick` | `(product, event: MouseEvent<HTMLElement>) => void` | Called when a product is clicked |
|
|
191
|
+
|
|
192
|
+
The results carry the page header and optional sections, all of which can be absent:
|
|
193
|
+
|
|
194
|
+
| Field | Type | Rendered as |
|
|
195
|
+
|-------|------|-------------|
|
|
196
|
+
| `title` | `string` | Heading above the products (`<h1>` by default, see `headingLevel`) |
|
|
197
|
+
| `description` | `string` | `<p>` below the title |
|
|
198
|
+
| `sections` | `{ title?: string; products: SearchProduct[] }[]` | One grid per section, with a heading for its title. When empty or absent, `products` is rendered as a single grid |
|
|
199
|
+
| `total` | `number` | Number of matching products, shown as the count |
|
|
200
|
+
| `nextPageToken` | `string` | Present while there are more products. The next page loads when the end of the grid scrolls into view |
|
|
201
|
+
| `facets` | `{ key: string; values: { value: string; label: string; available: boolean }[] }[]` | The filter values to offer. A group (`category`, `gender`, `size`, `color`, `material`) is shown only when it has values; price and on sale are always offered. Values that are not `available` are disabled |
|
|
202
|
+
| `appliedFilters` | `{ key: string; values: string[]; labels: string[] }[]` | Labels of the applied filters |
|
|
203
|
+
|
|
204
|
+
Above the products the results show a filters button that opens a drawer (a bottom sheet below 768px) with every group, a pill for each group that opens its values (a popover on screens 768px and wider, a bottom sheet below), the count and a sort menu. The selection lives in the component and the products are fetched again when it changes. Products with more than one color show "+ N colors" below the price, from `variantCount`.
|
|
205
|
+
|
|
206
|
+
Without `initialResults` the component shows placeholders and fetches on the client. When `query` changes, the previous results stay visible, dimmed and marked `aria-busy`, until the new ones arrive. An empty `query` renders no results. Failed requests are reported and an error message is rendered.
|
|
207
|
+
|
|
208
|
+
## Tracking
|
|
209
|
+
|
|
210
|
+
Usage events are posted to the top window and forwarded by the ecomid loader script, which must be on the page. Without it no events are sent.
|
|
211
|
+
|
|
212
|
+
## Styling
|
|
213
|
+
|
|
214
|
+
Class names (`ecomid-search-*`) are internal and may change, so don't target them. Customise the components with these custom properties, set on `:root` or any ancestor of the modal and results:
|
|
215
|
+
|
|
216
|
+
| Property | Default | Affects |
|
|
217
|
+
|----------|---------|---------|
|
|
218
|
+
| `--ecomid-search-font-family` | `inherit` | Font of the modal and the results |
|
|
219
|
+
| `--ecomid-search-font-weight` | `400` | Regular text |
|
|
220
|
+
| `--ecomid-search-font-weight-bold` | `600` | Headings, pills and badge |
|
|
221
|
+
| `--ecomid-search-text-color` | `#222222` | Primary text and icons |
|
|
222
|
+
| `--ecomid-search-muted-color` | `#767676` | Suggestions, no-results text and the disabled submit icon |
|
|
223
|
+
| `--ecomid-search-placeholder-color` | `#b1b3b5` | Input placeholder |
|
|
224
|
+
| `--ecomid-search-surface` | `#fff` | Modal background |
|
|
225
|
+
| `--ecomid-search-backdrop-color` | `rgba(0, 0, 0, 0.01)` | Backdrop behind the modal |
|
|
226
|
+
| `--ecomid-search-border-color` | `#f0f2f4` (`#f7f8fa` on screens 768px and wider) | Line under the modal title and, on screens 768px and wider, under the input while typing |
|
|
227
|
+
| `--ecomid-search-radius` | `16px` | Modal corner radius on screens 768px and wider |
|
|
228
|
+
| `--ecomid-search-width` | `clamp(1000px, 64vw, 1200px)` | Modal width on screens 768px and wider, capped to the viewport minus 48px |
|
|
229
|
+
| `--ecomid-search-z-index` | `100000` | Stacking order of the modal |
|
|
230
|
+
| `--ecomid-outline-color` | `#222222` | Keyboard focus ring |
|
|
231
|
+
| `--ecomid-search-submit-bg` | `#000000` | Submit button |
|
|
232
|
+
| `--ecomid-search-submit-hover-bg` | `#262626` | Submit button on hover |
|
|
233
|
+
| `--ecomid-search-submit-pressed-bg` | `#333333` | Submit button while pressed |
|
|
234
|
+
| `--ecomid-search-submit-color` | `#ffffff` | Submit button icon |
|
|
235
|
+
| `--ecomid-search-icon-button-hover-bg` | `rgba(0, 0, 0, 0.05)` | Personalize button on hover on screens 768px and wider |
|
|
236
|
+
| `--ecomid-search-submit-empty-bg` | `#f7f8fa` | Submit button while the input is empty |
|
|
237
|
+
| `--ecomid-search-pill-bg` | `rgba(255, 255, 255, 0.85)` | Filter, chip and starter pills |
|
|
238
|
+
| `--ecomid-search-pill-border-color` | `#e3e5e8` | Filter, chip and starter pill border |
|
|
239
|
+
| `--ecomid-search-pill-hover-bg` | `rgba(247, 248, 250, 0.85)` | Filter, chip and starter pill on hover |
|
|
240
|
+
| `--ecomid-search-pill-hover-border-color` | `--ecomid-search-pill-border-color` | Filter and starter pill border on hover |
|
|
241
|
+
| `--ecomid-search-pill-pressed-bg` | `rgba(240, 242, 244, 0.85)` | Filter, chip and starter pill while pressed |
|
|
242
|
+
| `--ecomid-search-page-gutter` | `16px` (`24px` on screens 768px and wider) | Side padding of the results page, the composed page included. Carousels bleed into it and the filter pills scroll through it below 900px. Set it to `0` if your page already provides the gutter |
|
|
243
|
+
| `--ecomid-search-page-max-width` | `none` | Maximum width of the results page. The default fills the width of its container; set e.g. `1440px` to centre it |
|
|
244
|
+
| `--ecomid-search-grid-columns` | `4`, or `5` when the grid is 1760px or wider | Columns of the results grid on screens 768px and wider. When set, it applies at every width |
|
|
245
|
+
| `--ecomid-search-grid-gutter` | `0px` | Space between the screen edge and the results grid on screens narrower than 768px. The default runs the grid edge to edge while titles and the toolbar keep the page gutter |
|
|
246
|
+
| `--ecomid-search-text-max-width` | `720px` | Maximum width of readable text blocks on the results and composed pages: descriptions, intro and answer text, and the new search prompt pills |
|
|
247
|
+
| `--ecomid-search-grid-gap` | `16px 2px` | Row and column gap of product grids, including the popular products grid below 768px |
|
|
248
|
+
| `--ecomid-search-carousel-card-width` | `201.4px` | Card width in the popular products carousel on screens 768px and wider |
|
|
249
|
+
| `--ecomid-search-carousel-button-bg` | `#ffffff` | Carousel arrow buttons |
|
|
250
|
+
| `--ecomid-search-carousel-button-hover-bg` | `#f5f5f5` | Carousel arrow button on hover |
|
|
251
|
+
| `--ecomid-search-carousel-button-pressed-bg` | `#f0f0f0` | Carousel arrow button while pressed |
|
|
252
|
+
| `--ecomid-search-carousel-button-border-color` | `#f0f2f4` | Carousel arrow button border |
|
|
253
|
+
| `--ecomid-search-image-bg` | `#f0f2f4` | Product image placeholder |
|
|
254
|
+
| `--ecomid-search-white-bg` | `#dfdfd9` | Placeholder behind white-background product images |
|
|
255
|
+
| `--ecomid-search-sale-color` | `#d70015` | Price of a product on sale |
|
|
256
|
+
| `--ecomid-search-baseline-color` | `#767676` | Struck-through original price |
|
|
257
|
+
| `--ecomid-search-badge-bg` | `#ffffff` | Discount badge |
|
|
258
|
+
| `--ecomid-search-skeleton-color` | `#f2f2f2` | Loading placeholders |
|
|
259
|
+
| `--ecomid-search-count-color` | `#5c5c5c` | Product count above the results |
|
|
260
|
+
| `--ecomid-search-popover-z-index` | `1000` | Stacking order of the filter and sort popovers |
|
|
261
|
+
| `--ecomid-search-overlay-backdrop-color` | `rgba(0, 0, 0, 0.32)` | Backdrop behind the bottom sheets |
|
|
262
|
+
| `--ecomid-search-drawer-backdrop-color` | `rgba(0, 0, 0, 0.24)` | Backdrop behind the filter drawer |
|
|
263
|
+
| `--ecomid-search-drawer-width` | `420px` | Filter drawer width on screens 768px and wider |
|
|
264
|
+
| `--ecomid-search-row-hover-bg` | `#f9fafb` | Filter and sort options on hover |
|
|
265
|
+
| `--ecomid-search-checkbox-border-color` | `#b1b3b5` | Filter checkbox border |
|
|
266
|
+
| `--ecomid-search-checkbox-checked-bg` | `#000000` | Checked filter checkbox |
|
|
267
|
+
| `--ecomid-search-checkbox-checked-color` | `#ffffff` | Check mark in a checked filter checkbox |
|
|
268
|
+
| `--ecomid-search-input-border-color` | `#d9d9d9` | Min and Max price fields |
|
|
269
|
+
| `--ecomid-search-button-border-color` | `#e3e5e8` | Clear all button |
|
|
270
|
+
|
|
271
|
+
```css
|
|
272
|
+
:root {
|
|
273
|
+
--ecomid-search-font-family: 'Inter', sans-serif;
|
|
274
|
+
--ecomid-search-font-weight: 300;
|
|
275
|
+
--ecomid-search-surface: #fafafa;
|
|
276
|
+
}
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
The font weights default to 400 and 600 because most web fonts ship those. Set them only to use weights your font provides, for example on a variable font.
|
|
280
|
+
|
|
281
|
+
## Core
|
|
282
|
+
|
|
283
|
+
`@ecomid/modules/search` exports `createSearchStore`, `createResultsStore`, `fetchSuggestions`, `fetchSearchResults` and `fetchEmptyState`. They take the same `locale` (for example `sv-se`, market required) and optional `environment` as the components, and throw or reject for a missing locale or market. `fetchSearchResults` resolves to `SearchResultsData`: `{ query, lang, market, limit?, page?, products, total?, nextPageToken?, appliedFilters?, facets?, title?, description?, sections?, state? }`, where `query` is the trimmed query, `lang` and `market` come from the `locale` the results answer, `limit` is the requested limit and `page` the requested page, if any.
|
|
284
|
+
|
|
285
|
+
## Loader API
|
|
286
|
+
|
|
287
|
+
On pages that use the ecomid loader, the same modal is available without React:
|
|
288
|
+
|
|
289
|
+
```js
|
|
290
|
+
const modal = window.ecomid.search.modal({
|
|
291
|
+
clientId: 'YOUR_CLIENT_ID',
|
|
292
|
+
locale: 'sv-se',
|
|
293
|
+
resultsUrl: '/search',
|
|
294
|
+
})
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
The handle has `open()`, `close()` and `destroy()`. Pass `renderProduct` and `callbacks` (`onOpen`, `onClose`, `onSubmit`, `onProductClick`) only if you need them, as in the table below.
|
|
298
|
+
|
|
299
|
+
| Option | Equivalent React prop |
|
|
300
|
+
|--------|-----------------------|
|
|
301
|
+
| `clientId`, `locale`, `resultsUrl` | the same props |
|
|
302
|
+
| `renderProduct` | `renderProduct`, called as `(product, { position, menuButton })`. `menuButton` is an `HTMLElement` we own and render the product menu button into; append it anywhere in your element. Must return an `HTMLElement`. `null` or `undefined` uses the default card; any other value is reported and the default card is used |
|
|
303
|
+
| `callbacks.onSubmit` | `onSubmit` |
|
|
304
|
+
| `callbacks.onProductClick` | `onProductClick` (receives a DOM `MouseEvent`) |
|
|
305
|
+
| `callbacks.onOpen` | `onOpen` |
|
|
306
|
+
| `callbacks.onClose` | `onClose` |
|
|
307
|
+
|
|
308
|
+
Invalid `clientId`, `locale` or market are reported by the loader, which then returns a handle that does nothing. Options are fixed at init; to change them call `modal()` again, which destroys the previous instance.
|
|
309
|
+
|
|
310
|
+
### Results without React
|
|
311
|
+
|
|
312
|
+
`window.ecomid.search.results` renders the same results, with filters, sort and infinite loading, into an element:
|
|
313
|
+
|
|
314
|
+
On the page `resultsUrl` points to:
|
|
315
|
+
|
|
316
|
+
```js
|
|
317
|
+
window.ecomid.search.results({
|
|
318
|
+
clientId: 'YOUR_CLIENT_ID',
|
|
319
|
+
locale: 'sv-se',
|
|
320
|
+
element: document.getElementById('results'),
|
|
321
|
+
})
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
The results read the page from `location.search` (`request`, or `term`, `filter`, `sort` and so on). Without `query` and without page params nothing is rendered and no request is sent. Pass `query` to show results for a fixed text when the URL holds no page, and `update({ query })` to change it later. The handle also has `destroy()`.
|
|
325
|
+
|
|
326
|
+
`limit` and `headingLevel` are accepted as on the React component, and `renderProduct` and `onProductClick` behave as on the modal. Each call renders its own instance; call `destroy()` to remove it.
|
|
327
|
+
|
|
328
|
+
The results keep the page in the URL by default: on init, if `location.search` holds page params, the results start from that page instead of `query`; each new page is written with `history.pushState` (the first one with `replaceState`), other params are kept, and back and forward restore the page. Pass `url: false` to leave the URL alone.
|
|
329
|
+
|
|
330
|
+
### `onOpen` and `onClose`
|
|
331
|
+
|
|
332
|
+
| | React | Loader |
|
|
333
|
+
|-|-------|--------|
|
|
334
|
+
| `onOpen` | After the `open` prop becomes `true` | When `open()` is called |
|
|
335
|
+
| `onClose` | When the modal asks to close (Escape, backdrop, close button, submit, plain product click). Not called when you set `open` to `false` yourself | The same, plus when `close()` is called, and when `destroy()` is called while open |
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// src/translations/search/widget/cs.json
|
|
2
|
+
var e = "Co hledáte?", t = "Hledat", n = "Personalizovat", r = "Návrhy", i = "Zeptejte se na “{query}”", a = "Produkty", o = "Nebyly nalezeny žádné výsledky", s = "Něco se pokazilo. Zkuste to prosím znovu.", c = {
|
|
3
|
+
sale: "Akční cena {price}",
|
|
4
|
+
original: "Původní cena {price}"
|
|
5
|
+
}, l = {
|
|
6
|
+
title_singular: "{count} výsledek pro \"{query}\"",
|
|
7
|
+
title_plural: "Výsledky pro \"{query}\": {count}"
|
|
8
|
+
}, u = {
|
|
9
|
+
singular: "{count} produkt",
|
|
10
|
+
plural: "Produkty: {count}"
|
|
11
|
+
}, d = {
|
|
12
|
+
singular: "+ {count} barva",
|
|
13
|
+
plural: "Další barvy: +{count}"
|
|
14
|
+
}, f = {
|
|
15
|
+
more_like_this: "Podobné",
|
|
16
|
+
similar_to: "Podobné jako {name}",
|
|
17
|
+
open: "Podobné: {name}"
|
|
18
|
+
}, p = {
|
|
19
|
+
title: "Filtry",
|
|
20
|
+
all: "Všechny filtry",
|
|
21
|
+
more_count: "Další filtry: {count}",
|
|
22
|
+
clear_all: "Vymazat vše",
|
|
23
|
+
show_products: {
|
|
24
|
+
singular: "Zobrazit {count} produkt",
|
|
25
|
+
plural: "Zobrazit produkty: {count}"
|
|
26
|
+
},
|
|
27
|
+
min: "Min",
|
|
28
|
+
max: "Max",
|
|
29
|
+
price_under: "Do {price}",
|
|
30
|
+
any_price: "Jakákoli cena",
|
|
31
|
+
on_sale: "Ve slevě",
|
|
32
|
+
remove: "Odebrat: {filter}",
|
|
33
|
+
remove_exclusion: "Odebrat vyloučení: {filter}",
|
|
34
|
+
groups: {
|
|
35
|
+
category: "Kategorie",
|
|
36
|
+
gender: "Pohlaví",
|
|
37
|
+
size: "Velikost",
|
|
38
|
+
color: "Barva",
|
|
39
|
+
price: "Cena",
|
|
40
|
+
material: "Materiál"
|
|
41
|
+
}
|
|
42
|
+
}, m = {
|
|
43
|
+
label: "Seřadit",
|
|
44
|
+
selected: "Seřadit: {option}",
|
|
45
|
+
options: {
|
|
46
|
+
relevance: "Doporučené",
|
|
47
|
+
newest: "Nejnovější",
|
|
48
|
+
cheapest: "Cena od nejnižší",
|
|
49
|
+
most_expensive: "Cena od nejvyšší"
|
|
50
|
+
}
|
|
51
|
+
}, h = {
|
|
52
|
+
placeholder: "Zeptejte se na něco jiného",
|
|
53
|
+
send: "Odeslat"
|
|
54
|
+
}, g = {
|
|
55
|
+
search: "Hledat",
|
|
56
|
+
for_you: "Pro vás",
|
|
57
|
+
new_search: "Nové hledání",
|
|
58
|
+
back_to_top: "Zpět nahoru"
|
|
59
|
+
}, _ = "Již brzy", v = {
|
|
60
|
+
title: "Žádný produkt pro “{query}”",
|
|
61
|
+
hint: "Zkuste jiná slova nebo popište, co potřebujete",
|
|
62
|
+
filtered_title: "Nebyly nalezeny žádné produkty",
|
|
63
|
+
filtered_hint: "Zkuste odebrat filtr",
|
|
64
|
+
popular: "Oblíbené produkty"
|
|
65
|
+
}, y = { describe_placeholder: "Popište nebo se zeptejte" }, b = {
|
|
66
|
+
title: "Dřívější kroky",
|
|
67
|
+
now: "Nyní"
|
|
68
|
+
}, x = {
|
|
69
|
+
close: "Zavřít",
|
|
70
|
+
submit: "Zobrazit výsledky",
|
|
71
|
+
previous: "Předchozí snímek",
|
|
72
|
+
next: "Další snímek"
|
|
73
|
+
}, S = {
|
|
74
|
+
placeholder: e,
|
|
75
|
+
dialog_label: t,
|
|
76
|
+
personalize: n,
|
|
77
|
+
suggestions: r,
|
|
78
|
+
ask_suggestion: i,
|
|
79
|
+
products: a,
|
|
80
|
+
no_results: o,
|
|
81
|
+
results_error: s,
|
|
82
|
+
price: c,
|
|
83
|
+
results_status: l,
|
|
84
|
+
results_count: u,
|
|
85
|
+
more_colors: d,
|
|
86
|
+
card_menu: f,
|
|
87
|
+
filters: p,
|
|
88
|
+
sort: m,
|
|
89
|
+
compose: h,
|
|
90
|
+
shell: g,
|
|
91
|
+
coming_soon: _,
|
|
92
|
+
empty: v,
|
|
93
|
+
bar: y,
|
|
94
|
+
history: b,
|
|
95
|
+
actions: x
|
|
96
|
+
};
|
|
97
|
+
export { x as actions, i as ask_suggestion, y as bar, f as card_menu, _ as coming_soon, h as compose, S as default, t as dialog_label, v as empty, p as filters, b as history, d as more_colors, o as no_results, n as personalize, e as placeholder, c as price, a as products, u as results_count, s as results_error, l as results_status, g as shell, m as sort, r as suggestions };
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// src/translations/search/widget/da.json
|
|
2
|
+
var e = "Hvad leder du efter?", t = "Søg", n = "Tilpas", r = "Forslag", i = "Spørg “{query}”", a = "Produkter", o = "Ingen resultater fundet", s = "Noget gik galt. Prøv venligst igen.", c = {
|
|
3
|
+
sale: "Tilbudspris {price}",
|
|
4
|
+
original: "Oprindelig pris {price}"
|
|
5
|
+
}, l = {
|
|
6
|
+
title_singular: "{count} resultat for \"{query}\"",
|
|
7
|
+
title_plural: "{count} resultater for \"{query}\""
|
|
8
|
+
}, u = {
|
|
9
|
+
singular: "{count} produkt",
|
|
10
|
+
plural: "{count} produkter"
|
|
11
|
+
}, d = {
|
|
12
|
+
singular: "+ {count} farve",
|
|
13
|
+
plural: "+ {count} farver"
|
|
14
|
+
}, f = {
|
|
15
|
+
more_like_this: "Mere som dette",
|
|
16
|
+
similar_to: "Lignende {name}",
|
|
17
|
+
open: "Mere som dette: {name}"
|
|
18
|
+
}, p = {
|
|
19
|
+
title: "Filtre",
|
|
20
|
+
all: "Alle filtre",
|
|
21
|
+
more_count: "Flere filtre: {count}",
|
|
22
|
+
clear_all: "Ryd alle",
|
|
23
|
+
show_products: {
|
|
24
|
+
singular: "Vis {count} produkt",
|
|
25
|
+
plural: "Vis {count} produkter"
|
|
26
|
+
},
|
|
27
|
+
min: "Min",
|
|
28
|
+
max: "Maks",
|
|
29
|
+
price_under: "Under {price}",
|
|
30
|
+
any_price: "Alle priser",
|
|
31
|
+
on_sale: "Tilbud",
|
|
32
|
+
remove: "Fjern {filter}",
|
|
33
|
+
remove_exclusion: "Fjern udelukkelse af {filter}",
|
|
34
|
+
groups: {
|
|
35
|
+
category: "Kategori",
|
|
36
|
+
gender: "Køn",
|
|
37
|
+
size: "Størrelse",
|
|
38
|
+
color: "Farve",
|
|
39
|
+
price: "Pris",
|
|
40
|
+
material: "Materiale"
|
|
41
|
+
}
|
|
42
|
+
}, m = {
|
|
43
|
+
label: "Sorter",
|
|
44
|
+
selected: "Sorter: {option}",
|
|
45
|
+
options: {
|
|
46
|
+
relevance: "Anbefalet",
|
|
47
|
+
newest: "Nyeste",
|
|
48
|
+
cheapest: "Laveste pris først",
|
|
49
|
+
most_expensive: "Højeste pris først"
|
|
50
|
+
}
|
|
51
|
+
}, h = {
|
|
52
|
+
placeholder: "Spørg om noget andet",
|
|
53
|
+
send: "Send"
|
|
54
|
+
}, g = {
|
|
55
|
+
search: "Søg",
|
|
56
|
+
for_you: "Til dig",
|
|
57
|
+
new_search: "Ny søgning",
|
|
58
|
+
back_to_top: "Til toppen"
|
|
59
|
+
}, _ = "Kommer snart", v = {
|
|
60
|
+
title: "Intet produkt til “{query}”",
|
|
61
|
+
hint: "Prøv andre ord, eller beskriv, hvad du har brug for",
|
|
62
|
+
filtered_title: "Ingen produkter fundet",
|
|
63
|
+
filtered_hint: "Prøv at fjerne et filter",
|
|
64
|
+
popular: "Populære produkter"
|
|
65
|
+
}, y = { describe_placeholder: "Beskriv eller spørg" }, b = {
|
|
66
|
+
title: "Tidligere trin",
|
|
67
|
+
now: "Nu"
|
|
68
|
+
}, x = {
|
|
69
|
+
close: "Luk",
|
|
70
|
+
submit: "Vis resultater",
|
|
71
|
+
previous: "Forrige dias",
|
|
72
|
+
next: "Næste slide"
|
|
73
|
+
}, S = {
|
|
74
|
+
placeholder: e,
|
|
75
|
+
dialog_label: t,
|
|
76
|
+
personalize: n,
|
|
77
|
+
suggestions: r,
|
|
78
|
+
ask_suggestion: i,
|
|
79
|
+
products: a,
|
|
80
|
+
no_results: o,
|
|
81
|
+
results_error: s,
|
|
82
|
+
price: c,
|
|
83
|
+
results_status: l,
|
|
84
|
+
results_count: u,
|
|
85
|
+
more_colors: d,
|
|
86
|
+
card_menu: f,
|
|
87
|
+
filters: p,
|
|
88
|
+
sort: m,
|
|
89
|
+
compose: h,
|
|
90
|
+
shell: g,
|
|
91
|
+
coming_soon: _,
|
|
92
|
+
empty: v,
|
|
93
|
+
bar: y,
|
|
94
|
+
history: b,
|
|
95
|
+
actions: x
|
|
96
|
+
};
|
|
97
|
+
export { x as actions, i as ask_suggestion, y as bar, f as card_menu, _ as coming_soon, h as compose, S as default, t as dialog_label, v as empty, p as filters, b as history, d as more_colors, o as no_results, n as personalize, e as placeholder, c as price, a as products, u as results_count, s as results_error, l as results_status, g as shell, m as sort, r as suggestions };
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// src/translations/search/widget/de.json
|
|
2
|
+
var e = "Wonach suchst du?", t = "Suche", n = "Personalisieren", r = "Vorschläge", i = "“{query}” fragen", a = "Produkte", o = "Keine Ergebnisse gefunden", s = "Etwas ist schiefgelaufen. Bitte versuche es erneut.", c = {
|
|
3
|
+
sale: "Angebotspreis {price}",
|
|
4
|
+
original: "Ursprünglicher Preis {price}"
|
|
5
|
+
}, l = {
|
|
6
|
+
title_singular: "{count} Ergebnis für \"{query}\"",
|
|
7
|
+
title_plural: "{count} Ergebnisse für \"{query}\""
|
|
8
|
+
}, u = {
|
|
9
|
+
singular: "{count} Produkt",
|
|
10
|
+
plural: "{count} Produkte"
|
|
11
|
+
}, d = {
|
|
12
|
+
singular: "+ {count} Farbe",
|
|
13
|
+
plural: "+ {count} Farben"
|
|
14
|
+
}, f = {
|
|
15
|
+
more_like_this: "Mehr davon",
|
|
16
|
+
similar_to: "Ähnlich wie {name}",
|
|
17
|
+
open: "Mehr davon: {name}"
|
|
18
|
+
}, p = {
|
|
19
|
+
title: "Filter",
|
|
20
|
+
all: "Alle Filter",
|
|
21
|
+
more_count: "Weitere Filter: {count}",
|
|
22
|
+
clear_all: "Alle löschen",
|
|
23
|
+
show_products: {
|
|
24
|
+
singular: "{count} Produkt anzeigen",
|
|
25
|
+
plural: "{count} Produkte anzeigen"
|
|
26
|
+
},
|
|
27
|
+
min: "Min",
|
|
28
|
+
max: "Max",
|
|
29
|
+
price_under: "Unter {price}",
|
|
30
|
+
any_price: "Beliebiger Preis",
|
|
31
|
+
on_sale: "Im Angebot",
|
|
32
|
+
remove: "{filter} entfernen",
|
|
33
|
+
remove_exclusion: "Ausschluss von {filter} entfernen",
|
|
34
|
+
groups: {
|
|
35
|
+
category: "Kategorie",
|
|
36
|
+
gender: "Geschlecht",
|
|
37
|
+
size: "Größe",
|
|
38
|
+
color: "Farbe",
|
|
39
|
+
price: "Preis",
|
|
40
|
+
material: "Material"
|
|
41
|
+
}
|
|
42
|
+
}, m = {
|
|
43
|
+
label: "Sortieren",
|
|
44
|
+
selected: "Sortieren: {option}",
|
|
45
|
+
options: {
|
|
46
|
+
relevance: "Empfohlen",
|
|
47
|
+
newest: "Neueste",
|
|
48
|
+
cheapest: "Preis aufsteigend",
|
|
49
|
+
most_expensive: "Preis absteigend"
|
|
50
|
+
}
|
|
51
|
+
}, h = {
|
|
52
|
+
placeholder: "Frag etwas anderes",
|
|
53
|
+
send: "Senden"
|
|
54
|
+
}, g = {
|
|
55
|
+
search: "Suche",
|
|
56
|
+
for_you: "Für dich",
|
|
57
|
+
new_search: "Neue Suche",
|
|
58
|
+
back_to_top: "Nach oben"
|
|
59
|
+
}, _ = "Demnächst verfügbar", v = {
|
|
60
|
+
title: "Kein Produkt für “{query}”",
|
|
61
|
+
hint: "Probier andere Wörter aus oder beschreibe, was du brauchst",
|
|
62
|
+
filtered_title: "Keine Produkte gefunden",
|
|
63
|
+
filtered_hint: "Probier, einen Filter zu entfernen",
|
|
64
|
+
popular: "Beliebte Produkte"
|
|
65
|
+
}, y = { describe_placeholder: "Beschreibe oder frag" }, b = {
|
|
66
|
+
title: "Frühere Schritte",
|
|
67
|
+
now: "Jetzt"
|
|
68
|
+
}, x = {
|
|
69
|
+
close: "Schließen",
|
|
70
|
+
submit: "Ergebnisse anzeigen",
|
|
71
|
+
previous: "Vorherige Folie",
|
|
72
|
+
next: "Nächste Folie"
|
|
73
|
+
}, S = {
|
|
74
|
+
placeholder: e,
|
|
75
|
+
dialog_label: t,
|
|
76
|
+
personalize: n,
|
|
77
|
+
suggestions: r,
|
|
78
|
+
ask_suggestion: i,
|
|
79
|
+
products: a,
|
|
80
|
+
no_results: o,
|
|
81
|
+
results_error: s,
|
|
82
|
+
price: c,
|
|
83
|
+
results_status: l,
|
|
84
|
+
results_count: u,
|
|
85
|
+
more_colors: d,
|
|
86
|
+
card_menu: f,
|
|
87
|
+
filters: p,
|
|
88
|
+
sort: m,
|
|
89
|
+
compose: h,
|
|
90
|
+
shell: g,
|
|
91
|
+
coming_soon: _,
|
|
92
|
+
empty: v,
|
|
93
|
+
bar: y,
|
|
94
|
+
history: b,
|
|
95
|
+
actions: x
|
|
96
|
+
};
|
|
97
|
+
export { x as actions, i as ask_suggestion, y as bar, f as card_menu, _ as coming_soon, h as compose, S as default, t as dialog_label, v as empty, p as filters, b as history, d as more_colors, o as no_results, n as personalize, e as placeholder, c as price, a as products, u as results_count, s as results_error, l as results_status, g as shell, m as sort, r as suggestions };
|