UNPKG

@bemit/consent-ui-mui

Version:

133 lines (132 loc) 6.52 kB
"use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } Object.defineProperty(exports, "__esModule", { value: true }); exports.EmbedTweet = exports.ConsentUiEmbedTwitter = void 0; var _react = _interopRequireDefault(require("react")); var _Box = _interopRequireDefault(require("@mui/material/Box")); var _Paper = _interopRequireDefault(require("@mui/material/Paper")); var _Typography = _interopRequireDefault(require("@mui/material/Typography")); var _CircularProgress = _interopRequireDefault(require("@mui/material/CircularProgress")); var _ConsentUiBoxEmbed = require("@bemit/consent-ui-mui/ConsentUiBoxEmbed"); var _useEmbedState2 = require("@bemit/consent-ui-react/useEmbedState"); var _jsxRuntime = require("react/jsx-runtime"); var _excluded = ["service", "labels", "children", "px", "py", "icon", "title", "infoBtnUp", "infoMaxWidth", "pos"]; function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; } function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; } function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; } var ConsentUiEmbedTwitter = exports.ConsentUiEmbedTwitter = function ConsentUiEmbedTwitter(_ref) { var service = _ref.service, labels = _ref.labels, children = _ref.children, _ref$px = _ref.px, px = _ref$px === void 0 ? 3 : _ref$px, _ref$py = _ref.py, py = _ref$py === void 0 ? 5 : _ref$py, icon = _ref.icon, title = _ref.title, infoBtnUp = _ref.infoBtnUp, infoMaxWidth = _ref.infoMaxWidth, pos = _ref.pos, props = _objectWithoutProperties(_ref, _excluded); var _useEmbedState = (0, _useEmbedState2.useEmbedState)(service), serviceConsent = _useEmbedState.serviceConsent, setServiceConsent = _useEmbedState.setServiceConsent, serviceInfo = _useEmbedState.serviceInfo; return (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, { children: [serviceConsent ? null : (0, _jsxRuntime.jsx)(_Paper["default"], { variant: 'outlined', style: { width: '100%', borderRadius: 6 }, children: (0, _jsxRuntime.jsx)(_Box["default"], { px: px, py: py, style: { width: '100%', display: 'flex', flexDirection: 'column', alignItems: 'center' }, children: (0, _jsxRuntime.jsx)(_ConsentUiBoxEmbed.ConsentUiBoxEmbed, { service: service, icon: icon, title: title, labels: labels, serviceConsent: serviceConsent, setServiceConsent: setServiceConsent, serviceInfo: serviceInfo, infoBtnUp: infoBtnUp, infoMaxWidth: infoMaxWidth, pos: pos }) }) }), serviceConsent ? (0, _jsxRuntime.jsx)(EmbedTweet, _objectSpread({ consent: serviceConsent, py: py }, props)) : null] }); }; var loadedState = { current: false }; var EmbedTweet = exports.EmbedTweet = function EmbedTweet(_ref2) { var consent = _ref2.consent, user = _ref2.user, tweet = _ref2.tweet, py = _ref2.py; var consentB = Boolean(consent); _react["default"].useEffect(function () { if (consentB) { if (!loadedState.current) { loadedState.current = true; var scriptTwitter = document.createElement('script'); scriptTwitter.async = true; scriptTwitter.src = 'https://platform.twitter.com/widgets.js'; scriptTwitter.onload = function () { if (window.twttr) { window.twttr.widgets.load(); } }; document.body.append(scriptTwitter); } else { if (window.twttr) { window.twttr.widgets.load(); } } } }, [tweet, consentB]); return (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, { children: consent ? (0, _jsxRuntime.jsxs)("blockquote", { className: "twitter-tweet", style: { display: 'flex', flexDirection: 'column', alignItems: 'center', width: '100%' }, children: [(0, _jsxRuntime.jsx)("a", { href: 'https://twitter.com/' + user + '/status/' + tweet + '' }), (0, _jsxRuntime.jsxs)(_Box["default"], { my: py, style: { display: 'flex', flexDirection: 'column', alignItems: 'center', width: '100%' }, children: [(0, _jsxRuntime.jsx)(_Typography["default"], { gutterBottom: true, children: "Loading Tweet" }), (0, _jsxRuntime.jsx)(_CircularProgress["default"], {})] })] }) : null }); };