From 1194a7e9e99e6377906799f2c142c0b843112256 Mon Sep 17 00:00:00 2001 From: adamviktora <84135613+adamviktora@users.noreply.github.com> Date: Thu, 19 Oct 2023 22:42:39 +0200 Subject: [PATCH] chore(Nav): convert demos to TS (#9487) * chore(Nav): convert demos to TS * fix(Nav): omit in useState * fix(Nav): subnav aria-label * chore(Nav): rename components * chore(Nav): add preventDefault prop to NavItem components in demos * refactor(Nav examples): simplify Array.apply, renaming * fix(Nav demo): update JS shortcuts to TS warnings should disappear once issue #9544 is closed * docs(Nav): fix Flyout nav demo: hide sidebar bug * chore(Nav demo): update DashboardHeader/Wrapper imports * chore(Nav demo): use JS shortcut, since docs build still failing on ts * refactor(Nav demo): get rid of Array.apply --- packages/react-core/src/demos/Nav.md | 1683 +---------------- .../src/demos/examples/Nav/NavDefault.tsx | 98 + .../src/demos/examples/Nav/NavDrilldown.tsx | 2 + .../src/demos/examples/Nav/NavExpandable.tsx | 124 ++ .../src/demos/examples/Nav/NavFlyout.tsx | 278 +++ .../src/demos/examples/Nav/NavGrouped.tsx | 99 + .../src/demos/examples/Nav/NavHorizontal.tsx | 237 +++ .../examples/Nav/NavHorizontalWithSubnav.tsx | 297 +++ .../src/demos/examples/Nav/NavManual.tsx | 273 +++ .../src/demos/examples/Nav/NavWithSubnav.tsx | 142 ++ .../examples/Nav/deprecated/NavLight.tsx | 96 + .../examples/Nav/deprecated/NavTertiary.tsx | 92 + 12 files changed, 1748 insertions(+), 1673 deletions(-) create mode 100644 packages/react-core/src/demos/examples/Nav/NavDefault.tsx create mode 100644 packages/react-core/src/demos/examples/Nav/NavExpandable.tsx create mode 100644 packages/react-core/src/demos/examples/Nav/NavFlyout.tsx create mode 100644 packages/react-core/src/demos/examples/Nav/NavGrouped.tsx create mode 100644 packages/react-core/src/demos/examples/Nav/NavHorizontal.tsx create mode 100644 packages/react-core/src/demos/examples/Nav/NavHorizontalWithSubnav.tsx create mode 100644 packages/react-core/src/demos/examples/Nav/NavManual.tsx create mode 100644 packages/react-core/src/demos/examples/Nav/NavWithSubnav.tsx create mode 100644 packages/react-core/src/demos/examples/Nav/deprecated/NavLight.tsx create mode 100644 packages/react-core/src/demos/examples/Nav/deprecated/NavTertiary.tsx diff --git a/packages/react-core/src/demos/Nav.md b/packages/react-core/src/demos/Nav.md index 3bd3de7475f..74b6e3fdc3d 100644 --- a/packages/react-core/src/demos/Nav.md +++ b/packages/react-core/src/demos/Nav.md @@ -16,1718 +16,55 @@ import pfLogo from '@patternfly/react-core/src/demos/assets/pf-logo.svg'; ### Default nav -```js isFullscreen -import React from 'react'; -import { - Card, - CardBody, - Gallery, - GalleryItem, - Nav, - NavItem, - NavList, - Page, - PageSection, - PageSectionVariants, - PageSidebar, - PageSidebarBody, - SkipToContent, - TextContent, - Text -} from '@patternfly/react-core'; -import { DashboardBreadcrumb } from '@patternfly/react-core/src/demos/DashboardWrapper'; -import { DashboardHeader } from '@patternfly/react-core/src/demos/DashboardHeader'; - -class PageLayoutDefaultNav extends React.Component { - constructor(props) { - super(props); - this.state = { - activeItem: 0 - }; - - this.onNavSelect = (_event, result) => { - this.setState({ - activeItem: result.itemId - }); - }; - } - - render() { - const { activeItem } = this.state; - - const PageNav = ( - - ); - - const Sidebar = ( - - {PageNav} - - ); - const pageId = 'main-content-page-layout-default-nav'; - const PageSkipToContent = Skip to content; - - return ( - - } - sidebar={Sidebar} - isManagedSidebar - skipToContent={PageSkipToContent} - breadcrumb={DashboardBreadcrumb} - mainContainerId={pageId} - > - - - Main title - - Body text should be Overpass Regular at 16px. It should have leading of 24px because
- of its relative line height of 1.5. -
-
-
- - - {Array.apply(0, Array(10)).map((x, i) => ( - - - This is a card - - - ))} - - -
-
- ); - } -} +```js file='./examples/Nav/NavDefault.tsx' isFullscreen ``` ### Grouped nav -```js isFullscreen -import React from 'react'; -import { - Nav, - NavGroup, - NavItem, - Page, - PageSection, - PageSectionVariants, - PageSidebar, - PageSidebarBody, - SkipToContent, - TextContent, - Text -} from '@patternfly/react-core'; -import { DashboardHeader } from '@patternfly/react-core/src/demos/DashboardHeader'; - -class PageLayoutGroupsNav extends React.Component { - constructor(props) { - super(props); - this.state = { - activeItem: 'grp-1_itm-1' - }; - - this.onNavSelect = (_event, result) => { - this.setState({ - activeItem: result.itemId - }); - }; - } - - render() { - const { activeItem } = this.state; - - const PageNav = ( - - ); - - const Sidebar = ( - - {PageNav} - - ); - const pageId = 'main-content-page-layout-group-nav'; - const PageSkipToContent = Skip to Content; - - return ( - - } - sidebar={Sidebar} - isManagedSidebar - skipToContent={PageSkipToContent} - mainContainerId={pageId} - > - - - Main title - - Body text should be Overpass Regular at 16px. It should have leading of 24px because
- of its relative line height of 1.5. -
-
-
- Light - Dark - Darker - Content -
-
- ); - } -} +```js file='./examples/Nav/NavGrouped.tsx' isFullscreen ``` ### Expandable nav -```js isFullscreen -import React from 'react'; -import { - Card, - CardBody, - Gallery, - GalleryItem, - Nav, - NavExpandable, - NavItem, - NavList, - Page, - PageSection, - PageSectionVariants, - PageSidebar, - PageSidebarBody, - SkipToContent, - TextContent, - Text -} from '@patternfly/react-core'; -import { DashboardBreadcrumb } from '@patternfly/react-core/src/demos/DashboardWrapper'; -import { DashboardHeader } from '@patternfly/react-core/src/demos/DashboardHeader'; - -class PageLayoutExpandableNav extends React.Component { - constructor(props) { - super(props); - this.state = { - activeGroup: 'grp-1', - activeItem: 'grp-1_itm-1' - }; - - this.onNavSelect = (_event, result) => { - this.setState({ - activeItem: result.itemId, - activeGroup: result.groupId - }); - }; - } - - render() { - const { activeItem, activeGroup } = this.state; - - const PageNav = ( - - ); - - const Sidebar = ( - - {PageNav} - - ); - const pageId = 'main-content-page-layout-expandable-nav'; - const PageSkipToContent = Skip to content; - - return ( - - } - sidebar={Sidebar} - isManagedSidebar - skipToContent={PageSkipToContent} - breadcrumb={DashboardBreadcrumb} - mainContainerId={pageId} - > - - - Main title - - Body text should be Overpass Regular at 16px. It should have leading of 24px because
- of its relative line height of 1.5. -
-
-
- - - {Array.apply(0, Array(10)).map((x, i) => ( - - - This is a card - - - ))} - - -
-
- ); - } -} +```js file='./examples/Nav/NavExpandable.tsx' isFullscreen ``` ### Horizontal nav -```js isFullscreen -import React from 'react'; -import { - Avatar, - Brand, - Button, - ButtonVariant, - Card, - CardBody, - Dropdown, - DropdownItem, - DropdownList, - Gallery, - GalleryItem, - Masthead, - MastheadMain, - MastheadBrand, - MastheadContent, - MenuToggle, - Nav, - NavItem, - NavList, - Page, - PageSection, - PageSectionVariants, - SkipToContent, - TextContent, - Text, - Toolbar, - ToolbarContent, - ToolbarGroup, - ToolbarItem -} from '@patternfly/react-core'; -import CogIcon from '@patternfly/react-icons/dist/esm/icons/cog-icon'; -import HelpIcon from '@patternfly/react-icons/dist/esm/icons/help-icon'; -import QuestionCircleIcon from '@patternfly/react-icons/dist/esm/icons/question-circle-icon'; -import EllipsisVIcon from '@patternfly/react-icons/dist/esm/icons/ellipsis-v-icon'; -import BellIcon from '@patternfly/react-icons/dist/esm/icons/bell-icon'; -import imgAvatar from '@patternfly/react-core/src/components/assets/avatarImg.svg'; -import pfLogo from '@patternfly/react-core/src/demos/assets/pf-logo.svg'; -import { DashboardBreadcrumb } from '@patternfly/react-core/src/demos/DashboardWrapper'; - -class PageLayoutHorizontalNav extends React.Component { - constructor(props) { - super(props); - this.state = { - isDropdownOpen: false, - isKebabDropdownOpen: false, - isFullKebabDropdownOpen: false, - activeItem: 0 - }; - - this.onDropdownToggle = () => { - this.setState((prevState) => ({ - isDropdownOpen: !prevState.isDropdownOpen - })); - }; - - this.onDropdownSelect = () => { - this.setState({ - isDropdownOpen: false - }); - }; - - this.onKebabDropdownToggle = () => { - this.setState((prevState) => ({ - isKebabDropdownOpen: !prevState.isKebabDropdownOpen - })); - }; - - this.onKebabDropdownSelect = () => { - this.setState({ - isKebabDropdownOpen: false - }); - }; - - this.onFullKebabToggle = () => { - this.setState((prevState) => ({ - isFullKebabDropdownOpen: !prevState.isFullKebabDropdownOpen - })); - }; - - this.onNavSelect = (_event, result) => { - this.setState({ - activeItem: result.itemId - }); - }; - } - - render() { - const { isDropdownOpen, isKebabDropdownOpen, isFullKebabDropdownOpen, activeItem } = this.state; - - const PageNav = ( - - ); - const kebabDropdownItems = ( - <> - - Settings - - - Help - - - ); - const userDropdownItems = ( - <> - My profile - User management - Logout - - ); - - const headerToolbar = ( - - - {PageNav} - - -