@findify/react-components
Version:
Findify react UI components
42 lines (39 loc) • 1.82 kB
JavaScript
/**
* @module components/Cards/Product/Price
*/
import cx from 'classnames';
import { getPrice } from "../../../../helpers/getPrice";
import { priceIsSampleArray } from "../../../../helpers/getPrice";
import { useConfig } from '@findify/react-connect';
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
var styles = {
"price-wrapper": "findify-components--cards--product--price__price-wrapper",
"simple": "findify-components--cards--product--price__simple",
"price": "findify-components--cards--product--price__price",
"compare": "findify-components--cards--product--price__compare",
"sale-price": "findify-components--cards--product--price__sale-price",
"priceWrapper": "findify-components--cards--product--price__price-wrapper",
"salePrice": "findify-components--cards--product--price__sale-price"
};
/** List of props that Price component accepts */
export default (function (_ref) {
var className = _ref.className,
_ref$theme = _ref.theme,
theme = _ref$theme === void 0 ? styles : _ref$theme,
item = _ref.item;
var _useConfig = useConfig(),
config = _useConfig.config;
var hasDiscount = !item.get('compare_at') && item.get('discount') && item.get('discount').size > 0 && priceIsSampleArray(item.get('price'));
var hasCompare = !!item.get('compare_at');
return /*#__PURE__*/_jsxs("div", {
className: cx(theme.priceWrapper, className),
children: [/*#__PURE__*/_jsx("span", {
className: cx(theme.price, (hasDiscount || hasCompare) && theme.salePrice),
children: getPrice(item.get('price'), config.get('currency'))
}), hasCompare ? /*#__PURE__*/_jsx("span", {
className: cx(theme.compare),
children: getPrice(item.get('compare_at'), config.get('currency'))
}) : null]
});
});