All files / src/components/ui/menu style.ts

36.67% Statements 11/30
0% Branches 0/3
0% Functions 0/17
34.48% Lines 10/29

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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1551x 1x           1x                         1x                           1x                               1x                                               1x                                                               1x                                                   1x                                 1x          
import API from "renderer/lib/api";
import styled, { css } from "styled-components";
 
export interface StyledMenuAcceleratorProps {
  $accelerator: string;
}
 
export const acceleratorForPlatform = (accelerator: string) => {
  Iif (API.platform === "darwin") {
    return accelerator
      .replace(/CommandOrControl\+/g, "⌘")
      .replace(/Shift\+/g, "⇧")
      .replace(/Alt\+/g, "⌥");
  }
  return accelerator
    .replace(/CommandOrControl\+/g, "Ctrl+")
    .replace(/Shift\+/g, "Shift+")
    .replace(/Alt\+/g, "Alt+");
};
 
export const StyledMenuAccelerator = styled.div.attrs<StyledMenuAcceleratorProps>(
  (props) => ({
    children: acceleratorForPlatform(props.$accelerator),
  })
)<StyledMenuAcceleratorProps>`
  flex-grow: 1;
  font-size: 0.8em;
  text-align: right;
  margin-left: 20px;
  color: ${(props) => props.theme.colors.secondaryText};
`;
 
// #region MenuItemCaret
 
export const StyledMenuItemCaret = styled.div`
  flex-grow: 1;
  text-align: right;
  margin-left: 5px;
  svg {
    display: inline-block;
    width: 10px;
    height: 10px;
    fill: ${(props) => props.theme.colors.text};
  }
`;
 
// #endregion MenuItemCaret
 
// #region Menu
 
export const StyledMenu = styled.div`
  display: flex;
  flex-direction: column;
  border-radius: ${(props) => props.theme.borderRadius}px;
  width: max-content;
  min-width: 100px;
  user-select: none;
  box-shadow: ${(props) => props.theme.colors.menu.boxShadow};
  background: ${(props) => props.theme.colors.menu.background};
  color: ${(props) => props.theme.colors.text};
  font-size: ${(props) => props.theme.typography.menuFontSize};
  padding: 4px 0;
  font-weight: normal;
  line-height: 15px;
`;
 
// #endregion Menu
 
// #region MenuItem
 
export interface StyledMenuItemProps {
  readonly $selected?: boolean;
}
 
export const StyledMenuItem = styled.div<StyledMenuItemProps>`
  display: flex;
  align-items: center;
  padding: 5px 10px;
  font-size: ${(props) => props.theme.typography.menuFontSize};
  white-space: nowrap;
 
  &:hover,
  &:focus {
    background: ${(props) => props.theme.colors.menu.hoverBackground};
    outline: none;
    box-shadow: none;
  }
 
  &:active {
    background: ${(props) => props.theme.colors.menu.activeBackground};
  }
 
  ${StyledMenu}:hover &:focus&:not(:hover) {
    background: ${(props) => props.theme.colors.menu.activeBackground};
  }
 
  ${(props) =>
    props.$selected
      ? css`
          background: ${(props) => props.theme.colors.menu.hoverBackground};
          outline: none;
          box-shadow: none;
        `
      : ""}
`;
 
export const StyledMenuItemIcon = styled.div`
  width: 15px;
  height: 15px;
  display: flex;
  flex-shrink: 0;
  justify-content: center;
  align-items: center;
  svg {
    width: 12px;
    height: 12px;
    fill: ${(props) => props.theme.colors.text};
  }
  &:nth-child(1) {
    margin-left: -5px;
    margin-right: 5px;
  }
  &:last-child:not(:first-child) {
    margin-left: 5px;
    margin-right: 0px;
  }
`;
 
// #endregion MenuItem
 
// #region MenuGroup
 
export const StyledMenuGroup = styled.div`
  display: flex;
  align-items: center;
  padding: 5px 10px;
  font-size: 10px;
  text-transform: uppercase;
  opacity: 0.8;
 
  ${StyledMenuItem} + & {
    margin-top: 10px;
  }
`;
 
// #endregion MenuGroup
 
// #region MenuDivider
 
export const StyledMenuDivider = styled.div`
  border-bottom: 1px solid ${(props) => props.theme.colors.menu.divider};
`;
 
// #region MenuDivider