Skip to content

Commit

Permalink
[Wave9] Progress Bar UI and Storybook (#64)
Browse files Browse the repository at this point in the history
* Implement progress bar

* Render progressBar with precedence of header

* Story for progressBar

* Missing semicolons

* Drop shouldShowProgressBar

* Fix double header rendered

* Wrap around useMemo

---------

Co-authored-by: Mateusz Rajski <mateusz.rajski@swmansion.com>
  • Loading branch information
MaciejSWM and mateuuszzzzz authored Feb 19, 2024
1 parent 756f846 commit 46eb9a6
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 15 deletions.
47 changes: 33 additions & 14 deletions src/components/HeaderWithBackButton/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useMemo } from 'react';
import {Keyboard, StyleSheet, View} from 'react-native';
import AvatarWithDisplayName from '@components/AvatarWithDisplayName';
import Header from '@components/Header';
Expand Down Expand Up @@ -58,6 +58,7 @@ function HeaderWithBackButton({
shouldOverlay = false,
singleExecution = (func) => func,
shouldNavigateToTopMostReport = false,
progressBarPercentage,
}: HeaderWithBackButtonProps) {
const theme = useTheme();
const styles = useThemeStyles();
Expand All @@ -70,6 +71,36 @@ function HeaderWithBackButton({
// If the icon is present, the header bar should be taller and use different font.
const isCentralPaneSettings = !!icon;

const middleContent = useMemo(() => {
if (progressBarPercentage) {
return (
<View>
<View style={styles.progressBarWrapper}>
<View style={[{width: `${progressBarPercentage}%`}, styles.progressBar]} />
</View>
</View>
);
}

if (shouldShowAvatarWithDisplay) {
return (
<AvatarWithDisplayName
report={report}
policy={policy}
shouldEnableDetailPageNavigation={shouldEnableDetailPageNavigation}
/>
);
}

return (
<Header
title={title}
subtitle={stepCounter ? translate('stepCounter', stepCounter) : subtitle}
textStyles={titleColor ? [StyleUtils.getTextColorStyle(titleColor)] : []}
/>
);
}, [StyleUtils, policy, progressBarPercentage, report, shouldEnableDetailPageNavigation, shouldShowAvatarWithDisplay, stepCounter, styles.progressBar, styles.progressBarWrapper, subtitle, title, titleColor, translate]);

return (
<View
// Hover on some part of close icons will not work on Electron if dragArea is true
Expand Down Expand Up @@ -118,19 +149,7 @@ function HeaderWithBackButton({
additionalStyles={[styles.mr2]}
/>
)}
{shouldShowAvatarWithDisplay ? (
<AvatarWithDisplayName
report={report}
policy={policy}
shouldEnableDetailPageNavigation={shouldEnableDetailPageNavigation}
/>
) : (
<Header
title={title}
subtitle={stepCounter ? translate('stepCounter', stepCounter) : subtitle}
textStyles={[titleColor ? StyleUtils.getTextColorStyle(titleColor) : {}, isCentralPaneSettings && styles.textHeadlineH1]}
/>
)}
{middleContent}
<View style={[styles.reportOptions, styles.flexRow, styles.pr5, styles.alignItemsCenter]}>
{children}
{shouldShowDownloadButton && (
Expand Down
3 changes: 3 additions & 0 deletions src/components/HeaderWithBackButton/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ type HeaderWithBackButtonProps = Partial<ChildrenProps> & {

/** Whether we should overlay the 3 dots menu */
shouldOverlayDots?: boolean;

/** 0 - 100 number indicating current progress of the progress bar */
progressBarPercentage?: number;
};

export type {ThreeDotsMenuItem};
Expand Down
9 changes: 8 additions & 1 deletion src/stories/HeaderWithBackButton.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ function Template(args) {
const Default = Template.bind({});
const Attachment = Template.bind({});
const Profile = Template.bind({});
const ProgressBar = Template.bind({});

Default.args = {
title: 'Settings',
};
Expand All @@ -35,6 +37,11 @@ Profile.args = {
title: 'Profile',
shouldShowBackButton: true,
};
ProgressBar.args = {
title: 'ProgressBar',
shouldShowBackButton: true,
progressBarPercentage: 33,
};

export default story;
export {Default, Attachment, Profile};
export {Default, Attachment, Profile, ProgressBar};
15 changes: 15 additions & 0 deletions src/styles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4343,6 +4343,21 @@ const styles = (theme: ThemeColors) =>
borderColor: theme.icon,
},

progressBarWrapper: {
position: 'absolute',
width: variables.componentSizeMedium,
height: 4,
borderRadius: variables.componentBorderRadiusRounded,
backgroundColor: theme.progressBarBackground,
alignSelf: 'center',
},

progressBar: {
borderRadius: variables.componentBorderRadiusRounded,
height: '100%',
backgroundColor: theme.progressBarFill,
},

interactiveStepHeaderContainer: {
flex: 1,
alignSelf: 'center',
Expand Down
2 changes: 2 additions & 0 deletions src/styles/theme/themes/dark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ const darkTheme = {
loungeAccessOverlay: colors.blue800,
mapAttributionText: colors.black,
white: colors.white,
progressBarBackground: colors.green800,
progressBarFill: colors.green400,

// Adding a color here will animate the status bar to the right color when the screen is opened.
// Note that it needs to be a screen name, not a route url.
Expand Down
2 changes: 2 additions & 0 deletions src/styles/theme/themes/light.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ const lightTheme = {
loungeAccessOverlay: colors.blue800,
mapAttributionText: colors.black,
white: colors.white,
progressBarBackground: colors.green800,
progressBarFill: colors.green400,

// Adding a color here will animate the status bar to the right color when the screen is opened.
// Note that it needs to be a screen name, not a route url.
Expand Down
2 changes: 2 additions & 0 deletions src/styles/theme/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ type ThemeColors = {
loungeAccessOverlay: Color;
mapAttributionText: Color;
white: Color;
progressBarBackground: Color;
progressBarFill: Color;

PAGE_THEMES: Record<string, {backgroundColor: Color; statusBarStyle: StatusBarStyle}>;

Expand Down

0 comments on commit 46eb9a6

Please sign in to comment.