@constructor-io/constructorio-ui-plp 1.5.0 → 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/dist/constructorio-ui-plp-bundled.js +11 -11
- package/lib/cjs/components/ProductCard/ProductCard.js +24 -21
- 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/hooks/useCioPlpProvider.js +3 -1
- package/lib/cjs/version.js +1 -1
- package/lib/mjs/components/ProductCard/ProductCard.js +23 -21
- 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/hooks/useCioPlpProvider.js +3 -1
- package/lib/mjs/version.js +1 -1
- package/lib/types/components/ProductCard/ProductCard.d.ts +1 -51
- 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/index.d.ts +0 -1
- package/lib/types/types.d.ts +57 -0
- package/lib/types/version.d.ts +1 -1
- package/package.json +1 -1
|
@@ -7,11 +7,13 @@ const callbacks_1 = require("../../hooks/callbacks");
|
|
|
7
7
|
const ProductSwatch_1 = tslib_1.__importDefault(require("../ProductSwatch"));
|
|
8
8
|
const useProduct_1 = tslib_1.__importDefault(require("../../hooks/useProduct"));
|
|
9
9
|
const utils_1 = require("../../utils");
|
|
10
|
+
const RenderPropsWrapper_1 = tslib_1.__importDefault(require("../RenderPropsWrapper/RenderPropsWrapper"));
|
|
10
11
|
const constants_1 = require("../../constants");
|
|
11
12
|
/**
|
|
12
13
|
* ProductCard component that has Constructor tracking built-in.
|
|
13
14
|
*/
|
|
14
15
|
function ProductCard(props) {
|
|
16
|
+
var _a;
|
|
15
17
|
const [isRolloverImageShown, setIsRolloverImageShown] = (0, react_1.useState)(false);
|
|
16
18
|
const cardRef = (0, react_1.useRef)(null);
|
|
17
19
|
const { item, children } = props;
|
|
@@ -52,26 +54,27 @@ function ProductCard(props) {
|
|
|
52
54
|
}
|
|
53
55
|
handleRolloverImageState(false);
|
|
54
56
|
};
|
|
55
|
-
return (react_1.default.createElement(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
react_1.default.createElement("
|
|
67
|
-
react_1.default.createElement("
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
react_1.default.createElement("div", { className: 'cio-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
57
|
+
return (react_1.default.createElement(RenderPropsWrapper_1.default, { props: {
|
|
58
|
+
item,
|
|
59
|
+
productInfo,
|
|
60
|
+
formatPrice,
|
|
61
|
+
onAddToCart,
|
|
62
|
+
onClick,
|
|
63
|
+
onMouseEnter,
|
|
64
|
+
onMouseLeave,
|
|
65
|
+
isRolloverImageShown,
|
|
66
|
+
productCardCnstrcDataAttributes: cnstrcData,
|
|
67
|
+
}, override: children, htmlOverride: (_a = state.renderOverrides.productCard) === null || _a === void 0 ? void 0 : _a.renderHtml, topLevelAttributes: Object.assign(Object.assign({}, cnstrcData), { className: 'cio-product-card' }) },
|
|
68
|
+
react_1.default.createElement("a", Object.assign({}, cnstrcData, { className: 'cio-product-card', href: itemUrl, ref: cardRef, onClick: (e) => { var _a; return onClick(e, item, (_a = productSwatch === null || productSwatch === void 0 ? void 0 : productSwatch.selectedVariation) === null || _a === void 0 ? void 0 : _a.variationId); } }),
|
|
69
|
+
react_1.default.createElement("div", { className: 'cio-image-container', onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave },
|
|
70
|
+
react_1.default.createElement("img", { alt: itemName, src: itemImageUrl, className: 'cio-image' }),
|
|
71
|
+
rolloverImage && (react_1.default.createElement("img", { alt: `${itemName} rollover`, src: rolloverImage, loading: 'lazy', className: (0, utils_1.concatStyles)('cio-image cio-rollover-image', isRolloverImageShown && 'is-active') }))),
|
|
72
|
+
react_1.default.createElement("div", { className: 'cio-content' },
|
|
73
|
+
react_1.default.createElement("div", { className: 'cio-item-prices-container' },
|
|
74
|
+
hasSalePrice && (react_1.default.createElement("div", { className: 'cio-item-price', id: 'cio-sale-price' }, formatPrice(salePrice))),
|
|
75
|
+
Number(itemPrice) >= 0 && (react_1.default.createElement("div", { className: (0, utils_1.concatStyles)('cio-item-price', hasSalePrice && 'cio-item-price-strikethrough') }, formatPrice(itemPrice)))),
|
|
76
|
+
react_1.default.createElement("div", { className: 'cio-item-name' }, itemName),
|
|
77
|
+
productSwatch && react_1.default.createElement(ProductSwatch_1.default, { swatchObject: productSwatch })),
|
|
78
|
+
react_1.default.createElement("button", { className: 'cio-add-to-cart-button', type: 'button', onClick: (e) => { var _a; return onAddToCart(e, item, itemPrice, (_a = productSwatch === null || productSwatch === void 0 ? void 0 : productSwatch.selectedVariation) === null || _a === void 0 ? void 0 : _a.variationId); } }, "Add to Cart"))));
|
|
76
79
|
}
|
|
77
80
|
exports.default = ProductCard;
|
|
@@ -2,5 +2,4 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const ProductCard_1 = tslib_1.__importDefault(require("./ProductCard"));
|
|
5
|
-
tslib_1.__exportStar(require("./ProductCard"), exports);
|
|
6
5
|
exports.default = ProductCard_1.default;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const react_1 = tslib_1.__importStar(require("react"));
|
|
5
|
+
function CustomHtmlRender(props) {
|
|
6
|
+
const { renderHtml, topLevelAttributes = {} } = props, otherProps = tslib_1.__rest(props, ["renderHtml", "topLevelAttributes"]);
|
|
7
|
+
const ref = (0, react_1.useRef)(null);
|
|
8
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
9
|
+
const customElement = renderHtml(otherProps);
|
|
10
|
+
const isDomElement = customElement instanceof HTMLElement;
|
|
11
|
+
const isReactNode = (0, react_1.isValidElement)(customElement);
|
|
12
|
+
if (isDomElement && ref.current) {
|
|
13
|
+
ref.current.innerHTML = ''; // Clear previous content
|
|
14
|
+
ref.current.appendChild(customElement);
|
|
15
|
+
}
|
|
16
|
+
if (isReactNode) {
|
|
17
|
+
return customElement;
|
|
18
|
+
}
|
|
19
|
+
if (isDomElement) {
|
|
20
|
+
return react_1.default.createElement("div", Object.assign({}, topLevelAttributes, { ref: ref }));
|
|
21
|
+
}
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
exports.default = CustomHtmlRender;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
/* eslint-disable no-nested-ternary */
|
|
5
|
+
const react_1 = tslib_1.__importDefault(require("react"));
|
|
6
|
+
const CustomHtmlRender_1 = tslib_1.__importDefault(require("./CustomHtmlRender"));
|
|
7
|
+
function RenderPropsWrapper({ props, children, override, htmlOverride, topLevelAttributes, }) {
|
|
8
|
+
const isRenderProps = typeof override === 'function';
|
|
9
|
+
const isJSX = typeof override === 'object';
|
|
10
|
+
const isHtmlOverride = typeof htmlOverride === 'function';
|
|
11
|
+
return (react_1.default.createElement(react_1.default.Fragment, null, isRenderProps ? (override(props)) : isJSX ? (override) : isHtmlOverride ? (react_1.default.createElement(CustomHtmlRender_1.default, Object.assign({}, props, { renderHtml: htmlOverride, topLevelAttributes: topLevelAttributes }))) : (
|
|
12
|
+
// Default implementation
|
|
13
|
+
children)));
|
|
14
|
+
}
|
|
15
|
+
exports.default = RenderPropsWrapper;
|
|
@@ -7,7 +7,7 @@ const defaultGetters = tslib_1.__importStar(require("../utils/itemFieldGetters")
|
|
|
7
7
|
const defaultFormatters = tslib_1.__importStar(require("../utils/formatters"));
|
|
8
8
|
const defaultUrlHelpers = tslib_1.__importStar(require("../utils/urlHelpers"));
|
|
9
9
|
function useCioPlpProvider(props) {
|
|
10
|
-
const { apiKey, formatters, callbacks, itemFieldGetters, urlHelpers, staticRequestConfigs = {}, cioClient: customCioClient, cioClientOptions: customCioClientOptions = {}, } = props;
|
|
10
|
+
const { apiKey, formatters, callbacks, itemFieldGetters, urlHelpers, staticRequestConfigs = {}, renderOverrides = {}, cioClient: customCioClient, cioClientOptions: customCioClientOptions = {}, } = props;
|
|
11
11
|
const [cioClientOptions, setCioClientOptions] = (0, react_1.useState)(customCioClientOptions);
|
|
12
12
|
const cioClient = (0, useCioClient_1.default)({ apiKey, cioClient: customCioClient, options: cioClientOptions });
|
|
13
13
|
const contextValue = (0, react_1.useMemo)(() => ({
|
|
@@ -19,6 +19,7 @@ function useCioPlpProvider(props) {
|
|
|
19
19
|
formatters: Object.assign(Object.assign({}, defaultFormatters), formatters),
|
|
20
20
|
callbacks: Object.assign({}, callbacks),
|
|
21
21
|
urlHelpers: Object.assign(Object.assign({}, defaultUrlHelpers), urlHelpers),
|
|
22
|
+
renderOverrides: Object.assign({}, renderOverrides),
|
|
22
23
|
}), [
|
|
23
24
|
cioClient,
|
|
24
25
|
cioClientOptions,
|
|
@@ -26,6 +27,7 @@ function useCioPlpProvider(props) {
|
|
|
26
27
|
formatters,
|
|
27
28
|
callbacks,
|
|
28
29
|
urlHelpers,
|
|
30
|
+
renderOverrides,
|
|
29
31
|
staticRequestConfigs,
|
|
30
32
|
]);
|
|
31
33
|
return contextValue;
|
package/lib/cjs/version.js
CHANGED
|
@@ -4,6 +4,7 @@ import { useOnAddToCart, useOnProductCardClick } from '../../hooks/callbacks';
|
|
|
4
4
|
import ProductSwatch from '../ProductSwatch';
|
|
5
5
|
import useProductInfo from '../../hooks/useProduct';
|
|
6
6
|
import { concatStyles, getProductCardCnstrcDataAttributes } from '../../utils';
|
|
7
|
+
import RenderPropsWrapper from '../RenderPropsWrapper/RenderPropsWrapper';
|
|
7
8
|
import { EMITTED_EVENTS } from '../../constants';
|
|
8
9
|
/**
|
|
9
10
|
* ProductCard component that has Constructor tracking built-in.
|
|
@@ -48,25 +49,26 @@ export default function ProductCard(props) {
|
|
|
48
49
|
}
|
|
49
50
|
handleRolloverImageState(false);
|
|
50
51
|
};
|
|
51
|
-
return (React.createElement(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
React.createElement("
|
|
63
|
-
React.createElement("
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
React.createElement("div", { className: 'cio-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
52
|
+
return (React.createElement(RenderPropsWrapper, { props: {
|
|
53
|
+
item,
|
|
54
|
+
productInfo,
|
|
55
|
+
formatPrice,
|
|
56
|
+
onAddToCart,
|
|
57
|
+
onClick,
|
|
58
|
+
onMouseEnter,
|
|
59
|
+
onMouseLeave,
|
|
60
|
+
isRolloverImageShown,
|
|
61
|
+
productCardCnstrcDataAttributes: cnstrcData,
|
|
62
|
+
}, override: children, htmlOverride: state.renderOverrides.productCard?.renderHtml, topLevelAttributes: { ...cnstrcData, className: 'cio-product-card' } },
|
|
63
|
+
React.createElement("a", { ...cnstrcData, className: 'cio-product-card', href: itemUrl, ref: cardRef, onClick: (e) => onClick(e, item, productSwatch?.selectedVariation?.variationId) },
|
|
64
|
+
React.createElement("div", { className: 'cio-image-container', onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave },
|
|
65
|
+
React.createElement("img", { alt: itemName, src: itemImageUrl, className: 'cio-image' }),
|
|
66
|
+
rolloverImage && (React.createElement("img", { alt: `${itemName} rollover`, src: rolloverImage, loading: 'lazy', className: concatStyles('cio-image cio-rollover-image', isRolloverImageShown && 'is-active') }))),
|
|
67
|
+
React.createElement("div", { className: 'cio-content' },
|
|
68
|
+
React.createElement("div", { className: 'cio-item-prices-container' },
|
|
69
|
+
hasSalePrice && (React.createElement("div", { className: 'cio-item-price', id: 'cio-sale-price' }, formatPrice(salePrice))),
|
|
70
|
+
Number(itemPrice) >= 0 && (React.createElement("div", { className: concatStyles('cio-item-price', hasSalePrice && 'cio-item-price-strikethrough') }, formatPrice(itemPrice)))),
|
|
71
|
+
React.createElement("div", { className: 'cio-item-name' }, itemName),
|
|
72
|
+
productSwatch && React.createElement(ProductSwatch, { swatchObject: productSwatch })),
|
|
73
|
+
React.createElement("button", { className: 'cio-add-to-cart-button', type: 'button', onClick: (e) => onAddToCart(e, item, itemPrice, productSwatch?.selectedVariation?.variationId) }, "Add to Cart"))));
|
|
72
74
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React, { useRef, isValidElement } from 'react';
|
|
2
|
+
export default function CustomHtmlRender(props) {
|
|
3
|
+
const { renderHtml, topLevelAttributes = {}, ...otherProps } = props;
|
|
4
|
+
const ref = useRef(null);
|
|
5
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
6
|
+
const customElement = renderHtml(otherProps);
|
|
7
|
+
const isDomElement = customElement instanceof HTMLElement;
|
|
8
|
+
const isReactNode = isValidElement(customElement);
|
|
9
|
+
if (isDomElement && ref.current) {
|
|
10
|
+
ref.current.innerHTML = ''; // Clear previous content
|
|
11
|
+
ref.current.appendChild(customElement);
|
|
12
|
+
}
|
|
13
|
+
if (isReactNode) {
|
|
14
|
+
return customElement;
|
|
15
|
+
}
|
|
16
|
+
if (isDomElement) {
|
|
17
|
+
return React.createElement("div", { ...topLevelAttributes, ref: ref });
|
|
18
|
+
}
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/* eslint-disable no-nested-ternary */
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import CustomHtmlRender from './CustomHtmlRender';
|
|
4
|
+
export default function RenderPropsWrapper({ props, children, override, htmlOverride, topLevelAttributes, }) {
|
|
5
|
+
const isRenderProps = typeof override === 'function';
|
|
6
|
+
const isJSX = typeof override === 'object';
|
|
7
|
+
const isHtmlOverride = typeof htmlOverride === 'function';
|
|
8
|
+
return (React.createElement(React.Fragment, null, isRenderProps ? (override(props)) : isJSX ? (override) : isHtmlOverride ? (React.createElement(CustomHtmlRender, { ...props, renderHtml: htmlOverride, topLevelAttributes: topLevelAttributes })) : (
|
|
9
|
+
// Default implementation
|
|
10
|
+
children)));
|
|
11
|
+
}
|
|
@@ -4,7 +4,7 @@ import * as defaultGetters from '../utils/itemFieldGetters';
|
|
|
4
4
|
import * as defaultFormatters from '../utils/formatters';
|
|
5
5
|
import * as defaultUrlHelpers from '../utils/urlHelpers';
|
|
6
6
|
export default function useCioPlpProvider(props) {
|
|
7
|
-
const { apiKey, formatters, callbacks, itemFieldGetters, urlHelpers, staticRequestConfigs = {}, cioClient: customCioClient, cioClientOptions: customCioClientOptions = {}, } = props;
|
|
7
|
+
const { apiKey, formatters, callbacks, itemFieldGetters, urlHelpers, staticRequestConfigs = {}, renderOverrides = {}, cioClient: customCioClient, cioClientOptions: customCioClientOptions = {}, } = props;
|
|
8
8
|
const [cioClientOptions, setCioClientOptions] = useState(customCioClientOptions);
|
|
9
9
|
const cioClient = useCioClient({ apiKey, cioClient: customCioClient, options: cioClientOptions });
|
|
10
10
|
const contextValue = useMemo(() => ({
|
|
@@ -16,6 +16,7 @@ export default function useCioPlpProvider(props) {
|
|
|
16
16
|
formatters: { ...defaultFormatters, ...formatters },
|
|
17
17
|
callbacks: { ...callbacks },
|
|
18
18
|
urlHelpers: { ...defaultUrlHelpers, ...urlHelpers },
|
|
19
|
+
renderOverrides: { ...renderOverrides },
|
|
19
20
|
}), [
|
|
20
21
|
cioClient,
|
|
21
22
|
cioClientOptions,
|
|
@@ -23,6 +24,7 @@ export default function useCioPlpProvider(props) {
|
|
|
23
24
|
formatters,
|
|
24
25
|
callbacks,
|
|
25
26
|
urlHelpers,
|
|
27
|
+
renderOverrides,
|
|
26
28
|
staticRequestConfigs,
|
|
27
29
|
]);
|
|
28
30
|
return contextValue;
|
package/lib/mjs/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '1.
|
|
1
|
+
export default '1.6.0';
|
|
@@ -1,56 +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
|
-
* Callback to run on Product Card Mouse Enter.
|
|
34
|
-
* Set globally at the CioPlp provider level.
|
|
35
|
-
*/
|
|
36
|
-
onMouseEnter: (event: React.MouseEvent, item: Item) => void;
|
|
37
|
-
/**
|
|
38
|
-
* Callback to run on Product Card Mouse Leave.
|
|
39
|
-
* Set globally at the CioPlp provider level.
|
|
40
|
-
*/
|
|
41
|
-
onMouseLeave: (event: React.MouseEvent, item: Item) => void;
|
|
42
|
-
/**
|
|
43
|
-
* Boolean to show/hide the rollover image.
|
|
44
|
-
*/
|
|
45
|
-
isRolloverImageShown: boolean;
|
|
46
|
-
/**
|
|
47
|
-
* Data Attributes to surface on parent div of product card.
|
|
48
|
-
*/
|
|
49
|
-
productCardCnstrcDataAttributes: CnstrcData;
|
|
50
|
-
}
|
|
51
|
-
export type ProductCardProps = IncludeRenderProps<Props, ProductCardRenderProps>;
|
|
2
|
+
import { ProductCardProps } from '../../types';
|
|
52
3
|
/**
|
|
53
4
|
* ProductCard component that has Constructor tracking built-in.
|
|
54
5
|
*/
|
|
55
6
|
export default function ProductCard(props: ProductCardProps): React.JSX.Element;
|
|
56
|
-
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/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
|
@@ -28,6 +28,60 @@ export interface Callbacks {
|
|
|
28
28
|
onSwatchClick?: (event: React.MouseEvent, swatch: SwatchItem) => void;
|
|
29
29
|
onRedirect?: (url: string) => void;
|
|
30
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
|
+
}
|
|
31
85
|
export type PlpSearchData = PlpSearchDataResults | PlpSearchDataRedirect;
|
|
32
86
|
export interface PlpSearchDataResults {
|
|
33
87
|
resultId: string;
|
|
@@ -96,6 +150,7 @@ export interface PlpContextValue {
|
|
|
96
150
|
formatters: Formatters;
|
|
97
151
|
callbacks: Callbacks;
|
|
98
152
|
urlHelpers: UrlHelpers;
|
|
153
|
+
renderOverrides: RenderOverrides;
|
|
99
154
|
}
|
|
100
155
|
export interface PrimaryColorStyles {
|
|
101
156
|
'--primary-color-h': string;
|
|
@@ -154,6 +209,7 @@ export interface CioPlpProviderProps {
|
|
|
154
209
|
formatters?: Partial<Formatters>;
|
|
155
210
|
callbacks?: Partial<Callbacks>;
|
|
156
211
|
itemFieldGetters?: Partial<ItemFieldGetters>;
|
|
212
|
+
renderOverrides?: Partial<RenderOverrides>;
|
|
157
213
|
urlHelpers?: Partial<UrlHelpers>;
|
|
158
214
|
initialSearchResponse?: SearchResponse;
|
|
159
215
|
initialBrowseResponse?: GetBrowseResultsResponse;
|
|
@@ -242,6 +298,7 @@ export type CnstrcData = Record<`data-cnstrc-${string}`, string | number | boole
|
|
|
242
298
|
export type PropsWithChildren<P> = P & {
|
|
243
299
|
children?: ReactNode;
|
|
244
300
|
};
|
|
301
|
+
export type RenderPropsChildren<RenderProps> = ((props: RenderProps) => ReactNode) | ReactNode;
|
|
245
302
|
/**
|
|
246
303
|
* Composes a type for a Component that accepts
|
|
247
304
|
* - Props P,
|
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;
|