@ramses-superapp/ramses-ui
Version:
Skinless UI primitives for Ramses Built Apps
61 lines (60 loc) • 1.94 kB
JavaScript
"use strict";
import { StyleSheet, TouchableOpacity, ActivityIndicator } from 'react-native';
import { useTheme } from "../hooks/ThemeProvider.js";
import Colors from "../styles/colors.js";
import { useMemo } from 'react';
import RsText from "./RsText.js";
import { jsx as _jsx } from "react/jsx-runtime";
const RsButton = ({
primary = true,
fontSize = 24,
fontWeight = 'Bold',
width = '100%',
title = 'Ramses Button',
isLoading = false,
disabled = false,
style,
onPress = () => {},
textStyle
}) => {
const theme = useTheme();
const styles = useMemo(() => generateStyles(theme, {
primary,
fontSize,
fontWeight,
width,
disabled,
isLoading
}), [theme, primary, fontSize, fontWeight, width, disabled, isLoading]);
return /*#__PURE__*/_jsx(TouchableOpacity, {
style: [styles.button, style],
onPress: onPress,
disabled: disabled || isLoading,
activeOpacity: 0.75,
children: isLoading ? /*#__PURE__*/_jsx(ActivityIndicator, {
size: "small",
color: primary ? theme.Text.primaryButtonText : theme.Text.secondaryButtonText
}) : /*#__PURE__*/_jsx(RsText, {
style: textStyle,
text: title,
fontSize: fontSize,
fontWeight: fontWeight,
color: primary ? theme.Text.primaryButtonText : theme.Text.secondaryButtonText
})
});
};
export default RsButton;
const generateStyles = (theme, style) => StyleSheet.create({
button: {
backgroundColor: style.primary ? style.disabled || style.isLoading ? Colors.gray6 : theme.Background.primaryButton : theme.Background.secondaryButton,
alignItems: 'center',
justifyContent: 'center',
padding: 10,
borderWidth: 1,
borderRadius: 10,
borderColor: style.disabled || style.isLoading ? Colors.gray6 : style.primary ? theme.Borders.primaryButton : theme.Borders.secondaryButton,
width: style.width || '100%',
height: 48
}
});
//# sourceMappingURL=RsButton.js.map