UNPKG

@livelike/react-native

Version:

LiveLike React Native package

75 lines (74 loc) 2.96 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LLVoteWidgetBody = LLVoteWidgetBody; 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 LLVoteWidgetBody(_ref) { let { widgetId, styles: stylesProp, VoteOptionComponent = _LLWidgetOption.LLWidgetVoteOption, VoteOptionComponentStyles } = _ref; const [selectedOptionIndex, setSelectedOptionIndex] = (0, _react.useState)(-1); const styles = (0, _hooks.useStyles)({ componentStylesFn: getVoteWidgetBodyStyles, stylesProp }); const widgetOptions = (0, _hooks.useWidgetOptions)({ 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: widgetOptions[selectedOptionIndex] }); }, [widgetId, widgetOptions]); if (!(widgetOptions !== null && widgetOptions !== void 0 && widgetOptions.length)) { return undefined; } return /*#__PURE__*/_react.default.createElement(_reactNative.View, { style: styles.bodyContainer }, widgetOptions.map((option, index) => /*#__PURE__*/_react.default.createElement(VoteOptionComponent, { key: option.id, optionIndex: index, widgetId: widgetId, selectedOptionIndex: selectedOptionIndex, onOptionChange: onOptionHandler, OptionComponentStyles: VoteOptionComponentStyles }))); } const getVoteWidgetBodyStyles = _ref2 => { let { theme } = _ref2; return _reactNative.StyleSheet.create({ bodyContainer: { display: 'flex', flexDirection: 'column', marginHorizontal: 16, marginBottom: 14 } }); }; //# sourceMappingURL=LLVoteWidgetBody.js.map