import React from 'react'; import { Avatar, Brand, Breadcrumb, BreadcrumbItem, Button, ButtonVariant, Divider, Dropdown, DropdownItem, DropdownList, EmptyState, EmptyStateActions, EmptyStateBody, EmptyStateIcon, EmptyStateHeader, EmptyStateFooter, EmptyStateVariant, MenuToggle, Nav, NavItem, NavList, NotificationBadge, NotificationDrawer, NotificationDrawerBody, NotificationDrawerHeader, NotificationDrawerList, NotificationDrawerListItem, NotificationDrawerListItemBody, NotificationDrawerListItemHeader, Page, PageSection, PageSectionVariants, PageSidebar, PageSidebarBody, SkipToContent, TextContent, Text, PageToggleButton, Masthead, MastheadMain, MastheadToggle, MastheadContent, MastheadBrand, Toolbar, ToolbarItem, ToolbarGroup, ToolbarContent } from '@patternfly/react-core'; import BellIcon from '@patternfly/react-icons/dist/esm/icons/bell-icon'; 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 BarsIcon from '@patternfly/react-icons/dist/js/icons/bars-icon'; import imgAvatar from '@patternfly/react-core/src/components/assets/avatarImg.svg'; import SearchIcon from '@patternfly/react-icons/dist/esm/icons/search-icon'; import pfLogo from '@patternfly/react-core/src/demos/assets/pf-logo.svg'; export const NotificationDrawerBasic: React.FunctionComponent = () => { const drawerRef = React.useRef(null); const [isDropdownOpen, setIsDropdownOpen] = React.useState(false); const [isKebabDropdownOpen, setIsKebabDropdownOpen] = React.useState(false); const [isDrawerExpanded, setIsDrawerExpanded] = React.useState(false); interface UnreadMap { [notificationId: string]: boolean; } const [activeItem, setActiveItem] = React.useState(0); const [isUnreadMap, setIsUnreadMap] = React.useState({ 'notification-1': true, 'notification-2': true, 'notification-3': false, 'notification-4': false }); const [shouldShowNotifications, setShouldShowNotifications] = React.useState(true); interface ActionsMenu { [toggleId: string]: boolean; } const [isActionsMenuOpen, setIsActionsMenuOpen] = React.useState({}); const onNavSelect = ( _event: React.FormEvent, selectedItem: { groupId: number | string; itemId: number | string; to: string; } ) => setActiveItem(selectedItem.itemId); const onDropdownToggle = () => setIsDropdownOpen((prevState) => !prevState); const onDropdownSelect = () => setIsDropdownOpen(false); const onKebabDropdownToggle = () => setIsKebabDropdownOpen((prevState) => !prevState); const onKebabDropdownSelect = () => setIsKebabDropdownOpen(false); const onCloseNotificationDrawer = (_event: any) => setIsDrawerExpanded((prevState) => !prevState); const onToggle = (id: string) => { setIsActionsMenuOpen({ [id]: !isActionsMenuOpen[id] }); }; const closeActionsMenu = () => setIsActionsMenuOpen({}); const onListItemClick = (id: string) => { if (!isUnreadMap) { return; } setIsUnreadMap({ ...isUnreadMap, [id]: false }); }; const getNumberUnread: () => number = () => { if (!isUnreadMap) { return 0; } return Object.values(isUnreadMap).reduce((count, value) => count + (value ? 1 : 0), 0); }; const markAllRead = () => setIsUnreadMap(null); const showNotifications = (showNotifications: boolean) => { setIsUnreadMap(null); setShouldShowNotifications(showNotifications); }; const focusDrawer = (_event: any) => { if (drawerRef.current === null) { return; } const firstTabbableItem = drawerRef.current.querySelector('a, button') as | HTMLAnchorElement | HTMLButtonElement | null; firstTabbableItem?.focus(); }; const PageNav = ( ); const kebabDropdownItems = ( <> Settings Help ); const userDropdownItems = ( <> My profile User management Logout ); const headerToolbar = ( onCloseNotificationDrawer(event)} aria-label="Notifications" isExpanded={isDrawerExpanded} > ); const Header = ( {headerToolbar} ); const Sidebar = ( {PageNav} ); const pageId = 'main-content-page-layout-default-nav'; const PageSkipToContent = Skip to content; const PageBreadcrumb = ( Section home Section title Section title Section landing ); const notificationDrawerActions = ( <> Mark all read showNotifications(false)}> Clear all showNotifications(true)}> Unclear last Settings ); const notificationDrawerDropdownItems = ( <> ev.preventDefault()} > Link Action Disabled Link ); const notificationDrawer = ( !isOpen && closeActionsMenu()} popperProps={{ position: 'right' }} toggle={(toggleRef: React.RefObject) => ( onToggle('toggle-id-0')} isExpanded={isActionsMenuOpen['toggle-id-0'] || false} > )} > {notificationDrawerActions} {shouldShowNotifications && ( onListItemClick('notification-1')} isRead={isUnreadMap === null || !isUnreadMap['notification-1']} > !isOpen && closeActionsMenu()} popperProps={{ position: 'right' }} toggle={(toggleRef: React.RefObject) => ( onToggle('toggle-id-1')} isExpanded={isActionsMenuOpen['toggle-id-1'] || false} > )} > {notificationDrawerDropdownItems} This is an info notification description. onListItemClick('notification-2')} isRead={isUnreadMap === null || !isUnreadMap['notification-2']} > !isOpen && closeActionsMenu()} popperProps={{ position: 'right' }} toggle={(toggleRef: React.RefObject) => ( onToggle('toggle-id-2')} isExpanded={isActionsMenuOpen['toggle-id-2'] || false} > )} > {notificationDrawerDropdownItems} This is a danger notification description. This is a long description to show how the title will wrap if it is long and wraps to multiple lines. onListItemClick('notification-3')} isRead={isUnreadMap === null || !isUnreadMap['notification-3']} > !isOpen && closeActionsMenu()} popperProps={{ position: 'right' }} toggle={(toggleRef: React.RefObject) => ( onToggle('toggle-id-3')} isExpanded={isActionsMenuOpen['toggle-id-3'] || false} > )} > {notificationDrawerDropdownItems} This is a warning notification description. onListItemClick('notification-4')} isRead={isUnreadMap === null || !isUnreadMap['notification-4']} > !isOpen && closeActionsMenu()} popperProps={{ position: 'right' }} toggle={(toggleRef: React.RefObject) => ( onToggle('toggle-id-4')} isExpanded={isActionsMenuOpen['toggle-id-4'] || false} > )} > {notificationDrawerDropdownItems} This is a success notification description. )} {!shouldShowNotifications && ( } /> There are currently no alerts. There may be silenced critical alerts however. )} ); return ( | KeyboardEvent | React.TransitionEvent ) => focusDrawer(event)} isNotificationDrawerExpanded={isDrawerExpanded} skipToContent={PageSkipToContent} breadcrumb={PageBreadcrumb} 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.
Panel section content
); };