UNPKG

@tra-tech/react-native-kitra

Version:
60 lines 2.4 kB
/* eslint-disable no-unused-expressions */ import { useState } from 'react'; import { StyleSheet, Text, TouchableOpacity, View } from 'react-native'; import { opacity } from '../../utilities'; import { applyDefaults } from '../../core/KitraProvider'; const ToggleButton = _ref => { let { typography, theme, buttons, size = 'medium' } = _ref; const [buttonList, setButtonList] = useState(buttons.map((item, index) => ({ ...item, id: index, active: false }))); return /*#__PURE__*/React.createElement(View, { style: { flexDirection: 'row' } }, buttonList === null || buttonList === void 0 ? void 0 : buttonList.map((item, index) => /*#__PURE__*/React.createElement(TouchableOpacity, { testID: `toggleButton-item-${index}`, activeOpacity: 0.5, key: item.label, onPress: () => { item.onPress(!buttonList[index].active); const tempButtonList = [...buttonList]; buttonList[index].active ? tempButtonList[index].active = false : tempButtonList[index].active = true; setButtonList(tempButtonList); }, style: [{ backgroundColor: item.active ? theme === null || theme === void 0 ? void 0 : theme.focused : opacity((theme === null || theme === void 0 ? void 0 : theme.primary) || '#000000', 5), borderColor: theme === null || theme === void 0 ? void 0 : theme.primary, paddingHorizontal: size === 'small' ? 10 : 20, paddingVertical: size === 'small' ? 5 : 10 }, styles.containerStyle, index < buttonList.length - 1 ? { borderRightWidth: 0 } : { borderRightWidth: 1 }, index === 0 ? { borderTopLeftRadius: 5, borderBottomLeftRadius: 5 } : null, index === buttonList.length - 1 ? { borderTopRightRadius: 5, borderBottomRightRadius: 5 } : null] }, /*#__PURE__*/React.createElement(Text, { style: [size === 'small' ? typography === null || typography === void 0 ? void 0 : typography.body.smedium : typography === null || typography === void 0 ? void 0 : typography.body.medium, { color: item.active ? theme === null || theme === void 0 ? void 0 : theme.white : theme === null || theme === void 0 ? void 0 : theme.primary }] }, item.label)))); }; export default applyDefaults(ToggleButton); const styles = StyleSheet.create({ containerStyle: { borderWidth: 1 } }); //# sourceMappingURL=ToggleButton.js.map