UNPKG

@livelike/react-native

Version:

LiveLike React Native package

67 lines 2.06 kB
import React, { useCallback, useState } from 'react'; import { StyleSheet, View } from 'react-native'; import { useStyles, useWidgetActions, useWidgetChoices, useWidgetInteractedAnalytics } from '../../hooks'; import { LLWidgetChoiceOption } from '../LLWidgetOption'; export function LLQuizWidgetBody(_ref) { let { widgetId, styles: stylesProp, ChoiceOptionComponent = LLWidgetChoiceOption, ChoiceOptionComponentStyles } = _ref; const [selectedOptionIndex, setSelectedOptionIndex] = useState(-1); const styles = useStyles({ componentStylesFn: getQuizWidgetBodyStyles, stylesProp }); const widgetChoices = useWidgetChoices({ widgetId }); const { updateSelectedOptionIndexAction } = useWidgetActions({ widgetId }); const { trackWidgetInteractedAction } = useWidgetInteractedAnalytics({ widgetId }); const onOptionHandler = 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.createElement(View, { style: styles.bodyContainer }, widgetChoices === null || widgetChoices === void 0 ? void 0 : widgetChoices.map((choice, index) => /*#__PURE__*/React.createElement(ChoiceOptionComponent, { key: choice.id, optionIndex: index, widgetId: widgetId, selectedOptionIndex: selectedOptionIndex, onOptionChange: onOptionHandler, OptionComponentStyles: ChoiceOptionComponentStyles }))); } const getQuizWidgetBodyStyles = _ref2 => { let { theme } = _ref2; return StyleSheet.create({ bodyContainer: { display: 'flex', flexDirection: 'column', marginHorizontal: 16, marginBottom: 14 } }); }; //# sourceMappingURL=LLQuizWidgetBody.js.map