UNPKG

@nexara/nativeflow

Version:

Beautiful, responsive, and customizable UI components for React Native – built for performance and seamless experiences.

116 lines (115 loc) 4.66 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _react = _interopRequireWildcard(require("react")); var _reactNative = require("react-native"); var _index = require("../StyledComponents/index.js"); var _index2 = require("../../hooks/index.js"); var _ResponsiveCalculations = require("../../helpers/ResponsiveCalculations.js"); var _index3 = require("../../assets/svg/index.js"); var _jsxRuntime = require("react/jsx-runtime"); function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } const CheckBox = ({ variant = 'square', isChecked = false, defaultValue = false, activeBgColor, inActiveBgColor = 'transparent', iconColor, disableBuiltInState = false, disabled = false, text, fs, textVariant = 'h6', size = 20, iconSize, containerStyle, textStyle, checkBoxStyle, onPress }) => { const [isCheckboxChecked, setIsCheckboxChecked] = (0, _react.useState)(defaultValue); (0, _react.useEffect)(() => { setIsCheckboxChecked(defaultValue); }, [defaultValue]); const STYLES = (0, _react.useMemo)(Styles, []); const scaleVal = (0, _react.useRef)(new _reactNative.Animated.Value(1)).current; const { colors } = (0, _index2.useTheme)(); activeBgColor = disabled ? colors.disable : activeBgColor ?? colors.primary; iconSize = iconSize ?? size / 1.5; const bgColor = !disableBuiltInState && isCheckboxChecked || disableBuiltInState && isChecked ? activeBgColor : inActiveBgColor; const textColor = disabled ? colors.textDisable : colors.textPrimary; const dynamicMainContStyles = { height: (0, _ResponsiveCalculations.verticalScale)(size), width: (0, _ResponsiveCalculations.verticalScale)(size), borderColor: disabled ? colors.disable : activeBgColor, borderRadius: variant === 'square' ? 5 : (0, _ResponsiveCalculations.verticalScale)(size), backgroundColor: bgColor }; const animatedStyle = { transform: [{ scale: scaleVal }] }; const animateScale = toValue => { _reactNative.Animated.spring(scaleVal, { toValue, speed: 20, bounciness: 8, useNativeDriver: true }).start(); }; const onUserClick = () => { if (!disableBuiltInState) { onPress?.(!isCheckboxChecked); setIsCheckboxChecked(!isCheckboxChecked); } else { onPress?.(!isChecked); } }; return /*#__PURE__*/(0, _jsxRuntime.jsx)(_index.StyledView, { children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.TouchableWithoutFeedback, { onPressIn: () => animateScale(0.8), onPressOut: () => animateScale(1), onPress: onUserClick, disabled: disabled, children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_index.StyledView, { style: [STYLES.CONTAINER, containerStyle], children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Animated.View, { style: [STYLES.CHECKBOX_PARENT_CONT, dynamicMainContStyles, checkBoxStyle, animatedStyle], children: (disableBuiltInState ? isChecked : isCheckboxChecked) && /*#__PURE__*/(0, _jsxRuntime.jsx)(_index3.Check, { color: iconColor ?? colors.iconSecondary, size: (0, _ResponsiveCalculations.verticalScale)(iconSize) }) }), text && /*#__PURE__*/(0, _jsxRuntime.jsx)(_index.StyledText, { style: textStyle, fs: fs, color: textColor, variant: textVariant, primary: true, children: text })] }) }) }); }; var _default = exports.default = CheckBox; const Styles = () => _reactNative.StyleSheet.create({ CONTAINER: { flexDirection: 'row', gap: (0, _ResponsiveCalculations.horizontalScale)(10), alignItems: 'center' }, CHECKBOX_PARENT_CONT: { borderWidth: 0.8, alignItems: 'center', justifyContent: 'center', padding: (0, _ResponsiveCalculations.verticalScale)(7) } }); //# sourceMappingURL=CheckBox.js.map