ilink-world/app/components/CustomButton/index.js

80 lines
2.1 KiB
JavaScript
Raw Normal View History

2020-04-17 22:03:04 +00:00
import React from "react";
2021-12-07 05:25:01 +00:00
import {ActivityIndicator, StyleSheet, TouchableOpacity} from "react-native";
import {Color} from '../../config/Color';
2020-04-17 22:03:04 +00:00
import PropTypes from "prop-types";
import CustomText from "../CustomText";
import styles from "./styles";
export default function CustomButton(props) {
2021-12-07 05:25:01 +00:00
const {
style,
styleCustomText,
icon,
outline,
onPress,
full,
round,
loading,
children,
...rest
} = props;
2020-04-17 22:03:04 +00:00
2021-12-07 05:25:01 +00:00
return (
<TouchableOpacity
{...rest}
style={StyleSheet.flatten([
[styles.default, {backgroundColor: Color.primaryColor}],
outline && [
styles.outline,
{backgroundColor: Color.cardBackgroundColor, borderColor: Color.primaryColor}
],
full && styles.full,
round && styles.round,
style
])}
activeOpacity={0.9}
onPress={onPress}
>
{icon ? icon : null}
<CustomText
style={StyleSheet.flatten([
styles.textDefault,
outline && {color: Color.primaryColor},
styleCustomText
])}
numberOfLines={1}
>
{children || "CustomButton"}
</CustomText>
{loading ? (
<ActivityIndicator
size="small"
color={outline ? Color.primaryColor : Color.whiteColor}
style={{paddingLeft: 5}}
/>
) : null}
</TouchableOpacity>
);
2020-04-17 22:03:04 +00:00
}
CustomButton.propTypes = {
2021-12-07 05:25:01 +00:00
style: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
icon: PropTypes.node,
outline: PropTypes.bool,
full: PropTypes.bool,
onPress: PropTypes.func,
round: PropTypes.bool,
loading: PropTypes.bool
2020-04-17 22:03:04 +00:00
};
CustomButton.defaultProps = {
2021-12-07 05:25:01 +00:00
style: {},
icon: null,
outline: false,
full: false,
onPress: () => {
},
round: false,
loading: false
2020-04-17 22:03:04 +00:00
};