Debian Codegraph @

node/@patternfly/react-core/src/demos/Nav.md

raw
1 ---
2 id: Navigation
3 section: components
4 ---
5
6 import { Fragment, useState, useRef, useEffect } from 'react';
7 import RhUiSettingsFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-settings-fill-icon';
8 import HelpIcon from '@patternfly/react-icons/dist/esm/icons/help-icon';
9 import RhUiQuestionMarkCircleFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-question-mark-circle-fill-icon';
10 import RhUiEllipsisVerticalFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-ellipsis-vertical-fill-icon';
11 import RhUiNotificationFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-notification-fill-icon';
12 import RhUiMenuBarsIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-menu-bars-icon';
13 import imgAvatar from '@patternfly/react-core/src/components/assets/avatarImg.svg';
14 import pfLogo from '@patternfly/react-core/src/demos/assets/PF-HorizontalLogo-Color.svg';
15 import CubeIcon from '@patternfly/react-icons/dist/esm/icons/cube-icon';
16 import FolderIcon from '@patternfly/react-icons/dist/esm/icons/folder-icon';
17 import CloudIcon from '@patternfly/react-icons/dist/esm/icons/cloud-icon';
18 import RhUiCodeIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-code-icon';
19 import RhUiThumbnailViewSmallFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-thumbnail-view-small-fill-icon';
20 import SearchIcon from '@patternfly/react-icons/dist/esm/icons/search-icon';
21 import pfIconLogo from '@patternfly/react-core/src/demos/assets/PF-IconLogo-color.svg';
22 import { DashboardBreadcrumb } from '@patternfly/react-core/dist/js/demos/DashboardWrapper';
23 import { DashboardHeader } from '@patternfly/react-core/dist/js/demos/DashboardHeader';
24 import globalBreakpointXl from '@patternfly/react-tokens/dist/esm/t_global_breakpoint_xl';
25
26 ## Demos
27
28 ### Default nav
29
30 ```ts file="./examples/Nav/NavDefault.tsx" isFullscreen
31
32 ```
33
34 ### Grouped nav
35
36 ```ts file="./examples/Nav/NavGrouped.tsx" isFullscreen
37
38 ```
39
40 ### Expandable nav
41
42 ```ts file="./examples/Nav/NavExpandable.tsx" isFullscreen
43
44 ```
45
46 ### Horizontal nav
47
48 ```ts file="./examples/Nav/NavHorizontal.tsx" isFullscreen
49
50 ```
51
52 ### Horizontal subnav
53
54 ```ts file="./examples/Nav/NavWithSubnav.tsx" isFullscreen
55
56 ```
57
58 ### Horizontal nav with horizontal subnav
59
60 ```ts file="./examples/Nav/NavHorizontalWithSubnav.tsx" isFullscreen
61
62 ```
63
64 ### Manual nav
65
66 ```ts file="./examples/Nav/NavManual.tsx" isFullscreen
67
68 ```
69
70 ### Flyout nav
71
72 ```ts file="./examples/Nav/NavFlyout.tsx" isFullscreen
73
74 ```
75
76 ### Drilldown nav
77
78 ```ts isFullscreen file="./examples/Nav/NavDrilldown.tsx"
79
80 ```
81
82 ### Docked nav
83
84 To save space in the UI, you can use docked navigation to replace text-labeled navigation items with relevant icons. On mobile (or narrow viewports), docked navigation appears as an overlay, while on desktop (or wider viewports) it displays as a persistent vertical sidebar that can toggle between icon-only and text+icon modes.
85
86 This demo includes the following features:
87
88 1. A [page](/components/page) component with a docked layout, enabled via `variant="docked"`. Control the mobile overlay with `isDockExpanded` and the desktop label visibility with `isDockTextExpanded`.
89
90 2. Two separate [masthead](/components/masthead) components:
91 - **Horizontal mobile masthead**: Shown on small viewports using `display={{ default: 'inline' }}`, with a hamburger menu toggle button, brand logo, and action buttons that should be immediately visible to users.
92 - **Vertical docked masthead**: Uses `variant="docked"` to create a thinner navigation sidebar with a hamburger menu toggle button, nav items, and action buttons.
93
94 3. A [navigation](/components/navigation) component with `variant="docked"` and multiple `<NavItem>` components that must include both icons and text labels. To control text visibility, `isTextExpanded={isDockTextExpanded}` is passed to the `<Nav>` component.
95
96 4. [Button](/components/button) and [menu toggle](/components/menus/menu-toggle) components, which use `isDocked` and `isTextExpanded` to toggle between icon-only and text+icon styles. When the nav is docked, and only icons are shown, [tooltips](/components/tooltip) must provide full text labels for the navigation items, buttons, and menu toggles.
97
98 5. A `<MastheadLogo>` component that uses `isCompact` to show an icon-only logo when the dock is collapsed, and a full logo with text when expanded.
99
100 **Note**: For better keyboard accessibility, ensure that focus shifts between the hamburger menu toggle button in the mobile masthead and the docked overlay menu toggle button as the navigation is opened and closed.
101
102 ```ts file="./examples/Nav/NavDockedNav.tsx" isFullscreen
103
104 ```