# All files / src/layout LayoutNavigation.tsx

0% Statements 0/120
0% Branches 0/1
0% Functions 0/1
0% Lines 0/120

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121

     import { cnb } from "cnbuilder";
    import type { ReactElement } from "react";
    import { Sheet } from "../sheet";
    import type { TreeItemNode } from "../tree";
    import { bem } from "../utils";
    import { DefaultMiniLayoutNavigationItemRenderer } from "./DefaultLayoutNavigationMiniItemRenderer";
    import { LayoutNavigationHeader } from "./LayoutNavigationHeader";
    import { useLayoutConfig } from "./LayoutProvider";
    import { LayoutTree } from "./LayoutTree";
    import type { LayoutNavigationItem, LayoutNavigationProps } from "./types";
    import {
      isPersistentLayout,
      isTemporaryLayout,
      isToggleableLayout,
    } from "./utils";

    const styles = bem("rmd-layout-navigation");

    /**
     * The container for the main navigation within the `Layout` that renders
     * differently depending on the current layout type.
     */
    export function LayoutNavigation<T extends TreeItemNode = LayoutNavigationItem>(
      props: LayoutNavigationProps<T>
    ): ReactElement {
      const {
        id: propId,
        "aria-label": ariaLabel = "Navigation",
        "aria-labelledby": ariaLabelledby,
        className,
        children,
        mini = false,
        header: propHeader,
        headerProps,
        headerTitle,
        headerTitleProps,
        closeNav,
        closeNavProps,
        treeProps,
        sticky = false,
        temporary = false,
        miniNavItemRenderer = DefaultMiniLayoutNavigationItemRenderer,
        ...remaining
      } = props;

      const {
        baseId,
        layout,
        visible: isNonMiniVisible,
        hideNav,
      } = useLayoutConfig();
      const visible = mini || isNonMiniVisible;
      const id = propId || `${baseId}-${mini ? "mini-" : ""}nav-container`;

      const isTemporary = !mini && isTemporaryLayout(layout);
      const isPersistent = mini || isPersistentLayout(layout);
      const isToggleable = isToggleableLayout(layout);
      const floating = layout === "floating";

      let header = propHeader;
      if (!mini && typeof header === "undefined") {
        header = (
          <LayoutNavigationHeader
            key="header"
            closeNav={closeNav}
            closeNavProps={closeNavProps}
            title={headerTitle}
            titleProps={headerTitleProps}
            {...headerProps}
          />
        );
      }

      return (
        <Sheet
          {...remaining}
          // why did I add this key? removing it helps switch between the different layouts
          // with less animations
          // key={layout}
          id={id}
          // ref={ref}
          aria-label={ariaLabel}
          aria-labelledby={ariaLabelledby}
          role={!isPersistent ? "dialog" : "none"}
          visible={visible}
          temporary={temporary}
          onRequestClose={hideNav}
          // do not want to portal for the other types so that logical tab order
          // is preserved
          disablePortal={!isTemporary}
          disableOverlay={!isTemporary}
          disableScrollLock={!isTemporary}
          isFocusTypeDisabled={(type) =>
            type === "keyboard" && (isToggleable || isPersistent)
          }
          className={cnb(
            styles({
              mini,
              sticky,
              floating,
              "header-offset": layout === "clipped" || floating,
            }),
            className
          )}
        >
          {header}
          {children}
          {treeProps && (
            <LayoutTree
              key="tree"
              miniItemRenderer={miniNavItemRenderer}
              sticky={mini && sticky}
              {...treeProps}
              mini={mini}
            />
          )}
        </Sheet>
      );
    }
    // });