-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathBreadcrumbs.tsx
84 lines (75 loc) · 2.94 KB
/
Breadcrumbs.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import React from 'react';
import type {StyleProp, ViewStyle} from 'react-native';
import {PixelRatio, View} from 'react-native';
import LogoComponent from '@assets/images/expensify-wordmark.svg';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import variables from '@styles/variables';
import CONST from '@src/CONST';
import Header from './Header';
import ImageSVG from './ImageSVG';
import Text from './Text';
type BreadcrumbHeader = {
type: typeof CONST.BREADCRUMB_TYPE.ROOT;
};
type BreadcrumbStrong = {
text: string;
type: typeof CONST.BREADCRUMB_TYPE.STRONG;
};
type Breadcrumb = {
text: string;
type?: typeof CONST.BREADCRUMB_TYPE.NORMAL;
};
type BreadcrumbsProps = {
/** An array of breadcrumbs consisting of the root/strong breadcrumb, followed by an optional second level breadcrumb */
breadcrumbs: [BreadcrumbHeader | BreadcrumbStrong, Breadcrumb | undefined];
/** Styles to apply to the container */
style?: StyleProp<ViewStyle>;
};
function Breadcrumbs({breadcrumbs, style}: BreadcrumbsProps) {
const theme = useTheme();
const styles = useThemeStyles();
const [primaryBreadcrumb, secondaryBreadcrumb] = breadcrumbs;
const fontScale = PixelRatio.getFontScale() > CONST.LOGO_MAX_SCALE ? CONST.LOGO_MAX_SCALE : PixelRatio.getFontScale();
return (
<View style={[styles.flexRow, styles.alignItemsCenter, styles.gap1, styles.w100, styles.breadcrumsContainer, style]}>
{primaryBreadcrumb.type === CONST.BREADCRUMB_TYPE.ROOT ? (
<View style={styles.breadcrumbLogo}>
<Header
title={
<ImageSVG
contentFit="contain"
src={LogoComponent}
fill={theme.text}
width={variables.lhnLogoWidth * fontScale}
height={variables.lhnLogoHeight * fontScale}
/>
}
shouldShowEnvironmentBadge
/>
</View>
) : (
<Text
numberOfLines={1}
style={[styles.flexShrink1, styles.breadcrumb, styles.breadcrumbStrong]}
>
{primaryBreadcrumb.text}
</Text>
)}
{!!secondaryBreadcrumb && (
<>
<Text style={[styles.breadcrumbSeparator]}>/</Text>
<Text
numberOfLines={1}
style={[styles.mw75, styles.flexShrink0, styles.breadcrumb, styles.flex1]}
>
{secondaryBreadcrumb.text}
</Text>
</>
)}
</View>
);
}
Breadcrumbs.displayName = 'Breadcrumbs';
export type {BreadcrumbsProps};
export default Breadcrumbs;