@livelike/react-native
Version:
LiveLike React Native package
73 lines (72 loc) • 2.27 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.LLCheerMeterWidgetResult = LLCheerMeterWidgetResult;
var _react = _interopRequireDefault(require("react"));
var _reactNative = require("react-native");
var _hooks = require("../../hooks");
var _LLText = require("../LLText");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function LLCheerMeterWidgetResult(_ref) {
let {
widgetOptions,
styles: stylesProp
} = _ref;
const styles = (0, _hooks.useStyles)({
componentStylesFn: getCheerMeterWidgetResultStyles,
stylesProp
});
if (!(widgetOptions !== null && widgetOptions !== void 0 && widgetOptions.length)) {
return undefined;
}
const totalCount = widgetOptions.reduce((total, option) => total + option.vote_count, 0);
return /*#__PURE__*/_react.default.createElement(_reactNative.View, {
style: styles.resultContainer
}, widgetOptions.map((option, index) => /*#__PURE__*/_react.default.createElement(_reactNative.View, {
style: [{
width: `${Math.round(option.vote_count / totalCount * 100)}%`
}, !totalCount && {
flex: 1
}, styles.optionContainer, index === 0 ? styles.leftOptionContainer : styles.rightOptionContainer],
key: option.id
}, /*#__PURE__*/_react.default.createElement(_LLText.LLText, {
style: styles.optionText,
numberOfLines: 1,
ellipsizeMode: 'tail'
}, option.description))));
}
const getCheerMeterWidgetResultStyles = _ref2 => {
let {
theme
} = _ref2;
return _reactNative.StyleSheet.create({
resultContainer: {
display: 'flex',
flexDirection: 'row',
marginTop: 4
},
optionContainer: {
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
height: 30,
paddingHorizontal: 6
},
leftOptionContainer: {
borderTopLeftRadius: 4,
borderBottomLeftRadius: 4,
backgroundColor: theme.correct
},
rightOptionContainer: {
borderTopRightRadius: 4,
borderBottomRightRadius: 4,
backgroundColor: theme.incorrect
},
optionText: {
color: theme.correctIncorrectText
}
});
};
//# sourceMappingURL=LLCheerMeterWidgetResult.js.map