-
Notifications
You must be signed in to change notification settings - Fork 393
feat(Nav,Compass,Page): add support for expandable nav items in docked nav #12630
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
420a948
c98086f
739aeea
614620d
7f71ec1
282d609
6f45eda
3e5381a
591b5fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| import { useState } from 'react'; | ||
| import { Nav, NavItem, NavList, NavExpandable } from '@patternfly/react-core'; | ||
| import RhUiCubesIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-cubes-icon'; | ||
| import RhUiFolderIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-folder-icon'; | ||
| import RhUiCodeIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-code-icon'; | ||
| import RhUiCloudIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-cloud-icon'; | ||
|
|
||
| export const NavDocked: React.FunctionComponent = () => { | ||
| const [activeItem, setActiveItem] = useState(0); | ||
| const [isGroupExpanded, setIsGroupExpanded] = useState(false); | ||
|
|
||
| const onSelect = (_event: React.FormEvent<HTMLInputElement>, result: { itemId: number | string }) => { | ||
| setActiveItem(result.itemId as number); | ||
| }; | ||
|
|
||
| const onToggle = ( | ||
| _event: React.MouseEvent<HTMLButtonElement>, | ||
| result: { groupId: number | string; isExpanded: boolean } | ||
| ) => { | ||
| setIsGroupExpanded(result.isExpanded); | ||
| }; | ||
|
|
||
| return ( | ||
| <Nav variant="docked" onSelect={onSelect} onToggle={onToggle} aria-label="Default global" ouiaId="DefaultNav"> | ||
| <NavList> | ||
| <NavItem | ||
| icon={<RhUiCubesIcon />} | ||
| preventDefault | ||
| id="nav-default-link1" | ||
| to="#nav-default-link1" | ||
| itemId={0} | ||
| isActive={activeItem === 0} | ||
| > | ||
| Default Link 1 | ||
| </NavItem> | ||
| <NavItem | ||
| icon={<RhUiCloudIcon />} | ||
| preventDefault | ||
| id="nav-default-link2" | ||
| to="#nav-default-link2" | ||
| itemId={1} | ||
| isActive={activeItem === 1} | ||
| > | ||
| Default Link 2 | ||
| </NavItem> | ||
| <NavItem | ||
| icon={<RhUiCodeIcon />} | ||
| preventDefault | ||
| id="nav-default-link3" | ||
| to="#nav-default-link3" | ||
| itemId={2} | ||
| isActive={activeItem === 2} | ||
| > | ||
| Default Link 3 | ||
| </NavItem> | ||
| <NavExpandable | ||
| title="Expandable Group 1" | ||
| groupId="nav-expandable-group-1" | ||
| icon={<RhUiFolderIcon />} | ||
| isExpanded={isGroupExpanded} | ||
| hasExpandableIcon | ||
| buttonProps={{ 'aria-label': 'Expandable Group 1' }} | ||
| > | ||
| <NavItem | ||
| preventDefault | ||
| id="expandable-1" | ||
| to="#expandable-1" | ||
| groupId="nav-expandable-group-1" | ||
| itemId={3} | ||
| isActive={activeItem === 3} | ||
| > | ||
| Subnav 1 Link 1 | ||
| </NavItem> | ||
| <NavItem | ||
| preventDefault | ||
| id="expandable-2" | ||
| to="#expandable-2" | ||
| groupId="nav-expandable-group-1" | ||
| itemId={4} | ||
| isActive={activeItem === 4} | ||
| > | ||
| Subnav 1 Link 2 | ||
| </NavItem> | ||
| <NavItem | ||
| preventDefault | ||
| id="expandable-3" | ||
| to="#expandable-3" | ||
| groupId="nav-expandable-group-1" | ||
| itemId={5} | ||
| isActive={activeItem === 5} | ||
| > | ||
| Subnav 1 Link 3 | ||
| </NavItem> | ||
| </NavExpandable> | ||
| </NavList> | ||
| </Nav> | ||
| ); | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,8 @@ export interface PageProps extends React.HTMLProps<HTMLDivElement> { | |
| variant?: 'default' | 'docked'; | ||
| /** @beta Flag indicating the docked nav is expanded on mobile. Only applies when variant is docked. */ | ||
| isDockExpanded?: boolean; | ||
| /** @beta Flag indicating a docked nav is expanded as an overlay, triggered by expandable nav children. Only applies when dock content is passed. */ | ||
| isDockExpandableExpanded?: boolean; | ||
| /** @beta Flag indicating the docked nav should display text on desktop. Only applies when variant is docked, and | ||
| * will handle toggling the visibility of the text in individual isDocked components. | ||
| */ | ||
|
|
@@ -134,6 +136,7 @@ class Page extends Component<PageProps, PageState> { | |
| defaultManagedSidebarIsOpen: true, | ||
| mainTabIndex: -1, | ||
| isNotificationDrawerExpanded: false, | ||
| isDockExpandableExpanded: false, | ||
| onNotificationDrawerExpand: () => null, | ||
| mainComponent: 'main', | ||
| getBreakpoint, | ||
|
|
@@ -248,6 +251,7 @@ class Page extends Component<PageProps, PageState> { | |
| variant, | ||
| isDockExpanded = false, | ||
| isDockTextExpanded = false, | ||
| isDockExpandableExpanded = false, | ||
| masthead, | ||
| dockContent, | ||
| sidebar, | ||
|
|
@@ -374,6 +378,7 @@ class Page extends Component<PageProps, PageState> { | |
| className={css( | ||
| styles.pageDock, | ||
| isDockExpanded && styles.modifiers.expanded, | ||
| isDockExpandableExpanded && styles.modifiers.expandableExpanded, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Gate this modifier on The prop documentation says it applies only when dock content is passed, but Line 381 checks only Add a content guard and a regression test for a docked page without 🤖 Prompt for AI Agents |
||
| isDockTextExpanded && styles.modifiers.textExpanded | ||
| )} | ||
| > | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.