@nexara/nativeflow
Version:
Beautiful, responsive, and customizable UI components for React Native – built for performance and seamless experiences.
119 lines (118 loc) • 3.92 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _react = require("react");
var _reactNative = require("react-native");
var _index = require("../StyledComponents/index.js");
var _index2 = require("../../hooks/index.js");
var _index3 = require("../../helpers/index.js");
var _index4 = require("../../assets/svg/index.js");
var _jsxRuntime = require("react/jsx-runtime");
const CheckBox = ({
variant = 'square',
isChecked = false,
defaultValue = false,
activeBgColor,
inActiveBgColor = 'transparent',
iconColor,
disableBuiltInState = false,
disabled = false,
label = 'Checkbox',
fScale = 'xs',
fs,
ff,
size = 20,
iconSize,
containerStyle,
labelStyle,
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.states.disabled : activeBgColor ?? colors.brand.primary;
iconSize = iconSize ?? size / 1.5;
const bgColor = !disableBuiltInState && isCheckboxChecked || disableBuiltInState && isChecked ? activeBgColor : inActiveBgColor;
const textColor = disabled ? colors.typography.disabled : colors.typography.primary;
const dynamicMainContStyles = {
height: (0, _index3.verticalScale)(size),
width: (0, _index3.verticalScale)(size),
borderColor: disabled ? colors.border.default : activeBgColor,
borderRadius: (0, _index3.verticalScale)(variant === 'square' ? 5 : 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.jsxs)(_index.StyledView, {
style: [STYLES.CONTAINER, containerStyle],
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.TouchableWithoutFeedback, {
onPressIn: () => animateScale(0.8),
onPressOut: () => animateScale(1),
onPress: onUserClick,
disabled: disabled,
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Animated.View, {
style: [STYLES.CHECKBOX_PARENT_CONT, dynamicMainContStyles, checkBoxStyle, animatedStyle],
children: (disableBuiltInState ? isChecked : isCheckboxChecked) && /*#__PURE__*/(0, _jsxRuntime.jsx)(_index4.Check, {
color: disabled ? colors.states.disabled : iconColor ?? colors.brand.onPrimary,
size: (0, _index3.verticalScale)(iconSize)
})
})
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.TouchableOpacity, {
onPressIn: () => animateScale(0.8),
onPressOut: () => animateScale(1),
onPress: onUserClick,
disabled: disabled,
children: label && /*#__PURE__*/(0, _jsxRuntime.jsx)(_index.StyledText, {
style: labelStyle,
fs: fs,
ff: ff,
color: textColor,
fScale: fScale,
children: label
})
})]
});
};
var _default = exports.default = CheckBox;
const Styles = () => _reactNative.StyleSheet.create({
CONTAINER: {
flexDirection: 'row',
gap: (0, _index3.horizontalScale)(10),
alignItems: 'center'
},
CHECKBOX_PARENT_CONT: {
borderWidth: 0.8,
alignItems: 'center',
justifyContent: 'center',
padding: (0, _index3.horizontalScale)(7)
}
});
//# sourceMappingURL=CheckBox.js.map