All files / src/components/common/Radio Radio.tsx

66.66% Statements 4/6
0% Branches 0/4
33.33% Functions 1/3
66.66% Lines 4/6

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                                      34x                                                                                             34x 68x                                                           34x                          
import React from "react";
import { palette } from "@palette";
import { styled } from "@mui/material/styles";
import {
  Stack,
  Radio as MuiRadio,
  RadioProps as MuiRadioProps,
} from "@mui/material";
import { Text } from "@common/Text";
import { ITextProps } from "@common/Text/Text";
 
export type RadioProps = MuiRadioProps & {
  size?: "small" | "medium";
  title?: string;
  helper?: string;
  titleProps?: ITextProps;
  radioIconSize?: string;
};
 
export const Radio: React.FC<RadioProps> = ({
  size,
  title,
  helper,
  titleProps,
  radioIconSize,
  ...rest
}) => {
  return (
    <Stack direction="row" gap={1} alignItems="center">
      <MuiRadio
        sx={{
          padding: 0,
        }}
        disableRipple
        checkedIcon={
          <BpCheckedIcon className="RadioIcon" radioIconSize={radioIconSize} />
        }
        icon={<BpIcon className="RadioIcon" radioIconSize={radioIconSize} />}
        size={size}
        {...rest}
      />
      <Stack direction="column" gap="2px" justifyContent="flex-start">
        <Text
          fontSize="16px"
          lineHeight="19px"
          letterSpacing="-0.01em"
          fontWeight="regular"
          color={palette.black[200]}
          {...titleProps}
        >
          {title}
        </Text>
        <Text
          fontSize="14px"
          lineHeight="17px"
          letterSpacing="-0.01em"
          fontWeight="regular"
          color={palette.gray[300]}
        >
          {helper}
        </Text>
      </Stack>
    </Stack>
  );
};
 
const BpIcon = styled("span", {
  shouldForwardProp: (prop) => prop !== "radioIconSize",
})(({ radioIconSize }: { radioIconSize?: string }) => ({
  border: `2px solid ${palette.liftedWhite[300]}`,
  position: "relative",
  borderRadius: "50%",
  height: radioIconSize || "24px",
  width: radioIconSize || "24px",
  backgroundColor: palette.liftedWhite.main,
  ".Mui-focusVisible &": {
    outline: "none",
  },
  "input:hover ~ &": {
    backgroundColor: palette.neutral.white,
    border: `2px solid ${palette.gray[300]}`,
  },
  "input:active ~ &": {
    backgroundColor: palette.neutral.white,
    border: `2px solid ${palette.gray[300]}`,
  },
  "input:disabled ~ &": {
    boxShadow: "none",
    border: "none",
    backgroundColor: palette.gray[100],
 
    "&:before": {
      backgroundColor: palette.liftedWhite[300],
    },
  },
}));
 
const BpCheckedIcon = styled(BpIcon)({
  "&:before": {
    position: "absolute",
    content: '""',
    width: "14px",
    top: "50%",
    left: "50%",
    height: "14px",
    borderRadius: "50%",
    transform: "translate(-50%, -50%)",
    backgroundColor: palette.black[200],
  },
});