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

72.72% Statements 8/11
25% Branches 2/8
66.66% Functions 2/3
70% Lines 7/10

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                                                  506x             506x                                                                 506x         4891x 4601x   290x                       506x          
import React from "react";
import {
  Button as MuiButton,
  ButtonProps as MuiButtonProps,
} from "@mui/material";
import { styled } from "@mui/material/styles";
import { BtnBGTypes, RebrandedButtonProps, StyledButton_V2 } from "./Button_V2";
import { CustomToolTip } from "@common/BusinessOwners/CustomToolTip";
 
export type TooltipProps = {
  show: boolean;
  message: string;
  extraMessage?: string;
  maxWidth?: string;
};
 
export type ButtonProps = MuiButtonProps & {
  children?: React.ReactNode;
  middleIcon?: React.ReactNode;
  background?: BtnBGTypes;
  size?: "small" | "medium" | "large";
  tooltipProps?: TooltipProps;
  isEnterprise?: boolean;
};
 
const MiddleIcon = styled("span")({
  display: "inherit",
  marginLeft: "0px",
  marginRight: 0,
  textTransform: "capitalize",
});
 
export const Button: React.FC<ButtonProps> = ({
  children,
  middleIcon,
  tooltipProps,
  ...props
}) => {
  if (!tooltipProps) {
    return (
      <MuiButton {...props}>
        {children}
        {middleIcon && <MiddleIcon>{middleIcon}</MiddleIcon>}
      </MuiButton>
    );
  }
  return (
    <CustomToolTip
      showToolTip={tooltipProps.show}
      message={tooltipProps.message}
      extraMessage={tooltipProps.extraMessage}
      maxWidth={tooltipProps.maxWidth}
    >
      <MuiButton {...props}>
        {children}
        {middleIcon && <MiddleIcon>{middleIcon}</MiddleIcon>}
      </MuiButton>
    </CustomToolTip>
  );
};
 
export interface Button_V2Props extends RebrandedButtonProps {
  tooltipProps?: TooltipProps;
}
 
export const Button_V2: React.FC<Button_V2Props> = ({
  children,
  tooltipProps,
  ...props
}) => {
  if (!tooltipProps) {
    return <StyledButton_V2 {...props}>{children}</StyledButton_V2>;
  }
  return (
    <CustomToolTip
      showToolTip={tooltipProps.show}
      message={tooltipProps.message}
      extraMessage={tooltipProps.extraMessage}
      maxWidth={tooltipProps.maxWidth}
    >
      <StyledButton_V2 {...props}>{children}</StyledButton_V2>
    </CustomToolTip>
  );
};
 
export const CloseButton = styled(Button_V2)(() => ({
  padding: 0,
  minWidth: 0,
  height: 24,
}));