All files / src/components/ui/menu Menu.tsx

70.37% Statements 19/27
0% Branches 0/4
0% Functions 0/8
65% Lines 13/20

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 931x 1x 1x 1x                   1x                                 1x                                   1x               1x       1x               1x           1x       1x                 1x          
import React, { forwardRef, ReactNode } from "react";
import styled from "styled-components";
import { CaretRightIcon } from "ui/icons/Icons";
import {
  StyledMenu,
  StyledMenuAccelerator,
  StyledMenuDivider,
  StyledMenuGroup,
  StyledMenuItem,
  StyledMenuItemCaret,
  StyledMenuItemIcon,
} from "ui/menu/style";
 
export const Menu = forwardRef<
  HTMLDivElement,
  React.HTMLAttributes<HTMLDivElement>
>((props, outerRef) => <StyledMenu ref={outerRef} role="menu" {...props} />);
 
export interface MenuItemProps extends React.HTMLAttributes<HTMLDivElement> {
  readonly "data-index"?: number;
  readonly selected?: boolean;
  readonly onClick?: (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => void;
  readonly onMouseEnter?: (
    e: React.MouseEvent<HTMLDivElement, MouseEvent>
  ) => void;
  readonly subMenu?: React.ReactElement[];
  readonly icon?: ReactNode;
  readonly children?: ReactNode;
}
 
export const MenuItem = ({
  selected,
  subMenu,
  children,
  icon,
  ...props
}: MenuItemProps) => (
  <StyledMenuItem $selected={selected} {...props}>
    {icon && <StyledMenuItemIcon>{icon}</StyledMenuItemIcon>}
    {children}
    {subMenu && <MenuItemCaret />}
  </StyledMenuItem>
);
 
export interface MenuItemIconProps {
  readonly children?: ReactNode;
}
 
export const MenuItemIcon = ({ children }: MenuItemIconProps) => (
  <StyledMenuItemIcon children={children} />
);
 
interface MenuGroupProps {
  children?: ReactNode;
}
 
export const MenuGroup = ({ children }: MenuGroupProps) => (
  <StyledMenuGroup children={children} />
);
 
export const MenuSection = styled.div`
  display: flex;
  align-items: center;
  padding: 5px 10px;
  font-size: ${(props) => props.theme.typography.menuFontSize};
  white-space: nowrap;
`;
 
export const MenuDivider = () => <StyledMenuDivider />;
 
export interface MenuAcceleratorProps {
  accelerator: string;
}
 
export const MenuAccelerator = ({ accelerator }: MenuAcceleratorProps) => (
  <StyledMenuAccelerator $accelerator={accelerator} />
);
 
export const MenuOverlay = styled.div`
  position: fixed;
  top: 0px;
  left: 0px;
  right: 0px;
  bottom: 0px;
  z-index: 1000;
`;
 
export const MenuItemCaret = () => (
  <StyledMenuItemCaret>
    <CaretRightIcon />
  </StyledMenuItemCaret>
);