diff --git a/packages/core-components/src/layout/Sidebar/Items.tsx b/packages/core-components/src/layout/Sidebar/Items.tsx index 544d7010fe..501b735176 100644 --- a/packages/core-components/src/layout/Sidebar/Items.tsx +++ b/packages/core-components/src/layout/Sidebar/Items.tsx @@ -43,7 +43,7 @@ import { import { sidebarConfig, SidebarContext, - ItemWithSubmenuContext, + SidebarItemWithSubmenuContext, } from './config'; import { SidebarSubmenu } from './SidebarSubmenu'; @@ -96,11 +96,13 @@ const useStyles = makeStyles( }, highlightable: { '&:hover': { - background: theme.palette.navigation.navItem.hoverBackground, + background: + theme.palette.navigation.navItem?.hoverBackground ?? '#404040', }, }, highlighted: { - background: theme.palette.navigation.navItem.hoverBackground, + background: + theme.palette.navigation.navItem?.hoverBackground ?? '#404040', }, label: { // XXX (@koroeskohr): I can't seem to achieve the desired font-weight from the designs @@ -168,7 +170,10 @@ const useStyles = makeStyles( { name: 'BackstageSidebarItem' }, ); -function isItemWithSubmenuActive(submenu: ReactNode, locationPathname: string) { +function isSidebarItemWithSubmenuActive( + submenu: ReactNode, + locationPathname: string, +) { // Item is active if any of submenu items have active paths const toPathnames: string[] = []; let isActive = false; @@ -194,16 +199,16 @@ function isItemWithSubmenuActive(submenu: ReactNode, locationPathname: string) { return isActive; } -const ItemWithSubmenu = ({ +const SidebarItemWithSubmenu = ({ text, hasNotifications = false, icon: Icon, children, -}: PropsWithChildren) => { +}: PropsWithChildren) => { const classes = useStyles(); const [isHoveredOn, setIsHoveredOn] = useState(false); const { pathname: locationPathname } = useLocation(); - const isActive = isItemWithSubmenuActive(children, locationPathname); + const isActive = isSidebarItemWithSubmenuActive(children, locationPathname); const handleMouseEnter = () => { setIsHoveredOn(true); @@ -240,7 +245,7 @@ const ItemWithSubmenu = ({ const closedContent = itemIcon; return ( - {isHoveredOn && children} - + ); }; @@ -290,7 +295,7 @@ type SidebarItemLinkProps = SidebarItemBaseProps & { onClick?: (ev: React.MouseEvent) => void; } & NavLinkProps; -type ItemWithSubmenuProps = SidebarItemBaseProps & { +type SidebarItemWithSubmenuProps = SidebarItemBaseProps & { to?: string; onClick?: (ev: React.MouseEvent) => void; children: ReactNode; @@ -304,7 +309,7 @@ type ItemWithSubmenuProps = SidebarItemBaseProps & { type SidebarItemProps = | SidebarItemLinkProps | SidebarItemButtonProps - | ItemWithSubmenuProps; + | SidebarItemWithSubmenuProps; function isButtonItem( props: SidebarItemProps, @@ -427,11 +432,7 @@ export const SidebarItem = forwardRef((props, ref) => { ).type; // Filter children for SidebarSubmenu components const submenus = useElementFilter(children, elements => - elements - .getElements() - .filter( - child => React.isValidElement(child) && child.type === componentType, - ), + elements.getElements().filter(child => child.type === componentType), ); // Error thrown if more than one SidebarSubmenu in a SidebarItem if (submenus.length > 1) { @@ -445,13 +446,13 @@ export const SidebarItem = forwardRef((props, ref) => { if (hasSubmenu) { return ( - {submenu} - + ); } diff --git a/packages/core-components/src/layout/Sidebar/Sidebar.stories.tsx b/packages/core-components/src/layout/Sidebar/Sidebar.stories.tsx index 7102d40f14..c070c90b2d 100644 --- a/packages/core-components/src/layout/Sidebar/Sidebar.stories.tsx +++ b/packages/core-components/src/layout/Sidebar/Sidebar.stories.tsx @@ -72,7 +72,7 @@ export const SampleScalableSidebar = () => ( - {}} text="Catalog"> + diff --git a/packages/core-components/src/layout/Sidebar/SidebarSubmenu.tsx b/packages/core-components/src/layout/Sidebar/SidebarSubmenu.tsx index 9b8b9ca145..51324980fe 100644 --- a/packages/core-components/src/layout/Sidebar/SidebarSubmenu.tsx +++ b/packages/core-components/src/layout/Sidebar/SidebarSubmenu.tsx @@ -18,7 +18,7 @@ import Typography from '@material-ui/core/Typography'; import clsx from 'clsx'; import React, { PropsWithChildren, ReactNode, useContext } from 'react'; import { - ItemWithSubmenuContext, + SidebarItemWithSubmenuContext, sidebarConfig, SidebarContext, submenuConfig, @@ -42,7 +42,7 @@ const useStyles = (props: { left: number }) => top: 0, bottom: 0, padding: 0, - background: theme.palette.navigation.submenu.background, + background: theme.palette.navigation.submenu?.background ?? '#404040', overflowX: 'hidden', msOverflowStyle: 'none', scrollbarWidth: 'none', @@ -94,7 +94,7 @@ export const SidebarSubmenu = ({ const props = { left: left }; const classes = useStyles(props)(); - const { isHoveredOn } = useContext(ItemWithSubmenuContext); + const { isHoveredOn } = useContext(SidebarItemWithSubmenuContext); return (
(theme => ({ item: { @@ -118,7 +118,7 @@ export const SidebarSubmenuItem = (props: SidebarSubmenuItemProps) => { const classes = useStyles(); const { pathname: locationPathname } = useLocation(); const { pathname: toPathname } = useResolvedPath(to); - const { setIsHoveredOn } = useContext(ItemWithSubmenuContext); + const { setIsHoveredOn } = useContext(SidebarItemWithSubmenuContext); const closeSubmenu = () => { setIsHoveredOn(false); }; diff --git a/packages/core-components/src/layout/Sidebar/config.ts b/packages/core-components/src/layout/Sidebar/config.ts index c4f73d0a9d..dbcdb7d788 100644 --- a/packages/core-components/src/layout/Sidebar/config.ts +++ b/packages/core-components/src/layout/Sidebar/config.ts @@ -67,14 +67,13 @@ export const SidebarContext = createContext({ setOpen: _open => {}, }); -export type ItemWithSubmenuContextType = { +export type SidebarItemWithSubmenuContextType = { isHoveredOn: boolean; setIsHoveredOn: Dispatch>; }; -export const ItemWithSubmenuContext = createContext( - { +export const SidebarItemWithSubmenuContext = + createContext({ isHoveredOn: false, setIsHoveredOn: () => {}, - }, -); + }); diff --git a/packages/theme/src/types.ts b/packages/theme/src/types.ts index 44d9165417..3d1a64c38f 100644 --- a/packages/theme/src/types.ts +++ b/packages/theme/src/types.ts @@ -53,10 +53,10 @@ export type BackstagePaletteAdditions = { indicator: string; color: string; selectedColor: string; - navItem: { + navItem?: { hoverBackground: string; }; - submenu: { + submenu?: { background: string; }; };