@jpmorganchase/mosaic-layouts 0.1.0-beta.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (206) hide show
  1. package/.turbo/turbo-build.log +4 -0
  2. package/CHANGELOG.md +22 -0
  3. package/README.md +39 -0
  4. package/dist/Fade.d.ts +11 -0
  5. package/dist/Fade.js +1 -0
  6. package/dist/LayoutBase/index.css +1 -0
  7. package/dist/LayoutBase/index.d.ts +6 -0
  8. package/dist/LayoutBase/index.js +1 -0
  9. package/dist/LayoutBase/styles.css.css +1 -0
  10. package/dist/LayoutBase/styles.css.d.ts +8 -0
  11. package/dist/LayoutBase/styles.css.js +1 -0
  12. package/dist/LayoutColumns/index.css +1 -0
  13. package/dist/LayoutColumns/index.d.ts +7 -0
  14. package/dist/LayoutColumns/index.js +1 -0
  15. package/dist/LayoutColumns/styles.css.css +1 -0
  16. package/dist/LayoutColumns/styles.css.d.ts +9 -0
  17. package/dist/LayoutColumns/styles.css.js +1 -0
  18. package/dist/LayoutConfigProvider/index.d.ts +6 -0
  19. package/dist/LayoutConfigProvider/index.js +1 -0
  20. package/dist/LayoutFullWidth/index.css +1 -0
  21. package/dist/LayoutFullWidth/index.d.ts +7 -0
  22. package/dist/LayoutFullWidth/index.js +1 -0
  23. package/dist/LayoutFullWidth/styles.css.css +1 -0
  24. package/dist/LayoutFullWidth/styles.css.d.ts +4 -0
  25. package/dist/LayoutFullWidth/styles.css.js +1 -0
  26. package/dist/LayoutProvider.css +1 -0
  27. package/dist/LayoutProvider.d.ts +10 -0
  28. package/dist/LayoutProvider.js +1 -0
  29. package/dist/Sidebars/Drawer.css +1 -0
  30. package/dist/Sidebars/Drawer.d.ts +5 -0
  31. package/dist/Sidebars/Drawer.js +1 -0
  32. package/dist/Sidebars/SidebarLeft.css +1 -0
  33. package/dist/Sidebars/SidebarLeft.d.ts +5 -0
  34. package/dist/Sidebars/SidebarLeft.js +1 -0
  35. package/dist/Sidebars/SidebarRight.css +1 -0
  36. package/dist/Sidebars/SidebarRight.d.ts +5 -0
  37. package/dist/Sidebars/SidebarRight.js +1 -0
  38. package/dist/Sidebars/index.css +1 -0
  39. package/dist/Sidebars/index.d.ts +2 -0
  40. package/dist/Sidebars/index.js +1 -0
  41. package/dist/Sidebars/styles.css.css +1 -0
  42. package/dist/Sidebars/styles.css.d.ts +13 -0
  43. package/dist/Sidebars/styles.css.js +1 -0
  44. package/dist/chunk-25KPR4KC.js +1 -0
  45. package/dist/chunk-36VRRJYH.js +1 -0
  46. package/dist/chunk-475WQFFV.js +0 -0
  47. package/dist/chunk-4Z46UYNW.js +1 -0
  48. package/dist/chunk-53T3BYR6.js +1 -0
  49. package/dist/chunk-5HRFKBMO.js +1 -0
  50. package/dist/chunk-6TKQWZGT.js +1 -0
  51. package/dist/chunk-77TJQXKX.js +1 -0
  52. package/dist/chunk-ASVIILPC.js +1 -0
  53. package/dist/chunk-BKZGSG52.js +1 -0
  54. package/dist/chunk-DE36TWIF.js +1 -0
  55. package/dist/chunk-DTW4UURD.js +1 -0
  56. package/dist/chunk-E6MQWWR2.js +1 -0
  57. package/dist/chunk-FEIY7W7S.js +1 -0
  58. package/dist/chunk-FVHDTNGX.js +1 -0
  59. package/dist/chunk-G5JIKQRF.js +1 -0
  60. package/dist/chunk-GAMD2B7L.js +1 -0
  61. package/dist/chunk-GVN4L242.js +1 -0
  62. package/dist/chunk-HTHD7YMF.js +1 -0
  63. package/dist/chunk-JATFIZBE.js +1 -0
  64. package/dist/chunk-KER5XROW.js +1 -0
  65. package/dist/chunk-KZ6ZH4EY.js +1 -0
  66. package/dist/chunk-LAW2KABC.js +1 -0
  67. package/dist/chunk-NDZQ5OZP.js +0 -0
  68. package/dist/chunk-OMED577C.js +1 -0
  69. package/dist/chunk-OOBVDA2T.js +1 -0
  70. package/dist/chunk-PHW5SXKA.js +1 -0
  71. package/dist/chunk-PKAR7XZI.js +0 -0
  72. package/dist/chunk-Q3Z3PB5J.js +1 -0
  73. package/dist/chunk-RWWDUWAZ.js +1 -0
  74. package/dist/chunk-S2SS5ZQ2.js +1 -0
  75. package/dist/chunk-S7HNXMC4.js +1 -0
  76. package/dist/chunk-T5JOF44G.js +1 -0
  77. package/dist/chunk-WNZGJWRV.js +1 -0
  78. package/dist/chunk-X52NEVFW.js +1 -0
  79. package/dist/chunk-YA5BIJYR.js +1 -0
  80. package/dist/chunk-Z4UFTC3H.js +1 -0
  81. package/dist/chunk-ZUEPDUKR.js +1 -0
  82. package/dist/chunk-ZUHN4T3Z.js +1 -0
  83. package/dist/hooks/useIsLoading.d.ts +6 -0
  84. package/dist/hooks/useIsLoading.js +1 -0
  85. package/dist/index.css +1 -0
  86. package/dist/index.d.ts +8 -0
  87. package/dist/index.js +1 -0
  88. package/dist/layouts/App/index.css +1 -0
  89. package/dist/layouts/App/index.d.ts +3 -0
  90. package/dist/layouts/App/index.js +1 -0
  91. package/dist/layouts/App/styles.css.css +1 -0
  92. package/dist/layouts/App/styles.css.d.ts +4 -0
  93. package/dist/layouts/App/styles.css.js +1 -0
  94. package/dist/layouts/Detail/DetailContentOnly.css +1 -0
  95. package/dist/layouts/Detail/DetailContentOnly.d.ts +3 -0
  96. package/dist/layouts/Detail/DetailContentOnly.js +1 -0
  97. package/dist/layouts/Detail/DetailHighlight.css +1 -0
  98. package/dist/layouts/Detail/DetailHighlight.d.ts +3 -0
  99. package/dist/layouts/Detail/DetailHighlight.js +1 -0
  100. package/dist/layouts/Detail/DetailOverview.css +1 -0
  101. package/dist/layouts/Detail/DetailOverview.d.ts +3 -0
  102. package/dist/layouts/Detail/DetailOverview.js +1 -0
  103. package/dist/layouts/Detail/DetailTechnical.css +1 -0
  104. package/dist/layouts/Detail/DetailTechnical.d.ts +3 -0
  105. package/dist/layouts/Detail/DetailTechnical.js +1 -0
  106. package/dist/layouts/Detail/index.css +1 -0
  107. package/dist/layouts/Detail/index.d.ts +4 -0
  108. package/dist/layouts/Detail/index.js +1 -0
  109. package/dist/layouts/Detail/styles.css.css +1 -0
  110. package/dist/layouts/Detail/styles.css.d.ts +4 -0
  111. package/dist/layouts/Detail/styles.css.js +1 -0
  112. package/dist/layouts/Edit/index.css +1 -0
  113. package/dist/layouts/Edit/index.d.ts +3 -0
  114. package/dist/layouts/Edit/index.js +1 -0
  115. package/dist/layouts/Edit/styles.css.css +1 -0
  116. package/dist/layouts/Edit/styles.css.d.ts +5 -0
  117. package/dist/layouts/Edit/styles.css.js +1 -0
  118. package/dist/layouts/FullWidth/index.css +1 -0
  119. package/dist/layouts/FullWidth/index.d.ts +3 -0
  120. package/dist/layouts/FullWidth/index.js +1 -0
  121. package/dist/layouts/Landing/index.css +1 -0
  122. package/dist/layouts/Landing/index.d.ts +3 -0
  123. package/dist/layouts/Landing/index.js +1 -0
  124. package/dist/layouts/Newsletter/index.css +1 -0
  125. package/dist/layouts/Newsletter/index.d.ts +5 -0
  126. package/dist/layouts/Newsletter/index.js +1 -0
  127. package/dist/layouts/Product/ProductDiscover.css +1 -0
  128. package/dist/layouts/Product/ProductDiscover.d.ts +3 -0
  129. package/dist/layouts/Product/ProductDiscover.js +1 -0
  130. package/dist/layouts/Product/ProductPreview.css +1 -0
  131. package/dist/layouts/Product/ProductPreview.d.ts +3 -0
  132. package/dist/layouts/Product/ProductPreview.js +1 -0
  133. package/dist/layouts/Product/index.css +1 -0
  134. package/dist/layouts/Product/index.d.ts +2 -0
  135. package/dist/layouts/Product/index.js +1 -0
  136. package/dist/layouts/PythonDoc/index.css +1 -0
  137. package/dist/layouts/PythonDoc/index.d.ts +3 -0
  138. package/dist/layouts/PythonDoc/index.js +1 -0
  139. package/dist/layouts/PythonDoc/styles.css.css +1 -0
  140. package/dist/layouts/PythonDoc/styles.css.d.ts +12 -0
  141. package/dist/layouts/PythonDoc/styles.css.js +1 -0
  142. package/dist/layouts/TypeDoc/ExportsSidebar/index.css +1 -0
  143. package/dist/layouts/TypeDoc/ExportsSidebar/index.d.ts +9 -0
  144. package/dist/layouts/TypeDoc/ExportsSidebar/index.js +1 -0
  145. package/dist/layouts/TypeDoc/ExportsSidebar/styles.css.css +1 -0
  146. package/dist/layouts/TypeDoc/ExportsSidebar/styles.css.d.ts +6 -0
  147. package/dist/layouts/TypeDoc/ExportsSidebar/styles.css.js +1 -0
  148. package/dist/layouts/TypeDoc/index.css +1 -0
  149. package/dist/layouts/TypeDoc/index.d.ts +3 -0
  150. package/dist/layouts/TypeDoc/index.js +1 -0
  151. package/dist/layouts/TypeDoc/styles.css.css +1 -0
  152. package/dist/layouts/TypeDoc/styles.css.d.ts +7 -0
  153. package/dist/layouts/TypeDoc/styles.css.js +1 -0
  154. package/dist/layouts/index.css +1 -0
  155. package/dist/layouts/index.d.ts +9 -0
  156. package/dist/layouts/index.js +1 -0
  157. package/dist/types/index.d.ts +34 -0
  158. package/dist/types/index.js +0 -0
  159. package/package.json +42 -0
  160. package/src/Fade.tsx +48 -0
  161. package/src/LayoutBase/index.tsx +35 -0
  162. package/src/LayoutBase/styles.css.ts +73 -0
  163. package/src/LayoutColumns/index.tsx +36 -0
  164. package/src/LayoutColumns/styles.css.ts +64 -0
  165. package/src/LayoutConfigProvider/index.tsx +22 -0
  166. package/src/LayoutFullWidth/index.tsx +21 -0
  167. package/src/LayoutFullWidth/styles.css.ts +17 -0
  168. package/src/LayoutProvider.tsx +35 -0
  169. package/src/Sidebars/Drawer.tsx +66 -0
  170. package/src/Sidebars/SidebarLeft.tsx +15 -0
  171. package/src/Sidebars/SidebarRight.tsx +13 -0
  172. package/src/Sidebars/index.tsx +2 -0
  173. package/src/Sidebars/styles.css.ts +101 -0
  174. package/src/hooks/useIsLoading.ts +75 -0
  175. package/src/index.ts +9 -0
  176. package/src/layouts/App/index.tsx +12 -0
  177. package/src/layouts/App/styles.css.ts +23 -0
  178. package/src/layouts/Detail/DetailContentOnly.tsx +15 -0
  179. package/src/layouts/Detail/DetailHighlight.tsx +24 -0
  180. package/src/layouts/Detail/DetailOverview.tsx +47 -0
  181. package/src/layouts/Detail/DetailTechnical.tsx +53 -0
  182. package/src/layouts/Detail/index.tsx +4 -0
  183. package/src/layouts/Detail/styles.css.ts +5 -0
  184. package/src/layouts/Edit/index.tsx +35 -0
  185. package/src/layouts/Edit/styles.css.ts +23 -0
  186. package/src/layouts/FullWidth/index.tsx +12 -0
  187. package/src/layouts/Landing/index.tsx +12 -0
  188. package/src/layouts/Newsletter/index.tsx +29 -0
  189. package/src/layouts/Product/ProductDiscover.tsx +15 -0
  190. package/src/layouts/Product/ProductPreview.tsx +12 -0
  191. package/src/layouts/Product/index.tsx +2 -0
  192. package/src/layouts/PythonDoc/index.tsx +86 -0
  193. package/src/layouts/PythonDoc/styles.css.ts +67 -0
  194. package/src/layouts/TypeDoc/ExportsSidebar/index.tsx +36 -0
  195. package/src/layouts/TypeDoc/ExportsSidebar/styles.css.ts +44 -0
  196. package/src/layouts/TypeDoc/icons.css +944 -0
  197. package/src/layouts/TypeDoc/icons.png +0 -0
  198. package/src/layouts/TypeDoc/icons@2x.png +0 -0
  199. package/src/layouts/TypeDoc/index.tsx +80 -0
  200. package/src/layouts/TypeDoc/style.css +689 -0
  201. package/src/layouts/TypeDoc/styles.css.ts +41 -0
  202. package/src/layouts/TypeDoc/widgets.png +0 -0
  203. package/src/layouts/TypeDoc/widgets@2x.png +0 -0
  204. package/src/layouts/index.ts +9 -0
  205. package/src/types/index.tsx +28 -0
  206. package/tsconfig.json +8 -0
@@ -0,0 +1,21 @@
1
+ import React from 'react';
2
+ import classnames from 'classnames';
3
+
4
+ import styles from './styles.css';
5
+
6
+ export interface LayoutFullWidthProps {
7
+ Footer?: React.ReactElement;
8
+ children: React.ReactNode;
9
+ className?: string;
10
+ }
11
+
12
+ export const LayoutFullWidth: React.FC<LayoutFullWidthProps> = ({
13
+ Footer,
14
+ children = null,
15
+ className
16
+ }) => (
17
+ <div className={classnames(styles.root, className)}>
18
+ <main>{children}</main>
19
+ {Footer && Footer}
20
+ </div>
21
+ );
@@ -0,0 +1,17 @@
1
+ import { config, responsiveSprinkles } from '@jpmorganchase/mosaic-theme';
2
+ import { style } from '@vanilla-extract/css';
3
+
4
+ export default {
5
+ root: style([
6
+ style({
7
+ maxWidth: `${config.main.width}px`,
8
+ marginLeft: 'auto',
9
+ marginRight: 'auto'
10
+ }),
11
+ responsiveSprinkles({
12
+ marginTop: ['x10', 'x10', 'x20', 'x20'],
13
+ paddingLeft: ['x4', 'x6', 'x6', 'x6'],
14
+ paddingRight: ['x4', 'x6', 'x6', 'x6']
15
+ })
16
+ ])
17
+ };
@@ -0,0 +1,35 @@
1
+ import React, { FC, ReactNode } from 'react';
2
+ import { useLayout } from '@jpmorganchase/mosaic-store';
3
+ import { usePageState } from '@jpmorganchase/mosaic-content-editor-plugin';
4
+ import { FullWidth } from './layouts/FullWidth';
5
+
6
+ import type { LayoutProps } from './types';
7
+
8
+ export type LayoutProviderProps = {
9
+ layoutComponents?: {
10
+ [name: string]: React.FC<LayoutProps> | undefined;
11
+ };
12
+ LayoutProps?: LayoutProps;
13
+ children: ReactNode;
14
+ };
15
+
16
+ export const LayoutProvider: FC<LayoutProviderProps> = ({
17
+ children,
18
+ layoutComponents,
19
+ LayoutProps = {}
20
+ }) => {
21
+ const { layout: layoutInStore = 'FullWidth' } = useLayout();
22
+ const { pageState } = usePageState();
23
+ const layout = pageState !== 'VIEW' ? 'EditLayout' : layoutInStore;
24
+
25
+ let LayoutComponent: FC<LayoutProps> | undefined = layoutComponents?.[layout] as FC<LayoutProps>;
26
+ if (!LayoutComponent) {
27
+ console.error(`Layout ${layout} is not supported, defaulting to FullWidth`);
28
+ LayoutComponent = FullWidth;
29
+ }
30
+ return LayoutComponent ? (
31
+ <LayoutComponent {...LayoutProps}>{children}</LayoutComponent>
32
+ ) : (
33
+ <>children</>
34
+ );
35
+ };
@@ -0,0 +1,66 @@
1
+ import React, { FC, ReactNode, useEffect, useLayoutEffect, useState } from 'react';
2
+ import { LayerLayout } from '@salt-ds/lab';
3
+ import { Icon, Button, useBreakpoint } from '@jpmorganchase/mosaic-components';
4
+ import styles from './styles.css';
5
+
6
+ export interface DrawerProps {
7
+ children?: ReactNode;
8
+ }
9
+
10
+ const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
11
+
12
+ export const Drawer: FC<DrawerProps> = ({ children }) => {
13
+ const [open, setOpen] = useState(false);
14
+ const [useDrawer, setUseDrawer] = useState(false);
15
+ const breakpoint = useBreakpoint();
16
+
17
+ const toggleDrawer = () => {
18
+ setOpen(old => !old);
19
+ };
20
+
21
+ useIsomorphicLayoutEffect(() => {
22
+ setUseDrawer(breakpoint === 'mobile' || breakpoint === 'tablet');
23
+ }, [breakpoint]);
24
+
25
+ useIsomorphicLayoutEffect(() => {
26
+ // Close drawer whenever a page loads
27
+ setOpen(false);
28
+ }, [children]);
29
+
30
+ return (
31
+ <>
32
+ {useDrawer && (
33
+ <>
34
+ <LayerLayout
35
+ className={styles.drawerInner}
36
+ aria-label="Overlaid Drawer"
37
+ isOpen={open}
38
+ disableScrim
39
+ position="left"
40
+ >
41
+ <aside className={styles.sidebarLeftDrawer}>{children}</aside>
42
+ </LayerLayout>
43
+ <div className={styles.toggleDrawer}>
44
+ <Button
45
+ className={styles.toggleButton}
46
+ onClick={toggleDrawer}
47
+ variant="regular"
48
+ aria-label="show the secondary navigation"
49
+ >
50
+ {open ? (
51
+ <Icon aria-label="close the main navigation" name="close" />
52
+ ) : (
53
+ <Icon aria-label="show the main navigation" name="menu" />
54
+ )}
55
+ </Button>
56
+ </div>
57
+ </>
58
+ )}
59
+ {!useDrawer && (
60
+ <aside className={styles.sidebarLeft}>
61
+ <div className={styles.sidebarStickyArea}>{children}</div>
62
+ </aside>
63
+ )}
64
+ </>
65
+ );
66
+ };
@@ -0,0 +1,15 @@
1
+ import React, { FC, ReactNode } from 'react';
2
+
3
+ import styles from './styles.css';
4
+ import { Drawer } from './Drawer';
5
+
6
+ export interface SidebarLeftProps {
7
+ children?: ReactNode;
8
+ }
9
+
10
+ export const SidebarLeft: FC<SidebarLeftProps> = ({ children }) => (
11
+ <>
12
+ {children && <Drawer>{children}</Drawer>}
13
+ {!children && <aside className={styles.sidebarLeftEmpty} />}
14
+ </>
15
+ );
@@ -0,0 +1,13 @@
1
+ import React, { FC, ReactNode } from 'react';
2
+
3
+ import styles from './styles.css';
4
+
5
+ export interface SidebarRightProps {
6
+ children?: ReactNode;
7
+ }
8
+
9
+ export const SidebarRight: FC<SidebarRightProps> = ({ children }) => (
10
+ <aside className={styles.sidebarRight}>
11
+ {children && <div className={styles.sidebarStickyArea}>{children}</div>}
12
+ </aside>
13
+ );
@@ -0,0 +1,2 @@
1
+ export * from './SidebarLeft';
2
+ export * from './SidebarRight';
@@ -0,0 +1,101 @@
1
+ import { keyframes, style } from '@vanilla-extract/css';
2
+ import {
3
+ button,
4
+ neutralBorder,
5
+ responsiveSprinkles,
6
+ sidebar,
7
+ config
8
+ } from '@jpmorganchase/mosaic-theme';
9
+
10
+ const fadeIn = keyframes({
11
+ '0%': { opacity: 0 },
12
+ '100%': { opacity: 1 }
13
+ });
14
+
15
+ export default {
16
+ sidebarLeft: style([
17
+ style({
18
+ flexShrink: 0,
19
+ flexGrow: 0,
20
+ zIndex: 1,
21
+ width: `${config.sidebarLeft.width}px`
22
+ }),
23
+ neutralBorder({ variant: 'low', borderRightWidth: 'thin' }),
24
+ sidebar({ variant: 'left' })
25
+ ]),
26
+ sidebarLeftDrawer: style([
27
+ responsiveSprinkles({
28
+ paddingTop: ['none', 'none', 'x6', 'x6']
29
+ })
30
+ ]),
31
+ sidebarLeftEmpty: style([
32
+ style({
33
+ flexShrink: 0,
34
+ zIndex: 1
35
+ }),
36
+ sidebar({ variant: 'leftEmpty' })
37
+ ]),
38
+ sidebarRight: style([
39
+ style({
40
+ flexShrink: 0,
41
+ zIndex: 3,
42
+ width: `${config.sidebarRight.width}px`
43
+ }),
44
+ sidebar({ variant: 'right' })
45
+ ]),
46
+ sidebarStickyArea: style([
47
+ style({
48
+ position: 'sticky',
49
+ overflow: 'auto',
50
+ height: `calc(100vh - ${config.appHeader.height}px)`,
51
+ top: `${config.appHeader.height}px`
52
+ }),
53
+ responsiveSprinkles({
54
+ paddingTop: ['x10', 'x10', 'x20', 'x20'],
55
+ paddingBottom: ['x4', 'x4', 'x4', 'x4']
56
+ })
57
+ ]),
58
+ toggleDrawer: style([
59
+ {
60
+ display: 'block',
61
+ position: 'fixed',
62
+ zIndex: 5
63
+ },
64
+ responsiveSprinkles({
65
+ bottom: ['x6', 'x6', 'x6', 'x6'],
66
+ right: ['x6', 'x6', 'x6', 'x6']
67
+ })
68
+ ]),
69
+ toggleButton: button({ variant: 'square' }),
70
+ closeDrawerButtonWrapper: style([
71
+ {
72
+ display: 'block',
73
+ position: 'fixed',
74
+ opacity: 0,
75
+ animationDuration: '100ms',
76
+ animationDelay: '225ms',
77
+ animationFillMode: 'forwards',
78
+ animationName: fadeIn
79
+ },
80
+ responsiveSprinkles({
81
+ bottom: ['x6', 'x6', 'x6', 'x6'],
82
+ right: ['x6', 'x6', 'x6', 'x6']
83
+ })
84
+ ]),
85
+ drawerInner: style([
86
+ style({
87
+ bottom: 0,
88
+ overflowY: 'scroll',
89
+ top: `${config.appHeader.height}px`,
90
+ height: `calc(100% - ${config.appHeader.height}px)`
91
+ }),
92
+ sidebar({ variant: 'drawer' }),
93
+ responsiveSprinkles({
94
+ paddingTop: ['x6', 'x6', 'none', 'none'],
95
+ paddingBottom: ['x6', 'x6', 'none', 'none']
96
+ })
97
+ ]),
98
+ drawerButton: style({
99
+ display: 'none'
100
+ })
101
+ };
@@ -0,0 +1,75 @@
1
+ import React from 'react';
2
+ import { useRouter } from 'next/router';
3
+
4
+ /**
5
+ * Returns an array with a boolean for `isLoading` and a boolean for `isBaseRouteChanging`
6
+ */
7
+ export function useIsLoading({ loadingDelay }: { loadingDelay?: number } = {}) {
8
+ const router = useRouter();
9
+ const [isLoading, setIsLoading] = React.useState<[boolean, boolean]>([!router.isReady, false]);
10
+ const isLoadingRef = React.useRef(isLoading[0]);
11
+ const lastBaseRootRef = React.useRef(router.asPath.split('/')[1]);
12
+ const deferredStateTimerIdRef = React.useRef<NodeJS.Timeout | null>();
13
+
14
+ const clearDeferredStateTimer = React.useCallback(() => {
15
+ if (deferredStateTimerIdRef.current) {
16
+ clearTimeout(deferredStateTimerIdRef.current);
17
+ deferredStateTimerIdRef.current = null;
18
+ }
19
+ }, []);
20
+
21
+ const handleRouteChangeStart = React.useCallback(
22
+ newRoute => {
23
+ const newBaseRoute = newRoute.split('/')[1];
24
+ const isBaseRouteChanging = newBaseRoute !== lastBaseRootRef.current;
25
+
26
+ isLoadingRef.current = true;
27
+
28
+ clearDeferredStateTimer();
29
+
30
+ if (loadingDelay) {
31
+ deferredStateTimerIdRef.current = setTimeout(() => {
32
+ if (isLoadingRef.current) {
33
+ setIsLoading([true, isBaseRouteChanging]);
34
+ }
35
+ }, loadingDelay);
36
+ } else {
37
+ setIsLoading([true, isBaseRouteChanging]);
38
+ }
39
+ },
40
+ [loadingDelay, clearDeferredStateTimer]
41
+ );
42
+ const handleRouteChangeError = React.useCallback(() => {
43
+ clearDeferredStateTimer();
44
+ if (isLoadingRef.current) {
45
+ setIsLoading([false, false]);
46
+ }
47
+ isLoadingRef.current = false;
48
+ }, [clearDeferredStateTimer]);
49
+ const handleRouteChangeComplete = React.useCallback(
50
+ newRoute => {
51
+ clearDeferredStateTimer();
52
+ if (isLoadingRef.current) {
53
+ setIsLoading([false, false]);
54
+ }
55
+ isLoadingRef.current = false;
56
+ lastBaseRootRef.current = newRoute.split('/')[1];
57
+ },
58
+ [clearDeferredStateTimer]
59
+ );
60
+
61
+ React.useEffect(() => {
62
+ router.events.on('routeChangeStart', handleRouteChangeStart);
63
+ router.events.on('routeChangeError', handleRouteChangeError);
64
+ router.events.on('routeChangeComplete', handleRouteChangeComplete);
65
+
66
+ return () => {
67
+ router.events.off('routeChangeStart', handleRouteChangeStart);
68
+ router.events.off('routeChangeError', handleRouteChangeError);
69
+ router.events.off('routeChangeComplete', handleRouteChangeComplete);
70
+ };
71
+ // eslint-disable-next-line react-hooks/exhaustive-deps
72
+ }, []);
73
+
74
+ return isLoading;
75
+ }
package/src/index.ts ADDED
@@ -0,0 +1,9 @@
1
+ export * from './LayoutBase';
2
+ export * from './LayoutColumns';
3
+ export * from './LayoutFullWidth';
4
+ export * from './Sidebars';
5
+ export * from './hooks/useIsLoading';
6
+ export * from './LayoutConfigProvider';
7
+ export * from './LayoutProvider';
8
+
9
+ export * as layouts from './layouts';
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ import { AppHeader } from '@jpmorganchase/mosaic-site-components';
3
+
4
+ import { LayoutBase } from '../../LayoutBase';
5
+ import type { LayoutProps } from '../../types';
6
+ import styles from './styles.css';
7
+
8
+ export const AppLayout: React.FC<LayoutProps> = ({ children }) => (
9
+ <LayoutBase Header={<AppHeader />}>
10
+ <div className={styles.root}>{children}</div>
11
+ </LayoutBase>
12
+ );
@@ -0,0 +1,23 @@
1
+ import { responsiveSprinkles, vars, config } from '@jpmorganchase/mosaic-theme';
2
+ import { style, globalStyle } from '@vanilla-extract/css';
3
+
4
+ const root = style([
5
+ style({
6
+ maxWidth: '100vw',
7
+ marginLeft: vars.space.horizontal.x10,
8
+ marginRight: vars.space.horizontal.x10
9
+ }),
10
+ responsiveSprinkles({
11
+ marginTop: ['x6', 'x6', 'x10', 'x10']
12
+ })
13
+ ]);
14
+
15
+ globalStyle(`${root} > footer`, {
16
+ maxWidth: `${config.main.width}px`,
17
+ marginLeft: 'auto',
18
+ marginRight: 'auto'
19
+ });
20
+
21
+ export default {
22
+ root
23
+ };
@@ -0,0 +1,15 @@
1
+ import React from 'react';
2
+ import { AppHeader, Breadcrumbs, Footer } from '@jpmorganchase/mosaic-site-components';
3
+
4
+ import { LayoutBase } from '../../LayoutBase';
5
+ import { LayoutFullWidth } from '../../LayoutFullWidth';
6
+ import type { LayoutProps } from '../../types';
7
+
8
+ export const DetailContentOnly: React.FC<LayoutProps> = ({ FooterProps, children }) => (
9
+ <LayoutBase Header={<AppHeader />}>
10
+ <LayoutFullWidth Footer={<Footer {...FooterProps} />}>
11
+ <Breadcrumbs />
12
+ {children}
13
+ </LayoutFullWidth>
14
+ </LayoutBase>
15
+ );
@@ -0,0 +1,24 @@
1
+ import React from 'react';
2
+ import {
3
+ AppHeader,
4
+ Breadcrumbs,
5
+ Footer,
6
+ TableOfContents
7
+ } from '@jpmorganchase/mosaic-site-components';
8
+
9
+ import { LayoutBase } from '../../LayoutBase';
10
+ import { LayoutColumns } from '../../LayoutColumns';
11
+ import type { LayoutProps } from '../../types';
12
+
13
+ export const DetailHighlight: React.FC<LayoutProps> = ({ FooterProps, children }) => (
14
+ <LayoutBase Header={<AppHeader />}>
15
+ <LayoutColumns
16
+ PrimarySidebar={null}
17
+ SecondarySidebar={<TableOfContents />}
18
+ Footer={<Footer {...FooterProps} />}
19
+ >
20
+ <Breadcrumbs />
21
+ {children}
22
+ </LayoutColumns>
23
+ </LayoutBase>
24
+ );
@@ -0,0 +1,47 @@
1
+ import React from 'react';
2
+ import { HelpLinks } from '@jpmorganchase/mosaic-components';
3
+ import {
4
+ AppHeader,
5
+ BackLink,
6
+ Breadcrumbs,
7
+ DocPaginator,
8
+ Footer,
9
+ VerticalNavigation
10
+ } from '@jpmorganchase/mosaic-site-components';
11
+
12
+ import { LayoutBase } from '../../LayoutBase';
13
+ import { LayoutColumns } from '../../LayoutColumns';
14
+ import type { LayoutProps } from '../../types';
15
+ import styles from './styles.css';
16
+
17
+ export const DetailOverview: React.FC<LayoutProps> = ({
18
+ BackLinkProps,
19
+ SidebarProps,
20
+ FooterProps,
21
+ children
22
+ }) => {
23
+ const Sidebar = (
24
+ <>
25
+ {BackLinkProps && (
26
+ <header className={styles.sidebarHeader}>
27
+ <BackLink {...BackLinkProps} />
28
+ </header>
29
+ )}
30
+ <VerticalNavigation />
31
+ {SidebarProps?.helpLinks && <HelpLinks subTitle="Need help?" {...SidebarProps.helpLinks} />}
32
+ </>
33
+ );
34
+ return (
35
+ <LayoutBase Header={<AppHeader />}>
36
+ <LayoutColumns
37
+ PrimarySidebar={Sidebar}
38
+ SecondarySidebar={null}
39
+ Footer={<Footer {...FooterProps} />}
40
+ >
41
+ <Breadcrumbs />
42
+ {children}
43
+ <DocPaginator />
44
+ </LayoutColumns>
45
+ </LayoutBase>
46
+ );
47
+ };
@@ -0,0 +1,53 @@
1
+ import React from 'react';
2
+ import { HelpLinks } from '@jpmorganchase/mosaic-components';
3
+ import {
4
+ AppHeader,
5
+ DocPaginator,
6
+ BackLink,
7
+ Breadcrumbs,
8
+ Footer,
9
+ TableOfContents,
10
+ VerticalNavigation
11
+ } from '@jpmorganchase/mosaic-site-components';
12
+
13
+ import { LayoutBase } from '../../LayoutBase';
14
+ import { LayoutColumns } from '../../LayoutColumns';
15
+ import type { LayoutProps } from '../../types';
16
+ import styles from './styles.css';
17
+
18
+ export const DetailTechnical: React.FC<LayoutProps> = ({
19
+ BackLinkProps,
20
+ FooterProps,
21
+ SidebarProps,
22
+ children
23
+ }) => {
24
+ const Header = <AppHeader />;
25
+
26
+ const PrimarySidebar = (
27
+ <>
28
+ {BackLinkProps && (
29
+ <header className={styles.sidebarHeader}>
30
+ <BackLink {...BackLinkProps} />
31
+ </header>
32
+ )}
33
+ <VerticalNavigation />
34
+ {SidebarProps?.helpLinks && <HelpLinks subTitle="Need help?" {...SidebarProps.helpLinks} />}
35
+ </>
36
+ );
37
+
38
+ const SecondarySidebar = <TableOfContents />;
39
+
40
+ return (
41
+ <LayoutBase Header={Header}>
42
+ <LayoutColumns
43
+ PrimarySidebar={PrimarySidebar}
44
+ SecondarySidebar={SecondarySidebar}
45
+ Footer={<Footer {...FooterProps} />}
46
+ >
47
+ <Breadcrumbs />
48
+ {children}
49
+ <DocPaginator />
50
+ </LayoutColumns>
51
+ </LayoutBase>
52
+ );
53
+ };
@@ -0,0 +1,4 @@
1
+ export { DetailContentOnly } from './DetailContentOnly';
2
+ export { DetailHighlight } from './DetailHighlight';
3
+ export { DetailOverview } from './DetailOverview';
4
+ export { DetailTechnical } from './DetailTechnical';
@@ -0,0 +1,5 @@
1
+ import { style } from '@vanilla-extract/css';
2
+
3
+ export default {
4
+ sidebarHeader: style({ flexShrink: 0 })
5
+ };
@@ -0,0 +1,35 @@
1
+ import React, { useEffect } from 'react';
2
+ import { useRouter } from 'next/router';
3
+ import { useContentEditor } from '@jpmorganchase/mosaic-content-editor-plugin';
4
+ import { AppHeader } from '@jpmorganchase/mosaic-site-components';
5
+
6
+ import { LayoutBase } from '../../LayoutBase';
7
+ import type { LayoutProps } from '../../types';
8
+ import styles from './styles.css';
9
+
10
+ export const EditLayout: React.FC<LayoutProps> = ({ children }) => {
11
+ const router = useRouter();
12
+ const { pageState, stopEditing } = useContentEditor();
13
+
14
+ useEffect(() => {
15
+ const handleRouteChange = () => {
16
+ if (pageState === 'EDIT') {
17
+ stopEditing();
18
+ }
19
+ };
20
+
21
+ router.events.on('routeChangeStart', handleRouteChange);
22
+
23
+ return () => {
24
+ router.events.off('routeChangeStart', handleRouteChange);
25
+ };
26
+ }, [pageState, router.events, stopEditing]);
27
+
28
+ return (
29
+ <LayoutBase className={styles.base} Header={<AppHeader />}>
30
+ <div id="edit-layout" className={styles.root}>
31
+ {children}
32
+ </div>
33
+ </LayoutBase>
34
+ );
35
+ };
@@ -0,0 +1,23 @@
1
+ import { responsiveSprinkles, vars, config } from '@jpmorganchase/mosaic-theme';
2
+ import { globalStyle, style } from '@vanilla-extract/css';
3
+
4
+ const base = style({});
5
+
6
+ globalStyle(`${base} > main`, {
7
+ overflow: 'hidden',
8
+ height: `calc(100% + ${config.appHeader.height}px)`
9
+ });
10
+
11
+ export default {
12
+ root: style([
13
+ style({
14
+ maxWidth: '100vw',
15
+ marginLeft: vars.space.horizontal.x10,
16
+ marginRight: vars.space.horizontal.x10
17
+ }),
18
+ responsiveSprinkles({
19
+ marginTop: ['x6', 'x6', 'x10', 'x10']
20
+ })
21
+ ]),
22
+ base
23
+ };
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ import { AppHeader } from '@jpmorganchase/mosaic-site-components';
3
+
4
+ import { LayoutBase } from '../../LayoutBase';
5
+ import { LayoutFullWidth } from '../../LayoutFullWidth';
6
+ import type { LayoutProps } from '../../types';
7
+
8
+ export const FullWidth: React.FC<LayoutProps> = ({ children }) => (
9
+ <LayoutBase Header={<AppHeader />}>
10
+ <LayoutFullWidth>{children}</LayoutFullWidth>
11
+ </LayoutBase>
12
+ );
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ import { AppHeader, Footer } from '@jpmorganchase/mosaic-site-components';
3
+
4
+ import { LayoutBase } from '../../LayoutBase';
5
+ import { LayoutFullWidth } from '../../LayoutFullWidth';
6
+ import type { LayoutProps } from '../../types';
7
+
8
+ export const Landing: React.FC<LayoutProps> = ({ FooterProps, children }) => (
9
+ <LayoutBase Header={<AppHeader />}>
10
+ <LayoutFullWidth Footer={<Footer {...FooterProps} />}>{children}</LayoutFullWidth>
11
+ </LayoutBase>
12
+ );
@@ -0,0 +1,29 @@
1
+ import React from 'react';
2
+ import { AppHeader, DocPaginator, BackLink, Footer } from '@jpmorganchase/mosaic-site-components';
3
+
4
+ import { LayoutBase } from '../../LayoutBase';
5
+ import { LayoutColumns } from '../../LayoutColumns';
6
+ import type { LayoutProps } from '../../types';
7
+ import styles from '../Detail/styles.css';
8
+
9
+ export interface NewsletterProps extends LayoutProps {}
10
+
11
+ export const Newsletter: React.FC<NewsletterProps> = ({ children, BackLinkProps, FooterProps }) => {
12
+ const Sidebar = BackLinkProps?.link ? (
13
+ <header className={styles.sidebarHeader}>
14
+ <BackLink {...BackLinkProps} />
15
+ </header>
16
+ ) : null;
17
+ return (
18
+ <LayoutBase Header={<AppHeader />}>
19
+ <LayoutColumns
20
+ PrimarySidebar={Sidebar}
21
+ Footer={<Footer {...FooterProps} />}
22
+ SecondarySidebar={null}
23
+ >
24
+ {children}
25
+ <DocPaginator linkSuffix="Post" />
26
+ </LayoutColumns>
27
+ </LayoutBase>
28
+ );
29
+ };