-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathToolbarButton.tsx
More file actions
83 lines (78 loc) · 1.6 KB
/
Copy pathToolbarButton.tsx
File metadata and controls
83 lines (78 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { type FC } from 'react';
import {
Pressable,
StyleSheet,
Text,
type StyleProp,
type ViewStyle,
} from 'react-native';
import { Icon, type IconName } from './Icon';
interface ToolbarButtonIconProps {
text?: never;
icon: IconName;
isActive: boolean;
isDisabled: boolean;
onPress: () => void;
testID?: string;
containerStyle?: StyleProp<ViewStyle>;
}
interface ToolbarButtonTextProps {
text: string;
icon?: never;
isActive: boolean;
isDisabled: boolean;
onPress: () => void;
testID?: string;
containerStyle?: StyleProp<ViewStyle>;
}
export type ToolbarButtonProps =
ToolbarButtonIconProps | ToolbarButtonTextProps;
export const ToolbarButton: FC<ToolbarButtonProps> = ({
icon,
text,
isActive,
isDisabled,
onPress,
testID,
containerStyle,
}) => {
return (
<Pressable
style={[
styles.container,
isActive && styles.containerActive,
isDisabled && styles.containerDisabled,
containerStyle,
]}
disabled={isDisabled}
onPress={onPress}
testID={testID}
>
{icon ? (
<Icon name={icon} size={20} color="white" />
) : (
<Text style={styles.text}>{text}</Text>
)}
</Pressable>
);
};
const styles = StyleSheet.create({
container: {
justifyContent: 'center',
alignItems: 'center',
width: 56,
height: 56,
backgroundColor: 'rgba(0, 26, 114, 0.8)',
},
containerActive: {
backgroundColor: 'rgb(0, 26, 114)',
},
containerDisabled: {
backgroundColor: 'rgb(0, 26, 114)',
opacity: 0.3,
},
text: {
color: 'white',
fontSize: 20,
},
});