Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement WorkflowCardBody Component #319

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

The WorkflowCard is a set of components that can be used to define custom screens within the workflows. Using these utility components will ensure that your custom screens match the style of the built-in screens for a seamless experience.

### WorkflowCardBody

This component is a simple wrapper that is used for layout. Your main screen contents should be children of this component.

The properties of the underlying React Native Paper [Card.Content](https://callstack.github.io/react-native-paper/docs/components/Card/CardContent) component are also available.

### WorkflowCardInstructions

| Prop Name | Type | Description | Default |
Expand Down
1 change: 0 additions & 1 deletion login-workflow/example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
"@babel/runtime": "^7.20.0",
"@brightlayer-ui/eslint-config": "^3.0.1",
"@brightlayer-ui/prettier-config": "^1.0.3",
"@brightlayer-ui/react-native-auth-workflow": "^6.0.0",
"@react-native/babel-preset": "0.74.0",
"@react-native/eslint-config": "0.74.0",
"@react-native/metro-config": "0.74.0",
Expand Down
23 changes: 3 additions & 20 deletions login-workflow/example/src/navigation/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,13 @@ import { View } from 'react-native';
import { NavigationDrawer } from './navigation-drawer';
import { createStackNavigator } from '@react-navigation/stack';
import Home from '../screens/home';
import PageOne from '../screens/pageOne';
import PageTwo from '../screens/pageTwo';
import { WorkflowCardInstructions } from '@brightlayer-ui/react-native-auth-workflow';
import { useExtendedTheme } from '@brightlayer-ui/react-native-themes';
import WorkFlowCardExample from '../screens/WorkFlowCardExample';

const Drawer = createDrawerNavigator();

export type RootStackParamList = {
Home: undefined;
PageOne: undefined;
PageTwo: undefined;
WorkflowCardInstructions: undefined;
WorkFlowCardExample: undefined;
NavigationDrawer: undefined;
};

Expand All @@ -28,16 +23,6 @@ const CustomDrawerContent = (props: any): any => (
</View>
);

const WorkflowCardInstructionsRenderer = (): JSX.Element => {
const theme = useExtendedTheme();
// marginTop has been added as instructions was going about the safe area view
return (
<View style={{ backgroundColor: theme.colors.background, flex: 1 }}>
<WorkflowCardInstructions style={{ marginTop: 80 }} instructions={'Test Instructions'} />
</View>
);
};

export const MainRouter = (): any => (
<NavigationContainer>
<Drawer.Navigator
Expand All @@ -48,9 +33,7 @@ export const MainRouter = (): any => (
drawerContent={(props: any): ReactNode => <CustomDrawerContent {...props} />}
>
<RootStack.Screen name="Home" component={Home} />
<RootStack.Screen name="PageOne" component={PageOne} />
<RootStack.Screen name="PageTwo" component={PageTwo} />
<RootStack.Screen name="WorkflowCardInstructions" component={WorkflowCardInstructionsRenderer} />
<RootStack.Screen name="WorkFlowCardExample" component={WorkFlowCardExample} />
</Drawer.Navigator>
</NavigationContainer>
);
9 changes: 2 additions & 7 deletions login-workflow/example/src/navigation/navigation-drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,8 @@ export const navGroupItems: NavItem[] = [
icon: { name: 'home' },
},
{
title: 'Page One',
itemID: 'PageOne',
icon: { name: 'looks-one' },
},
{
title: 'Page Two',
itemID: 'PageTwo',
title: 'Workflow Card',
itemID: 'WorkFlowCardExample',
icon: { name: 'looks-two' },
},
];
Expand Down
71 changes: 71 additions & 0 deletions login-workflow/example/src/screens/WorkFlowCardExample.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import React from 'react';
import { SafeAreaView, ScrollView } from 'react-native';
import { Header } from '@brightlayer-ui/react-native-components';
import { StackNavigationProp } from '@react-navigation/stack';
import { RootStackParamList } from '../navigation';
import { WorkflowCardBody, WorkflowCardInstructions } from '@brightlayer-ui/react-native-auth-workflow';
import { HelperText, TextInput } from 'react-native-paper';
import { useThemeContext } from '../context/ThemeContext';
import { useExtendedTheme } from '@brightlayer-ui/react-native-themes';
import { UserMenuExample } from '../components/UserMenuExample';
import { toggleRTL } from './home';

type AppProps = {
navigation: StackNavigationProp<RootStackParamList, 'WorkFlowCardExample'>;
};

const WorkFlowCardExample: React.FC<AppProps> = ({ navigation }): JSX.Element => {
const theme = useExtendedTheme();
const { theme: themeType, setTheme } = useThemeContext();
const [errorFilledText, setErrorFilledText] = React.useState('Hello');
const [hasError, setHasError] = React.useState(true);

return (
<>
<Header
title={'Workflow Card Example'}
icon={{ name: 'menu' }}
onIconPress={(): void => {
navigation.openDrawer();
}}
actionItems={[
{
icon: { name: 'more' },
onPress: (): void => {},
component: (
<UserMenuExample
onToggleRTL={toggleRTL}
onToggleTheme={(): void => setTheme(themeType === 'light' ? 'dark' : 'light')}
/>
),
},
]}
/>
<SafeAreaView style={{ backgroundColor: theme.colors.background, flex: 1 }}>
<ScrollView>
<WorkflowCardInstructions instructions={'Test Instructions'} />
<WorkflowCardBody>
<TextInput
label="TextInput"
mode="flat"
left={<TextInput.Icon icon="email" />}
right={<TextInput.Icon icon="menu-down" />}
value={errorFilledText}
underlineColor={theme.colors.surface}
onChangeText={(value: string): void => {
setErrorFilledText(value);
setHasError(value.length > 4);
}}
error={hasError}
/>
<HelperText type="error" visible={hasError} style={{ marginBottom: 8 }}>
Error Message
</HelperText>
</WorkflowCardBody>
</ScrollView>
</SafeAreaView>
</>
);
};

export default WorkFlowCardExample;
4 changes: 2 additions & 2 deletions login-workflow/example/src/screens/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ const Home: React.FC<AppProps> = ({ navigation }): JSX.Element => {
/>
<SafeAreaView style={defaultStyles.content}>
<ScrollView>
<Button onPress={() => navigation.navigate('WorkflowCardInstructions')}>
Workflow Card Instructions
<Button onPress={() => navigation.navigate('WorkFlowCardExample')}>
Workflow Card Body Exmaple
</Button>
</ScrollView>
</SafeAreaView>
Expand Down
3 changes: 1 addition & 2 deletions login-workflow/example/src/screens/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from './home';
export * from './pageOne';
export * from './pageTwo';
export * from './WorkFlowCardExample';
53 changes: 0 additions & 53 deletions login-workflow/example/src/screens/pageOne.tsx

This file was deleted.

53 changes: 0 additions & 53 deletions login-workflow/example/src/screens/pageTwo.tsx

This file was deleted.

24 changes: 0 additions & 24 deletions login-workflow/example/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1202,20 +1202,6 @@
resolved "https://registry.yarnpkg.com/@brightlayer-ui/prettier-config/-/prettier-config-1.0.3.tgz#e40a7ae7435c6fd5118acbf249080e0aa81e93af"
integrity sha512-EYm3+V7Qd+oYEF+8FadsXAZqXryEHHbGnrV1BMp9selhABjceqUqXPVE4Sn3SKWQdBNJ3En2A3EzgrzRbvRTaw==

"@brightlayer-ui/react-auth-shared@^4.0.0-alpha.2":
version "4.0.0-alpha.2"
resolved "https://registry.yarnpkg.com/@brightlayer-ui/react-auth-shared/-/react-auth-shared-4.0.0-alpha.2.tgz#d6b691d56dfc037103c51cc4df636984b8bab085"
integrity sha512-tDQ73nFi5HNAGn0IuiFxlMAIKNj7lIpBTej7FLEU6XTOCJePILuWjhuNbsBn3rQd5oQfAaFh5Yd1lOxz/JE6MA==

"@brightlayer-ui/react-native-auth-workflow@^6.0.0":
version "6.0.0-alpha.1"
resolved "https://registry.yarnpkg.com/@brightlayer-ui/react-native-auth-workflow/-/react-native-auth-workflow-6.0.0-alpha.1.tgz#633ad944d1a8649079c3a7895a3d4e3fd1edd68f"
integrity sha512-l1n5f2SCTW4bN7IgxXsD5khi+JXKo5kQm0cnL+8bOotePSv9nxVCryFHmuGHT01bGCRLzaBZL3h+Fp4Sm7M1Mw==
dependencies:
"@brightlayer-ui/react-auth-shared" "^4.0.0-alpha.2"
lodash.clonedeep "^4.5.0"
react-native-status-bar-height "^2.5.0"

"@brightlayer-ui/react-native-components@^8.0.0":
version "8.0.0"
resolved "https://registry.yarnpkg.com/@brightlayer-ui/react-native-components/-/react-native-components-8.0.0.tgz#518382c081b5bde308c95adea80b0adeecd323f6"
Expand Down Expand Up @@ -5400,11 +5386,6 @@ locate-path@^6.0.0:
dependencies:
p-locate "^5.0.0"

lodash.clonedeep@^4.5.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz#e23f3f9c4f8fbdde872529c1071857a086e5ccef"
integrity sha512-H5ZhCF25riFd9uB5UCkVKo61m3S/xZk1x4wA6yp/L3RFP6Z/eHH1ymQcGLo7J3GMPfm0V/7m1tryHuGVxpqEBQ==

lodash.debounce@^4.0.8:
version "4.0.8"
resolved "https://registry.yarnpkg.com/lodash.debounce/-/lodash.debounce-4.0.8.tgz#82d79bff30a67c4005ffd5e2515300ad9ca4d7af"
Expand Down Expand Up @@ -6605,11 +6586,6 @@ react-native-select-dropdown@^3.4.0:
resolved "https://registry.yarnpkg.com/react-native-select-dropdown/-/react-native-select-dropdown-3.4.0.tgz#3ce31dc2e5ffa1abf4c47e3297bf0da7144f1ea3"
integrity sha512-9xK1z4tYpwMxp3hsM0y1+xfqq/JoMh+l7sBsJ81b2eikFwT6ZbndFBqupQXrsQ1akce9hgC/10Nkzj0LjVjeXQ==

react-native-status-bar-height@^2.5.0:
version "2.6.0"
resolved "https://registry.yarnpkg.com/react-native-status-bar-height/-/react-native-status-bar-height-2.6.0.tgz#b6afd25b6e3d533c43d0fcdcfd5cafd775592cea"
integrity sha512-z3SGLF0mHT+OlJDq7B7h/jXPjWcdBT3V14Le5L2PjntjjWM3+EJzq2BcXDwV+v67KFNJic5pgA26cCmseYek6w==

react-native-svg-transformer@^0.14.3:
version "0.14.3"
resolved "https://registry.yarnpkg.com/react-native-svg-transformer/-/react-native-svg-transformer-0.14.3.tgz#43c8e176f5a11f16f39b87a64018e0ac090ffbdb"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
Copy link
Collaborator

@JeffGreiner-eaton JeffGreiner-eaton Jan 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe something like this..

/**
 * @format
 */

import React from 'react';
import { cleanup, render, screen } from '@testing-library/react-native';
import { WorkflowCardBody } from 'src/components/WorkflowCard';
import { Text } from 'react-native-paper';

describe('WorkflowCardBody Test', () => {
    afterEach(cleanup);
    it('WorkflowCardBody renders correctly', () => {
        render(
                <WorkflowCardBody>
                    <Text>This is workflow card body content.</Text>
                </WorkflowCardBody>
        )
            .toJSON();
        expect(render).toBeTruthy();
        expect(screen.getByText('This is workflow card body content.')).toBeTruthy();
    });
});

* @format
*/

import React from 'react';

import { cleanup } from '@testing-library/react-native';
import renderer from 'react-test-renderer';
import { WorkflowCardBody } from 'src/components/WorkflowCard';
import { Text } from 'react-native-paper';

describe('WorkflowCardBody Test', () => {
afterEach(cleanup);
it('WorkflowCardBody renders correctly', () => {
const rendered = renderer
.create(
<WorkflowCardBody>
<Text>This is workflow card body content.</Text>
</WorkflowCardBody>
)
.toJSON();
expect(rendered).toBeTruthy();
});
});
40 changes: 40 additions & 0 deletions login-workflow/src/components/WorkflowCard/WorkflowCardBody.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React from 'react';

import { StyleSheet, ViewStyle } from 'react-native';
import { Card, CardContentProps } from 'react-native-paper';
import { useScreenWidth } from '../../hooks/useScreenWidth';

const makeStyles = (
isTablet: boolean
): StyleSheet.NamedStyles<{
workflowBodyStyle: ViewStyle;
}> =>
StyleSheet.create({
workflowBodyStyle: {
flex: 1,
// TODO: move this to common style
marginHorizontal: isTablet ? 24 : 16,
marginTop: 32,
marginBottom: isTablet ? 32 : 24,
paddingHorizontal: 0,
},
});

/**
* Component that renders the body content for the workflow card.
*
* @param children content to render in the WorkflowCardBody
*
* @category Component
*/

export const WorkflowCardBody: React.FC<CardContentProps> = (props) => {
const { children, style, ...otherCardContentProps } = props;
const isTablet = useScreenWidth();
const defaultStyles = makeStyles(isTablet);
return (
<Card.Content style={[defaultStyles.workflowBodyStyle, style]} {...otherCardContentProps}>
{children}
</Card.Content>
);
};
1 change: 1 addition & 0 deletions login-workflow/src/components/WorkflowCard/index.tsx
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './WorkflowCardInstructions';
export * from './WorkflowCardBody';
Loading