Skip to content

Commit

Permalink
Merge pull request #46 from jpmorgan-payments/feature/embedded-compon…
Browse files Browse the repository at this point in the history
…ents

Add initial draft version of embedded components
  • Loading branch information
hyunghoseo authored Jul 2, 2024
2 parents 2875d9f + ca6d9b3 commit 7893616
Show file tree
Hide file tree
Showing 131 changed files with 57,000 additions and 298 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/releaseEBComponents.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Release EB Components to npm
on:
workflow_dispatch:

jobs:
build:
defaults:
run:
working-directory: "./embedded-components"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# Setup .npmrc file to publish to npm
- uses: actions/setup-node@v3
with:
node-version: "20.x"
registry-url: "https://registry.npmjs.org"
scope: "@jpmorgan-payments"
- name: Build and package
run: |
yarn install --frozen-lockfile
yarn run test
- name: Publish
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_JPMC_PUBLISHER }}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ This example requires Yarn.

To start our client code with mocked responses:

1. Clone this repo.
1. Clone this repo

2. Install the `client` folder:

Expand Down
2 changes: 2 additions & 0 deletions app/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"dependencies": {
"@emotion/react": "^11.9.3",
"@forgerock/javascript-sdk": "^4.2.0",
"@jpmorgan-payments/embedded-banking-components": "^0.1.0",
"@mantine/core": "^6.0.4",
"@mantine/dates": "^6.0.4",
"@mantine/form": "^6.0.4",
Expand All @@ -25,6 +26,7 @@
"msw": "^1.2.1",
"react": "^18.1.0",
"react-dom": "^18.1.0",
"react-error-boundary": "^4.0.12",
"react-number-format": "^4.9.2",
"react-router-dom": "^6.3.0",
"remeda": "^1.0.1",
Expand Down
10 changes: 10 additions & 0 deletions app/client/public/signIn.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions app/client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
Login,
SecureContent,
} from 'features/Authentication';
import { EmbeddedComponentsPage } from 'pages/EmbeddedComponentsPage';

const queryClient = new QueryClient({
defaultOptions: {
Expand Down Expand Up @@ -68,6 +69,10 @@ const App = () => {
<Route path="transactions" element={<TransactionsPage />} />
<Route path="debit-cards" element={<DebitCardsPage />} />
<Route path="cases" element={<CasesPage />} />
<Route
path="embedded-components"
element={<EmbeddedComponentsPage />}
/>
<Route path="/" element={<Navigate replace to="/overview" />} />
</Routes>
</Layout>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Box, Grid } from '@mantine/core';
import { Prism } from '@mantine/prism';

type ComponentSamplePanelProps = {
code: string;
component: React.ReactNode;
};

export const ComponentSamplePanel = ({ code, component }:ComponentSamplePanelProps) => {
return (
<Grid align="center" justify="center" style={{ width: '100%' }}>
<Grid.Col lg={8} sm={10}>
<Box p="lg">{component}</Box>
<Prism colorScheme="dark" language="javascript">
{code}
</Prism>
</Grid.Col>
</Grid>
);
};
13 changes: 11 additions & 2 deletions app/client/src/components/Layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import { useMediaQuery } from '@mantine/hooks';

import { NavbarLinks } from './NavbarLinks/NavbarLinks';
import { NavbarLinksComponentShowcase } from './NavbarLinks/NavbarLinksComponentShowcase';
import {
ThemeSelectMenu,
ThemeSelectMenuProps,
Expand All @@ -38,6 +39,10 @@ export const Layout = ({
}, [location]);

const lessThanSm = useMediaQuery(`(max-width: ${theme.breakpoints.sm})`);
const appTitle =
location?.pathname === '/embedded-components'
? 'Embedded Components'
: 'Embedded Banking Showcase';

return (
<AppShell
Expand All @@ -58,7 +63,11 @@ export const Layout = ({
hidden={!opened}
width={{ sm: 200, lg: 300 }}
>
<NavbarLinks />
{location?.pathname === '/embedded-components' ? (
<NavbarLinksComponentShowcase />
) : (
<NavbarLinks />
)}
</Navbar>
}
header={
Expand Down Expand Up @@ -86,7 +95,7 @@ export const Layout = ({
: theme.colors.dark[4]
}
>
{lessThanSm ? 'EB Showcase' : 'Embedded Banking Showcase'}
{lessThanSm ? 'EB Showcase' : appTitle}
</Text>

<ThemeSelectMenu {...themeProps} />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { useMatch, useResolvedPath } from 'react-router-dom';
import { Button, Text, useMantineTheme } from '@mantine/core';
import { useWindowScroll } from '@mantine/hooks';
import useStyles from './NavbarLinks.styles';

const menu = [
{
label: 'Getting Started',
items: [
{
label: 'Overview',
},
{
label: 'Installation',
},
{
label: 'Authentication Provider',
},
],
},
{
label: 'Components',
items: [
{
label: 'Link Account',
},
],
},
];

function getStartY(el: any) {
const rect = el?.getBoundingClientRect();
return rect?.top + window.scrollY - 200;
}

function getEndY(startY: any, el: any) {
const height = el?.offsetHeight;
return height + startY;
}

const NavbarLink = ({ children, to, title }: any) => {
const { classes, cx } = useStyles();
const resolved = useResolvedPath(to);
const match = useMatch({ path: resolved.pathname });
const childMatch = useMatch({ path: resolved.pathname + '/:child' });
const [scroll, scrollTo] = useWindowScroll();
const theme = useMantineTheme();
const elM = document.getElementById(`${title?.trim()}-panel`);
const startY = getStartY(elM);
const endY = getEndY(startY, elM);

return (
<Button
style={{
width: '100%',
backgroundColor:
scroll.y >= startY && scroll.y < endY
? theme.colors.gray[1]
: 'white',
}}
className={cx(classes.link, {
[classes.linkActive]: match || childMatch,
})}
onClick={() => scrollTo({ y: startY })}
>
{children}
</Button>
);
};

export const NavbarLinksComponentShowcase = () => {
const theme = useMantineTheme();
return (
<>
{menu.map((section) => (
<div key={`navbar${section.label}`}>
<Text mb={theme.spacing.sm} mt={theme.spacing.sm} weight={600}>
{section?.label}
</Text>
{section?.items.map((item) => (
<NavbarLink key={`${item.label}`} title={item?.label}>
<span>{item.label}</span>
</NavbarLink>
))}
</div>
))}
</>
);
};
12 changes: 11 additions & 1 deletion app/client/src/components/ObjectDisplay/ObjectDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import { Prism, PrismProps } from '@mantine/prism';
export interface ObjectDisplayProps extends PaperProps {
request?: object;
response?: object;
sampleCode?: string;
isLoading?: boolean;
scrollAreaHeight?: number;
}

export const ObjectDisplay = ({
request,
response,
sampleCode,
isLoading = false,
scrollAreaHeight,
...rest
Expand Down Expand Up @@ -46,7 +48,7 @@ export const ObjectDisplay = ({
>
<LoadingOverlay visible={isLoading} />
<Tabs
defaultValue={request ? 'request' : 'response'}
defaultValue={request ? 'request' : response ? 'response' : 'sample'}
styles={(theme) => ({
tabsList: {
backgroundColor: theme.colors.dark[6],
Expand All @@ -58,6 +60,7 @@ export const ObjectDisplay = ({
{(response || isLoading) && (
<Prism.Tab value="response">Sample Response</Prism.Tab>
)}
{sampleCode && <Prism.Tab value="sample">Sample Code</Prism.Tab>}
</Tabs.List>
{request && (
<Tabs.Panel value="request">
Expand All @@ -71,6 +74,13 @@ export const ObjectDisplay = ({
</Prism>
</Tabs.Panel>
)}
{sampleCode && (
<Tabs.Panel value="sample">
<Prism {...prismProps} language="jsx">
{sampleCode ?? ''}
</Prism>
</Tabs.Panel>
)}
</Tabs>
</Paper>
</MantineProvider>
Expand Down
9 changes: 8 additions & 1 deletion app/client/src/components/Panel/Panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ interface PanelProps extends PaperProps {
objectDisplayHeight?: number;
requestBody?: object;
responseBody?: object;
sampleCode?: string;
isLoading?: boolean;
title?: string;
apiCallType?: 'GET' | 'POST' | 'DELETE';
apiEndpoint?: string;
customBadge?: React.ReactNode;
}

const callTypeColor = {
Expand All @@ -37,10 +39,12 @@ export const Panel = forwardRef<HTMLDivElement, PanelProps>(
objectDisplayHeight,
requestBody,
responseBody,
sampleCode,
isLoading = false,
title,
apiCallType,
apiEndpoint,
customBadge,
style,
...props
},
Expand All @@ -57,6 +61,7 @@ export const Panel = forwardRef<HTMLDivElement, PanelProps>(
}}
ref={ref}
{...props}
id={`${title?.trim()}-panel`}
>
<Grid>
<Grid.Col xs={12} lg="auto">
Expand All @@ -78,19 +83,21 @@ export const Panel = forwardRef<HTMLDivElement, PanelProps>(
{apiCallType}
</Badge>
) : null}
{customBadge}
<Code sx={{ backgroundColor: 'unset' }}>{apiEndpoint}</Code>
</Group>
</Group>
) : null}
{children}
</Box>
</Grid.Col>
{requestBody || responseBody || isLoading ? (
{requestBody || responseBody || sampleCode || isLoading ? (
<Grid.Col xs={12} lg="content">
<MediaQuery styles={{ width: '100%' }} smallerThan="lg">
<ObjectDisplay
request={requestBody}
response={responseBody}
sampleCode={sampleCode}
isLoading={isLoading}
w={480}
h="100%"
Expand Down
1 change: 1 addition & 0 deletions app/client/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export { ValuesTable } from './ValuesTable/ValuesTable';
export { Panel } from './Panel/Panel';
export { ObjectDisplay } from './ObjectDisplay/ObjectDisplay';
export { TableWithJsonDisplay } from './TableWithJsonDisplay/TableWithJsonDisplay';
export { ComponentSamplePanel } from './ComponentSamplePanel/ComponentSamplePanel';
Loading

0 comments on commit 7893616

Please sign in to comment.