sidebarMenuItem.tsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import {css} from '@emotion/react';
  2. import styled from '@emotion/styled';
  3. import {Theme} from 'sentry/utils/theme';
  4. import SidebarMenuItemLink from './sidebarMenuItemLink';
  5. import SidebarOrgSummary from './sidebarOrgSummary';
  6. type Props = {
  7. children: React.ReactNode;
  8. } & React.ComponentProps<typeof SidebarMenuItemLink>;
  9. const SidebarMenuItem = ({to, children, href, ...props}: Props) => {
  10. const hasMenu = !to && !href;
  11. return (
  12. <StyledSidebarMenuItemLink to={to} href={href} {...props}>
  13. <MenuItemLabel hasMenu={hasMenu}>{children}</MenuItemLabel>
  14. </StyledSidebarMenuItemLink>
  15. );
  16. };
  17. const menuItemStyles = (
  18. p: Omit<React.ComponentProps<typeof SidebarMenuItemLink>, 'children'> & {theme: Theme}
  19. ) => css`
  20. color: ${p.theme.textColor};
  21. cursor: pointer;
  22. display: flex;
  23. font-size: ${p.theme.fontSizeMedium};
  24. line-height: 32px;
  25. padding: 0 ${p.theme.sidebar.menuSpacing};
  26. position: relative;
  27. transition: 0.1s all linear;
  28. ${(!!p.to || !!p.href) && 'overflow: hidden'};
  29. &:hover,
  30. &:active,
  31. &.focus-visible {
  32. background: ${p.theme.backgroundSecondary};
  33. color: ${p.theme.textColor};
  34. outline: none;
  35. }
  36. ${SidebarOrgSummary} {
  37. padding-left: 0;
  38. padding-right: 0;
  39. }
  40. `;
  41. const MenuItemLabel = styled('span')<{hasMenu?: boolean}>`
  42. flex: 1;
  43. ${p =>
  44. p.hasMenu
  45. ? css`
  46. margin: 0 -${p.theme.sidebar.menuSpacing};
  47. padding: 0 ${p.theme.sidebar.menuSpacing};
  48. `
  49. : css`
  50. overflow: hidden;
  51. `};
  52. `;
  53. const StyledSidebarMenuItemLink = styled(SidebarMenuItemLink)`
  54. ${menuItemStyles}
  55. `;
  56. export {menuItemStyles};
  57. export default SidebarMenuItem;