[5d6f37a] | 1 | import { Theme } from '@mui/material/styles';
|
---|
| 2 | import { BadgeProps, badgeClasses } from '@mui/material/Badge';
|
---|
| 3 |
|
---|
| 4 | // ----------------------------------------------------------------------
|
---|
| 5 |
|
---|
| 6 | // NEW VARIANT
|
---|
| 7 | declare module '@mui/material/Badge' {
|
---|
| 8 | interface BadgePropsVariantOverrides {
|
---|
| 9 | alway: true;
|
---|
| 10 | busy: true;
|
---|
| 11 | online: true;
|
---|
| 12 | offline: true;
|
---|
| 13 | invisible: true;
|
---|
| 14 | }
|
---|
| 15 | }
|
---|
| 16 |
|
---|
| 17 | export function badge(theme: Theme) {
|
---|
| 18 | return {
|
---|
| 19 | MuiBadge: {
|
---|
| 20 | styleOverrides: {
|
---|
| 21 | dot: {
|
---|
| 22 | borderRadius: '50%',
|
---|
| 23 | },
|
---|
| 24 | root: ({ ownerState }: { ownerState: BadgeProps }) => {
|
---|
| 25 | const alway = ownerState.variant === 'alway';
|
---|
| 26 |
|
---|
| 27 | const online = ownerState.variant === 'online';
|
---|
| 28 |
|
---|
| 29 | const busy = ownerState.variant === 'busy';
|
---|
| 30 |
|
---|
| 31 | const offline = ownerState.variant === 'offline';
|
---|
| 32 |
|
---|
| 33 | const invisible = ownerState.variant === 'invisible';
|
---|
| 34 |
|
---|
| 35 | const baseStyles = {
|
---|
| 36 | [`&.${badgeClasses.invisible}`]: {
|
---|
| 37 | transform: 'unset',
|
---|
| 38 | },
|
---|
| 39 | width: 10,
|
---|
| 40 | zIndex: 9,
|
---|
| 41 | padding: 0,
|
---|
| 42 | height: 10,
|
---|
| 43 | minWidth: 'auto',
|
---|
| 44 | '&:before, &:after': {
|
---|
| 45 | content: "''",
|
---|
| 46 | borderRadius: 1,
|
---|
| 47 | backgroundColor: theme.palette.common.white,
|
---|
| 48 | },
|
---|
| 49 | };
|
---|
| 50 |
|
---|
| 51 | return {
|
---|
| 52 | ...(online && {
|
---|
| 53 | [`& .${badgeClasses.badge}`]: {
|
---|
| 54 | ...baseStyles,
|
---|
| 55 | backgroundColor: theme.palette.success.main,
|
---|
| 56 | },
|
---|
| 57 | }),
|
---|
| 58 | ...(busy && {
|
---|
| 59 | [`& .${badgeClasses.badge}`]: {
|
---|
| 60 | ...baseStyles,
|
---|
| 61 | backgroundColor: theme.palette.error.main,
|
---|
| 62 | '&:before': { width: 6, height: 2 },
|
---|
| 63 | },
|
---|
| 64 | }),
|
---|
| 65 | ...(offline && {
|
---|
| 66 | [`& .${badgeClasses.badge}`]: {
|
---|
| 67 | ...baseStyles,
|
---|
| 68 | backgroundColor: theme.palette.text.disabled,
|
---|
| 69 | '&:before': {
|
---|
| 70 | width: 6,
|
---|
| 71 | height: 6,
|
---|
| 72 | borderRadius: '50%',
|
---|
| 73 | },
|
---|
| 74 | },
|
---|
| 75 | }),
|
---|
| 76 | ...(alway && {
|
---|
| 77 | [`& .${badgeClasses.badge}`]: {
|
---|
| 78 | ...baseStyles,
|
---|
| 79 | backgroundColor: theme.palette.warning.main,
|
---|
| 80 | '&:before': {
|
---|
| 81 | width: 2,
|
---|
| 82 | height: 4,
|
---|
| 83 | transform: 'translateX(1px) translateY(-1px)',
|
---|
| 84 | },
|
---|
| 85 | '&:after': {
|
---|
| 86 | width: 2,
|
---|
| 87 | height: 4,
|
---|
| 88 | transform: 'translateY(1px) rotate(125deg)',
|
---|
| 89 | },
|
---|
| 90 | },
|
---|
| 91 | }),
|
---|
| 92 | ...(invisible && {
|
---|
| 93 | [`& .${badgeClasses.badge}`]: {
|
---|
| 94 | display: 'none',
|
---|
| 95 | },
|
---|
| 96 | }),
|
---|
| 97 | };
|
---|
| 98 | },
|
---|
| 99 | },
|
---|
| 100 | },
|
---|
| 101 | };
|
---|
| 102 | }
|
---|