Repository URL to install this package:
Version:
0.9.6 ▾
|
ui-component-library
/
dist
/
components
/
presets
/
BundleCollection
/
ProductItem
/
renderProps.js
|
---|
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const react_1 = __importDefault(require("react"));
const exotic_1 = require("exotic");
const words_1 = require("src/words");
const Empty_1 = require("atoms/Empty");
const SwatchList_1 = require("presets/SwatchList");
const styled_1 = require("./styled");
function defaultRenderProduct(props) {
const { item, index, productCount } = props;
const { name, brandName, salePrice, regPrice, image, isBundleSubProduct, hasAddon, navigationUrl, } = item;
const value = exotic_1.isSafe(image)
? exotic_1.isSafe(image.value)
? image.value
: undefined
: undefined;
const captionColor = isBundleSubProduct && hasAddon ? '#ea7b0a' : '#195fbf';
const bundleCaption = `${words_1.wording.item} ${index + 1} of ${productCount}`;
const caption = isBundleSubProduct && hasAddon ? words_1.wording.addon : bundleCaption;
const imageView = isBundleSubProduct ? (react_1.default.createElement(styled_1.StyledProductImageWithCaption, { src: value, alt: name, caption: caption, captionColor: captionColor })) : (react_1.default.createElement(styled_1.StyledProductImage, { src: value, alt: name }));
return (react_1.default.createElement(react_1.default.Fragment, null,
react_1.default.createElement(styled_1.ProductNavigationLink, { to: navigationUrl }, imageView),
react_1.default.createElement(styled_1.StyledBrandName, { breedType: "h4", content: brandName }),
react_1.default.createElement(styled_1.ProductNavigationLink, { to: navigationUrl },
react_1.default.createElement(styled_1.StyledProductName, { content: name, breedType: "h2" })),
react_1.default.createElement(styled_1.StyledProductPrice, { saleprice: salePrice, regularprice: regPrice })));
}
exports.defaultRenderProduct = defaultRenderProduct;
function defaultRenderOptions(props) {
// return 'Preset/defaultRenderOptions'
// @example : This renderProp should be overriden for rendering ProductOptions anyway!
return (react_1.default.createElement(SwatchList_1.SwatchList, { list: [
{ isSelected: true, label: 'Regular', value: 'regular' },
{ label: 'Medium', value: 'medium' },
], title: 'Size' }));
}
exports.defaultRenderOptions = defaultRenderOptions;
function defaultRenderDescription(props) {
const { item } = props;
const { description, identifier } = item;
return (react_1.default.createElement(react_1.default.Fragment, null,
react_1.default.createElement(styled_1.StyledHeading, { breedType: "h3", content: words_1.wording.productDetails }),
exotic_1.isSafe(identifier) ? (react_1.default.createElement(styled_1.StyledProductIdentifier, { label: 'Product ID', value: identifier })) : (react_1.default.createElement(Empty_1.Empty, null)),
exotic_1.isSafe(description) ? (react_1.default.createElement(styled_1.StyledProductDescription, { content: description })) : (react_1.default.createElement(Empty_1.Empty, null))));
}
exports.defaultRenderDescription = defaultRenderDescription;
function defaultRenderRating(props) {
const { item, onWriteReviewClick } = props;
const { reviewrating } = item;
const ratings = exotic_1.isSafe(reviewrating)
? exotic_1.isSafe(reviewrating.ratings)
? reviewrating.ratings
: undefined
: undefined;
const reviewcount = exotic_1.isSafe(reviewrating)
? exotic_1.isSafe(reviewrating.reviewcount)
? reviewrating.reviewcount
: undefined
: undefined;
const handleWriteReviewClick = event => {
if (exotic_1.isFunction(onWriteReviewClick)) {
const changeArgs = { event };
onWriteReviewClick(changeArgs);
}
};
return (react_1.default.createElement(react_1.default.Fragment, null,
react_1.default.createElement(styled_1.StyledRatingTitle, null, words_1.wording.rating),
react_1.default.createElement(styled_1.StyledRating, { fillColor: "#000000", defaultColor: "#ffffff", shouldShowCount: true, starRating: ratings, width: 20, starGap: 5, isUserCount: true, userRating: reviewcount }),
react_1.default.createElement(styled_1.StyledWriteReview, { text: words_1.wording.writeReview, onClick: handleWriteReviewClick })));
}
exports.defaultRenderRating = defaultRenderRating;
function defaultRenderQuantity(props) {
const { item, onQuantityInputChange } = props;
const { hasAddon, isBundleSubProduct, isCollectionSubProduct } = item;
const isButton = (isBundleSubProduct && hasAddon) || isCollectionSubProduct;
const handleQuantityInputChange = changeArgs => {
if (exotic_1.isFunction(onQuantityInputChange)) {
onQuantityInputChange(changeArgs);
}
};
const view = isButton && (react_1.default.createElement(react_1.default.Fragment, null,
react_1.default.createElement(styled_1.StyledQuantity, { content: words_1.wording.quantity, defaultValue: 1, onChange: handleQuantityInputChange })));
return view;
}
exports.defaultRenderQuantity = defaultRenderQuantity;
function defaultRenderButton(props) {
const { item, onCheckBoxInputChange, onPrimaryButtonClick, onSecondaryButtonClick, } = props;
const { isCollectionSubProduct, isBundleSubProduct, hasAddon, isBundle, viewBundleUrl, } = item;
const handleCheckboxInputChange = args => {
if (exotic_1.isFunction(onCheckBoxInputChange)) {
const changeArgs = { isSelected: args.isSelected };
onCheckBoxInputChange(changeArgs);
}
};
const handlePrimaryButtonClick = event => {
if (exotic_1.isFunction(onPrimaryButtonClick)) {
const changeArgs = { event };
onPrimaryButtonClick(changeArgs);
}
};
const handleSecondaryButtonClick = event => {
if (exotic_1.isFunction(onSecondaryButtonClick)) {
const changeArgs = { event };
onSecondaryButtonClick(changeArgs);
}
};
if ((isBundleSubProduct && hasAddon) || isCollectionSubProduct) {
const primaryView = isCollectionSubProduct ? (isBundle ? (react_1.default.createElement(styled_1.StyledLink, { text: words_1.wording.viewBundle, to: viewBundleUrl, target: "_top" })) : (react_1.default.createElement(styled_1.PrimaryButton, { breedType: "icon-with-text", iconType: "cart", text: words_1.wording.addToCart, onClick: handlePrimaryButtonClick }))) : (react_1.default.createElement(styled_1.StyledCheckBox, { bgColor: '#159fd5', borderColor: '#a6afc1', tickColor: '#ffffff', iconType: 'checkbox', label: words_1.wording.addItem, onToggle: handleCheckboxInputChange }));
const secondaryView = (react_1.default.createElement(styled_1.SecondaryButton, { breedType: "icon-with-text", iconType: "favourite", text: words_1.wording.saveToLater, onClick: handleSecondaryButtonClick }));
return (react_1.default.createElement(react_1.default.Fragment, null,
primaryView,
secondaryView));
}
else {
return react_1.default.createElement(Empty_1.Empty, null);
}
}
exports.defaultRenderButton = defaultRenderButton;
//# sourceMappingURL=renderProps.js.map