UNPKG

1.87 kBJavaScriptView Raw
1import * as React from 'react';
2import PropTypes from 'prop-types';
3import { StyleSheet, Text, TouchableOpacity, View, } from 'react-native';
4import { useCallbackOne, useMemoOne } from 'use-memo-one';
5import Color from './Color';
6import { StylePropType } from './utils';
7import { TEST_ID } from './Constant';
8const styles = StyleSheet.create({
9 container: {
10 height: 44,
11 justifyContent: 'flex-end',
12 },
13 text: {
14 color: Color.defaultBlue,
15 fontWeight: '600',
16 fontSize: 17,
17 backgroundColor: Color.backgroundTransparent,
18 marginBottom: 12,
19 marginLeft: 10,
20 marginRight: 10,
21 },
22});
23export const Send = ({ text = '', containerStyle, children, textStyle, label = 'Send', alwaysShowSend = false, disabled = false, sendButtonProps, onSend = () => { }, }) => {
24 const handleOnPress = useCallbackOne(() => {
25 if (text && onSend) {
26 onSend({ text: text.trim() }, true);
27 }
28 }, [text, onSend]);
29 const showSend = useMemoOne(() => alwaysShowSend || (text && text.trim().length > 0), [alwaysShowSend, text]);
30 if (!showSend) {
31 return null;
32 }
33 return (<TouchableOpacity testID={TEST_ID.SEND_TOUCHABLE} accessible accessibilityLabel='send' style={[styles.container, containerStyle]} onPress={handleOnPress} accessibilityRole='button' disabled={disabled} {...sendButtonProps}>
34 <View>
35 {children || <Text style={[styles.text, textStyle]}>{label}</Text>}
36 </View>
37 </TouchableOpacity>);
38};
39Send.propTypes = {
40 text: PropTypes.string,
41 onSend: PropTypes.func,
42 label: PropTypes.string,
43 containerStyle: StylePropType,
44 textStyle: StylePropType,
45 children: PropTypes.element,
46 alwaysShowSend: PropTypes.bool,
47 disabled: PropTypes.bool,
48 sendButtonProps: PropTypes.object,
49};
50//# sourceMappingURL=Send.js.map
\No newline at end of file