@wayke-se/components-react 5.1.0-beta.0 → 5.1.0-beta.2
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/README.md +193 -119
- package/dist/index.d.ts +11 -3
- package/dist/index.js +3 -3
- package/dist/index.js.map +2 -2
- package/dist/index.mjs +3 -3
- package/dist/index.mjs.map +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,11 +18,16 @@ Install peer dependencies
|
|
|
18
18
|
npm install react react-dom styled-components
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
+
Install the ecom stylesheet (optional, only if you use `ecomSettings`, see [Ecom theme](#ecom-theme))
|
|
22
|
+
```bash
|
|
23
|
+
npm install @wayke-se/ecom-web
|
|
24
|
+
```
|
|
25
|
+
|
|
21
26
|
```javascript
|
|
22
27
|
import React from 'react';
|
|
23
|
-
import WaykeComposite from '@wayke-se/components-react'
|
|
28
|
+
import WaykeComposite, { WaykeProviderSettings } from '@wayke-se/components-react'
|
|
24
29
|
import '@wayke-se/components-react/dist/assets/default.css';
|
|
25
|
-
// Optional
|
|
30
|
+
// Optional, only if you use ecomSettings
|
|
26
31
|
import '@wayke-se/ecom-web/dist/index.css';
|
|
27
32
|
|
|
28
33
|
const ProviderSettings: WaykeProviderSettings = {
|
|
@@ -81,18 +86,20 @@ Examples given the application is located in `/search/vehicles`:
|
|
|
81
86
|
5) pathRoute is `a/b` => `//yoursite.com/search/a/b/00000000-0000-0000-0000-000000000000`
|
|
82
87
|
6) pathRoute is `https://www.wayke.se/objekt` => `https://www.wayke.se/objekt/00000000-0000-0000-0000-000000000000`
|
|
83
88
|
|
|
89
|
+
The id is appended with a `/`, so `pathRoute` should not end with a slash.
|
|
90
|
+
|
|
84
91
|
```javascript
|
|
85
92
|
import React from 'react';
|
|
86
|
-
import
|
|
87
|
-
import '@wayke
|
|
88
|
-
// Optional
|
|
93
|
+
import WaykeComposite from '@wayke-se/components-react'
|
|
94
|
+
import '@wayke-se/components-react/dist/assets/default.css';
|
|
95
|
+
// Optional, only if you use ecomSettings
|
|
89
96
|
import '@wayke-se/ecom-web/dist/index.css';
|
|
90
97
|
|
|
91
98
|
const App = () => (
|
|
92
99
|
<WaykeComposite
|
|
93
100
|
composite={{
|
|
94
|
-
|
|
95
|
-
pathRoute: "your/path/to/this/component
|
|
101
|
+
// ...other composite props
|
|
102
|
+
pathRoute: "/your/path/to/this/component"
|
|
96
103
|
}}
|
|
97
104
|
provider={ProviderSettings}
|
|
98
105
|
/>
|
|
@@ -108,8 +115,8 @@ import React, { useCallback } from 'react';
|
|
|
108
115
|
import { WaykeProvider, WaykeSearch } from '@wayke-se/components-react'
|
|
109
116
|
|
|
110
117
|
const App = () => {
|
|
111
|
-
const onClickSearchItem = useCallback((
|
|
112
|
-
console.log(id);
|
|
118
|
+
const onClickSearchItem = useCallback((data) => {
|
|
119
|
+
console.log(data.id, data.branchId, data.branchName);
|
|
113
120
|
}, []);
|
|
114
121
|
|
|
115
122
|
return (
|
|
@@ -120,6 +127,8 @@ const App = () => {
|
|
|
120
127
|
};
|
|
121
128
|
```
|
|
122
129
|
|
|
130
|
+
If neither `hashRoute` nor `pathRoute` is set, the vehicle cards are not links. Use `onClickSearchItem` to handle navigation to the vehicle yourself.
|
|
131
|
+
|
|
123
132
|
### I only want to use the Search Item component
|
|
124
133
|
|
|
125
134
|
It's recomended to place WaykeItemProvider close to app-root in order to keep the cache
|
|
@@ -127,16 +136,16 @@ It's recomended to place WaykeItemProvider close to app-root in order to keep th
|
|
|
127
136
|
```javascript
|
|
128
137
|
import React, { useCallback } from 'react';
|
|
129
138
|
import { WaykeItemProvider, WaykeSearchItem } from '@wayke-se/components-react'
|
|
130
|
-
import '@wayke
|
|
131
|
-
// Optional
|
|
139
|
+
import '@wayke-se/components-react/dist/assets/default.css';
|
|
140
|
+
// Optional, only if you use ecomSettings
|
|
132
141
|
import '@wayke-se/ecom-web/dist/index.css';
|
|
133
142
|
|
|
134
143
|
const App = ({}) => {
|
|
135
144
|
const id = 'd01f79a3-7552-49c4-9d4d-deb3aa581c31';
|
|
136
145
|
|
|
137
|
-
// Optional,
|
|
138
|
-
const onClickSearchItem = useCallback((
|
|
139
|
-
console.log(
|
|
146
|
+
// Optional, triggered when a related vehicle is clicked
|
|
147
|
+
const onClickSearchItem = useCallback((id: string) => {
|
|
148
|
+
console.log(id);
|
|
140
149
|
}, []);
|
|
141
150
|
|
|
142
151
|
return (
|
|
@@ -147,6 +156,47 @@ const App = ({}) => {
|
|
|
147
156
|
};
|
|
148
157
|
```
|
|
149
158
|
|
|
159
|
+
### I want to use the components on a site that doesn't use React
|
|
160
|
+
|
|
161
|
+
The components are built with React, but they can be mounted into any element on any website. React is then bundled with your JavaScript, which adds to the loading time of the site.
|
|
162
|
+
|
|
163
|
+
You need a bundler (for example webpack, esbuild, Rollup or Vite) that can bundle the JavaScript and the imported CSS files.
|
|
164
|
+
|
|
165
|
+
Install the package and its peer dependencies
|
|
166
|
+
```bash
|
|
167
|
+
npm install @wayke-se/components-react react react-dom styled-components
|
|
168
|
+
# Optional, only if you use ecomSettings
|
|
169
|
+
npm install @wayke-se/ecom-web
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
Add an element where the components should be rendered
|
|
173
|
+
```html
|
|
174
|
+
<div id="wayke-components"></div>
|
|
175
|
+
<script src="your-bundle.js"></script>
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Mount the component into the element. `createElement` is used instead of JSX, so no JSX transform is needed.
|
|
179
|
+
```javascript
|
|
180
|
+
import { createElement } from 'react';
|
|
181
|
+
import { createRoot } from 'react-dom/client';
|
|
182
|
+
import WaykeComposite from '@wayke-se/components-react';
|
|
183
|
+
import '@wayke-se/components-react/dist/assets/default.css';
|
|
184
|
+
// Optional, only if you use ecomSettings
|
|
185
|
+
import '@wayke-se/ecom-web/dist/index.css';
|
|
186
|
+
|
|
187
|
+
const settings = {
|
|
188
|
+
provider: ProviderSettings,
|
|
189
|
+
composite: {
|
|
190
|
+
modifyDocumentTitleItem: true,
|
|
191
|
+
},
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
const container = document.getElementById('wayke-components');
|
|
195
|
+
createRoot(container).render(createElement(WaykeComposite, settings));
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
`WaykeComposite` uses hash routing by default, so it works on a single page without any server configuration. See [path-route](#waykecomposite-uses-hash-route-i-want-to-use-path-route) if you want to use path routing instead.
|
|
199
|
+
|
|
150
200
|
## Components
|
|
151
201
|
|
|
152
202
|
### WaykeComposite
|
|
@@ -155,11 +205,13 @@ const App = ({}) => {
|
|
|
155
205
|
| provider | WaykeProviderSettings | true |
|
|
156
206
|
| composite | WaykeCompositeProps | false |
|
|
157
207
|
|
|
208
|
+
`WaykeComposite` shows `WaykeSearch` and switches to `WaykeSearchItem` when a vehicle id is found in the url. It uses hash routing unless `composite.pathRoute` is set.
|
|
209
|
+
|
|
158
210
|
### WaykeSearchItem
|
|
159
211
|
| Property | Type | Required | Value |
|
|
160
212
|
|--------------------------|------------|----------|----------------------|
|
|
161
213
|
| id | string | true | |
|
|
162
|
-
| marketCode | MarketCode | false | SE
|
|
214
|
+
| marketCode | MarketCode | false | SE \| NO |
|
|
163
215
|
| pathRoute | string | false | |
|
|
164
216
|
| hashRoute | boolean | false | |
|
|
165
217
|
| disableResetScrollOnInit | boolean | false | |
|
|
@@ -177,36 +229,36 @@ const App = ({}) => {
|
|
|
177
229
|
* `hashRoute` - If set to true, then if a item is clicked it will append #guid to the url (is not used if `pathRoute` is set).
|
|
178
230
|
* `disableResetScrollOnInit` - Loading the item page resets the scroll, here it's possible to disable it.
|
|
179
231
|
* `placeholderImage` - Provide custom placeholder image when image is missing.
|
|
180
|
-
* `onClickSearchItem` - Function that
|
|
181
|
-
* `modifyDocumentTitleItem` - Update document title with vehicle data
|
|
232
|
+
* `onClickSearchItem` - Function that will be triggered when a related vehicle is clicked.
|
|
233
|
+
* `modifyDocumentTitleItem` - Update document title with vehicle data (registration number, title and short description).
|
|
182
234
|
* `displayBranchName` - Displays branch name on related product cards and using branch name in presentation of where the vehicle exist
|
|
183
235
|
* `conversionOptions` - Which call-to-action buttons to render on the item page, and in which order. See [Conversion options](#conversion-options).
|
|
184
236
|
|
|
185
237
|
### WaykeSearch
|
|
186
238
|
| Property | Type | Values |
|
|
187
239
|
|---------------------------|---------------------------|---------------------------|
|
|
188
|
-
| marketCode | MarketCode | SE
|
|
240
|
+
| marketCode | MarketCode | SE \| NO |
|
|
189
241
|
| pathRoute | string | |
|
|
190
242
|
| hashRoute | boolean | |
|
|
191
243
|
| filterList | SearchFilterTypes[] | |
|
|
192
|
-
| initialQueryParams | URLSearchParams or string | query, manufacturer, modelSeries, fuelType, gearboxType, branch, color, environmentClass, properties.segment, drivingWheel, price.min, price.max, mileage.min, mileage.max, modelYear.min, modelYear.max, leasingPrice.min, leasingPrice.max, businessLeasingPrice.min, businessLeasingPrice.max |
|
|
244
|
+
| initialQueryParams | URLSearchParams or string | query, manufacturer, modelSeries, fuelType, gearboxType, branch, color, environmentClass, properties.segment, drivingWheel, price.min, price.max, mileage.min, mileage.max, odometerValueAsKm.min, odometerValueAsKm.max, modelYear.min, modelYear.max, leasingPrice.min, leasingPrice.max, businessLeasingPrice.min, businessLeasingPrice.max, sort, hits |
|
|
193
245
|
| removeSearchBar | boolean | |
|
|
194
246
|
| removeFilterOptions | boolean | |
|
|
195
247
|
| placeholderImage | string | |
|
|
196
|
-
| onClickSearchItem | function | (data:
|
|
248
|
+
| onClickSearchItem | function | (data: { id: string, branchId?: string, branchName?: string }) => void |
|
|
197
249
|
| modifyDocumentTitleSearch | string | |
|
|
198
|
-
| displayBranchName |
|
|
250
|
+
| displayBranchName | boolean | |
|
|
199
251
|
|
|
200
252
|
* Optional
|
|
201
253
|
* `marketCode` - Set the language, available options are SE and NO, default to SE.
|
|
202
254
|
* `pathRoute` - If set, then if a item is clicked it will use the provided url and append the guid. Supports both relative and absolute.
|
|
203
255
|
* `hashRoute` - If set to true, then if a item is clicked it will append #guid to the url (is not used if `pathRoute` is set).
|
|
204
|
-
* `filterList` - Select
|
|
205
|
-
* `initialQueryParams` - Set the default filter that should be
|
|
256
|
+
* `filterList` - Select which filters should be visible and in which order. See [SearchFilterTypes](#searchfiltertypes) for available filters. If not set, all filters are shown (see [Notes on MarketCode](#notes-on-marketcode)).
|
|
257
|
+
* `initialQueryParams` - Set the default filter that should be applied upon init. The parameters are passed on to the search API. `hits` defaults to `30` and `sort` to `published-desc`.
|
|
206
258
|
* `removeSearchBar` - Removes search bar.
|
|
207
259
|
* `removeFilterOptions` - Removes filter options.
|
|
208
260
|
* `placeholderImage` - Provide custom placeholder image when image is missing.
|
|
209
|
-
* `onClickSearchItem` - Function that
|
|
261
|
+
* `onClickSearchItem` - Function that will be triggered when a vehicle is clicked.
|
|
210
262
|
* `modifyDocumentTitleSearch` - Set custom document title
|
|
211
263
|
* `displayBranchName` - Displays branch name on product cards
|
|
212
264
|
|
|
@@ -243,16 +295,17 @@ Every option accepts:
|
|
|
243
295
|
* `name` - Custom button label. Defaults to the translated label for the type.
|
|
244
296
|
* `primary` - `true` renders a primary button, `false` a secondary one.
|
|
245
297
|
|
|
246
|
-
`leadMessage` and `leadCallMe` open a form and post the lead to Wayke, where it ends up in Wayke Dealer for the branch that owns the vehicle. The lead is tagged with the hostname of the page it was sent from (`source`), the button used (`sourceMechanism`: `cta.email` or `cta.callme`) and this package (`client`: `components-react`, `clientVersion`).
|
|
298
|
+
`leadMessage` and `leadCallMe` open a form and post the lead to Wayke (`/lead` on the same host as the provider `url`), where it ends up in Wayke Dealer for the branch that owns the vehicle. The lead is tagged with the hostname of the page it was sent from (`source`), the button used (`sourceMechanism`: `cta.email` or `cta.callme`) and this package (`client`: `components-react`, `clientVersion`).
|
|
247
299
|
|
|
248
|
-
`email` opens the visitor's mail client with a pre-populated subject and body so the dealer can tell where the request came from
|
|
249
|
-
|
|
300
|
+
`email` opens the visitor's mail client with a pre-populated subject and body so the dealer can tell where the request came from. The texts are translated by `marketCode`, for example with `SE`:
|
|
301
|
+
* Subject: `<hostname> – Jag är intresserad av <reg no>, <make> <model>`
|
|
302
|
+
* Body: `Länk till bilen: <url of the current page>`
|
|
250
303
|
|
|
251
304
|
Both can be customized, as a string or a function of the vehicle:
|
|
252
305
|
```javascript
|
|
253
306
|
{
|
|
254
307
|
type: 'email',
|
|
255
|
-
subject: (vehicle) => `Inquiry from
|
|
308
|
+
subject: (vehicle) => `Inquiry from example.com – ${vehicle.registrationNumber}`,
|
|
256
309
|
body: false, // omit body
|
|
257
310
|
}
|
|
258
311
|
```
|
|
@@ -260,42 +313,45 @@ Both can be customized, as a string or a function of the vehicle:
|
|
|
260
313
|
Events published along the way: `MailVisible`, `MailClick`, `PhonenumberVisible`, `PhonenumberCall`, `LeadOpen`, `LeadSent`. See [Subscribe to events](#subscribe-to-events).
|
|
261
314
|
|
|
262
315
|
### Notes on MarketCode
|
|
263
|
-
`marketCode` defines what
|
|
264
|
-
- `SE` will exclude the filter `
|
|
316
|
+
`marketCode` defines what language that will be used, `SE` - Swedish (default) or `NO` - Norwegian. Other things that `marketCode` will affect:
|
|
317
|
+
- If no `filterList` is set, `SE` will exclude the filter `odometerValueAsKm` and instead use `mileage`, while `NO` will do the opposite. The difference between the two filters is the unit used. For `odometerValueAsKm` the unit is kilometer, while `mileage` is kilometer/10 (Scandinavian miles).
|
|
318
|
+
- The language is set once, by the first component that is rendered.
|
|
265
319
|
|
|
266
320
|
|
|
267
321
|
## Types
|
|
268
322
|
|
|
269
323
|
### WaykeCompositeProps
|
|
270
|
-
WaykeSearchItem & WaykeSearch combined without `id`
|
|
324
|
+
WaykeSearchItem & WaykeSearch combined without `id`. `hashRoute` and `onClickSearchItem` are deprecated and have no effect, since `WaykeComposite` handles routing itself. Subscribe to the `ItemClicked` event with [WaykePubSub](#subscribe-to-events) to know when a vehicle is clicked.
|
|
271
325
|
|
|
272
326
|
### WaykeProviderSettings
|
|
273
327
|
| Property | Type | Required |
|
|
274
328
|
|-----------------------|--------------|----------|
|
|
275
329
|
| url | string | true |
|
|
276
|
-
| urlMlt | string |
|
|
330
|
+
| urlMlt | string | false |
|
|
277
331
|
| graphQlUrl | string | true |
|
|
278
332
|
| apiKey | string | false |
|
|
279
333
|
| googleMapsApiKey | string | false |
|
|
280
334
|
| googleMapsMarker | string | false |
|
|
281
335
|
| ecomSettings | EcomSettings | false |
|
|
282
336
|
| useQueryParamsFromUrl | boolean | false |
|
|
337
|
+
| pathRoute | string | false |
|
|
283
338
|
|
|
284
339
|
* Required
|
|
285
340
|
* `url` - Url to Wayke ext-api.
|
|
286
|
-
* `urlMlt` - Url to Wayke ext-api for related vehicles. Used when displaying related vehicles for a given vehicle. If not provided `url` will be used, but then related vehicles are change to latest added.
|
|
287
341
|
* `graphQlUrl` - Url to the GraphQl endpoint.
|
|
288
342
|
* Optional
|
|
289
|
-
* `
|
|
290
|
-
* `
|
|
291
|
-
* `
|
|
292
|
-
* `
|
|
293
|
-
* `
|
|
343
|
+
* `urlMlt` - Url to Wayke ext-api for related vehicles. Used when displaying related vehicles for a given vehicle. If not provided `url` will be used, but then the latest added vehicles are shown instead of related vehicles.
|
|
344
|
+
* `apiKey` - Sent as `x-api-key` to Wayke ext-api. If no api key is provided, then the origin of the request is used as api key.
|
|
345
|
+
* `googleMapsApiKey` - Provide a Google Maps Static API key. The vehicle page shows a button for the map. With a `googleMapsApiKey` the button shows a static map, otherwise it opens Google Maps in another tab.
|
|
346
|
+
* `googleMapsMarker` - Url to a custom map marker for the static map.
|
|
347
|
+
* `ecomSettings` - Enables ecom.
|
|
348
|
+
* `useQueryParamsFromUrl` - Reading/writing query strings from/to the url. If true and `initialQueryParams` also exist, then each value in `initialQueryParams` is added unless the url already contains the same key with the same value.
|
|
349
|
+
* `pathRoute` - Used with `useQueryParamsFromUrl`. When the search query is written to the url, the part of the path from `pathRoute` and onwards is removed. `WaykeComposite` does not pass `composite.pathRoute` on, so set it here as well.
|
|
294
350
|
|
|
295
351
|
### EcomSettings
|
|
296
352
|
| Property | Type | Required |
|
|
297
353
|
|--------------------|--------------|----------|
|
|
298
|
-
| url |
|
|
354
|
+
| url | string | true |
|
|
299
355
|
| useBankId | boolean | false |
|
|
300
356
|
| displayBankIdAlert | boolean | false |
|
|
301
357
|
| serviceLogotypeUrl | string | false |
|
|
@@ -304,18 +360,18 @@ WaykeSearchItem & WaykeSearch combined without `id`
|
|
|
304
360
|
* Required
|
|
305
361
|
* `url` - Wayke ecom url.
|
|
306
362
|
* Optional
|
|
307
|
-
* `useBankId`:
|
|
308
|
-
* `displayBankIdAlert`:
|
|
309
|
-
* `serviceLogotypeUrl`:
|
|
310
|
-
* `bankIdThumbprint`: Custom
|
|
363
|
+
* `useBankId`: Deprecated, not used since 3.0.0.
|
|
364
|
+
* `displayBankIdAlert`: Deprecated, not used since 3.0.0.
|
|
365
|
+
* `serviceLogotypeUrl`: Url to the logo shown in ecom. By default the manufacturers logo will be used. Use a url to an image file, a `data:` url is not supported.
|
|
366
|
+
* `bankIdThumbprint`: Custom BankID certificate thumbprint.
|
|
311
367
|
|
|
312
|
-
> For more information about
|
|
368
|
+
> For more information about ecom see https://github.com/wayke-se/wayke-ecom-web.
|
|
313
369
|
|
|
314
370
|
### WaykeItemProviderSettings
|
|
315
371
|
| Property | Type | Required |
|
|
316
372
|
|-----------------------|--------------|----------|
|
|
317
373
|
| url | string | true |
|
|
318
|
-
| urlMlt | string |
|
|
374
|
+
| urlMlt | string | false |
|
|
319
375
|
| graphQlUrl | string | true |
|
|
320
376
|
| apiKey | string | false |
|
|
321
377
|
| googleMapsApiKey | string | false |
|
|
@@ -324,13 +380,13 @@ WaykeSearchItem & WaykeSearch combined without `id`
|
|
|
324
380
|
|
|
325
381
|
* Required
|
|
326
382
|
* `url` - Url to Wayke ext-api.
|
|
327
|
-
* `urlMlt` - Url to Wayke ext-api for related vehicles. Used when displaying related vehicles for a given vehicle. If not provided `url` will be used, but then related vehicles are change to latest added.
|
|
328
383
|
* `graphQlUrl` - Url to the GraphQl endpoint.
|
|
329
384
|
* Optional
|
|
330
|
-
* `
|
|
331
|
-
* `
|
|
332
|
-
* `
|
|
333
|
-
* `
|
|
385
|
+
* `urlMlt` - Url to Wayke ext-api for related vehicles. Used when displaying related vehicles for a given vehicle. If not provided `url` will be used, but then the latest added vehicles are shown instead of related vehicles.
|
|
386
|
+
* `apiKey` - Sent as `x-api-key` to Wayke ext-api. If no api key is provided, then the origin of the request is used as api key.
|
|
387
|
+
* `googleMapsApiKey` - Provide a Google Maps Static API key. The vehicle page shows a button for the map. With a `googleMapsApiKey` the button shows a static map, otherwise it opens Google Maps in another tab.
|
|
388
|
+
* `googleMapsMarker` - Url to a custom map marker for the static map.
|
|
389
|
+
* `ecomSettings` - Enables ecom.
|
|
334
390
|
|
|
335
391
|
### SearchFilterTypes
|
|
336
392
|
| Property | Type | Required | Values |
|
|
@@ -338,16 +394,20 @@ WaykeSearchItem & WaykeSearch combined without `id`
|
|
|
338
394
|
| filterName | SearchFilterNameTypes | true | manufacturer, modelSeries, fuelType, gearboxType, branch, color, environmentClass, properties.segment, drivingWheel, price, mileage, odometerValueAsKm, modelYear, leasingPrice, businessLeasingPrice |
|
|
339
395
|
| displayName | string | false | |
|
|
340
396
|
|
|
341
|
-
* `displayName`
|
|
397
|
+
* `displayName` - Override the default translation of the filter title.
|
|
342
398
|
|
|
343
399
|
### Set initial query filter
|
|
344
400
|
```javascript
|
|
345
401
|
import WaykeComposite from '@wayke-se/components-react'
|
|
346
402
|
|
|
403
|
+
const initialQueryParams = new URLSearchParams();
|
|
404
|
+
initialQueryParams.set('modelYear.min', '2018');
|
|
405
|
+
initialQueryParams.append('modelSeries', 'A5');
|
|
406
|
+
|
|
347
407
|
const App = () => (
|
|
348
408
|
<WaykeComposite
|
|
349
409
|
provider={ProviderSettings}
|
|
350
|
-
composite={{
|
|
410
|
+
composite={{
|
|
351
411
|
initialQueryParams,
|
|
352
412
|
}}
|
|
353
413
|
/>
|
|
@@ -360,7 +420,7 @@ const App = () => (
|
|
|
360
420
|
Order will have effect
|
|
361
421
|
|
|
362
422
|
```javascript
|
|
363
|
-
import WaykeComposite from '@wayke-se/components-react'
|
|
423
|
+
import WaykeComposite, { SearchFilterTypes } from '@wayke-se/components-react'
|
|
364
424
|
|
|
365
425
|
const filterList: SearchFilterTypes[] = [
|
|
366
426
|
{
|
|
@@ -375,8 +435,8 @@ const filterList: SearchFilterTypes[] = [
|
|
|
375
435
|
const App = () => (
|
|
376
436
|
<WaykeComposite
|
|
377
437
|
provider={ProviderSettings}
|
|
378
|
-
composite={{
|
|
379
|
-
filterList
|
|
438
|
+
composite={{
|
|
439
|
+
filterList,
|
|
380
440
|
}}
|
|
381
441
|
/>
|
|
382
442
|
)
|
|
@@ -385,7 +445,7 @@ const App = () => (
|
|
|
385
445
|
## Subscribe to events
|
|
386
446
|
|
|
387
447
|
```javascript
|
|
388
|
-
import { WaykePubSub}
|
|
448
|
+
import { WaykePubSub } from '@wayke-se/components-react';
|
|
389
449
|
|
|
390
450
|
const event = {
|
|
391
451
|
eventName: 'ItemClicked',
|
|
@@ -394,16 +454,15 @@ const event = {
|
|
|
394
454
|
|
|
395
455
|
WaykePubSub.subscribe(event);
|
|
396
456
|
WaykePubSub.unsubscribe(event);
|
|
397
|
-
|
|
398
457
|
```
|
|
399
458
|
|
|
400
|
-
| Method | Arguments
|
|
401
|
-
|
|
402
|
-
| subscribe |
|
|
403
|
-
| unsubscribe |
|
|
404
|
-
| publish | eventName:
|
|
459
|
+
| Method | Arguments |
|
|
460
|
+
|--------------|----------------------------------------------------------------|
|
|
461
|
+
| subscribe | event: EventType |
|
|
462
|
+
| unsubscribe | event: EventType (the same object that was passed to `subscribe`) |
|
|
463
|
+
| publish | eventName: EventNames, data |
|
|
405
464
|
|
|
406
|
-
###
|
|
465
|
+
### EventType
|
|
407
466
|
| eventName | callback | Data |
|
|
408
467
|
|-----------------------|---------------------------|---------------------------------------------------------------------------------------------------------------------------------|
|
|
409
468
|
| View | (data) => void | CallbackViewData |
|
|
@@ -430,9 +489,11 @@ WaykePubSub.unsubscribe(event);
|
|
|
430
489
|
| SearchCompleted | (data) => void | CallbackSearchCompletedData |
|
|
431
490
|
| Search | (data) => void | CallbackSearchData |
|
|
432
491
|
| FilterApply | (data) => void | CallbackFilterApplyData |
|
|
433
|
-
| All | (eventName, data) => void | CallbackViewData \| CallbackHashRouteChangeData \|
|
|
492
|
+
| All | (eventName, data) => void | CallbackViewData \| CallbackHashRouteChangeData \| CallbackItemData \| CallbackLeadData \| CallbackEcomData \| CallbackSearchClearQueryData \| CallbackSearchClearAllFiltersQueryData \| CallbackSearchInitiatedData \| CallbackSearchCompletedData \| CallbackSearchData \| CallbackFilterApplyData |
|
|
434
493
|
* `All` - Subscribes to all events.
|
|
435
494
|
|
|
495
|
+
> The `Callback*Data` names below describe the payloads. They are not exported from the package.
|
|
496
|
+
|
|
436
497
|
#### CallbackViewData
|
|
437
498
|
Published once when the search page or an item page is shown. Either of:
|
|
438
499
|
|
|
@@ -442,40 +503,44 @@ Published once when the search page or an item page is shown. Either of:
|
|
|
442
503
|
| id | string (item only) |
|
|
443
504
|
|
|
444
505
|
#### CallbackHashRouteChangeData
|
|
445
|
-
| Property | Type
|
|
446
|
-
|
|
447
|
-
| id | string
|
|
506
|
+
| Property | Type |
|
|
507
|
+
|-----------|-----------------------|
|
|
508
|
+
| id | string \| undefined |
|
|
509
|
+
|
|
510
|
+
`id` is `undefined` when the hash is removed.
|
|
448
511
|
|
|
449
512
|
#### CallbackItemData
|
|
450
|
-
| Property | Type
|
|
451
|
-
|
|
452
|
-
| id | string
|
|
453
|
-
| branchName | string
|
|
454
|
-
| branchId | string
|
|
513
|
+
| Property | Type |
|
|
514
|
+
|---------------|-----------------------|
|
|
515
|
+
| id | string |
|
|
516
|
+
| branchName | string \| undefined |
|
|
517
|
+
| branchId | string \| undefined |
|
|
455
518
|
|
|
456
519
|
#### CallbackLeadData
|
|
457
|
-
| Property | Type
|
|
458
|
-
|
|
459
|
-
| id | string
|
|
460
|
-
| branchName | string
|
|
461
|
-
| branchId | string
|
|
462
|
-
| communication | "email" \| "callme"
|
|
520
|
+
| Property | Type |
|
|
521
|
+
|---------------|-----------------------|
|
|
522
|
+
| id | string |
|
|
523
|
+
| branchName | string \| undefined |
|
|
524
|
+
| branchId | string \| undefined |
|
|
525
|
+
| communication | "email" \| "callme" |
|
|
463
526
|
|
|
464
527
|
#### CallbackEcomData
|
|
465
528
|
| Property | Type |
|
|
466
529
|
|---------------|-----------------------|
|
|
467
530
|
| id | string |
|
|
468
|
-
| branchName | string
|
|
469
|
-
| branchId | string
|
|
531
|
+
| branchName | string \| undefined |
|
|
532
|
+
| branchId | string \| undefined |
|
|
470
533
|
| view | EcomView |
|
|
471
|
-
| event |
|
|
534
|
+
| event | EcomEvent |
|
|
472
535
|
| currentStep | EcomStep \| undefined |
|
|
473
536
|
| data | any \| undefined |
|
|
474
537
|
|
|
538
|
+
`EcomView`, `EcomEvent` and `EcomStep` are exported from `@wayke-se/ecom-web`.
|
|
539
|
+
|
|
475
540
|
#### CallbackSearchClearQueryData
|
|
476
|
-
| Property | Type
|
|
477
|
-
|
|
478
|
-
| query | string
|
|
541
|
+
| Property | Type |
|
|
542
|
+
|-----------|------------------|
|
|
543
|
+
| query | string \| null |
|
|
479
544
|
|
|
480
545
|
#### CallbackSearchClearAllFiltersQueryData
|
|
481
546
|
| Property | Type |
|
|
@@ -504,19 +569,20 @@ Published once when the search page or an item page is shown. Either of:
|
|
|
504
569
|
|-----------|-----------------------|
|
|
505
570
|
| type | "checkbox" \| "range" |
|
|
506
571
|
| filter | string |
|
|
507
|
-
| value | string \| undefined
|
|
508
|
-
| checked | boolean \|
|
|
509
|
-
| min | number \|
|
|
510
|
-
| max | number \|
|
|
572
|
+
| value | string \| undefined (checkbox only) |
|
|
573
|
+
| checked | boolean \| undefined (checkbox only) |
|
|
574
|
+
| min | number \| undefined (range only) |
|
|
575
|
+
| max | number \| undefined (range only) |
|
|
511
576
|
|
|
512
577
|
## Theme
|
|
513
578
|
It is possible to apply a custom theme using *CSS*. The things that can be styled are:
|
|
514
579
|
- Primary brand color
|
|
515
580
|
- Secondary brand color
|
|
581
|
+
- Accent color
|
|
516
582
|
- Font (regular)
|
|
517
583
|
- Font (bold)
|
|
518
584
|
|
|
519
|
-
To style the components, copy the following snippet into your *CSS* file and modify
|
|
585
|
+
To style the components, copy the following snippet into your *CSS* file and modify it to your needs.
|
|
520
586
|
|
|
521
587
|
```css
|
|
522
588
|
/* === Color === */
|
|
@@ -621,67 +687,75 @@ To style the components, copy the following snippet into your *CSS* file and mod
|
|
|
621
687
|
}
|
|
622
688
|
```
|
|
623
689
|
|
|
690
|
+
> **It is highly recommended to *NOT* add or remove any properties defined above in the color selectors**. However, since fonts usually requires more configuration we encourage you to add the necessary font styling required to match your current profile. If you add new properties to the font selectors, please be careful and ensure everything looks as intended before going into production.
|
|
691
|
+
|
|
624
692
|
### Ecom theme
|
|
625
|
-
The
|
|
693
|
+
The ecom JavaScript is bundled with this package, but its stylesheet is not. If you use `ecomSettings`, install `@wayke-se/ecom-web` and import its stylesheet:
|
|
626
694
|
|
|
627
|
-
|
|
695
|
+
```bash
|
|
696
|
+
npm install @wayke-se/ecom-web
|
|
697
|
+
```
|
|
628
698
|
|
|
629
|
-
|
|
630
|
-
|
|
699
|
+
```javascript
|
|
700
|
+
import '@wayke-se/ecom-web/dist/index.css';
|
|
701
|
+
```
|
|
702
|
+
|
|
703
|
+
The ecom styles are scoped under `.waykeecom-root` and are built on CSS custom properties prefixed with `--waykeecom-`. To change the ecom colors, override the custom properties in a stylesheet loaded after the ecom stylesheet:
|
|
631
704
|
|
|
705
|
+
```css
|
|
706
|
+
.waykeecom-root {
|
|
707
|
+
--waykeecom--color-primary-main: #ff5a1c;
|
|
708
|
+
--waykeecom--color-primary-alt: #ffe6dc;
|
|
709
|
+
--waykeecom--color-link-main: #ff5a1c;
|
|
710
|
+
--waykeecom--color-action-main: #ff5a1c;
|
|
711
|
+
--waykeecom--color-action-alt: #ffe6dc;
|
|
712
|
+
}
|
|
713
|
+
```
|
|
632
714
|
|
|
715
|
+
See `@wayke-se/ecom-web/dist/index.css` for the full list of custom properties.
|
|
716
|
+
|
|
717
|
+
## Run example from repo
|
|
718
|
+
This repository contains an example app in `example/` that uses the components straight from `src/`.
|
|
633
719
|
|
|
634
|
-
|
|
720
|
+
Create an `.env` file in the repository root:
|
|
635
721
|
```
|
|
636
|
-
WAYKE_HOST=YOUR_HOST_1,YOUR_HOST_2
|
|
637
722
|
WAYKE_SEARCH_URL=https://api.wayketech.se/vehicles
|
|
638
723
|
WAYKE_SEARCH_MLT_URL=https://api.wayketech.se/vehicles-mlt-ext
|
|
639
|
-
WAYKE_SEARCH_X_API_KEY=YOUR_API_KEY
|
|
640
724
|
WAYKE_GRAPH_QL_URL=https://gql.wayketech.se/query
|
|
641
725
|
WAYKE_ECOM_URL=https://ecom.wayketech.se
|
|
642
726
|
GOOGLE_MAPS_API_KEY=YOUR_GOOGLE_MAPS_STATIC_API_KEY
|
|
643
727
|
```
|
|
644
728
|
|
|
645
|
-
* `WAYKE_SEARCH_MLT_URL` -
|
|
646
|
-
`
|
|
729
|
+
* `WAYKE_SEARCH_MLT_URL` - *Optional*. Fetches vehicles related to the current vehicle. If not provided, `WAYKE_SEARCH_URL` is used instead and the latest vehicles are shown.
|
|
730
|
+
* `GOOGLE_MAPS_API_KEY` - *Optional*. See `googleMapsApiKey`.
|
|
647
731
|
|
|
648
|
-
Then run the following:
|
|
732
|
+
Then run the following from the repository root:
|
|
649
733
|
```bash
|
|
650
734
|
npm install
|
|
651
|
-
cd example
|
|
652
|
-
npm install
|
|
653
735
|
npm start
|
|
654
736
|
```
|
|
655
737
|
|
|
656
|
-
|
|
657
|
-
Update your local host file and add:
|
|
658
|
-
127.0.0.1 test.com.localhost
|
|
659
|
-
This will change the origin, while still pointing to localhost.
|
|
660
|
-
Start the example and open `test.com.localhost:5000`.
|
|
738
|
+
The example is served on port `5000`. Set `PORT` to use another port, for example `PORT=5010 npm start`.
|
|
661
739
|
|
|
662
|
-
To
|
|
740
|
+
The example does not set an `apiKey`, so the origin of the request is used as API key. To use the API key of a specific site, add a host such as `test.com.localhost` to your hosts file:
|
|
663
741
|
```
|
|
664
|
-
|
|
742
|
+
127.0.0.1 test.com.localhost
|
|
665
743
|
```
|
|
666
|
-
|
|
667
|
-
|
|
744
|
+
Then open `test.com.localhost:5000`. This changes the origin while still pointing to localhost.
|
|
668
745
|
|
|
669
746
|
### Available Routes (Independent)
|
|
670
747
|
|
|
671
748
|
#### WaykeComposite
|
|
672
749
|
[http://localhost:5000](http://localhost:5000)
|
|
673
750
|
|
|
751
|
+
#### WaykeComposite with hash route
|
|
752
|
+
[http://localhost:5000/hash](http://localhost:5000/hash)
|
|
753
|
+
|
|
754
|
+
#### WaykeComposite with path route
|
|
755
|
+
[http://localhost:5000/a/b](http://localhost:5000/a/b)
|
|
756
|
+
|
|
674
757
|
#### WaykeSearch With WaykeProvider
|
|
675
758
|
[http://localhost:5000/search](http://localhost:5000/search)
|
|
676
759
|
|
|
677
760
|
#### WaykeSearchItem With WaykeProvider
|
|
678
761
|
[http://localhost:5000/search-item/d01f79a3-7552-49c4-9d4d-deb3aa581c31](http://localhost:5000/search-item/d01f79a3-7552-49c4-9d4d-deb3aa581c31)
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
## Example repositories
|
|
682
|
-
|
|
683
|
-
### React and Typescript example
|
|
684
|
-
[https://github.com/wayke-se/components-react-boilerplate](https://github.com/wayke-se/components-react-boilerplate)
|
|
685
|
-
|
|
686
|
-
### Non-React with/without Typescript example
|
|
687
|
-
[https://github.com/wayke-se/components-react-example](https://github.com/wayke-se/components-react-example)
|
package/dist/index.d.ts
CHANGED
|
@@ -852,8 +852,6 @@ declare module '@wayke-se/components-react/src/State/Settings/SettingsContext' {
|
|
|
852
852
|
googleMapsMarker?: string;
|
|
853
853
|
ecomSettings?: {
|
|
854
854
|
url: string;
|
|
855
|
-
useBankId?: boolean;
|
|
856
|
-
displayBankIdAlert?: boolean;
|
|
857
855
|
serviceLogotypeUrl?: string;
|
|
858
856
|
bankIdThumbprint?: string;
|
|
859
857
|
};
|
|
@@ -3500,7 +3498,13 @@ declare module '@wayke-se/components-react/src/layouts/WaykeComposite' {
|
|
|
3500
3498
|
import React from 'react';
|
|
3501
3499
|
import { WaykeSearchProps } from '@wayke-se/components-react/src/layouts/search/index';
|
|
3502
3500
|
import { WaykeSearchItemProps } from '@wayke-se/components-react/src/layouts/searchItem/index';
|
|
3503
|
-
|
|
3501
|
+
type WaykeCompositeBaseProps = Omit<WaykeSearchProps & WaykeSearchItemProps, 'id'>;
|
|
3502
|
+
export type WaykeCompositeProps = Omit<WaykeCompositeBaseProps, 'hashRoute' | 'onClickSearchItem'> & {
|
|
3503
|
+
/** @deprecated Has no effect. Hash routing is used unless `pathRoute` is set. */
|
|
3504
|
+
hashRoute?: WaykeCompositeBaseProps['hashRoute'];
|
|
3505
|
+
/** @deprecated Has no effect. Subscribe to the `ItemClicked` event with `WaykePubSub` instead. */
|
|
3506
|
+
onClickSearchItem?: WaykeCompositeBaseProps['onClickSearchItem'];
|
|
3507
|
+
};
|
|
3504
3508
|
const WaykeComposite: ({ marketCode, filterList, initialQueryParams, removeSearchBar, removeFilterOptions, disableResetScrollOnInit, placeholderImage, pathRoute, modifyDocumentTitleItem, modifyDocumentTitleSearch, displayBranchName, conversionOptions, }: WaykeCompositeProps) => React.JSX.Element | null;
|
|
3505
3509
|
export default WaykeComposite;
|
|
3506
3510
|
|
|
@@ -3752,7 +3756,9 @@ declare module '@wayke-se/components-react/src/providers/WaykeItemProvidet' {
|
|
|
3752
3756
|
import React from 'react';
|
|
3753
3757
|
export interface EcomSettings {
|
|
3754
3758
|
url: string;
|
|
3759
|
+
/** @deprecated Not used since 3.0.0. Will be removed in the next major version. */
|
|
3755
3760
|
useBankId?: boolean;
|
|
3761
|
+
/** @deprecated Not used since 3.0.0. Will be removed in the next major version. */
|
|
3756
3762
|
displayBankIdAlert?: boolean;
|
|
3757
3763
|
serviceLogotypeUrl?: string;
|
|
3758
3764
|
bankIdThumbprint?: string;
|
|
@@ -3777,7 +3783,9 @@ declare module '@wayke-se/components-react/src/providers/WaykeProvider' {
|
|
|
3777
3783
|
import React from 'react';
|
|
3778
3784
|
export interface EcomSettings {
|
|
3779
3785
|
url: string;
|
|
3786
|
+
/** @deprecated Not used since 3.0.0. Will be removed in the next major version. */
|
|
3780
3787
|
useBankId?: boolean;
|
|
3788
|
+
/** @deprecated Not used since 3.0.0. Will be removed in the next major version. */
|
|
3781
3789
|
displayBankIdAlert?: boolean;
|
|
3782
3790
|
serviceLogotypeUrl?: string;
|
|
3783
3791
|
bankIdThumbprint?: string;
|