@mopinion/survey
Version:
Collect customer feedback with the Mopinion survey library
109 lines (108 loc) • 5.77 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = SvgIcon;
var _preact = require("preact");
var _hooks = require("preact/hooks");
var _hooks2 = require("../../../hooks");
var _icons = _interopRequireDefault(require("../../../assets/icons/icons.json"));
var _api = _interopRequireDefault(require("../../../api"));
var _ConfigStore = require("../stores/ConfigStore");
var _excluded = ["icon", "className", "style"],
_excluded2 = ["name", "icon", "className", "style"],
_excluded3 = ["alt"],
_excluded4 = ["name", "className", "style"];
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
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 _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
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; }
function SvgIcon(_ref) {
var _iconMap$iconName;
var icon = _ref.icon,
_ref$className = _ref.className,
className = _ref$className === void 0 ? '' : _ref$className,
style = _ref.style,
props = _objectWithoutProperties(_ref, _excluded);
var _useConfigStore = (0, _ConfigStore.useConfigStore)(),
icons = _useConfigStore.icons;
var iconName = String(icon).replace('fa-', '').replace('fa ', '');
var iconData = (_iconMap$iconName = _icons["default"][iconName]) !== null && _iconMap$iconName !== void 0 ? _iconMap$iconName : icons[iconName];
if (iconData) {
return (0, _preact.h)(Icon, _extends({
name: iconName,
icon: iconData,
className: className,
style: style
}, props));
}
return (0, _preact.h)(FetchIcon, _extends({
name: iconName,
className: className,
style: style
}, props));
}
function Icon(_ref2) {
var name = _ref2.name,
_ref2$icon = _ref2.icon,
icon = _ref2$icon === void 0 ? {} : _ref2$icon,
_ref2$className = _ref2.className,
className = _ref2$className === void 0 ? '' : _ref2$className,
style = _ref2.style,
props = _objectWithoutProperties(_ref2, _excluded2);
var alt = props.alt,
rest = _objectWithoutProperties(props, _excluded3);
return (0, _preact.h)("i", _extends({
className: "mopicon mopicon-".concat(name, " ").concat(className),
role: "none",
style: style
}, rest), (0, _preact.h)("svg", _extends({
viewBox: icon.viewBox || '0 0 28 28',
role: alt ? 'img' : 'presentation'
}, !alt && {
'aria-hidden': 'true'
}), alt && (0, _preact.h)("title", null, alt), (0, _preact.h)("path", {
d: icon.path || '',
fill: "currentColor"
})));
}
function FetchIcon(_ref3) {
var name = _ref3.name,
className = _ref3.className,
style = _ref3.style,
props = _objectWithoutProperties(_ref3, _excluded4);
var _useFormProps = (0, _ConfigStore.useFormProps)(),
domain = _useFormProps.domain,
cacheDomain = _useFormProps.cacheDomain,
customDomain = _useFormProps.customDomain;
var _useState = (0, _hooks.useState)({}),
_useState2 = _slicedToArray(_useState, 2),
icon = _useState2[0],
setIcon = _useState2[1];
var isMounted = (0, _hooks2.useIsMounted)();
(0, _hooks.useEffect)(function () {
(0, _api["default"])({
domain: domain,
cacheDomain: cacheDomain,
customDomain: customDomain
}).getIcons(name).then(function (response) {
if (isMounted) {
var parsed = typeof r === 'string' ? JSON.parse(response) : response;
_icons["default"][name] = parsed[name];
setIcon(parsed[name]);
}
});
}, []);
return (0, _preact.h)(Icon, _extends({
icon: icon,
className: className,
style: style
}, props));
}
//# sourceMappingURL=SvgIcon.js.map