@databiosphere/findable-ui 7.0.0 → 8.0.1

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 (90) hide show
  1. package/lib/common/entities.d.ts +0 -9
  2. package/lib/common/entities.js +1 -9
  3. package/lib/components/Filter/components/FilterLabel/filterLabel.styles.d.ts +1 -1
  4. package/lib/components/Index/components/Tabs/common/utils.d.ts +8 -0
  5. package/lib/components/Index/components/Tabs/common/utils.js +18 -0
  6. package/lib/components/Index/components/Tabs/tabs.d.ts +2 -0
  7. package/lib/components/Index/components/Tabs/tabs.js +20 -0
  8. package/lib/components/Layout/components/Header/common/constants.d.ts +4 -9
  9. package/lib/components/Layout/components/Header/common/constants.js +8 -9
  10. package/lib/components/Layout/components/Header/common/entities.d.ts +6 -0
  11. package/lib/components/Layout/components/Header/common/utils.d.ts +12 -17
  12. package/lib/components/Layout/components/Header/common/utils.js +77 -59
  13. package/lib/components/Layout/components/Header/components/Announcements/announcements.d.ts +6 -0
  14. package/lib/components/Layout/components/Header/components/Announcements/announcements.js +7 -0
  15. package/lib/components/Layout/components/Header/components/Content/components/Actions/actions.d.ts +1 -2
  16. package/lib/components/Layout/components/Header/components/Content/components/Actions/actions.js +2 -2
  17. package/lib/components/Layout/components/Header/components/Content/components/Actions/components/Authentication/components/RequestAuthentication/requestAuthentication.js +8 -15
  18. package/lib/components/Layout/components/Header/components/Content/components/Actions/components/Authentication/components/RequestAuthentication/requestAuthentication.styles.d.ts +1 -1
  19. package/lib/components/Layout/components/Header/components/Content/components/Actions/components/Menu/components/Content/components/Navigation/navigation.styles.js +2 -0
  20. package/lib/components/Layout/components/Header/components/Content/components/Actions/components/Menu/components/Toolbar/toolbar.d.ts +4 -3
  21. package/lib/components/Layout/components/Header/components/Content/components/Actions/components/Menu/components/Toolbar/toolbar.js +4 -3
  22. package/lib/components/Layout/components/Header/components/Content/components/Actions/components/Menu/menu.d.ts +1 -0
  23. package/lib/components/Layout/components/Header/components/Content/components/Actions/components/Menu/menu.js +18 -20
  24. package/lib/components/Layout/components/Header/components/Content/components/Actions/components/Search/components/SearchButton/searchButton.js +5 -12
  25. package/lib/components/Layout/components/Header/components/Content/components/Actions/components/Search/components/SearchButton/searchButton.styles.d.ts +1 -1
  26. package/lib/components/Layout/components/Header/components/Content/components/Navigation/components/NavigationDrawer/navigationDrawer.d.ts +2 -1
  27. package/lib/components/Layout/components/Header/components/Content/components/Navigation/components/NavigationDrawer/navigationDrawer.js +2 -2
  28. package/lib/components/Layout/components/Header/components/Content/components/Navigation/components/NavigationMenu/navigationMenu.d.ts +2 -1
  29. package/lib/components/Layout/components/Header/components/Content/components/Navigation/components/NavigationMenu/navigationMenu.js +5 -6
  30. package/lib/components/Layout/components/Header/components/Content/components/Navigation/components/NavigationMenu/navigationMenu.styles.js +10 -4
  31. package/lib/components/Layout/components/Header/components/Content/components/Navigation/components/NavigationMenuItems/navigationMenuItems.d.ts +2 -1
  32. package/lib/components/Layout/components/Header/components/Content/components/Navigation/components/NavigationMenuItems/navigationMenuItems.js +3 -3
  33. package/lib/components/Layout/components/Header/components/Content/components/Navigation/navigation.d.ts +4 -3
  34. package/lib/components/Layout/components/Header/components/Content/components/Navigation/navigation.js +6 -8
  35. package/lib/components/Layout/components/Header/components/Content/components/Navigation/navigation.styles.d.ts +1 -6
  36. package/lib/components/Layout/components/Header/components/Content/components/Navigation/navigation.styles.js +5 -19
  37. package/lib/components/Layout/components/Header/header.d.ts +5 -7
  38. package/lib/components/Layout/components/Header/header.js +38 -59
  39. package/lib/components/Layout/components/Header/header.stories.js +38 -41
  40. package/lib/components/Layout/components/Header/header.styles.d.ts +13 -1
  41. package/lib/components/Layout/components/Header/header.styles.js +23 -3
  42. package/lib/components/Layout/components/Header/hooks/useHeaderVisibility.d.ts +20 -0
  43. package/lib/components/Layout/components/Header/hooks/useHeaderVisibility.js +46 -0
  44. package/lib/components/Layout/components/Header/hooks/useMeasureHeader.d.ts +5 -0
  45. package/lib/components/Layout/components/Header/hooks/useMeasureHeader.js +19 -0
  46. package/lib/config/entities.d.ts +2 -0
  47. package/lib/config/utils.js +1 -2
  48. package/lib/hooks/useBreakpoint.d.ts +17 -0
  49. package/lib/hooks/useBreakpoint.js +34 -0
  50. package/lib/hooks/useBreakpointHelper.d.ts +1 -1
  51. package/lib/hooks/useCurrentBreakpoint.d.ts +3 -0
  52. package/lib/hooks/useCurrentBreakpoint.js +11 -0
  53. package/lib/hooks/useMenu.d.ts +10 -0
  54. package/lib/hooks/useMenu.js +17 -0
  55. package/lib/theme/common/components.js +17 -0
  56. package/lib/views/ExploreView/exploreView.js +4 -29
  57. package/package.json +1 -1
  58. package/src/common/entities.ts +0 -11
  59. package/src/components/Index/components/Tabs/common/utils.ts +33 -0
  60. package/src/components/Index/components/Tabs/tabs.tsx +23 -0
  61. package/src/components/Layout/components/Header/common/constants.ts +14 -10
  62. package/src/components/Layout/components/Header/common/entities.ts +7 -0
  63. package/src/components/Layout/components/Header/common/utils.ts +89 -66
  64. package/src/components/Layout/components/Header/components/Announcements/announcements.tsx +14 -0
  65. package/src/components/Layout/components/Header/components/Content/components/Actions/actions.tsx +2 -6
  66. package/src/components/Layout/components/Header/components/Content/components/Actions/components/Authentication/components/RequestAuthentication/requestAuthentication.tsx +21 -32
  67. package/src/components/Layout/components/Header/components/Content/components/Actions/components/Menu/components/Content/components/Navigation/navigation.styles.ts +2 -0
  68. package/src/components/Layout/components/Header/components/Content/components/Actions/components/Menu/components/Toolbar/toolbar.tsx +8 -6
  69. package/src/components/Layout/components/Header/components/Content/components/Actions/components/Menu/menu.tsx +22 -27
  70. package/src/components/Layout/components/Header/components/Content/components/Actions/components/Search/components/SearchButton/searchButton.tsx +11 -22
  71. package/src/components/Layout/components/Header/components/Content/components/Navigation/components/NavigationDrawer/navigationDrawer.tsx +3 -0
  72. package/src/components/Layout/components/Header/components/Content/components/Navigation/components/NavigationMenu/navigationMenu.styles.ts +15 -5
  73. package/src/components/Layout/components/Header/components/Content/components/Navigation/components/NavigationMenu/navigationMenu.tsx +10 -8
  74. package/src/components/Layout/components/Header/components/Content/components/Navigation/components/NavigationMenuItems/navigationMenuItems.tsx +4 -0
  75. package/src/components/Layout/components/Header/components/Content/components/Navigation/navigation.styles.ts +6 -30
  76. package/src/components/Layout/components/Header/components/Content/components/Navigation/navigation.tsx +12 -21
  77. package/src/components/Layout/components/Header/header.stories.tsx +38 -41
  78. package/src/components/Layout/components/Header/header.styles.ts +27 -4
  79. package/src/components/Layout/components/Header/header.tsx +102 -137
  80. package/src/components/Layout/components/Header/hooks/useHeaderVisibility.ts +74 -0
  81. package/src/components/Layout/components/Header/hooks/useMeasureHeader.ts +28 -0
  82. package/src/config/entities.ts +2 -0
  83. package/src/config/utils.ts +1 -2
  84. package/src/hooks/useBreakpoint.ts +54 -0
  85. package/src/hooks/useBreakpointHelper.ts +1 -1
  86. package/src/hooks/useCurrentBreakpoint.ts +23 -0
  87. package/src/hooks/useMenu.ts +27 -0
  88. package/src/theme/common/components.ts +17 -0
  89. package/src/views/ExploreView/exploreView.tsx +5 -34
  90. package/types/data-explorer-ui.d.ts +1 -0
@@ -0,0 +1,17 @@
1
+ import { UseCurrentBreakpoint } from "./useCurrentBreakpoint";
2
+ export declare type UseBreakpoint = {
3
+ breakpoint?: UseCurrentBreakpoint;
4
+ lg: boolean;
5
+ lgDown: boolean;
6
+ lgUp: boolean;
7
+ md: boolean;
8
+ mdDown: boolean;
9
+ mdUp: boolean;
10
+ sm: boolean;
11
+ smDown: boolean;
12
+ smUp: boolean;
13
+ xs: boolean;
14
+ xsDown: boolean;
15
+ xsUp: boolean;
16
+ };
17
+ export declare const useBreakpoint: () => UseBreakpoint;
@@ -0,0 +1,34 @@
1
+ import { useCurrentBreakpoint, } from "./useCurrentBreakpoint";
2
+ export const useBreakpoint = () => {
3
+ const breakpoint = useCurrentBreakpoint();
4
+ // Current breakpoint.
5
+ const xs = breakpoint === "xs";
6
+ const sm = breakpoint === "sm";
7
+ const md = breakpoint === "md";
8
+ const lg = breakpoint === "lg";
9
+ // Current breakpoint, down.
10
+ const xsDown = xs;
11
+ const smDown = xs || sm;
12
+ const mdDown = xs || sm || md;
13
+ const lgDown = xs || sm || md || lg;
14
+ // Current breakpoint, up.
15
+ const xsUp = xs || sm || md || lg;
16
+ const smUp = sm || md || lg;
17
+ const mdUp = md || lg;
18
+ const lgUp = lg;
19
+ return {
20
+ breakpoint,
21
+ lg,
22
+ lgDown,
23
+ lgUp,
24
+ md,
25
+ mdDown,
26
+ mdUp,
27
+ sm,
28
+ smDown,
29
+ smUp,
30
+ xs,
31
+ xsDown,
32
+ xsUp,
33
+ };
34
+ };
@@ -9,6 +9,6 @@ export declare enum BREAKPOINT_FN_NAME {
9
9
  UP = "up"
10
10
  }
11
11
  declare type BreakpointFnName = BREAKPOINT_FN_NAME;
12
- declare type BreakpointKey = Breakpoint;
12
+ export declare type BreakpointKey = Breakpoint;
13
13
  export declare const useBreakpointHelper: (fnName: BreakpointFnName, breakpointKey: BreakpointKey) => boolean;
14
14
  export {};
@@ -0,0 +1,3 @@
1
+ import { BreakpointKey } from "./useBreakpointHelper";
2
+ export declare type UseCurrentBreakpoint = BreakpointKey | undefined;
3
+ export declare const useCurrentBreakpoint: () => UseCurrentBreakpoint;
@@ -0,0 +1,11 @@
1
+ import { useMemo } from "react";
2
+ import { BREAKPOINT_FN_NAME, useBreakpointHelper, } from "./useBreakpointHelper";
3
+ const breakpointKeys = ["xs", "sm", "md", "lg"];
4
+ export const useCurrentBreakpoint = () => {
5
+ const xs = useBreakpointHelper(BREAKPOINT_FN_NAME.ONLY, "xs");
6
+ const sm = useBreakpointHelper(BREAKPOINT_FN_NAME.ONLY, "sm");
7
+ const md = useBreakpointHelper(BREAKPOINT_FN_NAME.ONLY, "md");
8
+ const lg = useBreakpointHelper(BREAKPOINT_FN_NAME.ONLY, "lg");
9
+ const breakpoints = useMemo(() => ({ lg, md, sm, xs }), [lg, md, sm, xs]);
10
+ return breakpointKeys.find((key) => breakpoints[key]);
11
+ };
@@ -0,0 +1,10 @@
1
+ export interface UseMenu {
2
+ onClose: () => void;
3
+ onOpen: () => void;
4
+ open: boolean;
5
+ }
6
+ /**
7
+ * Menu functionality for menu dropdown.
8
+ * @returns menu functionality.
9
+ */
10
+ export declare const useMenu: () => UseMenu;
@@ -0,0 +1,17 @@
1
+ import { useCallback, useState } from "react";
2
+ /**
3
+ * Menu functionality for menu dropdown.
4
+ * @returns menu functionality.
5
+ */
6
+ export const useMenu = () => {
7
+ const [open, setOpen] = useState(false);
8
+ // Closes header menu.
9
+ const onClose = useCallback(() => {
10
+ setOpen(false);
11
+ }, []);
12
+ // Opens header menu.
13
+ const onOpen = useCallback(() => {
14
+ setOpen(true);
15
+ }, []);
16
+ return { onClose, onOpen, open };
17
+ };
@@ -383,6 +383,23 @@ export const MuiButton = (theme) => {
383
383
  },
384
384
  },
385
385
  variants: [
386
+ {
387
+ props: {
388
+ variant: "activeNav", // associated with "nav" variant.
389
+ },
390
+ style: {
391
+ ...theme.typography[TEXT_BODY_500],
392
+ backgroundColor: theme.palette.smoke.light,
393
+ color: theme.palette.ink.main,
394
+ minWidth: 0,
395
+ textTransform: "capitalize",
396
+ whiteSpace: "nowrap",
397
+ // eslint-disable-next-line sort-keys -- disabling key order for readability
398
+ "&:hover": {
399
+ backgroundColor: theme.palette.smoke.light,
400
+ },
401
+ },
402
+ },
386
403
  {
387
404
  props: {
388
405
  variant: "nav",
@@ -1,12 +1,11 @@
1
- import { useRouter } from "next/router";
2
1
  import React, { useEffect, useMemo, useState } from "react";
3
2
  import { track } from "../../common/analytics/analytics";
4
3
  import { EVENT_NAME, EVENT_PARAM } from "../../common/analytics/entities";
5
- import { Tabs } from "../../components/common/Tabs/tabs";
6
4
  import { ComponentCreator } from "../../components/ComponentCreator/ComponentCreator";
7
5
  import { ClearAllFilters } from "../../components/Filter/components/ClearAllFilters/clearAllFilters";
8
6
  import { Filters, } from "../../components/Filter/components/Filters/filters";
9
7
  import { SearchAllFilters } from "../../components/Filter/components/SearchAllFilters/searchAllFilters";
8
+ import { Tabs } from "../../components/Index/components/Tabs/tabs";
10
9
  import { Index as IndexView } from "../../components/Index/index";
11
10
  import { SidebarButton } from "../../components/Layout/components/Sidebar/components/SidebarButton/sidebarButton";
12
11
  import { SidebarLabel } from "../../components/Layout/components/Sidebar/components/SidebarLabel/sidebarLabel";
@@ -21,30 +20,15 @@ import { useSummary } from "../../hooks/useSummary";
21
20
  import { ExploreActionKind } from "../../providers/exploreState";
22
21
  import { SELECT_CATEGORY_KEY } from "../../providers/exploreState/constants";
23
22
  import { DESKTOP_SM } from "../../theme/common/breakpoints";
24
- /**
25
- * Returns tabs to be used as a prop for the Tabs component.
26
- * @param entities - Entities config.
27
- * @returns tabs list.
28
- */
29
- function getTabs(entities) {
30
- return entities.map(({ label, route, tabIcon: icon, tabIconPosition: iconPosition }) => ({
31
- icon,
32
- iconPosition,
33
- label,
34
- value: route,
35
- }));
36
- }
37
23
  export const ExploreView = (props) => {
38
24
  const [isDrawerOpen, setIsDrawerOpen] = useState(false);
39
25
  const tabletDown = useBreakpointHelper(BREAKPOINT_FN_NAME.DOWN, DESKTOP_SM);
40
26
  const { config, entityConfig } = useConfig(); // Get app level config.
41
27
  const { exploreDispatch, exploreState } = useExploreState(); // Get the useReducer state and dispatch for "Explore".
42
- const { entities, explorerTitle, summaryConfig, trackingConfig } = config;
28
+ const { explorerTitle, summaryConfig, trackingConfig } = config;
43
29
  const { listView } = entityConfig;
44
30
  const { listHero, subTitleHero } = listView || {};
45
- const { categoryGroups, categoryViews, filterCount, tabValue } = exploreState;
46
- const { push } = useRouter();
47
- const tabs = getTabs(entities);
31
+ const { categoryGroups, categoryViews, filterCount } = exploreState;
48
32
  const { response: summaryResponse } = useSummary(); // Fetch summary.
49
33
  useEntityList(props); // Fetch entities.
50
34
  const { entityListType } = props;
@@ -98,15 +82,6 @@ export const ExploreView = (props) => {
98
82
  const onOpenDrawer = () => {
99
83
  setIsDrawerOpen(true);
100
84
  };
101
- /**
102
- * Callback fired when selected tab value changes.
103
- * - Sets state tabsValue to selected tab value.
104
- * - Executes a pushState and resets pagination.
105
- * @param tabValue - Selected tab value.
106
- */
107
- const onTabChange = (tabValue) => {
108
- push(`/${tabValue}`);
109
- };
110
85
  /**
111
86
  * Dispatch a SelectedEntityType action when entityListType changes.
112
87
  */
@@ -128,7 +103,7 @@ export const ExploreView = (props) => {
128
103
  React.createElement(ClearAllFilters, null),
129
104
  React.createElement(SearchAllFilters, { categoryViews: categoryViews, drawerOpen: isDrawerOpen, onFilter: onFilterChange.bind(null, true) })),
130
105
  React.createElement(Filters, { categoryFilters: categoryFilters, closeAncestor: onCloseDrawer, onFilter: onFilterChange.bind(null, false), trackFilterOpened: trackingConfig?.trackFilterOpened }))),
131
- React.createElement(IndexView, { className: props.className, List: renderList(exploreState, entityConfig, entityListType), ListHero: renderComponent(listHero), SideBarButton: tabletDown ? (React.createElement(SidebarButton, { count: filterCount, label: "Filter", onClick: onOpenDrawer })) : undefined, SubTitleHero: renderComponent(subTitleHero), Summaries: renderSummary(summaryConfig, summaryResponse), Tabs: React.createElement(Tabs, { onTabChange: onTabChange, tabs: tabs, value: tabValue }), title: explorerTitle })));
106
+ React.createElement(IndexView, { className: props.className, List: renderList(exploreState, entityConfig, entityListType), ListHero: renderComponent(listHero), SideBarButton: tabletDown ? (React.createElement(SidebarButton, { count: filterCount, label: "Filter", onClick: onOpenDrawer })) : undefined, SubTitleHero: renderComponent(subTitleHero), Summaries: renderSummary(summaryConfig, summaryResponse), Tabs: React.createElement(Tabs, null), title: entityConfig.explorerTitle || explorerTitle })));
132
107
  };
133
108
  /**
134
109
  * Builds the category views into category views grouped by the given category group configuration.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@databiosphere/findable-ui",
3
- "version": "7.0.0",
3
+ "version": "8.0.1",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "test": "jest",
@@ -17,17 +17,6 @@ export interface CategoryTag {
17
17
  */
18
18
  export type CategoryValueKey = string;
19
19
 
20
- /**
21
- * Element alignment.
22
- */
23
- export enum ELEMENT_ALIGNMENT {
24
- CENTER = "CENTER",
25
- LEFT = "LEFT",
26
- RIGHT = "RIGHT",
27
- }
28
-
29
- export type ElementAlignment = ELEMENT_ALIGNMENT;
30
-
31
20
  /**
32
21
  * Set of selected category values.
33
22
  */
@@ -0,0 +1,33 @@
1
+ import { EntityConfig } from "../../../../../config/entities";
2
+ import { Tab } from "../../../../common/Tabs/tabs";
3
+
4
+ /**
5
+ * Returns entity list tabs list for the tabs component.
6
+ * @param entities - Entities config.
7
+ * @returns tabs list.
8
+ */
9
+ export function getEntityListTabs(entities: EntityConfig[]): Tab[] {
10
+ return entities.reduce(
11
+ (
12
+ acc: Tab[],
13
+ {
14
+ label,
15
+ listView: { enableTab = true } = {},
16
+ route,
17
+ tabIcon: icon,
18
+ tabIconPosition: iconPosition,
19
+ }
20
+ ) => {
21
+ if (enableTab) {
22
+ acc.push({
23
+ icon,
24
+ iconPosition,
25
+ label,
26
+ value: route,
27
+ });
28
+ }
29
+ return acc;
30
+ },
31
+ []
32
+ );
33
+ }
@@ -0,0 +1,23 @@
1
+ import Router from "next/router";
2
+ import React, { useCallback, useMemo } from "react";
3
+ import { useConfig } from "../../../../hooks/useConfig";
4
+ import { useExploreState } from "../../../../hooks/useExploreState";
5
+ import { Tabs as DXTabs, TabValue } from "../../../common/Tabs/tabs";
6
+ import { getEntityListTabs } from "./common/utils";
7
+
8
+ export const Tabs = (): JSX.Element | null => {
9
+ const { config } = useConfig();
10
+ const { exploreState } = useExploreState();
11
+ const { entities } = config;
12
+ const { tabValue } = exploreState;
13
+ const tabs = useMemo(() => getEntityListTabs(entities), [entities]);
14
+
15
+ // Callback fired when selected tab value changes.
16
+ const onTabChange = useCallback(async (tabValue: TabValue): Promise<void> => {
17
+ await Router.push(`/${tabValue}`);
18
+ }, []);
19
+
20
+ if (tabs.length <= 1) return null;
21
+
22
+ return <DXTabs onTabChange={onTabChange} tabs={tabs} value={tabValue} />;
23
+ };
@@ -1,17 +1,21 @@
1
- export const HEADER_HEIGHT = 56;
2
- export const HEADER_FADE_TIMEOUT = 0;
1
+ import {
2
+ AppBarProps as MAppBarProps,
3
+ ToolbarProps as MToolbarProps,
4
+ } from "@mui/material";
3
5
 
4
- export const FADE_TRANSITION_PROPS = {
5
- timeout: HEADER_FADE_TIMEOUT,
6
- unmountOnExit: true,
7
- };
6
+ export const HEADER_HEIGHT = 56;
8
7
 
9
- export const HEADER_NAVIGATION_LABEL = {
10
- MORE: "More",
11
- SOCIALS: "Follow Us",
8
+ export const APP_BAR_PROPS: Partial<MAppBarProps> = {
9
+ elevation: 1,
10
+ position: "fixed",
12
11
  };
13
12
 
14
- export const SWITCH_TRANSITION_PROPS = {
13
+ export const FADE_TRANSITION_PROPS = {
14
+ appear: false,
15
15
  timeout: 0,
16
16
  unmountOnExit: true,
17
17
  };
18
+
19
+ export const TOOLBAR_PROPS: Partial<MToolbarProps> = {
20
+ variant: "dense",
21
+ };
@@ -1,5 +1,12 @@
1
1
  import { ReactNode } from "react";
2
2
  import { Social } from "../../../../common/Socials/socials";
3
+ import { NavLinkItem } from "../components/Content/components/Navigation/navigation";
4
+
5
+ export type Navigation = [
6
+ NavLinkItem[] | undefined,
7
+ NavLinkItem[] | undefined,
8
+ NavLinkItem[] | undefined
9
+ ]; // [LEFT, CENTER, RIGHT]
3
10
 
4
11
  export interface SocialMedia {
5
12
  label: ReactNode;
@@ -1,84 +1,107 @@
1
- import { Social } from "../../../../common/Socials/socials";
2
- import { RenderComponent } from "../../../../ComponentCreator/components/RenderComponent/renderComponent";
3
- import { ANCHOR_TARGET } from "../../../../Links/common/entities";
4
- import { MenuItem } from "../components/Content/components/Navigation/components/NavigationMenuItems/navigationMenuItems";
1
+ import { Breakpoint } from "@mui/material";
5
2
  import { NavLinkItem } from "../components/Content/components/Navigation/navigation";
6
- import { HEADER_NAVIGATION_LABEL } from "./constants";
7
- import { SocialMedia } from "./entities";
3
+ import { Navigation } from "./entities";
8
4
 
9
5
  /**
10
- * Returns the navigation links as configured, where the "More" menu is flattened.
11
- * @param links - Header navigation links.
12
- * @returns header navigation links, without links grouped under the "More" menu.
6
+ * Returns the configured menu navigation links, for the current breakpoint.
7
+ * @param navigation - Navigation links.
8
+ * @param breakpoint - Current breakpoint.
9
+ * @returns navigation links.
13
10
  */
14
- export function flattenMoreLink(links: NavLinkItem[]): NavLinkItem[] {
15
- return links.flatMap((link: NavLinkItem) => {
16
- if (link.label === HEADER_NAVIGATION_LABEL.MORE) {
17
- if (link.flatten === false) {
18
- return link;
11
+ export function getMenuNavigationLinks(
12
+ navigation?: Navigation,
13
+ breakpoint?: Breakpoint
14
+ ): NavLinkItem[] {
15
+ if (!navigation) return [];
16
+ const navLinkItems = navigation.reduce((acc: NavLinkItem[], navLinkItems) => {
17
+ if (!navLinkItems) return acc;
18
+ acc.push(...navLinkItems);
19
+ return acc;
20
+ }, []);
21
+ return getNavigationLinks(navLinkItems, breakpoint);
22
+ }
23
+
24
+ /**
25
+ * Returns configured navigation links, for the current breakpoint.
26
+ * @param navigationLinks - Navigation links.
27
+ * @param breakpoint - Current breakpoint.
28
+ * @returns navigation links.
29
+ */
30
+ export function getNavigationLinks(
31
+ navigationLinks?: NavLinkItem[],
32
+ breakpoint?: Breakpoint
33
+ ): NavLinkItem[] {
34
+ if (!navigationLinks) return [];
35
+ return navigationLinks.reduce(
36
+ (acc: NavLinkItem[], navLinkItem: NavLinkItem) => {
37
+ const processedNavLink = processNavLinkItem(navLinkItem, breakpoint);
38
+ if (processedNavLink) {
39
+ acc.push(...processedNavLink);
19
40
  }
20
- return link.menuItems as NavLinkItem[];
21
- }
22
- return link;
23
- });
41
+ return acc;
42
+ },
43
+ []
44
+ );
24
45
  }
25
46
 
26
47
  /**
27
- * Returns the navigation links as configured, all menu links specified as "flatten" are flattened, including the "More" menu.
28
- * @param links - Header navigation links.
29
- * @returns header navigation links.
48
+ * Returns true if the link is flattened at the current breakpoint.
49
+ * @param navLinkItem - Navigation link.
50
+ * @param breakpoint - Current breakpoint.
51
+ * @returns true if the link is flattened.
30
52
  */
31
- export function flattenNavigationLinks(links: NavLinkItem[]): NavLinkItem[] {
32
- return links.flatMap((link: NavLinkItem) => {
33
- if (link.flatten || link.label === HEADER_NAVIGATION_LABEL.MORE) {
34
- return link.menuItems as NavLinkItem[];
35
- }
36
- return link;
37
- });
53
+ function isLinkFlattened(
54
+ navLinkItem: NavLinkItem,
55
+ breakpoint?: Breakpoint
56
+ ): boolean {
57
+ if (!breakpoint) return false; // Default is not flattened.
58
+ if (!navLinkItem.flatten) return false; // Default is not flattened.
59
+ return navLinkItem.flatten[breakpoint] === true;
38
60
  }
39
61
 
40
62
  /**
41
- * Returns header navigation links with socials appended with the corresponding label "Follow Us".
42
- * @param links - Header navigation links.
43
- * @param socialMedia - Header social media.
44
- * @param onlySmDesktop - Media breakpoint query is "true" for small desktop only.
45
- * @returns header navigation links.
63
+ * Returns true if the link is visible at the current breakpoint.
64
+ * @param navLinkItem - Navigation link.
65
+ * @param breakpoint - Current breakpoint.
66
+ * @returns true if the link is visible.
46
67
  */
47
- export function getHeaderNavigationLinks(
48
- links: NavLinkItem[],
49
- socialMedia: SocialMedia | undefined,
50
- onlySmDesktop: boolean
51
- ): NavLinkItem[] {
52
- if (onlySmDesktop) {
53
- const navLinks = [...links];
54
- if (socialMedia) {
55
- navLinks.push({
56
- label: socialMedia.label,
57
- menuItems: getFollowUsMenuItems(socialMedia.socials),
58
- url: "",
59
- });
60
- }
61
- return navLinks;
62
- }
63
- // Return the links without the "More" or "Follow Us" menu.
64
- return flattenMoreLink(links);
68
+ function isLinkVisible(
69
+ navLinkItem: NavLinkItem,
70
+ breakpoint?: Breakpoint
71
+ ): boolean {
72
+ if (!breakpoint) return true; // Default is visible.
73
+ if (!navLinkItem.visible) return true; // Default is visible.
74
+ return navLinkItem.visible[breakpoint] !== false;
65
75
  }
66
76
 
67
77
  /**
68
- * Returns menu items for the "Follow Us" menu.
69
- * @param socials - Social configuration.
70
- * @returns a list of social menu items for the "Follow Us" menu.
78
+ * Returns the processed navigation link item.
79
+ * Flattens menu items, and removes items that are not visible for the current breakpoint.
80
+ * @param navLinkItem - Navigation link.
81
+ * @param breakpoint - Current breakpoint.
82
+ * @returns processed navigation link item.
71
83
  */
72
- function getFollowUsMenuItems(socials: Social[]): MenuItem[] {
73
- return socials.map(({ Icon, label, url }) => {
74
- return {
75
- icon: RenderComponent({
76
- Component: Icon,
77
- ...{ fontSize: "small" },
78
- }),
79
- label,
80
- target: ANCHOR_TARGET.BLANK,
81
- url,
82
- };
83
- });
84
+ function processNavLinkItem(
85
+ navLinkItem: NavLinkItem,
86
+ breakpoint?: Breakpoint
87
+ ): NavLinkItem[] | undefined {
88
+ if (isLinkVisible(navLinkItem, breakpoint)) {
89
+ const cloneLink = { ...navLinkItem };
90
+ // Recursively process menu items.
91
+ if (cloneLink.menuItems) {
92
+ const menuItems = getNavigationLinks(navLinkItem.menuItems, breakpoint);
93
+ // Remove menu items if empty.
94
+ if (menuItems.length === 0) {
95
+ delete cloneLink.menuItems;
96
+ } else {
97
+ // Flatten the menu items if the navigation is flattened.
98
+ if (isLinkFlattened(cloneLink, breakpoint)) {
99
+ return menuItems;
100
+ } else {
101
+ cloneLink.menuItems = menuItems;
102
+ }
103
+ }
104
+ }
105
+ return [cloneLink];
106
+ }
84
107
  }
@@ -0,0 +1,14 @@
1
+ import React from "react";
2
+ import { ComponentsConfig } from "../../../../../../config/entities";
3
+ import { ComponentCreator } from "../../../../../ComponentCreator/ComponentCreator";
4
+
5
+ export interface AnnouncementsProps {
6
+ announcements?: ComponentsConfig;
7
+ }
8
+
9
+ export const Announcements = ({
10
+ announcements,
11
+ }: AnnouncementsProps): JSX.Element | null => {
12
+ if (!announcements) return null;
13
+ return <ComponentCreator components={announcements} response={{}} />;
14
+ };
@@ -3,12 +3,8 @@ import { HeaderActions } from "./actions.styles";
3
3
 
4
4
  export interface ActionsProps {
5
5
  children: ReactNode | ReactNode[];
6
- showActions?: boolean;
7
6
  }
8
7
 
9
- export const Actions = ({
10
- children,
11
- showActions = true,
12
- }: ActionsProps): JSX.Element => {
13
- return <>{showActions && <HeaderActions>{children}</HeaderActions>}</>;
8
+ export const Actions = ({ children }: ActionsProps): JSX.Element => {
9
+ return <HeaderActions>{children}</HeaderActions>;
14
10
  };
@@ -1,12 +1,7 @@
1
1
  import LoginRoundedIcon from "@mui/icons-material/LoginRounded";
2
- import { Fade, IconButton } from "@mui/material";
2
+ import { IconButton as MIconButton } from "@mui/material";
3
3
  import React from "react";
4
- import {
5
- BREAKPOINT_FN_NAME,
6
- useBreakpointHelper,
7
- } from "../../../../../../../../../../../../hooks/useBreakpointHelper";
8
- import { DESKTOP_SM } from "../../../../../../../../../../../../theme/common/breakpoints";
9
- import { SWITCH_TRANSITION_PROPS } from "../../../../../../../../common/constants";
4
+ import { useBreakpoint } from "../../../../../../../../../../../../hooks/useBreakpoint";
10
5
  import { Button } from "./requestAuthentication.styles";
11
6
 
12
7
  export interface RequestAuthenticationProps {
@@ -18,30 +13,24 @@ export const RequestAuthentication = ({
18
13
  closeMenu,
19
14
  requestAuthorization,
20
15
  }: RequestAuthenticationProps): JSX.Element => {
21
- const smDesktop = useBreakpointHelper(BREAKPOINT_FN_NAME.UP, DESKTOP_SM);
22
- const switchProps = SWITCH_TRANSITION_PROPS;
23
- return (
24
- <>
25
- <Fade in={smDesktop} {...switchProps}>
26
- <Button
27
- onClick={requestAuthorization}
28
- startIcon={<LoginRoundedIcon />}
29
- variant="nav"
30
- >
31
- Sign in
32
- </Button>
33
- </Fade>
34
- <Fade in={!smDesktop} {...switchProps}>
35
- <IconButton
36
- color="ink"
37
- onClick={(): void => {
38
- closeMenu();
39
- requestAuthorization();
40
- }}
41
- >
42
- <LoginRoundedIcon />
43
- </IconButton>
44
- </Fade>
45
- </>
16
+ const { mdUp } = useBreakpoint();
17
+ return mdUp ? (
18
+ <Button
19
+ onClick={requestAuthorization}
20
+ startIcon={<LoginRoundedIcon />}
21
+ variant="nav"
22
+ >
23
+ Sign in
24
+ </Button>
25
+ ) : (
26
+ <MIconButton
27
+ color="ink"
28
+ onClick={(): void => {
29
+ closeMenu();
30
+ requestAuthorization();
31
+ }}
32
+ >
33
+ <LoginRoundedIcon />
34
+ </MIconButton>
46
35
  );
47
36
  };
@@ -13,6 +13,7 @@ export const Navigation = styled(DXNavigation)`
13
13
  margin: 0;
14
14
  justify-content: flex-start;
15
15
 
16
+ .MuiButton-activeNav,
16
17
  .MuiButton-nav {
17
18
  ${textBodyLarge500};
18
19
  justify-content: space-between;
@@ -27,6 +28,7 @@ export const Navigation = styled(DXNavigation)`
27
28
  export const DrawerNavigation = styled(Navigation)`
28
29
  gap: 0;
29
30
 
31
+ .MuiButton-activeNav,
30
32
  .MuiButton-nav {
31
33
  ${textBody500};
32
34
  padding: 14px 24px;