forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Expensify#32221 from software-mansion-labs/wave8/b…
…readcrumbs [NoQA] [Wave8] Breadcrumbs
- Loading branch information
Showing
8 changed files
with
176 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import React from 'react'; | ||
import {StyleProp, View, ViewStyle} 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 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; | ||
|
||
return ( | ||
<View style={[styles.flexRow, styles.alignItemsCenter, styles.gap1, styles.w100, style]}> | ||
{primaryBreadcrumb.type === CONST.BREADCRUMB_TYPE.ROOT ? ( | ||
<View style={styles.breadcrumbLogo}> | ||
<Header | ||
title={ | ||
<LogoComponent | ||
fill={theme.text} | ||
width={variables.lhnLogoWidth} | ||
height={variables.lhnLogoHeight} | ||
/> | ||
} | ||
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]} | ||
> | ||
{secondaryBreadcrumb.text} | ||
</Text> | ||
</> | ||
)} | ||
</View> | ||
); | ||
} | ||
|
||
Breadcrumbs.displayName = 'Breadcrumbs'; | ||
|
||
export type {BreadcrumbsProps}; | ||
export default Breadcrumbs; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import React from 'react'; | ||
import Breadcrumbs, {BreadcrumbsProps} from '@components/Breadcrumbs'; | ||
import CONST from '@src/CONST'; | ||
|
||
/** | ||
* We use the Component Story Format for writing stories. Follow the docs here: | ||
* | ||
* https://storybook.js.org/docs/react/writing-stories/introduction#component-story-format | ||
*/ | ||
const story = { | ||
title: 'Components/Breadcrumbs', | ||
component: Breadcrumbs, | ||
}; | ||
|
||
type StoryType = typeof Template & {args?: Partial<BreadcrumbsProps>}; | ||
|
||
function Template(args: BreadcrumbsProps) { | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
return <Breadcrumbs {...args} />; | ||
} | ||
|
||
// Arguments can be passed to the component by binding | ||
// See: https://storybook.js.org/docs/react/writing-stories/introduction#using-args | ||
const Default: StoryType = Template.bind({}); | ||
Default.args = { | ||
breadcrumbs: [ | ||
{ | ||
type: CONST.BREADCRUMB_TYPE.ROOT, | ||
}, | ||
{ | ||
text: 'Chats', | ||
}, | ||
], | ||
}; | ||
|
||
const FirstBreadcrumbStrong: StoryType = Template.bind({}); | ||
FirstBreadcrumbStrong.args = { | ||
breadcrumbs: [ | ||
{ | ||
text: "Cathy's Croissants", | ||
type: CONST.BREADCRUMB_TYPE.STRONG, | ||
}, | ||
{ | ||
text: 'Chats', | ||
}, | ||
], | ||
}; | ||
|
||
export default story; | ||
export {Default, FirstBreadcrumbStrong}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,10 @@ export default { | |
maxWidth: 'auto', | ||
}, | ||
|
||
mw75: { | ||
maxWidth: '75%', | ||
}, | ||
|
||
mw100: { | ||
maxWidth: '100%', | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters