UNPKG

@mopinion/survey

Version:

Collect customer feedback with the Mopinion survey library

85 lines (84 loc) 5.66 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = FormHeader; var _preact = require("preact"); var _hooks = require("preact/hooks"); var _utils = require("../../../utils"); var _ConfigStore = require("../stores/ConfigStore"); var _FormStore = require("../stores/FormStore"); 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); } function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); } function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } } function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } } function _arrayWithHoles(r) { if (Array.isArray(r)) return r; } function calcLoadHeight(arr, formWidth) { try { if (formWidth > arr[0]) { return arr[1]; } else { return arr[1] * (formWidth / arr[0]); } } catch (e) { return 0; } } function FormHeader(_ref) { var _properties$advanced$, _properties$advanced, _properties$translati, _properties$translati2, _contentDivRef$curren, _text$logoAltText; var formKey = _ref.formKey, _ref$setFormHeaderHei = _ref.setFormHeaderHeight, setFormHeaderHeight = _ref$setFormHeaderHei === void 0 ? function () {} : _ref$setFormHeaderHei; var _useConfigStore = (0, _ConfigStore.useConfigStore)(), properties = _useConfigStore.properties, conversational = _useConfigStore.properties.conversational, text = _useConfigStore.text; var _useFormStore = (0, _FormStore.useFormStore)(), formIsCompleted = _useFormStore.formIsCompleted, formOpen = _useFormStore.formOpen, contentDivRef = _useFormStore.contentDivRef; var _useState = (0, _hooks.useState)(false), _useState2 = _slicedToArray(_useState, 2), logoLoaded = _useState2[0], setLogoLoaded = _useState2[1]; var headRef = (0, _hooks.useRef)(null); (0, _hooks.useEffect)(function () { try { var _headRef$current; setFormHeaderHeight((_headRef$current = headRef.current) === null || _headRef$current === void 0 ? void 0 : _headRef$current.clientHeight); } catch (e) {} }, []); var HeaderComponent = (_properties$advanced$ = (_properties$advanced = properties.advanced) === null || _properties$advanced === void 0 ? void 0 : _properties$advanced.headerElement) !== null && _properties$advanced$ !== void 0 ? _properties$advanced$ : 'h3'; var formTitle = !formIsCompleted || properties.conversational ? (0, _utils.mapBrFromString)(properties.title) : _typeof(properties.thanksPage) === 'object' ? properties.thanksPage.title : text === null || text === void 0 ? void 0 : text.lastPageTitle; var hasLanguageToggle = (properties === null || properties === void 0 || (_properties$translati = properties.translation) === null || _properties$translati === void 0 ? void 0 : _properties$translati.useTranslation) && (properties === null || properties === void 0 || (_properties$translati2 = properties.translation) === null || _properties$translati2 === void 0 ? void 0 : _properties$translati2.useToggle); var showLogo = properties.logo && (logoLoaded || formOpen || (0, _utils.isLandingPage)()); return (0, _preact.h)("div", { id: "surveyHead", className: "survey-header ".concat(hasLanguageToggle ? 'has-toggle' : ''), style: conversational ? { margin: 0, position: 'relative' } : {}, ref: headRef }, showLogo && (0, _preact.h)("img", { onLoad: function onLoad() { return setLogoLoaded(true); }, style: !logoLoaded ? { transition: 'opacity .3s', opacity: 0, height: calcLoadHeight(properties.logoSize, (_contentDivRef$curren = contentDivRef.current) === null || _contentDivRef$curren === void 0 ? void 0 : _contentDivRef$curren.clientWidth) } : { transition: 'opacity .3s', opacity: 1 }, src: (0, _utils.getImageUri)(properties.logo), alt: (_text$logoAltText = text === null || text === void 0 ? void 0 : text.logoAltText) !== null && _text$logoAltText !== void 0 ? _text$logoAltText : 'Logo' }), (0, _preact.h)("div", { id: "surveyTitle-".concat(formKey), "class": "srv-title main-title" }, formTitle && (0, _preact.h)(HeaderComponent, null, formTitle))); } //# sourceMappingURL=FormHeader.js.map