UNPKG

@eslam-elmeniawy/react-native-common-components

Version:

Common `ReactNative` components packed in library for usage in projects.

87 lines (84 loc) 2.44 kB
"use strict"; // External imports. import * as React from 'react'; import { View, StyleSheet } from 'react-native'; import { withTheme, TouchableRipple, Checkbox as PaperCheckbox } from 'react-native-paper'; import tinyColor from 'tinycolor2'; // Types imports. // Internal imports. import styles from "./CompoundButton.styles.js"; import { Text } from "../Text/index.js"; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; const Checkbox = /*#__PURE__*/React.memo(props => { const { text, checked, onPress, disabled, checkedColor, uncheckedColor, textProps, contentAlign, style, theme, ...other } = props; const { style: textStyle, ...rest } = textProps ?? {}; const _checkedColor = checkedColor ?? theme.colors.primary; const _rippleColor = tinyColor(_checkedColor).setAlpha(0.25).toHex8String(); const _flattenStyle = StyleSheet.flatten(style ?? {}); const { padding, paddingHorizontal, paddingVertical, paddingTop, paddingBottom, paddingStart, paddingEnd, paddingRight, paddingLeft } = _flattenStyle; const _borderRadius = (theme.isV3 ? 5 : 1) * theme.roundness; return /*#__PURE__*/_jsx(View, { style: StyleSheet.flatten([styles.container, { borderRadius: _borderRadius }, style, styles.noPadding]), ...other, children: /*#__PURE__*/_jsx(TouchableRipple, { onPress: onPress, disabled: disabled, rippleColor: _rippleColor, underlayColor: _rippleColor, children: /*#__PURE__*/_jsxs(View, { style: StyleSheet.flatten([styles.rippleView, { padding, paddingHorizontal, paddingVertical, paddingTop, paddingBottom, paddingStart, paddingEnd, paddingRight, paddingLeft, alignItems: contentAlign ?? 'center' }]), children: [/*#__PURE__*/_jsx(PaperCheckbox.Android, { status: checked ? 'checked' : 'unchecked', onPress: onPress, color: _checkedColor, uncheckedColor: uncheckedColor, disabled: disabled }), Boolean(text) && Boolean(text?.length) && /*#__PURE__*/_jsx(Text, { style: StyleSheet.flatten([styles.text, textStyle]), ...rest, children: text })] }) }) }); }); export default withTheme(Checkbox); //# sourceMappingURL=Checkbox.js.map