2022-07-07 12:29:18 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { useTranslation } from 'react-i18next';
|
2022-07-08 08:48:30 +00:00
|
|
|
import {
|
|
|
|
Button as NativePaperButton,
|
|
|
|
Text,
|
|
|
|
TouchableRipple
|
|
|
|
} from 'react-native-paper';
|
2022-07-07 12:29:18 +00:00
|
|
|
|
2022-11-09 12:45:55 +00:00
|
|
|
import { BUTTON_MODES, BUTTON_TYPES } from '../../constants.native';
|
2022-07-27 08:40:34 +00:00
|
|
|
import BaseTheme from '../BaseTheme.native';
|
2022-10-20 09:11:27 +00:00
|
|
|
import { IButtonProps } from '../types';
|
2022-07-27 08:40:34 +00:00
|
|
|
|
|
|
|
import styles from './buttonStyles';
|
2022-07-11 12:30:37 +00:00
|
|
|
|
2022-10-20 09:11:27 +00:00
|
|
|
export interface IProps extends IButtonProps {
|
2022-07-27 08:40:34 +00:00
|
|
|
color?: string;
|
2022-10-11 08:26:09 +00:00
|
|
|
contentStyle?: Object | undefined;
|
2022-07-27 08:40:34 +00:00
|
|
|
labelStyle?: Object | undefined;
|
|
|
|
style?: Object | undefined;
|
|
|
|
}
|
2022-07-07 12:29:18 +00:00
|
|
|
|
2022-10-20 09:11:27 +00:00
|
|
|
const Button: React.FC<IProps> = ({
|
2022-07-07 12:29:18 +00:00
|
|
|
accessibilityLabel,
|
|
|
|
color: buttonColor,
|
2022-10-11 08:26:09 +00:00
|
|
|
contentStyle,
|
2022-07-07 12:29:18 +00:00
|
|
|
disabled,
|
|
|
|
icon,
|
2022-08-22 09:40:59 +00:00
|
|
|
labelKey,
|
2022-07-07 12:29:18 +00:00
|
|
|
labelStyle,
|
2022-08-22 09:40:59 +00:00
|
|
|
onClick: onPress,
|
2022-07-07 12:29:18 +00:00
|
|
|
style,
|
|
|
|
type
|
2022-10-20 09:11:27 +00:00
|
|
|
}: IProps) => {
|
2022-07-07 12:29:18 +00:00
|
|
|
const { t } = useTranslation();
|
2022-07-08 08:48:30 +00:00
|
|
|
const { CONTAINED } = BUTTON_MODES;
|
2022-07-07 12:29:18 +00:00
|
|
|
const { DESTRUCTIVE, PRIMARY, SECONDARY, TERTIARY } = BUTTON_TYPES;
|
|
|
|
|
|
|
|
let buttonLabelStyles;
|
|
|
|
let buttonStyles;
|
|
|
|
let color;
|
|
|
|
let mode;
|
|
|
|
|
|
|
|
if (type === PRIMARY) {
|
|
|
|
buttonLabelStyles = styles.buttonLabelPrimary;
|
|
|
|
color = BaseTheme.palette.action01;
|
2022-07-11 12:30:37 +00:00
|
|
|
mode = CONTAINED;
|
2022-07-07 12:29:18 +00:00
|
|
|
} else if (type === SECONDARY) {
|
|
|
|
buttonLabelStyles = styles.buttonLabelSecondary;
|
|
|
|
color = BaseTheme.palette.action02;
|
2022-07-11 12:30:37 +00:00
|
|
|
mode = CONTAINED;
|
2022-07-07 12:29:18 +00:00
|
|
|
} else if (type === DESTRUCTIVE) {
|
|
|
|
color = BaseTheme.palette.actionDanger;
|
|
|
|
buttonLabelStyles = styles.buttonLabelDestructive;
|
2022-07-11 12:30:37 +00:00
|
|
|
mode = CONTAINED;
|
|
|
|
} else {
|
2022-07-07 12:29:18 +00:00
|
|
|
color = buttonColor;
|
|
|
|
buttonLabelStyles = styles.buttonLabel;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (disabled) {
|
|
|
|
buttonLabelStyles = styles.buttonLabelDisabled;
|
|
|
|
buttonStyles = styles.buttonDisabled;
|
|
|
|
} else {
|
|
|
|
buttonStyles = styles.button;
|
|
|
|
}
|
|
|
|
|
2022-07-11 12:30:37 +00:00
|
|
|
if (type === TERTIARY) {
|
2022-11-21 14:07:27 +00:00
|
|
|
buttonLabelStyles
|
|
|
|
= disabled ? styles.buttonLabelTertiaryDisabled : styles.buttonLabelTertiary;
|
|
|
|
|
2022-07-08 08:48:30 +00:00
|
|
|
return (
|
|
|
|
<TouchableRipple
|
|
|
|
accessibilityLabel = { accessibilityLabel }
|
|
|
|
disabled = { disabled }
|
|
|
|
onPress = { onPress }
|
2022-11-22 16:13:36 +00:00
|
|
|
rippleColor = { BaseTheme.palette.action03Active }
|
2022-07-08 08:48:30 +00:00
|
|
|
style = { [
|
|
|
|
buttonStyles,
|
|
|
|
style
|
|
|
|
] }>
|
|
|
|
<Text
|
|
|
|
style = { [
|
2022-07-11 12:30:37 +00:00
|
|
|
buttonLabelStyles,
|
|
|
|
labelStyle
|
2022-08-22 09:40:59 +00:00
|
|
|
] }>{ t(labelKey ?? '') }</Text>
|
2022-07-08 08:48:30 +00:00
|
|
|
</TouchableRipple>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-07-07 12:29:18 +00:00
|
|
|
return (
|
|
|
|
<NativePaperButton
|
2022-07-18 13:16:08 +00:00
|
|
|
accessibilityLabel = { t(accessibilityLabel ?? '') }
|
2023-01-10 09:18:03 +00:00
|
|
|
buttonColor = { color }
|
2022-08-22 09:40:59 +00:00
|
|
|
children = { t(labelKey ?? '') }
|
2022-10-11 08:26:09 +00:00
|
|
|
contentStyle = { [
|
|
|
|
styles.buttonContent,
|
|
|
|
contentStyle
|
|
|
|
] }
|
2022-07-07 12:29:18 +00:00
|
|
|
disabled = { disabled }
|
2022-10-11 10:47:54 +00:00
|
|
|
|
2022-08-22 09:40:59 +00:00
|
|
|
// @ts-ignore
|
2022-07-07 12:29:18 +00:00
|
|
|
icon = { icon }
|
|
|
|
labelStyle = { [
|
|
|
|
buttonLabelStyles,
|
|
|
|
labelStyle
|
|
|
|
] }
|
|
|
|
mode = { mode }
|
|
|
|
onPress = { onPress }
|
|
|
|
style = { [
|
|
|
|
buttonStyles,
|
|
|
|
style
|
|
|
|
] } />
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Button;
|