Repository URL to install this package:
|
Version:
2.1.14 ▾
|
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importDefault(require("react"));
const exotic_1 = require("exotic");
const Incrementer_1 = require("@skava/ui/dist/inputs/Incrementer");
const Empty_1 = require("@skava/ui/dist/components/atoms/Empty");
const styled_1 = require("./styled");
/** renderProp to render Brand Name */
function defaultRenderBrandName(props) {
const {
brandName = 'Brand Name',
type
} = props;
const productType = exotic_1.isSafe(type) && type !== '' ? type : 'vertical';
return exotic_1.isSafe(brandName) && react_1.default.createElement(styled_1.StyledBrandName, {
content: brandName,
breedType: 'h3',
type: productType
});
}
exports.defaultRenderBrandName = defaultRenderBrandName;
/** renderProp to render Product Name */
function defaultRenderProductName(props) {
const {
name = 'Product Name',
url,
identifier
} = props;
const productUrl = exotic_1.isSafe(url) ? url : `/product/${identifier}`;
return exotic_1.isSafe(name) && react_1.default.createElement(styled_1.StyledLink, {
target: '_self',
to: productUrl
}, react_1.default.createElement(styled_1.StyledProductName, {
content: name,
breedType: 'h4'
}));
}
exports.defaultRenderProductName = defaultRenderProductName;
/** renderProp to render Product Price */
function defaultRenderPrice(props) {
const {
price = exotic_1.EMPTY_OBJ,
type
} = props;
const productType = exotic_1.isSafe(type) && type !== '' ? type : 'vertical';
const {
salePrice,
regPrice
} = price;
const isOnlyPrice = !exotic_1.isSafe(salePrice) || !exotic_1.isSafe(regPrice);
const isEqualPrice = exotic_1.isSafe(salePrice) && exotic_1.isSafe(regPrice) && salePrice === regPrice;
const priceView = react_1.default.createElement(styled_1.PriceWrapper, {
type: productType
}, exotic_1.isSafe(salePrice) && react_1.default.createElement(styled_1.SalePrice, {
"aria-label": "sale-price"
}, salePrice), exotic_1.isSafe(regPrice) && isEqualPrice === false && react_1.default.createElement(styled_1.RegularPrice, {
"aria-label": "regular-price",
isOnlyPrice: isOnlyPrice
}, regPrice));
return priceView;
}
exports.defaultRenderPrice = defaultRenderPrice;
/** renderProp to render Product rating */
function defaultRenderRatings(props) {
const {
rating = exotic_1.EMPTY_OBJ
} = props;
const {
value,
reviewCount
} = rating;
const shouldShowCount = exotic_1.isSafe(reviewCount);
return exotic_1.isSafe(value) && react_1.default.createElement(styled_1.StyledRatings, {
starRating: value,
shouldShowCount: shouldShowCount,
userRating: reviewCount,
width: 12
});
}
exports.defaultRenderRatings = defaultRenderRatings;
/** renderProp to render Product Facet */
function defaultRenderFacetDetails(props) {
const {
facet = exotic_1.EMPTY_OBJ
} = props;
return exotic_1.isArray(facet) && react_1.default.createElement(styled_1.StyledDetailedList, {
list: facet
});
}
exports.defaultRenderFacetDetails = defaultRenderFacetDetails;
/** renderProp to render Product promo */
function defaultRenderPromoDetails(props) {
const {
promoOffer = exotic_1.EMPTY_ARRAY,
onPromoOfferClick
} = props;
const promoView = react_1.default.createElement(styled_1.StyledPromoWrapper, null, promoOffer.map((promo, index) => {
const {
name
} = promo;
const handlePromoOffer = () => {
if (exotic_1.isFunction(onPromoOfferClick)) {
const changeArgs = Object.assign({}, promo);
onPromoOfferClick(changeArgs);
}
};
return react_1.default.createElement(styled_1.StyledPromoText, {
key: index,
onClick: handlePromoOffer
}, name);
}));
return promoView;
}
exports.defaultRenderPromoDetails = defaultRenderPromoDetails;
/** renderProp to render Quantity */
function defaultRenderQuantity(props) {
const {
quantity = exotic_1.EMPTY_OBJ,
onQuantityChange,
type
} = props;
const productType = exotic_1.isSafe(type) && type !== '' ? type : 'vertical';
const {
value,
isIncrementer = false
} = quantity;
const handleQuantityChange = args => {
if (exotic_1.isFunction(onQuantityChange)) {
onQuantityChange(args);
}
};
const view = productType === 'checkout' && isIncrementer === true ? react_1.default.createElement(Incrementer_1.Incrementer, {
count: value,
onValueChange: handleQuantityChange
}) : exotic_1.isSafe(value) && react_1.default.createElement(react_1.default.Fragment, null, react_1.default.createElement(styled_1.StyledText, {
type: productType
}, 'Quantity:'), react_1.default.createElement(styled_1.StyledQuantityValue, null, value));
return react_1.default.createElement(styled_1.IncrementerWrapper, {
type: productType
}, view);
}
exports.defaultRenderQuantity = defaultRenderQuantity;
/** renderProp to render Product Total */
function defaultRenderTotal(props) {
const {
totalPriceDetails = exotic_1.EMPTY_OBJ,
type
} = props;
const productType = exotic_1.isSafe(type) && type !== '' ? type : 'vertical';
const {
totalPrice,
savePrice
} = totalPriceDetails;
return react_1.default.createElement(styled_1.TotalWrapper, {
type: productType
}, exotic_1.isSafe(totalPrice) && react_1.default.createElement(styled_1.TotalText, null, react_1.default.createElement(styled_1.StyledText, {
type: productType
}, 'Total:'), totalPrice), exotic_1.isSafe(savePrice) && react_1.default.createElement(styled_1.SaveText, null, 'You save ', savePrice));
}
exports.defaultRenderTotal = defaultRenderTotal;
/** renderProp to render Product Details */
function defaultRenderProductDetailsBox(props) {
const {
renderProductName,
renderBrandName,
renderPrice,
renderRatings,
renderFacetDetails,
renderQuantity,
productDetailsOrder = [],
renderPromoDetails
} = props,
remainingProps = tslib_1.__rest(props, ["renderProductName", "renderBrandName", "renderPrice", "renderRatings", "renderFacetDetails", "renderQuantity", "productDetailsOrder", "renderPromoDetails"]);
const productType = exotic_1.isSafe(props.type) && props.type !== '' ? props.type : 'vertical';
const mapNameToFunction = {
brandName: exotic_1.isFunction(renderBrandName) && renderBrandName(remainingProps),
productName: exotic_1.isFunction(renderProductName) && renderProductName(remainingProps),
promoOffer: exotic_1.isFunction(renderPromoDetails) && renderPromoDetails(remainingProps),
price: exotic_1.isFunction(renderPrice) && (productType === 'vertical' || productType === 'horizontal') && renderPrice(remainingProps),
facet: exotic_1.isFunction(renderFacetDetails) && renderFacetDetails(remainingProps),
rating: exotic_1.isFunction(renderRatings) && renderRatings(remainingProps),
quantity: exotic_1.isFunction(renderQuantity) && (productType === 'vertical' || productType === 'horizontal') && renderQuantity(remainingProps)
};
const view = react_1.default.createElement(react_1.default.Fragment, null, productDetailsOrder.map(name => {
return exotic_1.isSafe(mapNameToFunction[name]) ? mapNameToFunction[name] : react_1.default.createElement(Empty_1.Empty, null);
}));
return view;
}
exports.defaultRenderProductDetailsBox = defaultRenderProductDetailsBox;
/** renderProp to render Image */
function defaultRenderImage(props) {
const {
image,
url,
identifier,
onFavoriteClick,
hasFavoriteIcon = false,
isFavoriteActive = false,
name,
productCaption = ''
} = props;
const onClick = args => {
if (exotic_1.isFunction(onFavoriteClick)) {
const changeArgs = Object.assign({
identifier
}, args);
onFavoriteClick(changeArgs);
}
};
const productUrl = exotic_1.isSafe(url) ? url : `/product/${identifier}`;
const productType = exotic_1.isSafe(props.type) && props.type !== '' ? props.type : 'vertical';
const imageView = exotic_1.isSafe(image) ? react_1.default.createElement(styled_1.ImageWrapper, {
type: productType
}, hasFavoriteIcon === true && react_1.default.createElement(styled_1.StyledToggleFavorite, {
iconType: 'heart',
isSelected: isFavoriteActive,
onToggle: onClick
}), react_1.default.createElement(styled_1.StyledLink, {
target: '_self',
to: productUrl
}, react_1.default.createElement(styled_1.StyledProductImage, {
src: image,
caption: productCaption,
alt: name,
type: productType
}))) : react_1.default.createElement(styled_1.StyledImagePlaceholder, {
type: productType
});
return imageView;
}
exports.defaultRenderImage = defaultRenderImage;
/** renderProp to render Layout */
function defaultRenderBox(props) {
const {
renderImage,
renderProductDetailsBox,
renderCheckoutQuantity,
renderTotal
} = props,
remainingProps = tslib_1.__rest(props, ["renderImage", "renderProductDetailsBox", "renderCheckoutQuantity", "renderTotal"]);
const productType = exotic_1.isSafe(props.type) && props.type !== '' ? props.type : 'vertical';
const view = react_1.default.createElement(react_1.default.Fragment, null, exotic_1.isFunction(renderImage) && renderImage(remainingProps), react_1.default.createElement(styled_1.ProductWrapper, {
type: productType
}, react_1.default.createElement(styled_1.ProductDetailWrapper, null, exotic_1.isFunction(renderProductDetailsBox) && renderProductDetailsBox(remainingProps)), props.type === 'checkout' && react_1.default.createElement(react_1.default.Fragment, null, exotic_1.isFunction(defaultRenderQuantity) && defaultRenderQuantity(remainingProps), exotic_1.isFunction(props.renderPrice) && props.renderPrice(remainingProps), exotic_1.isFunction(renderTotal) && renderTotal(remainingProps))));
return view;
}
exports.defaultRenderBox = defaultRenderBox;
/** renderProp to render Wrapper */
function defaultRenderWrapper(props) {
const {
className,
children,
type,
dataQa
} = props;
const productType = exotic_1.isSafe(type) && type !== '' ? type : 'vertical';
const passThroughProps = {
type: productType,
className,
'data-qa': dataQa
};
return react_1.default.createElement(styled_1.Wrapper, Object.assign({}, passThroughProps), children);
}
exports.defaultRenderWrapper = defaultRenderWrapper;