@constructor-io/constructorio-ui-plp 1.4.7 → 1.6.0
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 +1 -1
- package/dist/constructorio-ui-plp-bundled.js +14 -14
- package/lib/cjs/components/ProductCard/ProductCard.css +14 -1
- package/lib/cjs/components/ProductCard/ProductCard.js +52 -19
- package/lib/cjs/components/ProductCard/index.js +0 -1
- package/lib/cjs/components/RenderPropsWrapper/CustomHtmlRender.js +24 -0
- package/lib/cjs/components/RenderPropsWrapper/RenderPropsWrapper.js +15 -0
- package/lib/cjs/constants.js +4 -1
- package/lib/cjs/hooks/useCioPlpProvider.js +3 -1
- package/lib/cjs/hooks/useProduct.js +14 -7
- package/lib/cjs/hooks/useProductSwatch.js +4 -3
- package/lib/cjs/utils/itemFieldGetters.js +8 -2
- package/lib/cjs/version.js +1 -1
- package/lib/mjs/components/ProductCard/ProductCard.css +14 -1
- package/lib/mjs/components/ProductCard/ProductCard.js +50 -19
- package/lib/mjs/components/ProductCard/index.js +0 -1
- package/lib/mjs/components/RenderPropsWrapper/CustomHtmlRender.js +20 -0
- package/lib/mjs/components/RenderPropsWrapper/RenderPropsWrapper.js +11 -0
- package/lib/mjs/constants.js +3 -0
- package/lib/mjs/hooks/useCioPlpProvider.js +3 -1
- package/lib/mjs/hooks/useProduct.js +8 -1
- package/lib/mjs/hooks/useProductSwatch.js +4 -3
- package/lib/mjs/utils/itemFieldGetters.js +6 -1
- package/lib/mjs/version.js +1 -1
- package/lib/types/components/ProductCard/ProductCard.d.ts +1 -37
- package/lib/types/components/ProductCard/index.d.ts +0 -1
- package/lib/types/components/RenderPropsWrapper/CustomHtmlRender.d.ts +7 -0
- package/lib/types/components/RenderPropsWrapper/RenderPropsWrapper.d.ts +25 -0
- package/lib/types/constants.d.ts +3 -0
- package/lib/types/index.d.ts +0 -1
- package/lib/types/types.d.ts +63 -1
- package/lib/types/utils/itemFieldGetters.d.ts +2 -1
- package/lib/types/version.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,42 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
interface Props {
|
|
4
|
-
/**
|
|
5
|
-
* Constructor's Transformed API Item Object.
|
|
6
|
-
*/
|
|
7
|
-
item: Item;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Props that will be passed to the renderProps function
|
|
11
|
-
*/
|
|
12
|
-
export interface ProductCardRenderProps extends ProductCardProps {
|
|
13
|
-
/**
|
|
14
|
-
* Function to format the price. Defaults to "$0.00".
|
|
15
|
-
* Set globally at the CioPlp provider level.
|
|
16
|
-
*/
|
|
17
|
-
formatPrice: (price: number) => string;
|
|
18
|
-
/**
|
|
19
|
-
* Object containing information about the current product, variation
|
|
20
|
-
*/
|
|
21
|
-
productInfo: ProductInfoObject;
|
|
22
|
-
/**
|
|
23
|
-
* Callback to run on add-to-cart event.
|
|
24
|
-
* Set globally at the CioPlp provider level.
|
|
25
|
-
*/
|
|
26
|
-
onAddToCart: (event: React.MouseEvent, item: Item, revenue: number, selectedVariation: string) => void;
|
|
27
|
-
/**
|
|
28
|
-
* Callback to run on Product Card Click.
|
|
29
|
-
* Set globally at the CioPlp provider level.
|
|
30
|
-
*/
|
|
31
|
-
onClick: (event: React.MouseEvent, item: Item) => void;
|
|
32
|
-
/**
|
|
33
|
-
* Data Attributes to surface on parent div of product card.
|
|
34
|
-
*/
|
|
35
|
-
productCardCnstrcDataAttributes: CnstrcData;
|
|
36
|
-
}
|
|
37
|
-
export type ProductCardProps = IncludeRenderProps<Props, ProductCardRenderProps>;
|
|
2
|
+
import { ProductCardProps } from '../../types';
|
|
38
3
|
/**
|
|
39
4
|
* ProductCard component that has Constructor tracking built-in.
|
|
40
5
|
*/
|
|
41
6
|
export default function ProductCard(props: ProductCardProps): React.JSX.Element;
|
|
42
|
-
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
interface CustomHtmlRenderProps<T> {
|
|
3
|
+
renderHtml: (props: T) => HTMLElement | ReactNode;
|
|
4
|
+
topLevelAttributes?: object;
|
|
5
|
+
}
|
|
6
|
+
export default function CustomHtmlRender<T>(props: T & CustomHtmlRenderProps<T>): React.JSX.Element | null;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
import { RenderPropsChildren } from '../../types';
|
|
3
|
+
export interface ReactPropsWrapperProps<T> {
|
|
4
|
+
/**
|
|
5
|
+
* The props to be passed to the render props function provided
|
|
6
|
+
*/
|
|
7
|
+
props: T;
|
|
8
|
+
/**
|
|
9
|
+
* The default implementation to be nested within the wrapper
|
|
10
|
+
*/
|
|
11
|
+
children: ReactNode;
|
|
12
|
+
/**
|
|
13
|
+
* One of Function<T> | JSX. Overrides default implementation
|
|
14
|
+
*/
|
|
15
|
+
override?: RenderPropsChildren<T>;
|
|
16
|
+
/**
|
|
17
|
+
* One of Function<T> -> HTMLElement. Overrides default implementation
|
|
18
|
+
*/
|
|
19
|
+
htmlOverride?: (props: T) => HTMLElement | ReactNode;
|
|
20
|
+
/**
|
|
21
|
+
* Object containing the attributes to be spread on the top-level div. To be used with `htmlOverride`
|
|
22
|
+
*/
|
|
23
|
+
topLevelAttributes?: object;
|
|
24
|
+
}
|
|
25
|
+
export default function RenderPropsWrapper<T>({ props, children, override, htmlOverride, topLevelAttributes, }: ReactPropsWrapperProps<T>): React.JSX.Element;
|
package/lib/types/constants.d.ts
CHANGED
package/lib/types/index.d.ts
CHANGED
|
@@ -28,7 +28,6 @@ export type { FiltersProps, FiltersWithRenderProps } from './components/Filters'
|
|
|
28
28
|
export type { GroupsProps, GroupsWithRenderProps } from './components/Groups';
|
|
29
29
|
export type { MobileModalProps } from './components/MobileModal';
|
|
30
30
|
export type { PaginationProps, PaginationWithRenderProps } from './components/Pagination';
|
|
31
|
-
export type { ProductCardProps } from './components/ProductCard';
|
|
32
31
|
export type { ProductSwatchProps } from './components/ProductSwatch';
|
|
33
32
|
export type { SortProps, SortWithRenderProps } from './components/Sort';
|
|
34
33
|
export type { UseOptionsListProps } from './hooks/useOptionsList';
|
package/lib/types/types.d.ts
CHANGED
|
@@ -13,8 +13,9 @@ export type CioClientOptions = Omit<ConstructorClientOptions, 'apiKey' | 'sendTr
|
|
|
13
13
|
export interface ItemFieldGetters {
|
|
14
14
|
getPrice: (item: Item | Variation) => number;
|
|
15
15
|
getSalePrice: (item: Item | Variation) => number | undefined;
|
|
16
|
+
getRolloverImage: (item: Item | Variation) => string | undefined;
|
|
16
17
|
getSwatchPreview: (variation: Variation) => string;
|
|
17
|
-
getSwatches: (item: Item, retrievePrice: ItemFieldGetters['getPrice'], retrieveSwatchPreview: ItemFieldGetters['getSwatchPreview'], retrieveSalePrice: ItemFieldGetters['getSalePrice']) => SwatchItem[] | undefined;
|
|
18
|
+
getSwatches: (item: Item, retrievePrice: ItemFieldGetters['getPrice'], retrieveSwatchPreview: ItemFieldGetters['getSwatchPreview'], retrieveSalePrice: ItemFieldGetters['getSalePrice'], retrieveRolloverImage: ItemFieldGetters['getRolloverImage']) => SwatchItem[] | undefined;
|
|
18
19
|
}
|
|
19
20
|
export interface Formatters {
|
|
20
21
|
formatPrice: (price?: number) => string;
|
|
@@ -22,9 +23,65 @@ export interface Formatters {
|
|
|
22
23
|
export interface Callbacks {
|
|
23
24
|
onAddToCart?: (event: React.MouseEvent, item: Item, selectedVariation?: Variation) => void;
|
|
24
25
|
onProductCardClick?: (event: React.MouseEvent, item: Item) => void;
|
|
26
|
+
onProductCardMouseEnter?: (event: React.MouseEvent, item: Item) => void;
|
|
27
|
+
onProductCardMouseLeave?: (event: React.MouseEvent, item: Item) => void;
|
|
25
28
|
onSwatchClick?: (event: React.MouseEvent, swatch: SwatchItem) => void;
|
|
26
29
|
onRedirect?: (url: string) => void;
|
|
27
30
|
}
|
|
31
|
+
interface ProductCardBaseProps {
|
|
32
|
+
/**
|
|
33
|
+
* Constructor's Transformed API Item Object.
|
|
34
|
+
*/
|
|
35
|
+
item: Item;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Props that will be passed to the renderProps function
|
|
39
|
+
*/
|
|
40
|
+
export interface ProductCardRenderProps extends ProductCardProps {
|
|
41
|
+
/**
|
|
42
|
+
* Function to format the price. Defaults to "$0.00".
|
|
43
|
+
* Set globally at the CioPlp provider level.
|
|
44
|
+
*/
|
|
45
|
+
formatPrice: (price: number) => string;
|
|
46
|
+
/**
|
|
47
|
+
* Object containing information about the current product, variation
|
|
48
|
+
*/
|
|
49
|
+
productInfo: ProductInfoObject;
|
|
50
|
+
/**
|
|
51
|
+
* Callback to run on add-to-cart event.
|
|
52
|
+
* Set globally at the CioPlp provider level.
|
|
53
|
+
*/
|
|
54
|
+
onAddToCart: (event: React.MouseEvent, item: Item, revenue: number, selectedVariation: string) => void;
|
|
55
|
+
/**
|
|
56
|
+
* Callback to run on Product Card Click.
|
|
57
|
+
* Set globally at the CioPlp provider level.
|
|
58
|
+
*/
|
|
59
|
+
onClick: (event: React.MouseEvent, item: Item) => void;
|
|
60
|
+
/**
|
|
61
|
+
* Callback to run on Product Card Mouse Enter.
|
|
62
|
+
* Set globally at the CioPlp provider level.
|
|
63
|
+
*/
|
|
64
|
+
onMouseEnter: (event: React.MouseEvent, item: Item) => void;
|
|
65
|
+
/**
|
|
66
|
+
* Callback to run on Product Card Mouse Leave.
|
|
67
|
+
* Set globally at the CioPlp provider level.
|
|
68
|
+
*/
|
|
69
|
+
onMouseLeave: (event: React.MouseEvent, item: Item) => void;
|
|
70
|
+
/**
|
|
71
|
+
* Boolean to show/hide the rollover image.
|
|
72
|
+
*/
|
|
73
|
+
isRolloverImageShown: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Data Attributes to surface on parent div of product card.
|
|
76
|
+
*/
|
|
77
|
+
productCardCnstrcDataAttributes: CnstrcData;
|
|
78
|
+
}
|
|
79
|
+
export type ProductCardProps = IncludeRenderProps<ProductCardBaseProps, ProductCardRenderProps>;
|
|
80
|
+
export interface RenderOverrides {
|
|
81
|
+
productCard?: {
|
|
82
|
+
renderHtml?: (props: ProductCardRenderProps) => HTMLElement | ReactNode;
|
|
83
|
+
};
|
|
84
|
+
}
|
|
28
85
|
export type PlpSearchData = PlpSearchDataResults | PlpSearchDataRedirect;
|
|
29
86
|
export interface PlpSearchDataResults {
|
|
30
87
|
resultId: string;
|
|
@@ -93,6 +150,7 @@ export interface PlpContextValue {
|
|
|
93
150
|
formatters: Formatters;
|
|
94
151
|
callbacks: Callbacks;
|
|
95
152
|
urlHelpers: UrlHelpers;
|
|
153
|
+
renderOverrides: RenderOverrides;
|
|
96
154
|
}
|
|
97
155
|
export interface PrimaryColorStyles {
|
|
98
156
|
'--primary-color-h': string;
|
|
@@ -134,6 +192,7 @@ export interface SwatchItem {
|
|
|
134
192
|
salePrice?: number;
|
|
135
193
|
swatchPreview: string;
|
|
136
194
|
variationId?: string;
|
|
195
|
+
rolloverImage?: string;
|
|
137
196
|
}
|
|
138
197
|
export interface PlpBrowseData {
|
|
139
198
|
resultId: string;
|
|
@@ -150,6 +209,7 @@ export interface CioPlpProviderProps {
|
|
|
150
209
|
formatters?: Partial<Formatters>;
|
|
151
210
|
callbacks?: Partial<Callbacks>;
|
|
152
211
|
itemFieldGetters?: Partial<ItemFieldGetters>;
|
|
212
|
+
renderOverrides?: Partial<RenderOverrides>;
|
|
153
213
|
urlHelpers?: Partial<UrlHelpers>;
|
|
154
214
|
initialSearchResponse?: SearchResponse;
|
|
155
215
|
initialBrowseResponse?: GetBrowseResultsResponse;
|
|
@@ -178,6 +238,7 @@ export interface ProductInfoObject {
|
|
|
178
238
|
itemUrl?: string;
|
|
179
239
|
itemImageUrl?: string;
|
|
180
240
|
variationId?: string;
|
|
241
|
+
rolloverImage?: string;
|
|
181
242
|
hasSalePrice?: boolean;
|
|
182
243
|
}
|
|
183
244
|
export type UseProductInfoProps = {
|
|
@@ -237,6 +298,7 @@ export type CnstrcData = Record<`data-cnstrc-${string}`, string | number | boole
|
|
|
237
298
|
export type PropsWithChildren<P> = P & {
|
|
238
299
|
children?: ReactNode;
|
|
239
300
|
};
|
|
301
|
+
export type RenderPropsChildren<RenderProps> = ((props: RenderProps) => ReactNode) | ReactNode;
|
|
240
302
|
/**
|
|
241
303
|
* Composes a type for a Component that accepts
|
|
242
304
|
* - Props P,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ItemFieldGetters, Item, SwatchItem, Variation } from '../types';
|
|
2
2
|
export declare function getPrice(item: Item | Variation): number;
|
|
3
3
|
export declare function getSalePrice(item: Item | Variation): number | undefined;
|
|
4
|
-
export declare function
|
|
4
|
+
export declare function getRolloverImage(item: Item | Variation): string | undefined;
|
|
5
|
+
export declare function getSwatches(item: Item, retrievePrice: ItemFieldGetters['getPrice'], retrieveSwatchPreview: ItemFieldGetters['getSwatchPreview'], retrieveSalePrice: ItemFieldGetters['getSalePrice'], retrieveRolloverImage: ItemFieldGetters['getRolloverImage']): SwatchItem[] | undefined;
|
|
5
6
|
export declare function getSwatchPreview(variation: Variation): string;
|
package/lib/types/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "1.
|
|
1
|
+
declare const _default: "1.6.0";
|
|
2
2
|
export default _default;
|