All files / src theme.ts

100% Statements 29/29
100% Branches 42/42
100% Functions 17/17
100% Lines 29/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 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283    6x                   6x         6x         6x             6x 9x   9x 9x   9x 225x     9x                                                             2x                     4x       1x             3x   2x                                                           2x             2x             2x                         2x                         2x                                           2x                                           2x                   2x                 2x     2x                         2x                         2x         2x                                          
import { createTheme, type Theme, type PaletteMode, type Shadows } from '@mui/material/styles';
 
const brandColors = {
  primary:   '#68B9B5',  
  secondary: '#0B1B2B',  
  accent:    '#F8E1B0',  
  info:      '#0085C7',  
  warning:   '#FFCD00',  
  error:     '#E31937',  
  success:   '#009739',  
};
 
const backgroundDefaults = {
  light: { default: '#F4F4F4', paper: '#FFFFFF' },
  dark:  { default: '#121212', paper: '#0C1F2B' },
};
 
const textDefaults = {
  light:   { primary: '#0C1B2B', secondary: '#576271' },
  dark:    { primary: '#F9E8C4', secondary: '#C0C0C0' },
};
 
const customShadows: Partial<Record<number, string>> = {
  1: '0px 1px 3px rgba(0,0,0,0.2)',
  2: '0px 1px 5px rgba(0,0,0,0.14)',
  3: '0px 1px 8px rgba(0,0,0,0.12)',
  4: '0px 2px 4px rgba(0,0,0,0.12)',
};
 
export const getAppTheme = (mode: PaletteMode): Theme => {
  const isLight = mode === 'light';
 
  const defaultTheme = createTheme();
  const defaultShadows: Shadows = defaultTheme.shadows;
 
  const shadows: Shadows = defaultShadows.map((sh, idx) =>
    customShadows[idx] ?? sh
  ) as Shadows;
 
  return createTheme({
    palette: {
      mode,
      primary: { main: brandColors.primary },
      secondary: { main: brandColors.secondary },
      error: { main: brandColors.error },
      warning: { main: brandColors.warning },
      info: { main: brandColors.info },
      success: { main: brandColors.success },
      background: backgroundDefaults[mode],
      text:       textDefaults[mode],
      divider: isLight ? 'rgba(0,0,0,0.12)' : 'rgba(255,255,255,0.12)',
    },
    shape: { borderRadius: 10 },   
    shadows,    
    typography: {
      fontFamily: 'Poppins, Arial, sans-serif',
      h1: { fontSize: '2.5rem', fontWeight: 700 },
      h2: { fontSize: '2rem', fontWeight: 700 },
      h3: { fontSize: '1.75rem', fontWeight: 700 },
      h4: { fontSize: '1.5rem', fontWeight: 400, textTransform: 'uppercase' },
      h5: { fontSize: '1.25rem', fontWeight: 400 },
      h6: { fontSize: '1.125rem', fontWeight: 500, textTransform: 'uppercase' },
      body1: { fontSize: '1rem', fontWeight: 400 },
      body2: { fontSize: '0.875rem', fontWeight: 400 },
      subtitle1: { fontSize: '1rem', fontWeight: 400 },
      subtitle2: { fontSize: '0.875rem', fontWeight: 500 },
    },
    components: {
      MuiCard: {
        styleOverrides: {
          root: ({ theme }) => ({
            border: `1px solid ${theme.palette.divider}`,
            borderRadius: 10,
            boxShadow: '0 4px 12px rgba(0,0,0,0.2)',
            padding: '40px 20px',
          }),
        },
      },
      MuiButton: {
        styleOverrides: {
          text: ({ theme, ownerState }) => {
            if (
              theme.palette.mode === 'light' &&
              ownerState.color !== 'inherit'
            ) {
              return {
                color: theme.palette.info.main,
                '&:hover': {
                  backgroundColor: `${theme.palette.info.main}10`,
                },
              };
            }
            return {}; // sinon, pas de changement
          },
          containedPrimary: ({ theme }) => ({
            backgroundColor:
              theme.palette.mode === 'dark'
                ? theme.palette.primary.dark
                : theme.palette.info.main,
            color:
              theme.palette.mode === 'dark'
                ? theme.palette.primary.contrastText
                : theme.palette.info.contrastText,
            '&:hover': {
              backgroundColor:
                theme.palette.mode === 'dark'
                  ? theme.palette.primary.main
                  : theme.palette.info.light,
            },
          }),
          ...(isLight && {
            outlinedPrimary: {
              borderColor:     brandColors.secondary,
              color:           brandColors.secondary,
              '&:hover': {
                borderColor:     brandColors.secondary,
                backgroundColor: `${brandColors.secondary}10`,
              },
            },
          }),
        },
      },
      MuiIconButton: {
        styleOverrides: {
          root: ({ theme }) => ({
            color: isLight ? theme.palette.info.main : theme.palette.text.primary,
          }),
        },
      },
      MuiListItemIcon: {
        styleOverrides: {
          root: ({ theme }) => ({
            color: isLight ? theme.palette.info.main : theme.palette.text.primary,
          }),
        },
      },
      MuiBadge: {
        styleOverrides: {
          badge: ({ theme }) => ({
            backgroundColor: isLight ? theme.palette.text.primary : theme.palette.info.main,
            color:           '#fff',
            minWidth:        16,
            height:          16,
            fontSize:        '0.625rem',
            borderRadius:    '50%',
            transform:       'translate(35%, 35%)',
          }),
        },
      },
      MuiLink: {
        styleOverrides: {
          root: ({ theme }) => ({
            color: theme.palette.mode === 'light'
              ? theme.palette.primary.dark
              : theme.palette.primary.light,
            textDecoration: 'underline',
            '&:hover': {
              color: theme.palette.primary.main,
            },
          }),
        },
      },
      MuiRadio: {
        styleOverrides: {
          root: ({ theme }) => ({
            color: theme.palette.text.secondary,
            '&.Mui-checked': {
              color: theme.palette.mode === 'dark'
                  ? theme.palette.primary.dark
                  : theme.palette.info.main,
            },
          }),
        },
      }, 
      MuiPagination: {
        styleOverrides: {
          root: {
            // Centrage et marge
            display: 'flex',
            justifyContent: 'center',
            padding: '1rem 0',
          },
        },
      },    
      MuiPaginationItem: {
        styleOverrides: {
          root: ({ theme }) => ({
            minWidth: 32,
            height:    32,
            margin:   '0 4px',
            '&.Mui-selected': {
              backgroundColor: theme.palette.mode === 'dark'
                  ? theme.palette.primary.dark
                  : theme.palette.info.main,
              color: theme.palette.mode === 'dark'
                ? theme.palette.primary.contrastText
                : theme.palette.info.contrastText,
              '&:hover': {
                backgroundColor: theme.palette.mode === 'dark'
                  ? theme.palette.primary.main
                  : theme.palette.info.light,
              },
            },  
          }),             
        },
      },
      MuiAccordion: {
        styleOverrides: {
          root: ({ theme }) => ({
            backgroundColor: theme.palette.background.paper,
            borderRadius: theme.shape.borderRadius,
            border: `1px solid ${theme.palette.divider}`,
            '&:before': { display: 'none' }
          }),
        },
      },
      MuiAccordionSummary: {
        styleOverrides: {
          root: ({ theme }) => ({
            backgroundColor: theme.palette.background.paper,
            borderRadius: theme.shape.borderRadius,
            '&.Mui-expanded': {
              borderBottomLeftRadius: 0,
              borderBottomRightRadius: 0,
            },
          }),
          expandIconWrapper: ({ theme }) => {
            const iconColor = theme.palette.mode === 'dark'
              ? theme.palette.text.primary
              : theme.palette.info.main;
            return {
              color: iconColor,
              borderRadius: '50%',
              padding: 4,
              '&:hover': {
                backgroundColor: theme.palette.action.hover
              },
            };
          },
        },
      },
      MuiAccordionDetails: {
        styleOverrides: {
          root: ({ theme }) => ({
            backgroundColor: theme.palette.background.paper,
            borderBottomLeftRadius: theme.shape.borderRadius,
            borderBottomRightRadius: theme.shape.borderRadius,
            '&.Mui-expanded': {
              borderBottomLeftRadius: theme.shape.borderRadius,
              borderBottomRightRadius: theme.shape.borderRadius,
            },
          }),
        },
      },
      MuiSwitch: {
        styleOverrides: {
          switchBase: ({ theme }) => ({
            color: theme.palette.mode === 'dark'
                ? theme.palette.primary.dark
                : theme.palette.info.main,
          }),
          root: ({ theme }) => ({
            '& .MuiSwitch-switchBase.Mui-checked .MuiSwitch-thumb': {
              color: theme.palette.mode === 'dark'
                ? theme.palette.primary.dark
                : theme.palette.info.main,
            },
            '& .MuiSwitch-switchBase.Mui-checked + .MuiSwitch-track': {
              backgroundColor: theme.palette.mode === 'dark'
                ? theme.palette.primary.dark
                : theme.palette.info.main,
            },
            '& .MuiSwitch-track': {
              backgroundColor: (theme.palette.mode === 'dark'
                ? theme.palette.primary.dark
                : theme.palette.info.main) + '80',
            },
          }),
        },
      },
    },
  });
};