-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathHeader.tsx
59 lines (51 loc) · 1.94 KB
/
Header.tsx
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
import type {ReactNode} from 'react';
import React from 'react';
import type {StyleProp, TextStyle} from 'react-native';
import {View} from 'react-native';
import useThemeStyles from '@hooks/useThemeStyles';
import EnvironmentBadge from './EnvironmentBadge';
import Text from './Text';
type HeaderProps = {
/** Title of the Header */
title?: ReactNode;
/** Subtitle of the header */
subtitle?: ReactNode;
/** Should we show the environment badge (dev/stg)? */
shouldShowEnvironmentBadge?: boolean;
/** Additional text styles */
textStyles?: StyleProp<TextStyle>;
};
function Header({title = '', subtitle = '', textStyles = [], shouldShowEnvironmentBadge = false}: HeaderProps) {
const styles = useThemeStyles();
return (
<View style={[styles.flex1, styles.flexRow]}>
<View style={styles.mw100}>
{typeof title === 'string'
? Boolean(title) && (
<Text
numberOfLines={2}
style={[styles.headerText, styles.textLarge, textStyles]}
>
{title}
</Text>
)
: title}
{/* If there's no subtitle then display a fragment to avoid an empty space which moves the main title */}
{typeof subtitle === 'string'
? Boolean(subtitle) && (
<Text
style={[styles.mutedTextLabel, styles.pre]}
numberOfLines={1}
>
{subtitle}
</Text>
)
: subtitle}
</View>
{shouldShowEnvironmentBadge && <EnvironmentBadge />}
</View>
);
}
Header.displayName = 'Header';
export default Header;
export type {HeaderProps};