UNPKG

@shopgate/engage

Version:
89 lines (88 loc) 2.74 kB
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose"; import React, { PureComponent, Fragment } from 'react'; import PropTypes from 'prop-types'; import { isBeta } from '@shopgate/engage/core'; import { Portal } from '@shopgate/engage/components'; import { PRODUCT_VARIANT_SELECT, PRODUCT_VARIANT_SELECT_AFTER, PRODUCT_VARIANT_SELECT_BEFORE } from '@shopgate/engage/product/constants'; import { ProductCharacteristics } from '@shopgate/engage/product/components'; import { ProductContext } from '@shopgate/engage/product/contexts'; import Characteristic from "./Characteristic"; import Swatch from "./Swatch"; /** * The Characteristics component. */ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime"; let Characteristics = /*#__PURE__*/function (_PureComponent) { function Characteristics(...args) { var _this; _this = _PureComponent.call.apply(_PureComponent, [this].concat(args)) || this; /** * @param {Object} props The consumer props. * @returns {JSX} */ _this.consumeRenderer = ({ conditioner, setCharacteristics, characteristics }) => { const { productId, variantId } = _this.props; return /*#__PURE__*/_jsx(ProductCharacteristics, { productId: productId, variantId: variantId, render: _this.renderer, conditioner: conditioner, finishTimeout: 200, setCharacteristics: setCharacteristics, characteristics: characteristics }); }; /** * @see ProductCharacteristics.render * @param {Object} props The renderer props. * @returns {JSX} */ _this.renderer = props => { if (isBeta() && !!props.swatch) { return /*#__PURE__*/_jsx(Swatch, { ...props }); } return /*#__PURE__*/_jsx(Characteristic, { ...props }); }; return _this; } _inheritsLoose(Characteristics, _PureComponent); var _proto = Characteristics.prototype; /** * @returns {JSX} */ _proto.render = function render() { return /*#__PURE__*/_jsxs(_Fragment, { children: [/*#__PURE__*/_jsx(Portal, { name: PRODUCT_VARIANT_SELECT_BEFORE }), /*#__PURE__*/_jsx(Portal, { name: PRODUCT_VARIANT_SELECT, children: /*#__PURE__*/_jsx(ProductContext.Consumer, { children: this.consumeRenderer }) }), /*#__PURE__*/_jsx(Portal, { name: PRODUCT_VARIANT_SELECT_AFTER })] }); }; return Characteristics; }(PureComponent); Characteristics.defaultProps = { productId: null, variantId: null }; Characteristics.defaultProps = { productId: null, variantId: null }; export default Characteristics;