Repository URL to install this package:
|
Version:
2.1.16 ▾
|
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importDefault(require("react"));
const utils_1 = require("@skava/utils");
const exotic_1 = require("exotic");
const Empty_1 = tslib_1.__importDefault(require("@skava/ui/dist/components/atoms/Empty"));
const deps_1 = require("../deps");
const styled_1 = require("./styled");
function defaultRenderImage(props) {
const {
imageUrl,
productTitle
} = props;
const placeholderImageUrl = 'https://raderain.sirv.com/placholders/image_icon.png';
const productImageUrl = exotic_1.fromIshToString(imageUrl);
const validProductImageUrl = utils_1.toUrlWithProtocol(productImageUrl) || placeholderImageUrl;
return react_1.default.createElement(styled_1.ProductImage, {
src: validProductImageUrl,
alt: productTitle
});
}
exports.defaultRenderImage = defaultRenderImage;
function defaultRenderBrandName(props) {
const {
brandName
} = props;
const validBrandName = exotic_1.fromIshToString(brandName);
return react_1.default.createElement(styled_1.ProductBrand, {
content: validBrandName
});
}
exports.defaultRenderBrandName = defaultRenderBrandName;
function defaultRenderDescription(props) {
const {
productDescription
} = props;
const validProductDescription = exotic_1.fromIshToString(productDescription);
return react_1.default.createElement(styled_1.ProductDescription, {
content: validProductDescription
});
}
exports.defaultRenderDescription = defaultRenderDescription;
function defaultRenderTitle(props) {
const {
productTitle
} = props;
const validProductTitle = exotic_1.fromIshToString(productTitle);
return react_1.default.createElement(styled_1.StyledProductTitle, {
content: validProductTitle
});
}
exports.defaultRenderTitle = defaultRenderTitle;
function defaultRenderPrice(props) {
const {
regularPrice,
salePrice
} = props;
const formatRegularPrice = deps_1.convertAsPrice(regularPrice);
const formatSalePrice = deps_1.convertAsPrice(salePrice);
return react_1.default.createElement(styled_1.ProductPricePanel, null, react_1.default.createElement(styled_1.SalePrice, {
content: formatRegularPrice
}), react_1.default.createElement(styled_1.RegularPrice, {
content: formatSalePrice
}));
}
exports.defaultRenderPrice = defaultRenderPrice;
function defaultRenderPromo(props) {
const {
promoDetails
} = props;
const validPromoDetails = exotic_1.fromIshToString(promoDetails);
return react_1.default.createElement(styled_1.PromoLabel, {
content: validPromoDetails
});
}
exports.defaultRenderPromo = defaultRenderPromo;
function defaultRenderRatings(props) {
const {
reviewRatings,
totalReviews
} = props;
const validReviewRatings = exotic_1.fromIshToNumber(reviewRatings);
const validTotalReviews = exotic_1.fromIshToNumber(totalReviews);
return react_1.default.createElement(styled_1.StyledRatings, {
value: validReviewRatings,
count: validTotalReviews
});
}
exports.defaultRenderRatings = defaultRenderRatings;
const renderViewType = props => {
const {
renderBrandName,
renderTitle,
renderDescription,
renderPrice,
renderPromo,
renderRatings
} = props,
remainingProps = tslib_1.__rest(props, ["renderBrandName", "renderTitle", "renderDescription", "renderPrice", "renderPromo", "renderRatings"]);
switch (props.viewType) {
case 'type2':
// Show tittle first
return react_1.default.createElement(react_1.default.Fragment, null, renderTitle(remainingProps), renderDescription(remainingProps), renderBrandName(remainingProps), renderPrice(remainingProps), renderPromo(remainingProps), renderRatings(remainingProps));
case 'type3':
// Show price first
return react_1.default.createElement(react_1.default.Fragment, null, renderPrice(remainingProps), renderPromo(remainingProps), renderTitle(remainingProps), renderDescription(remainingProps), renderBrandName(remainingProps), renderRatings(remainingProps));
case 'type4':
// Show rating first
return react_1.default.createElement(react_1.default.Fragment, null, renderRatings(remainingProps), renderPrice(remainingProps), renderPromo(remainingProps), renderTitle(remainingProps), renderDescription(remainingProps), renderBrandName(remainingProps));
// Show brand name first
case 'type1':
default:
return react_1.default.createElement(react_1.default.Fragment, null, renderBrandName(remainingProps), renderTitle(remainingProps), renderDescription(remainingProps), renderPrice(remainingProps), renderPromo(remainingProps), renderRatings(remainingProps));
}
};
function defaultRenderProductInformation(props) {
const view = renderViewType(props);
return react_1.default.createElement(styled_1.ProductInfoWrapper, null, view);
}
exports.defaultRenderProductInformation = defaultRenderProductInformation;
function defaultRenderBox(props) {
const {
isDisableProductImage,
isDisableProductInformation,
renderImage,
renderProductInformation
} = props,
remainingProps = tslib_1.__rest(props, ["isDisableProductImage", "isDisableProductInformation", "renderImage", "renderProductInformation"]);
const shouldDisableImage = exotic_1.toBoolean(isDisableProductImage);
const shouldDisableInfo = exotic_1.toBoolean(isDisableProductInformation);
return react_1.default.createElement(react_1.default.Fragment, null, shouldDisableImage ? react_1.default.createElement(Empty_1.default, null) : renderImage(remainingProps), shouldDisableInfo ? react_1.default.createElement(Empty_1.default, null) : renderProductInformation(remainingProps));
}
exports.defaultRenderBox = defaultRenderBox;
function defaultRenderWrapper(props) {
const {
className,
children,
dataQa
} = props;
return react_1.default.createElement(styled_1.ProductItemWrapper, {
className: className,
"data-qa": dataQa
}, children);
}
exports.defaultRenderWrapper = defaultRenderWrapper;