From 07e591071fe6fb1064c0fa4b5d557f6e993e3e57 Mon Sep 17 00:00:00 2001 From: Klink <85062+dogmar@users.noreply.github.com> Date: Fri, 5 Jan 2024 09:55:31 -0800 Subject: [PATCH] Update Sidebar --- www/src/components/layout/Sidebar.tsx | 182 ++++++++++++-------------- 1 file changed, 87 insertions(+), 95 deletions(-) diff --git a/www/src/components/layout/Sidebar.tsx b/www/src/components/layout/Sidebar.tsx index 92ab7ae7c..06baaad91 100644 --- a/www/src/components/layout/Sidebar.tsx +++ b/www/src/components/layout/Sidebar.tsx @@ -7,8 +7,9 @@ import { useState, } from 'react' import { Link, useLocation } from 'react-router-dom' -import { Avatar, Flex, Menu, MenuItem, Span, useOutsideClick } from 'honorable' +import { Menu, MenuItem } from 'honorable' import { + AppIcon, ArrowTopRightIcon, BellIcon, BrowseAppsIcon, @@ -28,8 +29,8 @@ import { SidebarSection, TerminalIcon, } from '@pluralsh/design-system' -import { useTheme } from 'styled-components' - +import styled, { useTheme } from 'styled-components' +import { useClickOutside } from '@react-hooks-library/core' import { getPreviousUserData } from '../../helpers/authentication' import { handlePreviousUserClick } from '../login/CurrentUser' import CurrentUserContext from '../../contexts/CurrentUserContext' @@ -104,15 +105,14 @@ function isActiveMenuItem( function SidebarWrapper() { const isCurrentlyOnboarding = useIsCurrentlyOnboarding() - return ( - - ) + return } +const FlexGrow1 = styled.div((_) => ({ + display: 'flex', + flexGrow: 1, +})) + function SidebarMenuItem({ tooltip, href, @@ -140,7 +140,30 @@ function SidebarMenuItem({ ) } -function Sidebar(props: ComponentProps) { +const SidebarSC = styled(DSSidebar).attrs(() => ({ variant: 'app' }))((_) => ({ + flexGrow: 1, + minHeight: 0, + height: 'auto', + overflow: 'auto', +})) + +const NotificationsCountSC = styled.div(({ theme }) => ({ + display: 'flex', + alignItems: 'center', + justifyContent: 'center', + color: theme.colors['text-always-white'], + backgroundColor: theme.colors['icon-danger-critical'], + borderRadius: '50%', + fontSize: 10, + height: 15, + width: 15, + position: 'absolute', + left: 16, + top: 2, + userSelect: 'none', +})) + +function Sidebar(props: Omit, 'variant'>) { const menuItemRef = useRef(null) const menuRef = useRef(null) const [isMenuOpen, setIsMenuOpened] = useState(false) @@ -161,8 +184,8 @@ function Sidebar(props: ComponentProps) { [pathname] ) const [readNotifications] = useReadNotificationsMutation() - const notificationsCount = useNotificationsCount() - const toggleNotifPanel = useCallback( + const notificationsCount = useNotificationsCount() ?? 0 + const toggleNotificationPanel = useCallback( (open) => { setIsNotificationsPanelOpen(open) if (!open) { @@ -172,7 +195,7 @@ function Sidebar(props: ComponentProps) { [setIsNotificationsPanelOpen, readNotifications] ) - useOutsideClick(menuRef, (event) => { + useClickOutside(menuRef, (event) => { if (!menuItemRef.current?.contains(event.target as any)) { setIsMenuOpened(false) } @@ -187,17 +210,12 @@ function Sidebar(props: ComponentProps) { return ( <> - + - {/* --- - MENU ITEMS - --- */} + {/* --- MENU ITEMS --- */} {menuItems.map((item, i) => { const isActive = active(item) @@ -213,27 +231,15 @@ function Sidebar(props: ComponentProps) { className={`sidebar-${item.text}`} as={Link} to={item.path} - backgroundColor={ - isActive ? theme.colors?.['fill-one-selected'] : null - } - _hover={{ - backgroundColor: isActive - ? theme.colors?.['fill-one-selected'] - : theme.colors?.['fill-one-hover'], - cursor: 'pointer', - }} - borderRadius="normal" - height={32} - width={32} + active={isActive} > {item.icon} ) })} - - {/* --- - SOCIAL - --- */} + + + {/* --- SOCIAL --- */} ) { > - {/* --- - NOTIFICATIONS BELL - --- */} + + {/* --- NOTIFICATIONS BELL --- */} 0 ? `${notificationsCount} ` : '' + } Notifications`} className="sidebar-notifications" onClick={(event) => { event.stopPropagation() - toggleNotifPanel((isOpen) => !isOpen) + toggleNotificationPanel(!isNotificationsPanelOpen) + }} + active={isNotificationsPanelOpen} + css={{ + position: 'relative', }} - backgroundColor={ - isNotificationsPanelOpen - ? theme.colors?.['fill-one-selected'] - : null - } - width={32} - height={32} > - {typeof notificationsCount === 'number' && - notificationsCount > 0 && ( - - - {notificationsCount > 99 ? '!' : notificationsCount} - - - )} + {notificationsCount > 0 && ( + + {notificationsCount > 99 ? '!' : notificationsCount} + + )} - {/* --- - USER - --- */} + + {/* --- USER -- */} ) { onClick={() => setIsMenuOpened((x) => !x)} userSelect="none" > - - - {/* --- - MENU - --- */} + + + {/* --- MENU --- */} {isMenuOpen && ( ) { color="inherit" textDecoration="none" > - + My profile ) { color="inherit" textDecoration="none" > - + Docs - + setIsCreatePublisherModalOpen(true)}> - + Create a publisher {!!previousUserData && ( - + Log back as {previousUserData.me.email} )} @@ -381,22 +375,20 @@ function Sidebar(props: ComponentProps) { onClick={handleLogout} color={theme.colors['icon-danger']} > - + Logout )} - {/* --- - NOTIFICATIONS PANEL - --- */} + + {/* --- NOTIFICATIONS PANEL --- */} - {/* --- - CREATE PUBLISHER MODAL - --- */} + + {/* --- CREATE PUBLISHER MODAL --- */} setIsCreatePublisherModalOpen(false)}