@servicetitan/navigation 11.0.0-canary.237.6ce8e81.0 → 11.0.0-canary.237.7d5e2c9.0

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 (81) hide show
  1. package/dist/components/badge-tag.d.ts +1 -1
  2. package/dist/components/badge-tag.d.ts.map +1 -1
  3. package/dist/components/logo/logo-titan-text.d.ts +1 -1
  4. package/dist/components/logo/logo-titan-text.d.ts.map +1 -1
  5. package/dist/components/profile-dropdown/profile-dropdown.d.ts +1 -0
  6. package/dist/components/profile-dropdown/profile-dropdown.d.ts.map +1 -1
  7. package/dist/components/profile-dropdown/profile-dropdown.js +2 -2
  8. package/dist/components/profile-dropdown/profile-dropdown.js.map +1 -1
  9. package/dist/components/profile-dropdown/profile-dropdown.module.less +2 -0
  10. package/dist/components/titan-layout/layout-context.js +1 -1
  11. package/dist/components/titan-layout/layout-context.js.map +1 -1
  12. package/dist/components/titan-layout/layout-header.d.ts +2 -0
  13. package/dist/components/titan-layout/layout-header.d.ts.map +1 -1
  14. package/dist/components/titan-layout/layout-header.js +3 -4
  15. package/dist/components/titan-layout/layout-header.js.map +1 -1
  16. package/dist/components/titan-layout/layout-header.module.less +55 -36
  17. package/dist/components/titan-layout/layout-logo.d.ts.map +1 -1
  18. package/dist/components/titan-layout/layout-logo.js +2 -1
  19. package/dist/components/titan-layout/layout-logo.js.map +1 -1
  20. package/dist/components/titan-layout/layout-profile.d.ts.map +1 -1
  21. package/dist/components/titan-layout/layout-profile.js +20 -5
  22. package/dist/components/titan-layout/layout-profile.js.map +1 -1
  23. package/dist/components/titan-layout/layout-profile.stories.js +1 -1
  24. package/dist/components/titan-layout/layout-profile.stories.js.map +1 -1
  25. package/dist/components/titan-layout/layout-sidebar-links-internal.d.ts +2 -2
  26. package/dist/components/titan-layout/layout-sidebar-links-internal.d.ts.map +1 -1
  27. package/dist/components/titan-layout/layout-sidebar-links-internal.js +4 -4
  28. package/dist/components/titan-layout/layout-sidebar-links-internal.js.map +1 -1
  29. package/dist/components/titan-layout/layout-sidebar-links.d.ts.map +1 -1
  30. package/dist/components/titan-layout/layout-sidebar-links.js +9 -2
  31. package/dist/components/titan-layout/layout-sidebar-links.js.map +1 -1
  32. package/dist/components/titan-layout/layout-sidebar.d.ts +2 -0
  33. package/dist/components/titan-layout/layout-sidebar.d.ts.map +1 -1
  34. package/dist/components/titan-layout/layout-sidebar.js +6 -4
  35. package/dist/components/titan-layout/layout-sidebar.js.map +1 -1
  36. package/dist/components/titan-layout/layout-sidebar.module.less +25 -5
  37. package/dist/components/titan-layout/notifications-context.d.ts +13 -0
  38. package/dist/components/titan-layout/notifications-context.d.ts.map +1 -0
  39. package/dist/components/titan-layout/notifications-context.js +23 -0
  40. package/dist/components/titan-layout/notifications-context.js.map +1 -0
  41. package/dist/components/titan-layout/titan-layout.d.ts +6 -3
  42. package/dist/components/titan-layout/titan-layout.d.ts.map +1 -1
  43. package/dist/components/titan-layout/titan-layout.js +77 -22
  44. package/dist/components/titan-layout/titan-layout.js.map +1 -1
  45. package/dist/components/titan-layout/titan-layout.module.less +29 -7
  46. package/dist/components/titan-layout/titan-layout.stories.d.ts +2 -0
  47. package/dist/components/titan-layout/titan-layout.stories.d.ts.map +1 -1
  48. package/dist/components/titan-layout/titan-layout.stories.js +8 -5
  49. package/dist/components/titan-layout/titan-layout.stories.js.map +1 -1
  50. package/dist/test/data.d.ts +4 -1
  51. package/dist/test/data.d.ts.map +1 -1
  52. package/dist/test/data.js +2 -3
  53. package/dist/test/data.js.map +1 -1
  54. package/dist/utils/use-breakpoint.d.ts +1 -0
  55. package/dist/utils/use-breakpoint.d.ts.map +1 -1
  56. package/dist/utils/use-breakpoint.js +3 -2
  57. package/dist/utils/use-breakpoint.js.map +1 -1
  58. package/package.json +2 -2
  59. package/src/components/badge-tag.tsx +1 -1
  60. package/src/components/logo/logo-titan-text.tsx +1 -1
  61. package/src/components/profile-dropdown/profile-dropdown.module.less +2 -0
  62. package/src/components/profile-dropdown/profile-dropdown.tsx +5 -1
  63. package/src/components/titan-layout/layout-context.tsx +1 -1
  64. package/src/components/titan-layout/layout-header.module.less +55 -36
  65. package/src/components/titan-layout/layout-header.module.less.d.ts +2 -0
  66. package/src/components/titan-layout/layout-header.tsx +12 -5
  67. package/src/components/titan-layout/layout-logo.tsx +13 -6
  68. package/src/components/titan-layout/layout-profile.stories.tsx +1 -1
  69. package/src/components/titan-layout/layout-profile.tsx +42 -19
  70. package/src/components/titan-layout/layout-sidebar-links-internal.tsx +18 -5
  71. package/src/components/titan-layout/layout-sidebar-links.tsx +11 -2
  72. package/src/components/titan-layout/layout-sidebar.module.less +25 -5
  73. package/src/components/titan-layout/layout-sidebar.module.less.d.ts +1 -0
  74. package/src/components/titan-layout/layout-sidebar.tsx +14 -5
  75. package/src/components/titan-layout/notifications-context.tsx +44 -0
  76. package/src/components/titan-layout/titan-layout.module.less +29 -7
  77. package/src/components/titan-layout/titan-layout.module.less.d.ts +2 -1
  78. package/src/components/titan-layout/titan-layout.stories.tsx +13 -4
  79. package/src/components/titan-layout/titan-layout.tsx +212 -93
  80. package/src/test/data.tsx +2 -3
  81. package/src/utils/use-breakpoint.ts +3 -1
@@ -29,24 +29,27 @@ import { TitanLayoutLogo, TitanLayoutLogoProps } from './layout-logo';
29
29
  import { LayoutSidebar } from './layout-sidebar';
30
30
  import { TitanLayoutSidebarLink, TitanLayoutSidebarTrigger } from './layout-sidebar-links';
31
31
  import { InternalSideNavigationTrigger } from './layout-sidebar-links-internal';
32
+ import { useNotificationsState } from './notifications-context';
32
33
  import * as Styles from './titan-layout.module.less';
33
34
 
34
35
  type TitanLayoutChild = ReactElement<TitanLayoutContentProps> | ReactElement<TitanLayoutLogoProps>;
35
36
 
36
37
  export type TitanLayoutProps = Omit<ComponentPropsWithoutRef<'div'>, 'children' | 'style'> & {
37
- empty?: boolean;
38
-
38
+ /** layout appearance */
39
39
  appearance?: 'legacy' | 'anvil1' | 'anvil2';
40
40
 
41
+ /** layout's content */
42
+ children?: TitanLayoutChild | TitanLayoutChild[];
43
+
44
+ /** show only content without side and top bars */
45
+ contentOnly?: boolean;
46
+
41
47
  /** component used for navigation */
42
48
  navigationComponent?: FC<NavLinkComponentProps>;
43
49
 
44
50
  /** data for main navigation links */
45
51
  navigationMainItems?: NavigationItemData[];
46
52
 
47
- /** layout's content */
48
- children?: TitanLayoutChild | TitanLayoutChild[];
49
-
50
53
  state?: TitanLayoutState;
51
54
  onStateChange?: (state: TitanLayoutState) => void;
52
55
 
@@ -57,6 +60,7 @@ export type TitanLayoutProps = Omit<ComponentPropsWithoutRef<'div'>, 'children'
57
60
  extraLinks?: ReactElement;
58
61
  extraLinksTop?: ReactElement;
59
62
  extraText?: string;
63
+ minContentWidth?: number;
60
64
  };
61
65
 
62
66
  const defaultSidebarContext: TitanLayoutSidebarContextType = {
@@ -115,6 +119,7 @@ const TitanLayoutComponent: FC<TitanLayoutProps> = ({
115
119
  appearance = 'anvil2',
116
120
  id,
117
121
  children,
122
+ contentOnly,
118
123
  navigationComponent,
119
124
  header,
120
125
  top,
@@ -125,10 +130,10 @@ const TitanLayoutComponent: FC<TitanLayoutProps> = ({
125
130
  extraLinks,
126
131
  extraLinksTop,
127
132
  extraText,
133
+ minContentWidth,
128
134
  sideTop,
129
135
  }) => {
130
136
  const breakpoint = useTitanBreakpoint();
131
- const isMobile = breakpoint.isMobile;
132
137
  const context: TitanLayoutContextType = useMemo(
133
138
  () => ({
134
139
  NavigationComponent: navigationComponent ?? DefaultNavLinkComponent,
@@ -141,21 +146,23 @@ const TitanLayoutComponent: FC<TitanLayoutProps> = ({
141
146
  const variant = useVariant(appearance);
142
147
  const [mobileDrawerOpened, setMobileDrawerOpened] = useState(false);
143
148
  const { content, logo } = useLayoutChildren(children);
149
+ const { hasNotifications, NotificationsContextProvider } = useNotificationsState();
150
+ const [anvil2Styles, setAnvil2Styles] = useState<object>({});
151
+ const updateIndicatorsHeight = useCallback((offset: number) => {
152
+ setAnvil2Styles({ '--offset': `calc(var(--nav-offset-top) + ${offset}px)` });
153
+ }, []);
154
+
155
+ const isMobile = breakpoint.isMobile;
156
+ const hasSideBar = !contentOnly && (!!navigationMainItems?.length || !!sideTop?.length);
157
+ const hasTopBar = !contentOnly;
144
158
 
145
159
  useEffect(() => {
146
- if (!isMobile) {
147
- setMobileDrawerOpened(false);
148
- return;
160
+ if (variant.isAnvil1) {
161
+ const bodyClassName = 'of-hidden-i';
162
+ document.body.classList.add(bodyClassName);
163
+ return () => document.body.classList.remove(bodyClassName);
149
164
  }
150
-
151
- const listener = () => {
152
- setMobileDrawerOpened(false);
153
- };
154
-
155
- document.addEventListener('click', listener);
156
-
157
- return () => document.removeEventListener('click', listener);
158
- }, [isMobile]);
165
+ }, [variant.isAnvil1]);
159
166
 
160
167
  const onBurgerClick = useCallback((e: MouseEvent) => {
161
168
  setMobileDrawerOpened(true);
@@ -181,6 +188,48 @@ const TitanLayoutComponent: FC<TitanLayoutProps> = ({
181
188
  },
182
189
  [state, onStateChange]
183
190
  );
191
+ const hasMenuNotifications = useMemo(() => {
192
+ try {
193
+ return (
194
+ navigationMainItems?.some(item => {
195
+ if (item.counter || item.tag?.value) {
196
+ return true;
197
+ } else if (item.submenu) {
198
+ return item.submenu.groups.some(group =>
199
+ group.links.some(link => !!link.counter || !!link.tag?.value)
200
+ );
201
+ }
202
+ return false;
203
+ }) ?? false
204
+ );
205
+ } catch {
206
+ return false;
207
+ }
208
+ }, [navigationMainItems]);
209
+
210
+ const limitContentWidth = useMemo(() => {
211
+ if (variant.isAnvil2 || !minContentWidth) {
212
+ return undefined;
213
+ }
214
+
215
+ if (breakpoint.width < minContentWidth) {
216
+ return minContentWidth;
217
+ }
218
+ }, [variant, minContentWidth, breakpoint.width]);
219
+
220
+ const contentStyles = useMemo(() => {
221
+ if (variant.isAnvil2) {
222
+ return anvil2Styles;
223
+ }
224
+
225
+ if (variant.isLegacy && limitContentWidth) {
226
+ return {
227
+ display: 'flex',
228
+ flexDirection: 'column',
229
+ minHeight: '100vh',
230
+ };
231
+ }
232
+ }, [variant, anvil2Styles, limitContentWidth]);
184
233
 
185
234
  const layoutClass = variant.isLegacy
186
235
  ? Styles.layoutLegacy
@@ -196,66 +245,88 @@ const TitanLayoutComponent: FC<TitanLayoutProps> = ({
196
245
  className={classNames(
197
246
  Styles.layout,
198
247
  isMobile ? Styles.layoutMobile : Styles.layoutDesktop,
199
- !isMobile && state?.navCollapsed
200
- ? Styles.layoutNavSlim
201
- : Styles.layoutNavWide,
248
+ {
249
+ [Styles.layoutTop]: hasTopBar,
250
+ [Styles.layoutNavSlim]: !isMobile && hasSideBar && state?.navCollapsed,
251
+ [Styles.layoutNavWide]: !isMobile && hasSideBar && !state?.navCollapsed,
252
+ },
202
253
  layoutClass
203
254
  )}
255
+ style={contentStyles}
204
256
  >
205
257
  {variant.isSequent && <div className={Styles.topPlaceholder} />}
206
- <LayoutHeader
207
- className={Styles.top}
208
- logo={logo}
209
- profile={isMobile ? undefined : profile}
210
- center={top}
211
- rightText={isMobile ? undefined : extraText}
212
- right={
213
- <Fragment>
214
- {extraLinksTop}
215
- {!isMobile && extraLinks}
216
- </Fragment>
217
- }
218
- onBurgerClick={onBurgerClick}
219
- />
220
-
221
- <LayoutSidebar
222
- className={Styles.side}
223
- mobile={breakpoint.isMobile}
224
- barExpanded={isMobile ? mobileDrawerOpened : !state?.navCollapsed}
225
- submenuExpanded={state?.submenuExpanded}
226
- onBarExpandChange={onBarExpandChange}
227
- onSubmenuExpandChange={onSubmenuExpandChange}
228
- top={sideTop}
229
- mainItems={navigationMainItems}
230
- navigationComponent={context.NavigationComponent}
231
- bottom={
232
- isMobile ? (
258
+ {hasTopBar && (
259
+ <LayoutHeader
260
+ className={Styles.top}
261
+ logo={logo}
262
+ profile={isMobile ? undefined : profile}
263
+ center={top}
264
+ rightText={isMobile ? undefined : extraText}
265
+ right={
233
266
  <Fragment>
234
- {profile}
235
- {extraLinks}
236
- {!!extraText && (
237
- <InternalSideNavigationTrigger
238
- id="__extra_text"
239
- title={extraText}
240
- submenuExpanded={undefined}
241
- dataPrefix="navigation-extra-text"
242
- tag={undefined}
243
- icon={undefined}
244
- iconActive={undefined}
245
- />
246
- )}
267
+ {extraLinksTop}
268
+ {!isMobile && extraLinks}
247
269
  </Fragment>
248
- ) : undefined
249
- }
250
- />
251
-
252
- <LayoutContent
253
- header={header}
254
- anvil2={variant.isAnvil2}
255
- anvil1={variant.isAnvil1}
256
- >
257
- {content}
258
- </LayoutContent>
270
+ }
271
+ isMobile={isMobile}
272
+ hasNotifications={hasNotifications || hasMenuNotifications}
273
+ onBurgerClick={onBurgerClick}
274
+ />
275
+ )}
276
+
277
+ {hasSideBar && (
278
+ <NotificationsContextProvider>
279
+ <LayoutSidebar
280
+ className={Styles.side}
281
+ mobile={breakpoint.isMobile}
282
+ barExpanded={!state?.navCollapsed}
283
+ onBarExpandChange={onBarExpandChange}
284
+ submenuExpanded={state?.submenuExpanded}
285
+ onSubmenuExpandChange={onSubmenuExpandChange}
286
+ drawerOpened={mobileDrawerOpened}
287
+ onDrawerOpenChange={setMobileDrawerOpened}
288
+ top={sideTop}
289
+ mainItems={navigationMainItems}
290
+ navigationComponent={context.NavigationComponent}
291
+ bottom={
292
+ isMobile ? (
293
+ <Fragment>
294
+ {profile}
295
+ {extraLinks}
296
+ {!!extraText && (
297
+ <InternalSideNavigationTrigger
298
+ id="__extra_text"
299
+ title={extraText}
300
+ submenuExpanded={undefined}
301
+ dataPrefix="navigation-extra-text"
302
+ tag={undefined}
303
+ icon={undefined}
304
+ iconActive={undefined}
305
+ />
306
+ )}
307
+ </Fragment>
308
+ ) : undefined
309
+ }
310
+ />
311
+ </NotificationsContextProvider>
312
+ )}
313
+
314
+ {variant.isAnvil1 ? (
315
+ <LayoutContentAnvil1 header={header} minWidth={limitContentWidth}>
316
+ {content}
317
+ </LayoutContentAnvil1>
318
+ ) : variant.isLegacy ? (
319
+ <LayoutContentLegacy header={header} minWidth={limitContentWidth}>
320
+ {content}
321
+ </LayoutContentLegacy>
322
+ ) : (
323
+ <LayoutContentAnvil2
324
+ header={header}
325
+ onHeaderHeightChange={updateIndicatorsHeight}
326
+ >
327
+ {content}
328
+ </LayoutContentAnvil2>
329
+ )}
259
330
  </div>
260
331
  </LayoutPlacementContext.Provider>
261
332
  </LayoutContext.Provider>
@@ -291,7 +362,14 @@ const TitanLayoutHeaderObserved: FC<{
291
362
  };
292
363
  }, [heightChange]);
293
364
  return (
294
- <div ref={ref} className={Styles.header}>
365
+ <div ref={ref} className={Styles.contentHeader} data-cy="layout-content-header">
366
+ {children}
367
+ </div>
368
+ );
369
+ };
370
+ const TitanLayoutHeader: FC<{ children: ReactNode }> = ({ children }) => {
371
+ return (
372
+ <div className={Styles.contentHeader} data-cy="layout-content-header">
295
373
  {children}
296
374
  </div>
297
375
  );
@@ -302,35 +380,76 @@ export interface TitanLayoutContentProps {
302
380
  }
303
381
  const TitanLayoutContent: FC<TitanLayoutContentProps> = ({ children }) => children;
304
382
 
305
- const LayoutContent: FC<{
383
+ const LayoutContentAnvil2: FC<{
306
384
  children: ReactNode;
307
385
  header?: ReactNode;
308
- anvil1: boolean;
309
- anvil2: boolean;
310
- }> = ({ anvil1, anvil2, children, header }) => {
311
- const [anvil2Styles, setAnvil2Styles] = useState<object>({});
312
- const updateIndicatorsHeight = useCallback((offset: number) => {
313
- setAnvil2Styles({ '--offset': `calc(var(--nav-offset-top) + ${offset}px)` });
314
- }, []);
386
+ onHeaderHeightChange?: (height: number) => void;
387
+ }> = ({ children, header, onHeaderHeightChange }) => {
388
+ return (
389
+ <Fragment>
390
+ <TitanLayoutHeaderObserved heightChange={onHeaderHeightChange}>
391
+ {header}
392
+ </TitanLayoutHeaderObserved>
393
+ {children}
394
+ </Fragment>
395
+ );
396
+ };
397
+
398
+ const LayoutContentAnvil1: FC<{
399
+ children: ReactNode;
400
+ header?: ReactNode;
401
+ minWidth?: number;
402
+ }> = ({ children, header, minWidth }) => {
403
+ const innerContentStyles: CSSProperties = useMemo(
404
+ () => ({
405
+ ...(minWidth ? { minWidth: `${minWidth}px` } : {}),
406
+ }),
407
+ [minWidth]
408
+ );
315
409
 
316
410
  return (
317
- <div className={Styles.content} style={anvil2Styles}>
318
- {!!header &&
319
- (anvil2 ? (
320
- <TitanLayoutHeaderObserved heightChange={updateIndicatorsHeight}>
321
- {header}
322
- </TitanLayoutHeaderObserved>
323
- ) : (
324
- header
325
- ))}
326
- {anvil1 ? (
327
- <div className="position-relative d-f flex-grow-1 flex-basis-0 of-hidden">
411
+ <Fragment>
412
+ <TitanLayoutHeader>{header}</TitanLayoutHeader>
413
+ <div
414
+ className={classNames(Styles.content, { 'of-x-auto': !!minWidth })}
415
+ data-cy="layout-content"
416
+ >
417
+ <div
418
+ className="position-relative d-f flex-grow-1 flex-basis-0 of-hidden"
419
+ style={innerContentStyles}
420
+ >
328
421
  {children}
329
422
  </div>
423
+ </div>
424
+ </Fragment>
425
+ );
426
+ };
427
+
428
+ const LayoutContentLegacy: FC<{
429
+ children: ReactNode;
430
+ header?: ReactNode;
431
+ minWidth: number | undefined;
432
+ }> = ({ children, header, minWidth }) => {
433
+ const innerContentStyles: CSSProperties = useMemo(
434
+ () => ({
435
+ position: 'relative',
436
+ minWidth: `${minWidth}px`,
437
+ }),
438
+ [minWidth]
439
+ );
440
+
441
+ return (
442
+ <Fragment>
443
+ <TitanLayoutHeader>{header}</TitanLayoutHeader>
444
+
445
+ {minWidth ? (
446
+ <div className="of-x-auto flex-basis-0 flex-grow-1">
447
+ <div style={innerContentStyles}>{children}</div>
448
+ </div>
330
449
  ) : (
331
450
  children
332
451
  )}
333
- </div>
452
+ </Fragment>
334
453
  );
335
454
  };
336
455
 
package/src/test/data.tsx CHANGED
@@ -66,7 +66,6 @@ export const NavLinkMock = forwardRef<any, NavLinkComponentProps>(
66
66
  {...rest}
67
67
  onClick={e => {
68
68
  e.preventDefault();
69
- e.stopPropagation();
70
69
 
71
70
  if (!to.startsWith('http')) {
72
71
  history.replace(to);
@@ -82,10 +81,10 @@ export const NavLinkMock = forwardRef<any, NavLinkComponentProps>(
82
81
  }
83
82
  );
84
83
 
85
- export const LocationInfo = () => {
84
+ export const LocationInfo: FC<{ className?: string }> = ({ className }) => {
86
85
  const location = useLocation();
87
86
 
88
- return <BodyText>current location - {location.pathname}</BodyText>;
87
+ return <BodyText className={className}>current location - {location.pathname}</BodyText>;
89
88
  };
90
89
 
91
90
  const LocationProvider: FC<{ children: any }> = ({ children }) => {
@@ -4,6 +4,7 @@ import { useMemo } from 'react';
4
4
  export interface TitanBreakpoint {
5
5
  name: BreakpointReturnProps['name'];
6
6
  isMobile: boolean;
7
+ width: number;
7
8
  }
8
9
 
9
10
  export const useTitanBreakpoint = (): TitanBreakpoint => {
@@ -12,7 +13,8 @@ export const useTitanBreakpoint = (): TitanBreakpoint => {
12
13
  return useMemo(
13
14
  () => ({
14
15
  name: breakpoint?.name ?? 'xl',
15
- isMobile: breakpoint ? breakpoint.innerWidth <= 768 : false,
16
+ isMobile: breakpoint ? breakpoint.innerWidth < 768 : false,
17
+ width: breakpoint?.innerWidth ?? 0,
16
18
  }),
17
19
  [breakpoint]
18
20
  );