UNPKG

@livelike/react-native

Version:

LiveLike React Native package

75 lines (74 loc) 3.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LLQuizWidgetBody = LLQuizWidgetBody; var _react = _interopRequireWildcard(require("react")); var _reactNative = require("react-native"); var _hooks = require("../../hooks"); var _LLWidgetOption = require("../LLWidgetOption"); function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } function LLQuizWidgetBody(_ref) { let { widgetId, styles: stylesProp, ChoiceOptionComponent = _LLWidgetOption.LLWidgetChoiceOption, ChoiceOptionComponentStyles } = _ref; const [selectedOptionIndex, setSelectedOptionIndex] = (0, _react.useState)(-1); const styles = (0, _hooks.useStyles)({ componentStylesFn: getQuizWidgetBodyStyles, stylesProp }); const widgetChoices = (0, _hooks.useWidgetChoices)({ widgetId }); const { updateSelectedOptionIndexAction } = (0, _hooks.useWidgetActions)({ widgetId }); const { trackWidgetInteractedAction } = (0, _hooks.useWidgetInteractedAnalytics)({ widgetId }); const onOptionHandler = (0, _react.useCallback)(selectedOptionIndex => { setSelectedOptionIndex(selectedOptionIndex); updateSelectedOptionIndexAction({ widgetId, selectedOptionIndex }); trackWidgetInteractedAction({ interactionItem: widgetChoices[selectedOptionIndex] }); }, [widgetId, widgetChoices]); if (!(widgetChoices !== null && widgetChoices !== void 0 && widgetChoices.length)) { return undefined; } return /*#__PURE__*/_react.default.createElement(_reactNative.View, { style: styles.bodyContainer }, widgetChoices === null || widgetChoices === void 0 ? void 0 : widgetChoices.map((choice, index) => /*#__PURE__*/_react.default.createElement(ChoiceOptionComponent, { key: choice.id, optionIndex: index, widgetId: widgetId, selectedOptionIndex: selectedOptionIndex, onOptionChange: onOptionHandler, OptionComponentStyles: ChoiceOptionComponentStyles }))); } const getQuizWidgetBodyStyles = _ref2 => { let { theme } = _ref2; return _reactNative.StyleSheet.create({ bodyContainer: { display: 'flex', flexDirection: 'column', marginHorizontal: 16, marginBottom: 14 } }); }; //# sourceMappingURL=LLQuizWidgetBody.js.map