UNPKG

@pactsafe/pactsafe-react-sdk

Version:

Ironclad Clickwrap React SDK - SDK for easy Ironclad Clickwrap implementations leveraging the Ironclad JavaScript Library & API

75 lines 3.11 kB
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } /* global _ps */ import React from 'react'; import PropTypes from 'prop-types'; import isRequiredIf from 'react-proptype-conditional-require'; import PSSnippet from './PSSnippet'; var PSBrowseWrap = /*#__PURE__*/function (_React$Component) { _inheritsLoose(PSBrowseWrap, _React$Component); function PSBrowseWrap(props) { var _this; _this = _React$Component.call(this, props) || this; var _this$props = _this.props, psScriptUrl = _this$props.psScriptUrl, groupKey = _this$props.groupKey, accessId = _this$props.accessId; if (!PSSnippet.isSnippetLoaded(psScriptUrl)) { PSSnippet.injectSnippet(psScriptUrl); } _this.targetSelector = "psbw-" + groupKey; _ps('create', accessId); return _this; } var _proto = PSBrowseWrap.prototype; _proto.componentDidMount = function componentDidMount() { var _this$props2 = this.props, groupKey = _this$props2.groupKey, position = _this$props2.position, badgeText = _this$props2.badgeText, alwaysVisible = _this$props2.alwaysVisible, openLegalCenter = _this$props2.openLegalCenter; _ps('load', groupKey, { target_selector: this.targetSelector, position: position, badge_text: badgeText, always_visible: alwaysVisible, open_legal_center: openLegalCenter }); }; _proto.componentWillUnmount = function componentWillUnmount() { var groupKey = this.props.groupKey; _ps.getByKey(groupKey).rendered = false; }; _proto.render = function render() { var _this$props3 = this.props, link = _this$props3.link, linkText = _this$props3.linkText; return /*#__PURE__*/React.createElement("a", { href: link, id: this.targetSelector }, linkText); }; return PSBrowseWrap; }(React.Component); PSBrowseWrap.MUST_PROVIDE_LINK_IF_OPEN_LEGAL_CENTER_FALSE = 'PSBrowseWrap Error: You must provide a link prop if openLegalCenter is passed false'; PSBrowseWrap.propTypes = process.env.NODE_ENV !== "production" ? { accessId: PropTypes.string.isRequired, alwaysVisible: PropTypes.bool, badgeText: PropTypes.string, groupKey: PropTypes.string.isRequired, link: isRequiredIf(PropTypes.string, function (props) { return props.hasOwnProperty('openLegalCenter') && props.openLegalCenter === false; }, PSBrowseWrap.MUST_PROVIDE_LINK_IF_OPEN_LEGAL_CENTER_FALSE), linkText: PropTypes.string.isRequired, openLegalCenter: PropTypes.bool, position: PropTypes.oneOf(['middle', 'left', 'right', 'auto']), psScriptUrl: PropTypes.string } : {}; PSBrowseWrap.defaultProps = { psScriptUrl: '//vault.pactsafe.io/ps.min.js', position: 'auto', link: '#', openLegalCenter: true }; export default PSBrowseWrap;