@shopgate/engage
Version:
Shopgate's ENGAGE library.
71 lines (70 loc) • 2.08 kB
JavaScript
import "core-js/modules/es.regexp.flags.js";
import React from 'react';
import PropTypes from 'prop-types';
import { ITEMS_PER_LOAD } from '@shopgate/pwa-common/constants/DisplayOptions';
import InfiniteContainer from '@shopgate/pwa-common/components/InfiniteContainer';
import LoadingIndicator from '@shopgate/pwa-ui-shared/LoadingIndicator';
import { ViewContext } from '@shopgate/engage/components/View';
import { ProductListTypeProvider } from '@shopgate/engage/product';
import Iterator from "./components/Iterator";
import Layout from "./components/Layout";
/**
* The Product List component.
* @param {Object} props The component props.
* @returns {JSX}
*/
import { jsx as _jsx } from "react/jsx-runtime";
const ProductList = ({
flags,
infiniteLoad,
handleGetProducts,
products,
totalProductCount,
requestHash,
scope
}) => {
if (!infiniteLoad) {
return /*#__PURE__*/_jsx(Layout, {
children: /*#__PURE__*/_jsx(ProductListTypeProvider, {
type: "productList",
subType: scope,
children: products.map(product => /*#__PURE__*/_jsx(Iterator, {
display: flags,
id: product.id,
...product
}, product.id))
})
});
}
return /*#__PURE__*/_jsx(ViewContext.Consumer, {
children: ({
getContentRef
}) => /*#__PURE__*/_jsx(ProductListTypeProvider, {
type: "productList",
subType: scope,
children: /*#__PURE__*/_jsx(InfiniteContainer, {
containerRef: getContentRef(),
wrapper: Layout,
iterator: Iterator,
loader: handleGetProducts,
items: products,
loadingIndicator: /*#__PURE__*/_jsx(LoadingIndicator, {}),
totalItems: totalProductCount,
initialLimit: 10,
limit: ITEMS_PER_LOAD,
requestHash: requestHash,
enablePromiseBasedLoading: true
})
})
});
};
ProductList.defaultProps = {
flags: null,
handleGetProducts: () => {},
infiniteLoad: true,
products: null,
requestHash: null,
totalProductCount: null,
scope: null
};
export default ProductList;