Skip to content

Commit

Permalink
fix: contrast text color
Browse files Browse the repository at this point in the history
  • Loading branch information
chybisov committed Aug 22, 2022
1 parent 7fa62be commit 4d090e9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
7 changes: 4 additions & 3 deletions packages/widget/src/config/theme.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { PaletteMode, SimplePaletteColorOptions } from '@mui/material';
import { common } from '@mui/material/colors';
import { dialogActionsClasses } from '@mui/material/DialogActions';
import {
alpha,
Expand Down Expand Up @@ -209,9 +210,9 @@ export const createTheme = (mode: PaletteMode, theme: ThemeConfig = {}) => {
contained: {
'&:hover': {
color:
getContrastRatio('rgb(0, 0, 0)', primaryMainColor) >= 3
? 'rgb(0, 0, 0)'
: 'rgb(255, 255, 255)',
getContrastRatio(common.white, primaryMainColor) >= 3
? common.white
: common.black,
},
},
},
Expand Down
8 changes: 4 additions & 4 deletions packages/widget/src/utils/colors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Theme } from '@mui/material';
import { common } from '@mui/material/colors';
import { getContrastRatio } from '@mui/material/styles';

export const getContrastAlphaColor = (theme: Theme, alpha: string | number) =>
Expand All @@ -7,7 +8,6 @@ export const getContrastAlphaColor = (theme: Theme, alpha: string | number) =>
: `rgb(255 255 255 / ${alpha})`;

export const getContrastTextColor = (theme: Theme, background?: string) =>
getContrastRatio('rgb(0, 0, 0)', background ?? theme.palette.primary.main) >=
3
? 'rgb(0, 0, 0)'
: 'rgb(255, 255, 255)';
getContrastRatio(common.white, background ?? theme.palette.primary.main) >= 3
? common.white
: common.black;

0 comments on commit 4d090e9

Please sign in to comment.