import * as React from 'react'; import { View as RNView, Animated as RNAnimated, Pressable as RNButton, ActivityIndicator as RNActivityIndicator, } from 'react-native'; import { getStyle } from './button.style'; import { useTheme } from '../../theme'; import { ButtonProps } from './button.type'; import { getThemeProperty, getThemeColor } from '../../theme/theme.service'; import { getUnderlayColor, getRippleColor } from './button.service'; import { Text } from '../text/text.component'; import { textProps } from '../../types'; import { getSpecificProps } from '../../utilities'; import { useDefaultProps } from '../../utilities/useDefaultProps'; const Button: React.FunctionComponent = (incomingProps) => { const props = useDefaultProps('Button', incomingProps, { bg: 'blue600', p: 'lg', color: 'white', rounded: 'sm', loading: false, disabled: false, loaderSize: '2xl', loaderColor: 'white', block: false, position: 'relative', shadowColor: 'gray800', shadow: 0, fontSize: 'lg', rippleColor: 'white', ripple: true, borderless: false, alignItems: 'center', justifyContent: 'center', alignSelf: 'flex-start', onPress: () => {}, flexDir: 'row', }); const { m, mt, mr, mb, ml, ms, p, pr, pt, pb, pl, h, w, bg, minW, minH, suffix, style, fontSize, fontWeight, prefix, rounded, roundedTop, roundedRight, roundedBottom, roundedLeft, color: colorProp, loading, disabled, loaderColor, loaderSize, children, borderColor, borderBottomColor, borderLeftColor, borderTopColor, borderRightColor, borderWidth, borderLeftWidth, borderRightWidth, borderBottomWidth, borderTopWidth, borderEndWidth, shadow, borderless, rippleColor, shadowColor, onPress, block, ripple, alignSelf, ...rest } = props; const { theme } = useTheme(); const computedStyle = getStyle(theme, props); const underlayColor = getUnderlayColor(theme, props); const calculatedRippleColor = getRippleColor(theme, props); /** * renders children based on type */ const renderChildren = () => { if (typeof children === 'string') { return ( {children} ); } return children; }; return ( [ computedStyle.button, pressed && !disabled && !loading && { backgroundColor: underlayColor }, ]} android_ripple={ !ripple ? { color: calculatedRippleColor, borderless, } : null } > {loading ? ( ) : ( <> {prefix} {renderChildren()} {suffix} )} ); }; // Button.defaultProps = { // bg: 'blue600', // p: 'lg', // color: 'white', // rounded: 'sm', // loading: false, // disabled: false, // loaderSize: '2xl', // loaderColor: 'white', // block: false, // position: 'relative', // shadowColor: 'gray800', // shadow: 0, // fontSize: 'lg', // rippleColor: 'white', // ripple: true, // borderless: false, // alignItems: 'center', // justifyContent: 'center', // alignSelf: 'flex-start', // onPress: () => {}, // flexDir: 'row', // }; export { Button };