All files / src/theme/ui/overrides/components button-group.jsx

18.75% Statements 3/16
0% Branches 0/18
25% Functions 1/4
20% Lines 3/15

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          10x             91x                                                                                                                                               91x                
import { alpha } from '@mui/material/styles';
import { buttonGroupClasses } from '@mui/material/ButtonGroup';
 
// ----------------------------------------------------------------------
 
const COLORS = ['primary', 'secondary', 'info', 'success', 'warning', 'error'];
 
// NEW VARIANT
 
// ----------------------------------------------------------------------
 
export function buttonGroup(theme) {
  const rootStyles = (ownerState) => {
    const inheritColor = ownerState.color === 'inherit';
 
    const containedVariant = ownerState.variant === 'contained';
 
    const outlinedVariant = ownerState.variant === 'outlined';
 
    const textVariant = ownerState.variant === 'text';
 
    const softVariant = ownerState.variant === 'soft';
 
    const horizontalOrientation = ownerState.orientation === 'horizontal';
 
    const verticalOrientation = ownerState.orientation === 'vertical';
 
    const defaultStyle = {
      [`& .${buttonGroupClasses.grouped}`]: {
        '&:not(:last-of-type)': {
          ...(!outlinedVariant && {
            borderStyle: 'solid',
            ...(inheritColor && {
              borderColor: alpha(theme.palette.grey[500], 0.32),
            }),
            // HORIZONTAL
            ...(horizontalOrientation && {
              borderWidth: '0px 1px 0px 0px',
            }),
            // VERTICAL
            ...(verticalOrientation && {
              borderWidth: '0px 0px 1px 0px',
            }),
          }),
        },
      },
    };
 
    const colorStyle = COLORS.map((color) => ({
      [`& .${buttonGroupClasses.grouped}`]: {
        '&:not(:last-of-type)': {
          ...(!outlinedVariant && {
            ...(ownerState.color === color && {
              // CONTAINED
              ...(containedVariant && {
                borderColor: alpha(theme.palette[color].dark, 0.48),
              }),
              // TEXT
              ...(textVariant && {
                borderColor: alpha(theme.palette[color].main, 0.48),
              }),
              // SOFT
              ...(softVariant && {
                borderColor: alpha(theme.palette[color].dark, 0.24),
              }),
            }),
          }),
        },
      },
    }));
 
    const disabledState = {
      [`& .${buttonGroupClasses.grouped}`]: {
        [`&.${buttonGroupClasses.disabled}`]: {
          '&:not(:last-of-type)': {
            borderColor: theme.palette.action.disabledBackground,
          },
        },
      },
    };
 
    return [defaultStyle, ...colorStyle, disabledState];
  };
 
  return {
    MuiButtonGroup: {
      styleOverrides: {
        root: ({ ownerState }) => rootStyles(ownerState),
      },
    },
  };
}