@livelike/react-native
Version:
LiveLike React Native package
70 lines • 2.19 kB
JavaScript
import React from 'react';
import { StyleSheet, View } from 'react-native';
import { useStyles, useWidgetOptions } from '../../hooks';
import { LLCheerMeterWidgetOption } from './LLCheerMeterWidgetOption';
import { LLCheerMeterWidgetResult } from './LLCheerMeterWidgetResult';
import { LLCheerMeterWidgetCheerCount } from './LLCheerMeterWidgetCheerCount';
export function LLCheerMeterWidgetBody(_ref) {
let {
widgetId,
ResultComponent = LLCheerMeterWidgetResult,
OptionComponent = LLCheerMeterWidgetOption,
CheerCountComponent = LLCheerMeterWidgetCheerCount,
ResultComponentStyles,
OptionComponentStyles,
CheerCountComponentStyles,
styles: stylesProp
} = _ref;
const styles = useStyles({
componentStylesFn: getCheerMeterWidgetBodyStyles,
stylesProp
});
const widgetOptions = useWidgetOptions({
widgetId
});
if (!(widgetOptions !== null && widgetOptions !== void 0 && widgetOptions.length)) {
return undefined;
}
const totalCheerCount = widgetOptions.reduce((total, _ref2) => {
let {
vote_count
} = _ref2;
return total + vote_count;
}, 0);
return /*#__PURE__*/React.createElement(View, {
style: styles.bodyContainer
}, /*#__PURE__*/React.createElement(ResultComponent, {
widgetId: widgetId,
widgetOptions: widgetOptions,
styles: ResultComponentStyles
}), /*#__PURE__*/React.createElement(View, {
style: styles.optionContainer
}, widgetOptions.map((option, index) => /*#__PURE__*/React.createElement(OptionComponent, {
key: option.id,
widgetId: widgetId,
optionIndex: index,
styles: OptionComponentStyles
})), /*#__PURE__*/React.createElement(CheerCountComponent, {
styles: CheerCountComponentStyles,
totalCheerCount: totalCheerCount
})));
}
const getCheerMeterWidgetBodyStyles = _ref3 => {
let {
theme
} = _ref3;
return StyleSheet.create({
bodyContainer: {
display: 'flex',
flexDirection: 'column',
marginHorizontal: 16,
marginBottom: 8
},
optionContainer: {
display: 'flex',
flexDirection: 'row',
position: 'relative'
}
});
};
//# sourceMappingURL=LLCheerMeterWidgetBody.js.map