All files / src/features/Permissions/ModalV2/components/AddPermissionModal AddPermissionModal.atoms.tsx

76.92% Statements 10/13
75% Branches 3/4
57.14% Functions 4/7
88.88% Lines 8/9

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                                  4x                     329x                                                             329x                       4x             65x 65x                               4x               65x                  
import CheckIcon from "@assets/icons/RebrandedIcons/CheckIcon";
import { SearchIcon } from "@assets/rebrandIcons";
import { Input } from "@common/Input";
import { Text, TruncateText } from "@common/Text";
import { Box, Stack, styled } from "@mui/material";
import { palette } from "@palette";
import { ChangeEvent } from "react";
import { TPermissionsData, TPermissionGroups } from "../../types";
 
type GroupStackProps = {
  groupName: string;
  isLast: boolean;
  uniqueGroups: TPermissionGroups;
  hashes: TPermissionsData;
  onClick: (key: string, value: TPermissionsData[string]) => void;
};
 
export const PermissionItem = ({
  permissionName,
  description,
  assigned,
  onClick,
}: {
  permissionName: string;
  description: string;
  assigned: boolean;
  onClick: () => void;
}) => {
  return (
    <PermissionWrapper onClick={onClick}>
      <Stack direction="row" alignItems="center" gap="4px">
        <TruncateText
          lineClamp={1}
          color={palette.black[100]}
          lineHeight="16.8px"
          fontWeight="book"
          flexGrow={1}
        >
          {permissionName}
        </TruncateText>
        <Box width="20px" height="20px">
          {assigned && (
            <CheckIcon width={20} height={20} fill={palette.black[300]} />
          )}
        </Box>
      </Stack>
      <TruncateText
        lineClamp={1}
        color={palette.gray[300]}
        lineHeight="16.8px"
        fontWeight="light"
        minHeight="16.8px"
      >
        {description}
      </TruncateText>
    </PermissionWrapper>
  );
};
 
const PermissionWrapper = styled(Stack)(() => ({
  padding: "4px 8px",
  flexDirection: "column",
  alignItems: "stretch",
  gap: "2px",
  borderRadius: "4px",
  "&:hover": {
    cursor: "pointer",
    backgroundColor: "rgba(0, 0, 0, 0.04)",
  },
}));
 
export const PermissionSearchBar = ({
  value,
  onChange,
}: {
  value: string;
  onChange: (value: string) => void;
}) => {
  const reset = () => onChange("");
  return (
    <StyledInput
      fullWidth
      placeholder="Search"
      value={value}
      onChange={(event: ChangeEvent<HTMLInputElement>) =>
        onChange(event.target.value)
      }
      startIcon={
        <SearchIcon width={20} height={20} stroke={palette.gray[300]} />
      }
      endIcon={value ? <EndIcon onClick={reset}>Clear</EndIcon> : undefined}
    />
  );
};
 
const EndIcon = styled(Text)(() => ({
  color: "#6D9CF8",
  fontWeight: 350,
  lineHeight: "16.8px",
  userSelect: "none",
  cursor: "pointer",
}));
 
const StyledInput = styled(Input)(() => ({
  "& .MuiInputBase-root.MuiOutlinedInput-root": {
    border: "none",
    borderBottom: `1px solid ${palette.liftedWhite[100]}`,
    padding: "14px 12px",
    borderRadius: 0,
    background: "transparent",
  },
}));