@depict-ai/react-ui 1.0.12 → 1.0.14
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 +2 -2
- package/dist/index.d.ts +489 -489
- package/dist/main.js +4 -4
- package/dist/module.js +4 -4
- package/dist-server/index.d.ts +54 -54
- package/dist-server/main.js +1 -1
- package/dist-server/module.js +1 -1
- package/locales/index.d.ts +2 -2
- package/locales/index.js +1 -1
- package/locales/require.js +1 -1
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
# React flavour of the Depict UI
|
|
2
|
-
|
|
1
|
+
# React flavour of the Depict UI
|
|
2
|
+
|
|
3
3
|
See the [documentation](https://docs.depict.ai/docs/sdk-intro).
|
package/dist/index.d.ts
CHANGED
|
@@ -1,489 +1,489 @@
|
|
|
1
|
-
import { BaseProductListingConfig, BaseProviderConfig, BaseSearchProviderConfig, BaseSearchPageConfig, BaseCategoryPageConfig, CategoryTitle, embedded_num_products, ImagePlaceholderProps, TextPlaceholderProps, fetchDepictRecommendations, ExclusiveId } from "@depict-ai/ui";
|
|
2
|
-
import { Display } from "@depict-ai/utilishared";
|
|
3
|
-
import React, { ReactNode, PropsWithChildren, ReactElement } from "react";
|
|
4
|
-
import { DPC } from "@depict-ai/dpc";
|
|
5
|
-
import { Locale } from "@depict-ai/ui/locales";
|
|
6
|
-
export const version = "1.0.
|
|
7
|
-
interface PLPConfig<T extends Display> extends BaseProductListingConfig {
|
|
8
|
-
/**
|
|
9
|
-
* The product card to use for rendering products.
|
|
10
|
-
*/
|
|
11
|
-
productCard: DepictProductCard<T>;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* The Depict product card props.
|
|
15
|
-
*/
|
|
16
|
-
export interface DepictProductCardProps<T extends Display> {
|
|
17
|
-
/** The display data to render. */
|
|
18
|
-
display: T | null;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Depict product card to use for rendering products.
|
|
22
|
-
*/
|
|
23
|
-
export type DepictProductCard<T extends Display> = (props: DepictProductCardProps<T>) => ReactNode;
|
|
24
|
-
interface UsePerformanceClientReturn {
|
|
25
|
-
dpc: DPC;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Hook used to access the Depict Performance Client.
|
|
29
|
-
* Calls on the returned DPC instance can not be done server side.
|
|
30
|
-
* @example
|
|
31
|
-
* Send an add-to-cart event
|
|
32
|
-
* ```tsx
|
|
33
|
-
* import { useEffect } from "react";
|
|
34
|
-
* import { usePerformanceClient } from "@depict-ai/react-ui";
|
|
35
|
-
*
|
|
36
|
-
* const ProductPage = ({ productId }) => {
|
|
37
|
-
* const { dpc } = usePerformanceClient();
|
|
38
|
-
*
|
|
39
|
-
* useEffect(() => {
|
|
40
|
-
* dpc.setProductId(productId);
|
|
41
|
-
* }, [dpc, productId]);
|
|
42
|
-
*
|
|
43
|
-
* return <div>Showing product {productId}</div>;
|
|
44
|
-
* }
|
|
45
|
-
* ```
|
|
46
|
-
* @returns {UsePerformanceClientReturn}
|
|
47
|
-
}
|
|
48
|
-
*/
|
|
49
|
-
export const usePerformanceClient: () => UsePerformanceClientReturn;
|
|
50
|
-
/**
|
|
51
|
-
* relativeUrl: The relative url to navigate to.
|
|
52
|
-
* replace: Whether to replace the current url or push a new one.
|
|
53
|
-
*/
|
|
54
|
-
type NavigateFunction = (relativeUrl: string, options: {
|
|
55
|
-
replace: boolean;
|
|
56
|
-
}) => void;
|
|
57
|
-
/**
|
|
58
|
-
* The config for the DepictProvider.
|
|
59
|
-
*/
|
|
60
|
-
type ProviderConfig = BaseProviderConfig & {
|
|
61
|
-
/**
|
|
62
|
-
* The function to use for navigating to a new page.
|
|
63
|
-
* This function will be used internally by our components to navigate.
|
|
64
|
-
*
|
|
65
|
-
* You don't need to provide any in a Next.js context.
|
|
66
|
-
*
|
|
67
|
-
* @param relativeUrl - The relative url to navigate to.
|
|
68
|
-
*
|
|
69
|
-
* @example
|
|
70
|
-
* Here is how you would use it with react-router, @reach/router, Gatsby or similar.
|
|
71
|
-
* ```tsx
|
|
72
|
-
* import { DepictProvider, Navigation } from "@depict-ai/react-ui";
|
|
73
|
-
* import { useNavigate } from "react-router-dom";
|
|
74
|
-
* // import { navigate } from "gatsby";
|
|
75
|
-
*
|
|
76
|
-
* function Router() {
|
|
77
|
-
* const navigate = useNavigate();
|
|
78
|
-
* return (
|
|
79
|
-
* <DepictProvider
|
|
80
|
-
* merchant="houdini"
|
|
81
|
-
* market="en-de"
|
|
82
|
-
* navigateFunction={navigate}
|
|
83
|
-
* search={{
|
|
84
|
-
* searchPagePath: "/search",
|
|
85
|
-
* }}
|
|
86
|
-
* >
|
|
87
|
-
* <Routes>[...]</Routes>
|
|
88
|
-
* </DepictProvider>
|
|
89
|
-
* );
|
|
90
|
-
* }
|
|
91
|
-
* ```
|
|
92
|
-
* @example
|
|
93
|
-
* If you're using another library, you can define your own navigate function, that's compatible with the `NavigateFunction` type.
|
|
94
|
-
* ```tsx
|
|
95
|
-
* const navigateFunction = (relativeUrl: string) => {
|
|
96
|
-
* router.push(relativeUrl);
|
|
97
|
-
* };
|
|
98
|
-
* ```
|
|
99
|
-
*/
|
|
100
|
-
navigateFunction?: NavigateFunction;
|
|
101
|
-
/**
|
|
102
|
-
* The locale to use for the Depict components.
|
|
103
|
-
* @default en
|
|
104
|
-
*/
|
|
105
|
-
locale?: Locale;
|
|
106
|
-
/**
|
|
107
|
-
* Unique ID of the currently logged in user, if applicable.
|
|
108
|
-
*/
|
|
109
|
-
userId?: string;
|
|
110
|
-
/**
|
|
111
|
-
* Options that are required for search functionality.
|
|
112
|
-
*/
|
|
113
|
-
search?: BaseSearchProviderConfig;
|
|
114
|
-
};
|
|
115
|
-
/**
|
|
116
|
-
* The DepictProvider is a wrapper component that should be used to wrap any component that uses Depict components.
|
|
117
|
-
*
|
|
118
|
-
* Make sure it's mounted on every page where the search modal should be available.
|
|
119
|
-
*
|
|
120
|
-
* @param props - The props for the DepictProvider.
|
|
121
|
-
*
|
|
122
|
-
* @example
|
|
123
|
-
* ```tsx
|
|
124
|
-
* const App = () => { *
|
|
125
|
-
* return (
|
|
126
|
-
* <DepictProvider
|
|
127
|
-
* merchant="YOUR_MERCHANT"
|
|
128
|
-
* market="YOUR_MARKET"
|
|
129
|
-
* search={{
|
|
130
|
-
* searchPagePath: "/search",
|
|
131
|
-
* }}
|
|
132
|
-
* >
|
|
133
|
-
* <App />
|
|
134
|
-
* </DepictProvider>
|
|
135
|
-
* );
|
|
136
|
-
* };
|
|
137
|
-
* ```
|
|
138
|
-
* @returns {JSX.Element} The DepictProvider.
|
|
139
|
-
*/
|
|
140
|
-
export function DepictProvider(props: PropsWithChildren<ProviderConfig>): import("react").FunctionComponentElement<{
|
|
141
|
-
children?: import("react").ReactNode;
|
|
142
|
-
}>;
|
|
143
|
-
/**
|
|
144
|
-
* A component used to align other Depict components to.
|
|
145
|
-
* @example
|
|
146
|
-
* Align the search modal
|
|
147
|
-
* ```tsx
|
|
148
|
-
* import React from "react";
|
|
149
|
-
* import { ComponentAligner, useSearchModal } from "@depict-ai/react-ui";
|
|
150
|
-
*
|
|
151
|
-
* const App = () => {
|
|
152
|
-
* const ref = React.createRef();
|
|
153
|
-
*
|
|
154
|
-
* const { open } = useSearchModal({
|
|
155
|
-
* location: "aligned",
|
|
156
|
-
* alignerRef: ref,
|
|
157
|
-
* });
|
|
158
|
-
*
|
|
159
|
-
* return (
|
|
160
|
-
* <div>
|
|
161
|
-
* <ComponentAligner ref={ref} />
|
|
162
|
-
* <button onClick={open}>Open</button>
|
|
163
|
-
* </div>
|
|
164
|
-
* );
|
|
165
|
-
* };
|
|
166
|
-
* ```
|
|
167
|
-
* @returns {JSX.Element}
|
|
168
|
-
*/
|
|
169
|
-
export const ComponentAligner: import("react").ForwardRefExoticComponent<import("react").RefAttributes<unknown>>;
|
|
170
|
-
interface SearchPageConfig<T extends Display> extends BaseSearchPageConfig, PLPConfig<T> {
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* SearchPage is a component that renders a Depict search results page.
|
|
174
|
-
* @param props - The props for the search page.
|
|
175
|
-
*
|
|
176
|
-
* @example
|
|
177
|
-
* ```tsx
|
|
178
|
-
* import { DepictProductCard, ImagePlaceholder, Display, SearchPage } from '@depict-ai/react-ui'
|
|
179
|
-
*
|
|
180
|
-
* function Search() {
|
|
181
|
-
* return <SearchPage productCard={MyCustomSearchProductCard} />
|
|
182
|
-
* }
|
|
183
|
-
*
|
|
184
|
-
* interface MyCustomDisplay extends Display {}
|
|
185
|
-
*
|
|
186
|
-
* export const MyCustomSearchProductCard: DepictProductCard<MyCustomDisplay> = ({
|
|
187
|
-
* display,
|
|
188
|
-
* }) => {
|
|
189
|
-
* if (!display) {
|
|
190
|
-
* return <ImagePlaceholder aspectRatio={3 / 4} />
|
|
191
|
-
* }
|
|
192
|
-
*
|
|
193
|
-
* return (
|
|
194
|
-
* <>
|
|
195
|
-
* <MyCustomProductCard
|
|
196
|
-
* product={{
|
|
197
|
-
* id: display.product_id,
|
|
198
|
-
* name: display.title,
|
|
199
|
-
* description: display.title,
|
|
200
|
-
* images: [{ url: display.image_url }],
|
|
201
|
-
* price: {
|
|
202
|
-
* value: display.sale_price,
|
|
203
|
-
* },
|
|
204
|
-
* }}
|
|
205
|
-
* />
|
|
206
|
-
* </>
|
|
207
|
-
* )
|
|
208
|
-
* }
|
|
209
|
-
*
|
|
210
|
-
* ```
|
|
211
|
-
*/
|
|
212
|
-
export function SearchPage<T extends Display>(props: SearchPageConfig<T>): import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
|
|
213
|
-
interface CategoryPageConfig<T extends Display> extends BaseCategoryPageConfig, PLPConfig<T> {
|
|
214
|
-
/**
|
|
215
|
-
* The category id to show.
|
|
216
|
-
*/
|
|
217
|
-
categoryId: string;
|
|
218
|
-
/**
|
|
219
|
-
* categoryTitlePlugin is an optional plugin that can be used to customize the title of the category page.
|
|
220
|
-
* @default CategoryTitle
|
|
221
|
-
*
|
|
222
|
-
* @example
|
|
223
|
-
* ```tsx
|
|
224
|
-
* <CategoryPage categoryId="jeans" productCard={MyCustomCategoryProductCard} categoryTitlePlugin={CategoryTitle} />
|
|
225
|
-
* ```
|
|
226
|
-
*/
|
|
227
|
-
categoryTitlePlugin?: typeof CategoryTitle | typeof embedded_num_products;
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* CategoryPage is a component that renders a Depict category page.
|
|
231
|
-
* @param props the props for the category page.
|
|
232
|
-
*
|
|
233
|
-
* @example
|
|
234
|
-
* ```tsx
|
|
235
|
-
* import { DepictProductCard, ImagePlaceholder, Display, CategoryPage } from '@depict-ai/react-ui'
|
|
236
|
-
*
|
|
237
|
-
* function Category() {
|
|
238
|
-
* return <CategoryPage categoryId="jeans" productCard={MyCustomCategoryProductCard} />
|
|
239
|
-
* }
|
|
240
|
-
*
|
|
241
|
-
* interface MyCustomDisplay extends Display {}
|
|
242
|
-
*
|
|
243
|
-
* export const MyCustomCategoryProductCard: DepictProductCard<MyCustomDisplay> = ({
|
|
244
|
-
* display,
|
|
245
|
-
* }) => {
|
|
246
|
-
* if (!display) {
|
|
247
|
-
* return <ImagePlaceholder aspectRatio={3 / 4} />
|
|
248
|
-
* }
|
|
249
|
-
*
|
|
250
|
-
* return (
|
|
251
|
-
* <>
|
|
252
|
-
* <MyCustomProductCard
|
|
253
|
-
* product={{
|
|
254
|
-
* id: display.product_id,
|
|
255
|
-
* name: display.title,
|
|
256
|
-
* description: display.title,
|
|
257
|
-
* images: [{ url: display.image_url }],
|
|
258
|
-
* price: {
|
|
259
|
-
* value: display.sale_price,
|
|
260
|
-
* },
|
|
261
|
-
* }}
|
|
262
|
-
* />
|
|
263
|
-
* </>
|
|
264
|
-
* )
|
|
265
|
-
* }
|
|
266
|
-
* ```
|
|
267
|
-
*/
|
|
268
|
-
export function CategoryPage<T extends Display>(props: CategoryPageConfig<T>): import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
|
|
269
|
-
/**
|
|
270
|
-
* BreadCrumbs is the "trail" in the header of a category page.
|
|
271
|
-
*/
|
|
272
|
-
export function BreadCrumbs(): import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
|
|
273
|
-
/**
|
|
274
|
-
* QuickLinks is a component enabling the user to go sideways and downwards in the category tree.
|
|
275
|
-
*/
|
|
276
|
-
export function QuickLinks(): import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
|
|
277
|
-
/**
|
|
278
|
-
* A placeholder image that can be used in place of an image that is loading.
|
|
279
|
-
* @param props
|
|
280
|
-
* @returns
|
|
281
|
-
*/
|
|
282
|
-
export const ImagePlaceholder: React.FC<ImagePlaceholderProps>;
|
|
283
|
-
/** A placeholder text that can be used in place of a text that is loading. */
|
|
284
|
-
export const TextPlaceholder: React.FC<TextPlaceholderProps>;
|
|
285
|
-
/**
|
|
286
|
-
* Parameters to configure the search modal.
|
|
287
|
-
*/
|
|
288
|
-
interface UseSearchModalParams {
|
|
289
|
-
/**
|
|
290
|
-
* How the modal should be opened.
|
|
291
|
-
* Will default to "centered" if nothing else is specified.
|
|
292
|
-
* - "centered" - The modal will be opened in the center of the screen.
|
|
293
|
-
* - "aligned" - The modal will be opened aligned to the alignerRef element.
|
|
294
|
-
*/
|
|
295
|
-
location?: ModalLocation;
|
|
296
|
-
/**
|
|
297
|
-
* The ref to the element that the modal should be aligned to.
|
|
298
|
-
* This is only used when location is "aligned".
|
|
299
|
-
* @default undefined
|
|
300
|
-
* @example
|
|
301
|
-
* ```tsx
|
|
302
|
-
import React from "react";
|
|
303
|
-
import { ComponentAligner, useSearchModal } from "@depict-ai/react-ui";
|
|
304
|
-
|
|
305
|
-
const App = () => {
|
|
306
|
-
const ref = React.createRef();
|
|
307
|
-
|
|
308
|
-
const { open } = useSearchModal({
|
|
309
|
-
location: "aligned",
|
|
310
|
-
alignerRef: ref,
|
|
311
|
-
});
|
|
312
|
-
|
|
313
|
-
return (
|
|
314
|
-
<div>
|
|
315
|
-
<ComponentAligner ref={ref} />
|
|
316
|
-
<button onClick={open}>Open</button>
|
|
317
|
-
</div>
|
|
318
|
-
);
|
|
319
|
-
};
|
|
320
|
-
* ```
|
|
321
|
-
*/
|
|
322
|
-
alignerRef?: React.RefObject<HTMLElement>;
|
|
323
|
-
}
|
|
324
|
-
type OpenModal = () => void;
|
|
325
|
-
/**
|
|
326
|
-
* How the modal should be opened.
|
|
327
|
-
*/
|
|
328
|
-
type ModalLocation = "centered" | "aligned";
|
|
329
|
-
interface UseSearchModalReturn {
|
|
330
|
-
open: OpenModal;
|
|
331
|
-
}
|
|
332
|
-
/**
|
|
333
|
-
* Hook used to open the search modal.
|
|
334
|
-
* @example
|
|
335
|
-
* Open a centered modal:
|
|
336
|
-
* ```tsx
|
|
337
|
-
* import React from "react";
|
|
338
|
-
* import { useSearchModal } from "@depict-ai/react-ui";
|
|
339
|
-
*
|
|
340
|
-
* const App = () => {
|
|
341
|
-
* const { open } = useSearchModal({
|
|
342
|
-
* location: "centered",
|
|
343
|
-
* });
|
|
344
|
-
*
|
|
345
|
-
* return (
|
|
346
|
-
* <div>
|
|
347
|
-
* <button onClick={open}>Open</button>
|
|
348
|
-
* </div>
|
|
349
|
-
* );
|
|
350
|
-
* };
|
|
351
|
-
* ```
|
|
352
|
-
* @returns {UseSearchModalReturn}
|
|
353
|
-
*/
|
|
354
|
-
export function useSearchModal(params?: UseSearchModalParams): UseSearchModalReturn;
|
|
355
|
-
interface SearchFieldProps {
|
|
356
|
-
/**
|
|
357
|
-
* A reference to the DOM element that the modal should be aligned to.
|
|
358
|
-
*
|
|
359
|
-
* The top of the modal will be aligned to the top of the element.
|
|
360
|
-
*
|
|
361
|
-
* The height of the search field in the modal will be the same as the height of the element.
|
|
362
|
-
* If not provided, the modal will be aligned to the search field itself.
|
|
363
|
-
*/
|
|
364
|
-
alignerRef?: React.RefObject<HTMLElement>;
|
|
365
|
-
}
|
|
366
|
-
interface UseSearchFieldReturn {
|
|
367
|
-
/**
|
|
368
|
-
* A React component that renders the search field.
|
|
369
|
-
*/
|
|
370
|
-
SearchField: () => ReactElement;
|
|
371
|
-
}
|
|
372
|
-
/**
|
|
373
|
-
* Hook used to configure the Depict search field.
|
|
374
|
-
* @example
|
|
375
|
-
* Render a search field that opens a modal aligned to the search field itself:
|
|
376
|
-
* ```tsx
|
|
377
|
-
* import React from "react";
|
|
378
|
-
* import { useSearchField } from "@depict-ai/react-ui";
|
|
379
|
-
*
|
|
380
|
-
* const App = () => {
|
|
381
|
-
* const { SearchField } = useSearchField();
|
|
382
|
-
*
|
|
383
|
-
* return (
|
|
384
|
-
* <div>
|
|
385
|
-
* <SearchField />
|
|
386
|
-
* </div>
|
|
387
|
-
* );
|
|
388
|
-
* };
|
|
389
|
-
* ```
|
|
390
|
-
* @example
|
|
391
|
-
* Render a search field that opens a modal aligned another DOM element:
|
|
392
|
-
* ```tsx
|
|
393
|
-
* import React from "react";
|
|
394
|
-
* import { ComponentAligner, useSearchField } from "@depict-ai/react-ui";
|
|
395
|
-
*
|
|
396
|
-
* const App = () => {
|
|
397
|
-
* const ref = useRef(null);
|
|
398
|
-
* const { SearchField } = useSearchField({
|
|
399
|
-
* alignerRef: ref
|
|
400
|
-
* });
|
|
401
|
-
*
|
|
402
|
-
* return (
|
|
403
|
-
* <div>
|
|
404
|
-
* <ComponentAligner ref={ref} />
|
|
405
|
-
* <SearchField />
|
|
406
|
-
* </div>
|
|
407
|
-
* );
|
|
408
|
-
* };
|
|
409
|
-
* ```
|
|
410
|
-
* @returns {UseSearchFieldReturn}
|
|
411
|
-
*/
|
|
412
|
-
export const useSearchField: (props?: SearchFieldProps) => UseSearchFieldReturn;
|
|
413
|
-
type FetchRecsOptions = Omit<Parameters<typeof fetchDepictRecommendations>[0], "merchant" | "market" | "userId" | "sessionId"> & ExclusiveId;
|
|
414
|
-
interface UseFetchRecommendationsReturn<T extends Display> {
|
|
415
|
-
/**
|
|
416
|
-
* Fetch recommendations from the Depict API.
|
|
417
|
-
* @example
|
|
418
|
-
* General recommendations for a landing page:
|
|
419
|
-
* ```tsx
|
|
420
|
-
* fetchRecommendations({ type: "landing_page" });
|
|
421
|
-
* ```
|
|
422
|
-
* @example
|
|
423
|
-
* Fetch targeted recommendations for a product details page (PDP):
|
|
424
|
-
* ```tsx
|
|
425
|
-
* fetchRecommendations({ type: "related", productId: "t-shirt-white" })
|
|
426
|
-
* ```
|
|
427
|
-
* @returns {Promise<T[]>}
|
|
428
|
-
*/
|
|
429
|
-
fetchRecommendations: (opts: FetchRecsOptions) => Promise<T[]>;
|
|
430
|
-
}
|
|
431
|
-
/**
|
|
432
|
-
* Hook used to fetch Depict recommendations.
|
|
433
|
-
* @example
|
|
434
|
-
* Fetch general recommendations for a landing page:
|
|
435
|
-
* ```tsx
|
|
436
|
-
* import React from "react";
|
|
437
|
-
* import { useFetchRecommendations } from "@depict-ai/react-ui";
|
|
438
|
-
*
|
|
439
|
-
* export const LandingPage = () => {
|
|
440
|
-
* const [recs, setRecs] = React.useState();
|
|
441
|
-
* const { fetchRecommendations } = useFetchRecommendations();
|
|
442
|
-
*
|
|
443
|
-
* React.useEffect(() => {
|
|
444
|
-
* fetchRecommendations({ type: "landing_page" }).then(setRecs);
|
|
445
|
-
* }, [fetchRecommendations]);
|
|
446
|
-
*
|
|
447
|
-
* return (
|
|
448
|
-
* <div>
|
|
449
|
-
* {recs?.map((display) => (
|
|
450
|
-
* <ProductCard display={display} />
|
|
451
|
-
* ))}
|
|
452
|
-
* </div>
|
|
453
|
-
* );
|
|
454
|
-
* };
|
|
455
|
-
* ```
|
|
456
|
-
* @example
|
|
457
|
-
* Fetch targeted recommendations for a product details page (PDP):
|
|
458
|
-
* ```tsx
|
|
459
|
-
* import React from "react";
|
|
460
|
-
* import { useFetchRecommendations } from "@depict-ai/react-ui";
|
|
461
|
-
*
|
|
462
|
-
* export const ProductPage = ({ productId }) => {
|
|
463
|
-
* const [recs, setRecs] = React.useState();
|
|
464
|
-
* const { fetchRecommendations } = useFetchRecommendations();
|
|
465
|
-
*
|
|
466
|
-
* React.useEffect(() => {
|
|
467
|
-
* fetchRecommendations({ type: "related", productId }).then(setRecs);
|
|
468
|
-
* }, [fetchRecommendations, productId]);
|
|
469
|
-
*
|
|
470
|
-
* return (
|
|
471
|
-
* <div>
|
|
472
|
-
* {recs?.map((display) => (
|
|
473
|
-
* <ProductCard display={display} />
|
|
474
|
-
* ))}
|
|
475
|
-
* </div>
|
|
476
|
-
* );
|
|
477
|
-
* };
|
|
478
|
-
* ```
|
|
479
|
-
* @returns {UseFetchRecommendationsReturn}
|
|
480
|
-
*/
|
|
481
|
-
export function useFetchRecommendations<T extends Display>(): UseFetchRecommendationsReturn<T>;
|
|
482
|
-
/**
|
|
483
|
-
* Helper function to navigate to a new page depending on the navigation library used.
|
|
484
|
-
*/
|
|
485
|
-
export const Navigation: {
|
|
486
|
-
nextRouterNavigation: (router: import("next/router").NextRouter) => (relativeUrl: string) => void;
|
|
487
|
-
};
|
|
488
|
-
export { CategoryTitle, embedded_num_products as EmbeddedNumProducts } from "@depict-ai/ui";
|
|
489
|
-
export type { Locale } from "@depict-ai/ui/locales";
|
|
1
|
+
import { BaseProductListingConfig, BaseProviderConfig, BaseSearchProviderConfig, BaseSearchPageConfig, BaseCategoryPageConfig, CategoryTitle, embedded_num_products, ImagePlaceholderProps, TextPlaceholderProps, fetchDepictRecommendations, ExclusiveId } from "@depict-ai/ui";
|
|
2
|
+
import { Display } from "@depict-ai/utilishared";
|
|
3
|
+
import React, { ReactNode, PropsWithChildren, ReactElement } from "react";
|
|
4
|
+
import { DPC } from "@depict-ai/dpc";
|
|
5
|
+
import { Locale } from "@depict-ai/ui/locales";
|
|
6
|
+
export const version = "1.0.14";
|
|
7
|
+
interface PLPConfig<T extends Display> extends BaseProductListingConfig {
|
|
8
|
+
/**
|
|
9
|
+
* The product card to use for rendering products.
|
|
10
|
+
*/
|
|
11
|
+
productCard: DepictProductCard<T>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The Depict product card props.
|
|
15
|
+
*/
|
|
16
|
+
export interface DepictProductCardProps<T extends Display> {
|
|
17
|
+
/** The display data to render. */
|
|
18
|
+
display: T | null;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Depict product card to use for rendering products.
|
|
22
|
+
*/
|
|
23
|
+
export type DepictProductCard<T extends Display> = (props: DepictProductCardProps<T>) => ReactNode;
|
|
24
|
+
interface UsePerformanceClientReturn {
|
|
25
|
+
dpc: DPC;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Hook used to access the Depict Performance Client.
|
|
29
|
+
* Calls on the returned DPC instance can not be done server side.
|
|
30
|
+
* @example
|
|
31
|
+
* Send an add-to-cart event
|
|
32
|
+
* ```tsx
|
|
33
|
+
* import { useEffect } from "react";
|
|
34
|
+
* import { usePerformanceClient } from "@depict-ai/react-ui";
|
|
35
|
+
*
|
|
36
|
+
* const ProductPage = ({ productId }) => {
|
|
37
|
+
* const { dpc } = usePerformanceClient();
|
|
38
|
+
*
|
|
39
|
+
* useEffect(() => {
|
|
40
|
+
* dpc.setProductId(productId);
|
|
41
|
+
* }, [dpc, productId]);
|
|
42
|
+
*
|
|
43
|
+
* return <div>Showing product {productId}</div>;
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
* @returns {UsePerformanceClientReturn}
|
|
47
|
+
}
|
|
48
|
+
*/
|
|
49
|
+
export const usePerformanceClient: () => UsePerformanceClientReturn;
|
|
50
|
+
/**
|
|
51
|
+
* relativeUrl: The relative url to navigate to.
|
|
52
|
+
* replace: Whether to replace the current url or push a new one.
|
|
53
|
+
*/
|
|
54
|
+
type NavigateFunction = (relativeUrl: string, options: {
|
|
55
|
+
replace: boolean;
|
|
56
|
+
}) => void;
|
|
57
|
+
/**
|
|
58
|
+
* The config for the DepictProvider.
|
|
59
|
+
*/
|
|
60
|
+
type ProviderConfig = BaseProviderConfig & {
|
|
61
|
+
/**
|
|
62
|
+
* The function to use for navigating to a new page.
|
|
63
|
+
* This function will be used internally by our components to navigate.
|
|
64
|
+
*
|
|
65
|
+
* You don't need to provide any in a Next.js context.
|
|
66
|
+
*
|
|
67
|
+
* @param relativeUrl - The relative url to navigate to.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* Here is how you would use it with react-router, @reach/router, Gatsby or similar.
|
|
71
|
+
* ```tsx
|
|
72
|
+
* import { DepictProvider, Navigation } from "@depict-ai/react-ui";
|
|
73
|
+
* import { useNavigate } from "react-router-dom";
|
|
74
|
+
* // import { navigate } from "gatsby";
|
|
75
|
+
*
|
|
76
|
+
* function Router() {
|
|
77
|
+
* const navigate = useNavigate();
|
|
78
|
+
* return (
|
|
79
|
+
* <DepictProvider
|
|
80
|
+
* merchant="houdini"
|
|
81
|
+
* market="en-de"
|
|
82
|
+
* navigateFunction={navigate}
|
|
83
|
+
* search={{
|
|
84
|
+
* searchPagePath: "/search",
|
|
85
|
+
* }}
|
|
86
|
+
* >
|
|
87
|
+
* <Routes>[...]</Routes>
|
|
88
|
+
* </DepictProvider>
|
|
89
|
+
* );
|
|
90
|
+
* }
|
|
91
|
+
* ```
|
|
92
|
+
* @example
|
|
93
|
+
* If you're using another library, you can define your own navigate function, that's compatible with the `NavigateFunction` type.
|
|
94
|
+
* ```tsx
|
|
95
|
+
* const navigateFunction = (relativeUrl: string) => {
|
|
96
|
+
* router.push(relativeUrl);
|
|
97
|
+
* };
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
navigateFunction?: NavigateFunction;
|
|
101
|
+
/**
|
|
102
|
+
* The locale to use for the Depict components.
|
|
103
|
+
* @default en
|
|
104
|
+
*/
|
|
105
|
+
locale?: Locale;
|
|
106
|
+
/**
|
|
107
|
+
* Unique ID of the currently logged in user, if applicable.
|
|
108
|
+
*/
|
|
109
|
+
userId?: string;
|
|
110
|
+
/**
|
|
111
|
+
* Options that are required for search functionality.
|
|
112
|
+
*/
|
|
113
|
+
search?: BaseSearchProviderConfig;
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* The DepictProvider is a wrapper component that should be used to wrap any component that uses Depict components.
|
|
117
|
+
*
|
|
118
|
+
* Make sure it's mounted on every page where the search modal should be available.
|
|
119
|
+
*
|
|
120
|
+
* @param props - The props for the DepictProvider.
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```tsx
|
|
124
|
+
* const App = () => { *
|
|
125
|
+
* return (
|
|
126
|
+
* <DepictProvider
|
|
127
|
+
* merchant="YOUR_MERCHANT"
|
|
128
|
+
* market="YOUR_MARKET"
|
|
129
|
+
* search={{
|
|
130
|
+
* searchPagePath: "/search",
|
|
131
|
+
* }}
|
|
132
|
+
* >
|
|
133
|
+
* <App />
|
|
134
|
+
* </DepictProvider>
|
|
135
|
+
* );
|
|
136
|
+
* };
|
|
137
|
+
* ```
|
|
138
|
+
* @returns {JSX.Element} The DepictProvider.
|
|
139
|
+
*/
|
|
140
|
+
export function DepictProvider(props: PropsWithChildren<ProviderConfig>): import("react").FunctionComponentElement<{
|
|
141
|
+
children?: import("react").ReactNode;
|
|
142
|
+
}>;
|
|
143
|
+
/**
|
|
144
|
+
* A component used to align other Depict components to.
|
|
145
|
+
* @example
|
|
146
|
+
* Align the search modal
|
|
147
|
+
* ```tsx
|
|
148
|
+
* import React from "react";
|
|
149
|
+
* import { ComponentAligner, useSearchModal } from "@depict-ai/react-ui";
|
|
150
|
+
*
|
|
151
|
+
* const App = () => {
|
|
152
|
+
* const ref = React.createRef();
|
|
153
|
+
*
|
|
154
|
+
* const { open } = useSearchModal({
|
|
155
|
+
* location: "aligned",
|
|
156
|
+
* alignerRef: ref,
|
|
157
|
+
* });
|
|
158
|
+
*
|
|
159
|
+
* return (
|
|
160
|
+
* <div>
|
|
161
|
+
* <ComponentAligner ref={ref} />
|
|
162
|
+
* <button onClick={open}>Open</button>
|
|
163
|
+
* </div>
|
|
164
|
+
* );
|
|
165
|
+
* };
|
|
166
|
+
* ```
|
|
167
|
+
* @returns {JSX.Element}
|
|
168
|
+
*/
|
|
169
|
+
export const ComponentAligner: import("react").ForwardRefExoticComponent<import("react").RefAttributes<unknown>>;
|
|
170
|
+
interface SearchPageConfig<T extends Display> extends BaseSearchPageConfig, PLPConfig<T> {
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* SearchPage is a component that renders a Depict search results page.
|
|
174
|
+
* @param props - The props for the search page.
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* ```tsx
|
|
178
|
+
* import { DepictProductCard, ImagePlaceholder, Display, SearchPage } from '@depict-ai/react-ui'
|
|
179
|
+
*
|
|
180
|
+
* function Search() {
|
|
181
|
+
* return <SearchPage productCard={MyCustomSearchProductCard} />
|
|
182
|
+
* }
|
|
183
|
+
*
|
|
184
|
+
* interface MyCustomDisplay extends Display {}
|
|
185
|
+
*
|
|
186
|
+
* export const MyCustomSearchProductCard: DepictProductCard<MyCustomDisplay> = ({
|
|
187
|
+
* display,
|
|
188
|
+
* }) => {
|
|
189
|
+
* if (!display) {
|
|
190
|
+
* return <ImagePlaceholder aspectRatio={3 / 4} />
|
|
191
|
+
* }
|
|
192
|
+
*
|
|
193
|
+
* return (
|
|
194
|
+
* <>
|
|
195
|
+
* <MyCustomProductCard
|
|
196
|
+
* product={{
|
|
197
|
+
* id: display.product_id,
|
|
198
|
+
* name: display.title,
|
|
199
|
+
* description: display.title,
|
|
200
|
+
* images: [{ url: display.image_url }],
|
|
201
|
+
* price: {
|
|
202
|
+
* value: display.sale_price,
|
|
203
|
+
* },
|
|
204
|
+
* }}
|
|
205
|
+
* />
|
|
206
|
+
* </>
|
|
207
|
+
* )
|
|
208
|
+
* }
|
|
209
|
+
*
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
212
|
+
export function SearchPage<T extends Display>(props: SearchPageConfig<T>): import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
|
|
213
|
+
interface CategoryPageConfig<T extends Display> extends BaseCategoryPageConfig, PLPConfig<T> {
|
|
214
|
+
/**
|
|
215
|
+
* The category id to show.
|
|
216
|
+
*/
|
|
217
|
+
categoryId: string;
|
|
218
|
+
/**
|
|
219
|
+
* categoryTitlePlugin is an optional plugin that can be used to customize the title of the category page.
|
|
220
|
+
* @default CategoryTitle
|
|
221
|
+
*
|
|
222
|
+
* @example
|
|
223
|
+
* ```tsx
|
|
224
|
+
* <CategoryPage categoryId="jeans" productCard={MyCustomCategoryProductCard} categoryTitlePlugin={CategoryTitle} />
|
|
225
|
+
* ```
|
|
226
|
+
*/
|
|
227
|
+
categoryTitlePlugin?: typeof CategoryTitle | typeof embedded_num_products;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* CategoryPage is a component that renders a Depict category page.
|
|
231
|
+
* @param props the props for the category page.
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* ```tsx
|
|
235
|
+
* import { DepictProductCard, ImagePlaceholder, Display, CategoryPage } from '@depict-ai/react-ui'
|
|
236
|
+
*
|
|
237
|
+
* function Category() {
|
|
238
|
+
* return <CategoryPage categoryId="jeans" productCard={MyCustomCategoryProductCard} />
|
|
239
|
+
* }
|
|
240
|
+
*
|
|
241
|
+
* interface MyCustomDisplay extends Display {}
|
|
242
|
+
*
|
|
243
|
+
* export const MyCustomCategoryProductCard: DepictProductCard<MyCustomDisplay> = ({
|
|
244
|
+
* display,
|
|
245
|
+
* }) => {
|
|
246
|
+
* if (!display) {
|
|
247
|
+
* return <ImagePlaceholder aspectRatio={3 / 4} />
|
|
248
|
+
* }
|
|
249
|
+
*
|
|
250
|
+
* return (
|
|
251
|
+
* <>
|
|
252
|
+
* <MyCustomProductCard
|
|
253
|
+
* product={{
|
|
254
|
+
* id: display.product_id,
|
|
255
|
+
* name: display.title,
|
|
256
|
+
* description: display.title,
|
|
257
|
+
* images: [{ url: display.image_url }],
|
|
258
|
+
* price: {
|
|
259
|
+
* value: display.sale_price,
|
|
260
|
+
* },
|
|
261
|
+
* }}
|
|
262
|
+
* />
|
|
263
|
+
* </>
|
|
264
|
+
* )
|
|
265
|
+
* }
|
|
266
|
+
* ```
|
|
267
|
+
*/
|
|
268
|
+
export function CategoryPage<T extends Display>(props: CategoryPageConfig<T>): import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
|
|
269
|
+
/**
|
|
270
|
+
* BreadCrumbs is the "trail" in the header of a category page.
|
|
271
|
+
*/
|
|
272
|
+
export function BreadCrumbs(): import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
|
|
273
|
+
/**
|
|
274
|
+
* QuickLinks is a component enabling the user to go sideways and downwards in the category tree.
|
|
275
|
+
*/
|
|
276
|
+
export function QuickLinks(): import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
|
|
277
|
+
/**
|
|
278
|
+
* A placeholder image that can be used in place of an image that is loading.
|
|
279
|
+
* @param props
|
|
280
|
+
* @returns
|
|
281
|
+
*/
|
|
282
|
+
export const ImagePlaceholder: React.FC<ImagePlaceholderProps>;
|
|
283
|
+
/** A placeholder text that can be used in place of a text that is loading. */
|
|
284
|
+
export const TextPlaceholder: React.FC<TextPlaceholderProps>;
|
|
285
|
+
/**
|
|
286
|
+
* Parameters to configure the search modal.
|
|
287
|
+
*/
|
|
288
|
+
interface UseSearchModalParams {
|
|
289
|
+
/**
|
|
290
|
+
* How the modal should be opened.
|
|
291
|
+
* Will default to "centered" if nothing else is specified.
|
|
292
|
+
* - "centered" - The modal will be opened in the center of the screen.
|
|
293
|
+
* - "aligned" - The modal will be opened aligned to the alignerRef element.
|
|
294
|
+
*/
|
|
295
|
+
location?: ModalLocation;
|
|
296
|
+
/**
|
|
297
|
+
* The ref to the element that the modal should be aligned to.
|
|
298
|
+
* This is only used when location is "aligned".
|
|
299
|
+
* @default undefined
|
|
300
|
+
* @example
|
|
301
|
+
* ```tsx
|
|
302
|
+
import React from "react";
|
|
303
|
+
import { ComponentAligner, useSearchModal } from "@depict-ai/react-ui";
|
|
304
|
+
|
|
305
|
+
const App = () => {
|
|
306
|
+
const ref = React.createRef();
|
|
307
|
+
|
|
308
|
+
const { open } = useSearchModal({
|
|
309
|
+
location: "aligned",
|
|
310
|
+
alignerRef: ref,
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
return (
|
|
314
|
+
<div>
|
|
315
|
+
<ComponentAligner ref={ref} />
|
|
316
|
+
<button onClick={open}>Open</button>
|
|
317
|
+
</div>
|
|
318
|
+
);
|
|
319
|
+
};
|
|
320
|
+
* ```
|
|
321
|
+
*/
|
|
322
|
+
alignerRef?: React.RefObject<HTMLElement>;
|
|
323
|
+
}
|
|
324
|
+
type OpenModal = () => void;
|
|
325
|
+
/**
|
|
326
|
+
* How the modal should be opened.
|
|
327
|
+
*/
|
|
328
|
+
type ModalLocation = "centered" | "aligned";
|
|
329
|
+
interface UseSearchModalReturn {
|
|
330
|
+
open: OpenModal;
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Hook used to open the search modal.
|
|
334
|
+
* @example
|
|
335
|
+
* Open a centered modal:
|
|
336
|
+
* ```tsx
|
|
337
|
+
* import React from "react";
|
|
338
|
+
* import { useSearchModal } from "@depict-ai/react-ui";
|
|
339
|
+
*
|
|
340
|
+
* const App = () => {
|
|
341
|
+
* const { open } = useSearchModal({
|
|
342
|
+
* location: "centered",
|
|
343
|
+
* });
|
|
344
|
+
*
|
|
345
|
+
* return (
|
|
346
|
+
* <div>
|
|
347
|
+
* <button onClick={open}>Open</button>
|
|
348
|
+
* </div>
|
|
349
|
+
* );
|
|
350
|
+
* };
|
|
351
|
+
* ```
|
|
352
|
+
* @returns {UseSearchModalReturn}
|
|
353
|
+
*/
|
|
354
|
+
export function useSearchModal(params?: UseSearchModalParams): UseSearchModalReturn;
|
|
355
|
+
interface SearchFieldProps {
|
|
356
|
+
/**
|
|
357
|
+
* A reference to the DOM element that the modal should be aligned to.
|
|
358
|
+
*
|
|
359
|
+
* The top of the modal will be aligned to the top of the element.
|
|
360
|
+
*
|
|
361
|
+
* The height of the search field in the modal will be the same as the height of the element.
|
|
362
|
+
* If not provided, the modal will be aligned to the search field itself.
|
|
363
|
+
*/
|
|
364
|
+
alignerRef?: React.RefObject<HTMLElement>;
|
|
365
|
+
}
|
|
366
|
+
interface UseSearchFieldReturn {
|
|
367
|
+
/**
|
|
368
|
+
* A React component that renders the search field.
|
|
369
|
+
*/
|
|
370
|
+
SearchField: () => ReactElement;
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Hook used to configure the Depict search field.
|
|
374
|
+
* @example
|
|
375
|
+
* Render a search field that opens a modal aligned to the search field itself:
|
|
376
|
+
* ```tsx
|
|
377
|
+
* import React from "react";
|
|
378
|
+
* import { useSearchField } from "@depict-ai/react-ui";
|
|
379
|
+
*
|
|
380
|
+
* const App = () => {
|
|
381
|
+
* const { SearchField } = useSearchField();
|
|
382
|
+
*
|
|
383
|
+
* return (
|
|
384
|
+
* <div>
|
|
385
|
+
* <SearchField />
|
|
386
|
+
* </div>
|
|
387
|
+
* );
|
|
388
|
+
* };
|
|
389
|
+
* ```
|
|
390
|
+
* @example
|
|
391
|
+
* Render a search field that opens a modal aligned another DOM element:
|
|
392
|
+
* ```tsx
|
|
393
|
+
* import React from "react";
|
|
394
|
+
* import { ComponentAligner, useSearchField } from "@depict-ai/react-ui";
|
|
395
|
+
*
|
|
396
|
+
* const App = () => {
|
|
397
|
+
* const ref = useRef(null);
|
|
398
|
+
* const { SearchField } = useSearchField({
|
|
399
|
+
* alignerRef: ref
|
|
400
|
+
* });
|
|
401
|
+
*
|
|
402
|
+
* return (
|
|
403
|
+
* <div>
|
|
404
|
+
* <ComponentAligner ref={ref} />
|
|
405
|
+
* <SearchField />
|
|
406
|
+
* </div>
|
|
407
|
+
* );
|
|
408
|
+
* };
|
|
409
|
+
* ```
|
|
410
|
+
* @returns {UseSearchFieldReturn}
|
|
411
|
+
*/
|
|
412
|
+
export const useSearchField: (props?: SearchFieldProps) => UseSearchFieldReturn;
|
|
413
|
+
type FetchRecsOptions = Omit<Parameters<typeof fetchDepictRecommendations>[0], "merchant" | "market" | "userId" | "sessionId"> & ExclusiveId;
|
|
414
|
+
interface UseFetchRecommendationsReturn<T extends Display> {
|
|
415
|
+
/**
|
|
416
|
+
* Fetch recommendations from the Depict API.
|
|
417
|
+
* @example
|
|
418
|
+
* General recommendations for a landing page:
|
|
419
|
+
* ```tsx
|
|
420
|
+
* fetchRecommendations({ type: "landing_page" });
|
|
421
|
+
* ```
|
|
422
|
+
* @example
|
|
423
|
+
* Fetch targeted recommendations for a product details page (PDP):
|
|
424
|
+
* ```tsx
|
|
425
|
+
* fetchRecommendations({ type: "related", productId: "t-shirt-white" })
|
|
426
|
+
* ```
|
|
427
|
+
* @returns {Promise<T[]>}
|
|
428
|
+
*/
|
|
429
|
+
fetchRecommendations: (opts: FetchRecsOptions) => Promise<T[]>;
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Hook used to fetch Depict recommendations.
|
|
433
|
+
* @example
|
|
434
|
+
* Fetch general recommendations for a landing page:
|
|
435
|
+
* ```tsx
|
|
436
|
+
* import React from "react";
|
|
437
|
+
* import { useFetchRecommendations } from "@depict-ai/react-ui";
|
|
438
|
+
*
|
|
439
|
+
* export const LandingPage = () => {
|
|
440
|
+
* const [recs, setRecs] = React.useState();
|
|
441
|
+
* const { fetchRecommendations } = useFetchRecommendations();
|
|
442
|
+
*
|
|
443
|
+
* React.useEffect(() => {
|
|
444
|
+
* fetchRecommendations({ type: "landing_page" }).then(setRecs);
|
|
445
|
+
* }, [fetchRecommendations]);
|
|
446
|
+
*
|
|
447
|
+
* return (
|
|
448
|
+
* <div>
|
|
449
|
+
* {recs?.map((display) => (
|
|
450
|
+
* <ProductCard display={display} />
|
|
451
|
+
* ))}
|
|
452
|
+
* </div>
|
|
453
|
+
* );
|
|
454
|
+
* };
|
|
455
|
+
* ```
|
|
456
|
+
* @example
|
|
457
|
+
* Fetch targeted recommendations for a product details page (PDP):
|
|
458
|
+
* ```tsx
|
|
459
|
+
* import React from "react";
|
|
460
|
+
* import { useFetchRecommendations } from "@depict-ai/react-ui";
|
|
461
|
+
*
|
|
462
|
+
* export const ProductPage = ({ productId }) => {
|
|
463
|
+
* const [recs, setRecs] = React.useState();
|
|
464
|
+
* const { fetchRecommendations } = useFetchRecommendations();
|
|
465
|
+
*
|
|
466
|
+
* React.useEffect(() => {
|
|
467
|
+
* fetchRecommendations({ type: "related", productId }).then(setRecs);
|
|
468
|
+
* }, [fetchRecommendations, productId]);
|
|
469
|
+
*
|
|
470
|
+
* return (
|
|
471
|
+
* <div>
|
|
472
|
+
* {recs?.map((display) => (
|
|
473
|
+
* <ProductCard display={display} />
|
|
474
|
+
* ))}
|
|
475
|
+
* </div>
|
|
476
|
+
* );
|
|
477
|
+
* };
|
|
478
|
+
* ```
|
|
479
|
+
* @returns {UseFetchRecommendationsReturn}
|
|
480
|
+
*/
|
|
481
|
+
export function useFetchRecommendations<T extends Display>(): UseFetchRecommendationsReturn<T>;
|
|
482
|
+
/**
|
|
483
|
+
* Helper function to navigate to a new page depending on the navigation library used.
|
|
484
|
+
*/
|
|
485
|
+
export const Navigation: {
|
|
486
|
+
nextRouterNavigation: (router: import("next/router").NextRouter) => (relativeUrl: string) => void;
|
|
487
|
+
};
|
|
488
|
+
export { CategoryTitle, embedded_num_products as EmbeddedNumProducts } from "@depict-ai/ui";
|
|
489
|
+
export type { Locale } from "@depict-ai/ui/locales";
|
package/dist/main.js
CHANGED
|
@@ -31,7 +31,7 @@ $parcel$export(module.exports, "version", () => $db7b67857900028b$export$83d89fb
|
|
|
31
31
|
$parcel$export(module.exports, "Navigation", () => $b742053c966024b4$export$b8a61e5c71402559);
|
|
32
32
|
/*! Depict.ai search and product listing react SDK wrapper */ // This is where the actual source of your React stuff should live
|
|
33
33
|
// Note, if you add an export here, also add one in src-server/main.ts
|
|
34
|
-
const $db7b67857900028b$export$83d89fbfd8236492 = "1.0.
|
|
34
|
+
const $db7b67857900028b$export$83d89fbfd8236492 = "1.0.14";
|
|
35
35
|
|
|
36
36
|
|
|
37
37
|
|
|
@@ -235,9 +235,9 @@ function $6319748b4f0426f0$export$6453cbc34515a94d() {
|
|
|
235
235
|
});
|
|
236
236
|
}));
|
|
237
237
|
}
|
|
238
|
-
/*
|
|
239
|
-
Here we want to be able to add padding that *definitely* gets applied and then be able to revert precisely to what was before.
|
|
240
|
-
The best way to achieve this is using an animation that with the fill set to none. This is because animations have the absolute highest precedence in CSS, even higher than !important. Then, to revert to the old padding, we just play the animation which is 1ms long so, it immediately finishes and whatever was defined before takes precedence again.
|
|
238
|
+
/*
|
|
239
|
+
Here we want to be able to add padding that *definitely* gets applied and then be able to revert precisely to what was before.
|
|
240
|
+
The best way to achieve this is using an animation that with the fill set to none. This is because animations have the absolute highest precedence in CSS, even higher than !important. Then, to revert to the old padding, we just play the animation which is 1ms long so, it immediately finishes and whatever was defined before takes precedence again.
|
|
241
241
|
*/ function $6319748b4f0426f0$var$addLotsOfPadding() {
|
|
242
242
|
if ($6319748b4f0426f0$var$padding_animation) return; // We're already showing a bunch of padding
|
|
243
243
|
$6319748b4f0426f0$var$padding_animation = document.body.animate({
|
package/dist/module.js
CHANGED
|
@@ -11,7 +11,7 @@ import {DPC as $TZSbU$DPC} from "@depict-ai/dpc";
|
|
|
11
11
|
|
|
12
12
|
/*! Depict.ai search and product listing react SDK wrapper */ // This is where the actual source of your React stuff should live
|
|
13
13
|
// Note, if you add an export here, also add one in src-server/main.ts
|
|
14
|
-
const $c9c4d066f9a5b51b$export$83d89fbfd8236492 = "1.0.
|
|
14
|
+
const $c9c4d066f9a5b51b$export$83d89fbfd8236492 = "1.0.14";
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
|
|
@@ -215,9 +215,9 @@ function $8071251ee4e9ffa1$export$6453cbc34515a94d() {
|
|
|
215
215
|
});
|
|
216
216
|
}));
|
|
217
217
|
}
|
|
218
|
-
/*
|
|
219
|
-
Here we want to be able to add padding that *definitely* gets applied and then be able to revert precisely to what was before.
|
|
220
|
-
The best way to achieve this is using an animation that with the fill set to none. This is because animations have the absolute highest precedence in CSS, even higher than !important. Then, to revert to the old padding, we just play the animation which is 1ms long so, it immediately finishes and whatever was defined before takes precedence again.
|
|
218
|
+
/*
|
|
219
|
+
Here we want to be able to add padding that *definitely* gets applied and then be able to revert precisely to what was before.
|
|
220
|
+
The best way to achieve this is using an animation that with the fill set to none. This is because animations have the absolute highest precedence in CSS, even higher than !important. Then, to revert to the old padding, we just play the animation which is 1ms long so, it immediately finishes and whatever was defined before takes precedence again.
|
|
221
221
|
*/ function $8071251ee4e9ffa1$var$addLotsOfPadding() {
|
|
222
222
|
if ($8071251ee4e9ffa1$var$padding_animation) return; // We're already showing a bunch of padding
|
|
223
223
|
$8071251ee4e9ffa1$var$padding_animation = document.body.animate({
|
package/dist-server/index.d.ts
CHANGED
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
import { ReactElement } from "react";
|
|
2
|
-
import { DPC } from "@depict-ai/dpc";
|
|
3
|
-
import { fetchDepictRecommendations, ExclusiveId } from "@depict-ai/ui";
|
|
4
|
-
import { Display } from "@depict-ai/utilishared";
|
|
5
|
-
type OpenModal = () => void;
|
|
6
|
-
interface UseSearchModalReturn {
|
|
7
|
-
open: OpenModal;
|
|
8
|
-
}
|
|
9
|
-
interface UseSearchFieldReturn {
|
|
10
|
-
/**
|
|
11
|
-
* A React component that renders the search field.
|
|
12
|
-
*/
|
|
13
|
-
SearchField: () => ReactElement;
|
|
14
|
-
}
|
|
15
|
-
interface UsePerformanceClientReturn {
|
|
16
|
-
dpc: DPC;
|
|
17
|
-
}
|
|
18
|
-
type FetchRecsOptions = Omit<Parameters<typeof fetchDepictRecommendations>[0], "merchant" | "market" | "userId" | "sessionId"> & ExclusiveId;
|
|
19
|
-
interface UseFetchRecommendationsReturn<T extends Display> {
|
|
20
|
-
/**
|
|
21
|
-
* Fetch recommendations from the Depict API.
|
|
22
|
-
* @example
|
|
23
|
-
* General recommendations for a landing page:
|
|
24
|
-
* ```tsx
|
|
25
|
-
* fetchRecommendations({ type: "landing_page" });
|
|
26
|
-
* ```
|
|
27
|
-
* @example
|
|
28
|
-
* Fetch targeted recommendations for a product details page (PDP):
|
|
29
|
-
* ```tsx
|
|
30
|
-
* fetchRecommendations({ type: "related", productId: "t-shirt-white" })
|
|
31
|
-
* ```
|
|
32
|
-
* @returns {Promise<T[]>}
|
|
33
|
-
*/
|
|
34
|
-
fetchRecommendations: (opts: FetchRecsOptions) => Promise<T[]>;
|
|
35
|
-
}
|
|
36
|
-
export const version = "1.0.
|
|
37
|
-
export function DepictProvider(props: any): any;
|
|
38
|
-
export function SearchPage(): any;
|
|
39
|
-
export function CategoryPage(): any;
|
|
40
|
-
export function BreadCrumbs(): any;
|
|
41
|
-
export function QuickLinks(): any;
|
|
42
|
-
export function ComponentAligner(): import("react").DetailedReactHTMLElement<{
|
|
43
|
-
className: string;
|
|
44
|
-
style: {
|
|
45
|
-
height: string;
|
|
46
|
-
};
|
|
47
|
-
}, HTMLElement>;
|
|
48
|
-
export function ImagePlaceholder(): any;
|
|
49
|
-
export function TextPlaceholder(): any;
|
|
50
|
-
export function useSearchField(): UseSearchFieldReturn;
|
|
51
|
-
export function openModal(): void;
|
|
52
|
-
export function useSearchModal(): UseSearchModalReturn;
|
|
53
|
-
export function usePerformanceClient(): UsePerformanceClientReturn;
|
|
54
|
-
export function useFetchRecommendations<T extends Display>(): UseFetchRecommendationsReturn<T>;
|
|
1
|
+
import { ReactElement } from "react";
|
|
2
|
+
import { DPC } from "@depict-ai/dpc";
|
|
3
|
+
import { fetchDepictRecommendations, ExclusiveId } from "@depict-ai/ui";
|
|
4
|
+
import { Display } from "@depict-ai/utilishared";
|
|
5
|
+
type OpenModal = () => void;
|
|
6
|
+
interface UseSearchModalReturn {
|
|
7
|
+
open: OpenModal;
|
|
8
|
+
}
|
|
9
|
+
interface UseSearchFieldReturn {
|
|
10
|
+
/**
|
|
11
|
+
* A React component that renders the search field.
|
|
12
|
+
*/
|
|
13
|
+
SearchField: () => ReactElement;
|
|
14
|
+
}
|
|
15
|
+
interface UsePerformanceClientReturn {
|
|
16
|
+
dpc: DPC;
|
|
17
|
+
}
|
|
18
|
+
type FetchRecsOptions = Omit<Parameters<typeof fetchDepictRecommendations>[0], "merchant" | "market" | "userId" | "sessionId"> & ExclusiveId;
|
|
19
|
+
interface UseFetchRecommendationsReturn<T extends Display> {
|
|
20
|
+
/**
|
|
21
|
+
* Fetch recommendations from the Depict API.
|
|
22
|
+
* @example
|
|
23
|
+
* General recommendations for a landing page:
|
|
24
|
+
* ```tsx
|
|
25
|
+
* fetchRecommendations({ type: "landing_page" });
|
|
26
|
+
* ```
|
|
27
|
+
* @example
|
|
28
|
+
* Fetch targeted recommendations for a product details page (PDP):
|
|
29
|
+
* ```tsx
|
|
30
|
+
* fetchRecommendations({ type: "related", productId: "t-shirt-white" })
|
|
31
|
+
* ```
|
|
32
|
+
* @returns {Promise<T[]>}
|
|
33
|
+
*/
|
|
34
|
+
fetchRecommendations: (opts: FetchRecsOptions) => Promise<T[]>;
|
|
35
|
+
}
|
|
36
|
+
export const version = "1.0.14";
|
|
37
|
+
export function DepictProvider(props: any): any;
|
|
38
|
+
export function SearchPage(): any;
|
|
39
|
+
export function CategoryPage(): any;
|
|
40
|
+
export function BreadCrumbs(): any;
|
|
41
|
+
export function QuickLinks(): any;
|
|
42
|
+
export function ComponentAligner(): import("react").DetailedReactHTMLElement<{
|
|
43
|
+
className: string;
|
|
44
|
+
style: {
|
|
45
|
+
height: string;
|
|
46
|
+
};
|
|
47
|
+
}, HTMLElement>;
|
|
48
|
+
export function ImagePlaceholder(): any;
|
|
49
|
+
export function TextPlaceholder(): any;
|
|
50
|
+
export function useSearchField(): UseSearchFieldReturn;
|
|
51
|
+
export function openModal(): void;
|
|
52
|
+
export function useSearchModal(): UseSearchModalReturn;
|
|
53
|
+
export function usePerformanceClient(): UsePerformanceClientReturn;
|
|
54
|
+
export function useFetchRecommendations<T extends Display>(): UseFetchRecommendationsReturn<T>;
|
package/dist-server/main.js
CHANGED
|
@@ -21,7 +21,7 @@ $parcel$export(module.exports, "useFetchRecommendations", () => $41e7e5d85b5e0d4
|
|
|
21
21
|
$parcel$export(module.exports, "version", () => $db7b67857900028b$export$83d89fbfd8236492);
|
|
22
22
|
|
|
23
23
|
|
|
24
|
-
const $db7b67857900028b$export$83d89fbfd8236492 = "1.0.
|
|
24
|
+
const $db7b67857900028b$export$83d89fbfd8236492 = "1.0.14";
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
function $41e7e5d85b5e0d49$export$9fac37a9c21c2f3b(props) {
|
package/dist-server/module.js
CHANGED
package/locales/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export type { plp_shared_i18n, search_i18n, category_i18n, Locale } from "@depict-ai/ui/locales";
|
|
2
|
-
export { cz, de, en, da, fi, pl, fr, sv, pt, no, nl, es, it } from "@depict-ai/ui/locales";
|
|
1
|
+
export type { plp_shared_i18n, search_i18n, category_i18n, Locale } from "@depict-ai/ui/locales";
|
|
2
|
+
export { cz, de, en, da, fi, pl, fr, sv, pt, no, nl, es, it } from "@depict-ai/ui/locales";
|
package/locales/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "@depict-ai/ui/locales";
|
|
1
|
+
export * from "@depict-ai/ui/locales";
|
package/locales/require.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
module.exports = require("@depict-ai/ui/locales");
|
|
1
|
+
module.exports = require("@depict-ai/ui/locales");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@depict-ai/react-ui",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.14",
|
|
4
4
|
"packageManager": "yarn@3.2.2",
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -97,10 +97,10 @@
|
|
|
97
97
|
"README.md"
|
|
98
98
|
],
|
|
99
99
|
"dependencies": {
|
|
100
|
-
"@depict-ai/dpc": "^1.0.
|
|
101
|
-
"@depict-ai/plp-styling": "^1.0.
|
|
102
|
-
"@depict-ai/ui": "^1.0.
|
|
103
|
-
"@depict-ai/utilishared": "^1.0.
|
|
100
|
+
"@depict-ai/dpc": "^1.0.14",
|
|
101
|
+
"@depict-ai/plp-styling": "^1.0.15",
|
|
102
|
+
"@depict-ai/ui": "^1.0.17",
|
|
103
|
+
"@depict-ai/utilishared": "^1.0.14",
|
|
104
104
|
"solid-js": "^1.7.3"
|
|
105
105
|
},
|
|
106
106
|
"peerDependencies": {
|
|
@@ -114,7 +114,7 @@
|
|
|
114
114
|
"@babel/preset-typescript": "latest",
|
|
115
115
|
"@babel/runtime": "latest",
|
|
116
116
|
"@babel/runtime-corejs3": "latest",
|
|
117
|
-
"@depict-ai/plp-styling": "^1.0.
|
|
117
|
+
"@depict-ai/plp-styling": "^1.0.15",
|
|
118
118
|
"@jest/globals": "^29.3.1",
|
|
119
119
|
"@parcel/babel-preset-env": "latest",
|
|
120
120
|
"@parcel/resolver-default": "^2.8.0",
|