UNPKG

@nexara/nativeflow

Version:

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

158 lines (157 loc) 4.68 kB
"use strict"; import React, { useMemo } from 'react'; import { StyleSheet, TouchableOpacity } from "react-native"; import { verticalScale, horizontalScale } from "../../helpers/ResponsiveCalculations.js"; import { StyledText, StyledView } from "../StyledComponents/index.js"; import { useTheme } from "../../hooks/index.js"; import { getButtonColors } from "./utils.js"; import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime"; const Button = ({ variant = 'contained', type = 'flat', fullWidth = false, paddingH = 19, paddingV = 14, bg, br = 5, stroke = 1, strokeColor, titleColor, title = 'Button', titleFS, titleVariant = 'h5', titleFF, size = 50, rippleColor, renderIcon, renderLeftIcon, renderRightIcon, disabled = false, buttonContainerStyle, textStyle, onPress, ...rest }) => { const theme = useTheme(); const { backgroundColor, buttonTextColor, buttonBorderColor, buttonIconColor } = getButtonColors({ theme, variant, bg, titleColor, strokeColor, disabled }); const STYLES = useMemo(Styles, []); const dynamicStyles = { BUTTON_CONT: { backgroundColor: backgroundColor, borderWidth: variant === 'contained' ? 0 : stroke, borderColor: buttonBorderColor }, BUTTON_TEXT: { color: buttonTextColor, fontFamily: titleFF ?? '' }, FLAT_BTN_MAIN_CONT: { borderRadius: verticalScale(br), alignSelf: fullWidth ? 'stretch' : 'flex-start' }, FLAT_BTN_INNER_CONT: { paddingVertical: verticalScale(paddingV), paddingHorizontal: horizontalScale(!fullWidth ? paddingH : 30), borderRadius: verticalScale(br) }, ROUND_BTN_INNER_CONT: { height: verticalScale(size), width: verticalScale(size) } }; const cloneElement = element => { if (/*#__PURE__*/React.isValidElement(element)) { return /*#__PURE__*/React.cloneElement(element, { color: element.props.color ?? buttonIconColor }); } return null; }; return /*#__PURE__*/_jsxs(_Fragment, { children: [type === 'flat' && /*#__PURE__*/_jsx(StyledView, { style: [STYLES.FLAT_BTN_MAIN_CONT, dynamicStyles.FLAT_BTN_MAIN_CONT], children: /*#__PURE__*/_jsx(TouchableOpacity, { onPress: onPress // rippleColor={rippleColor} , disabled: disabled // ref={ref} , ...rest, children: /*#__PURE__*/_jsxs(StyledView, { style: [STYLES.FLAT_BTN_INNER_CONT, STYLES.BUTTON_CONT, dynamicStyles.FLAT_BTN_INNER_CONT, dynamicStyles.BUTTON_CONT, buttonContainerStyle], children: [(renderLeftIcon || fullWidth && renderRightIcon) && /*#__PURE__*/_jsx(StyledView, { f: fullWidth ? 1 : undefined, children: renderLeftIcon && cloneElement(renderLeftIcon) }), /*#__PURE__*/_jsx(StyledView, { flexShrink: 1, f: fullWidth ? 8 : undefined, children: /*#__PURE__*/_jsx(StyledText, { numberOfLines: 1, fs: titleFS, variant: titleVariant, style: [STYLES.BUTTON_TEXT, dynamicStyles.BUTTON_TEXT, textStyle], children: title }) }), (renderRightIcon || fullWidth && renderLeftIcon) && /*#__PURE__*/_jsx(StyledView, { alignItems: "flex-end", f: fullWidth ? 1 : undefined, children: renderRightIcon && cloneElement(renderRightIcon) })] }) }) }), type === 'round' && /*#__PURE__*/_jsx(StyledView, { style: STYLES.ROUND_BTN_MAIN_CONT, children: /*#__PURE__*/_jsx(TouchableOpacity, { onPress: onPress // rippleColor={rippleColor} , ...rest, children: /*#__PURE__*/_jsx(StyledView, { style: [STYLES.BUTTON_CONT, STYLES.ROUND_BTN_INNER_CONT, dynamicStyles.BUTTON_CONT, dynamicStyles.ROUND_BTN_INNER_CONT, buttonContainerStyle], children: renderIcon && cloneElement(renderIcon) }) }) })] }); }; export default Button; const Styles = () => StyleSheet.create({ BUTTON_CONT: { maxWidth: '100%' }, BUTTON_TEXT: { textAlign: 'center' }, FLAT_BTN_MAIN_CONT: { overflow: 'hidden' }, FLAT_BTN_INNER_CONT: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', gap: horizontalScale(10) }, ROUND_BTN_MAIN_CONT: { overflow: 'hidden', borderRadius: verticalScale(100), alignSelf: 'flex-start' }, ROUND_BTN_INNER_CONT: { alignItems: 'center', justifyContent: 'center' } }); //# sourceMappingURL=Button.js.map