Files
mattermost-mobile/app/components/button/index.tsx
Elias Nahum 784b05fe97 Upgrade Dependencies (#7299)
* upgrade reanimated

* update devDependencies

* upgrade react-intl

* update react-native and some dependencies

* update react-native-permissions

* update RN

* use Share sheet for Report a problem

* update Sentry

* remove step to downloadWebRTC

* update detox deps

* feedback review
2023-04-21 12:16:54 -04:00

91 lines
2.4 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React, {useMemo} from 'react';
import {type StyleProp, StyleSheet, Text, type TextStyle, View, type ViewStyle} from 'react-native';
import RNButton from 'react-native-button';
import CompassIcon from '@components/compass_icon';
import {buttonBackgroundStyle, buttonTextStyle} from '@utils/buttonStyles';
type ConditionalProps = | {iconName: string; iconSize: number} | {iconName?: never; iconSize?: never}
type Props = ConditionalProps & {
theme: Theme;
backgroundStyle?: StyleProp<ViewStyle>;
textStyle?: StyleProp<TextStyle>;
size?: ButtonSize;
emphasis?: ButtonEmphasis;
buttonType?: ButtonType;
buttonState?: ButtonState;
testID?: string;
onPress: () => void;
text: string;
}
const styles = StyleSheet.create({
container: {flexDirection: 'row'},
icon: {marginRight: 7},
});
const Button = ({
theme,
backgroundStyle,
textStyle,
size,
emphasis,
buttonType,
buttonState,
onPress,
text,
testID,
iconName,
iconSize,
}: Props) => {
const bgStyle = useMemo(() => [
buttonBackgroundStyle(theme, size, emphasis, buttonType, buttonState),
backgroundStyle,
], [theme, backgroundStyle, size, emphasis, buttonType, buttonState]);
const txtStyle = useMemo(() => [
buttonTextStyle(theme, size, emphasis, buttonType),
textStyle,
], [theme, textStyle, size, emphasis, buttonType]);
const containerStyle = useMemo(
() =>
(iconSize ? [
styles.container,
{minHeight: iconSize},
] : styles.container),
[iconSize],
);
return (
<RNButton
containerStyle={bgStyle}
onPress={onPress}
testID={testID}
>
<View style={containerStyle}>
{Boolean(iconName) &&
<CompassIcon
name={iconName!}
size={iconSize}
color={StyleSheet.flatten(txtStyle).color}
style={styles.icon}
/>
}
<Text
style={txtStyle}
numberOfLines={1}
>
{text}
</Text>
</View>
</RNButton>
);
};
export default Button;