Skip to content

Commit

Permalink
Update alert style (#45)
Browse files Browse the repository at this point in the history
* feat: redesign notification

* Fix review issues

---------

Co-authored-by: ardier16 <[email protected]>
  • Loading branch information
WhiteNik16 and ardier16 authored Feb 13, 2024
1 parent c9200e3 commit aec7573
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 13 deletions.
20 changes: 10 additions & 10 deletions src/contexts/toasts-manager/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,6 @@ function ToastsManagerController({ children }: { children: ReactNode }) {
[t],
)

const defaultIcons = useMemo<Record<BusEvents, Icons | keyof typeof ICON_COMPONENTS>>(
() => ({
[BusEvents.success]: 'check',
[BusEvents.error]: 'errorOutline',
[BusEvents.warning]: 'warningAmber',
[BusEvents.info]: 'info',
}),
[],
)

const defaultMessages = useMemo(
() => ({
[BusEvents.success]: t('notifications.default-message-success'),
Expand All @@ -56,6 +46,16 @@ function ToastsManagerController({ children }: { children: ReactNode }) {
[t],
)

const defaultIcons = useMemo<Record<BusEvents, Icons | keyof typeof ICON_COMPONENTS>>(
() => ({
[BusEvents.success]: 'check',
[BusEvents.error]: 'errorOutline',
[BusEvents.warning]: 'warningAmber',
[BusEvents.info]: 'info',
}),
[],
)

const showToast = useCallback(
(messageType = BusEvents.info, payload: ToastPayload) => {
const title = payload?.title || defaultTitles[messageType]
Expand Down
4 changes: 2 additions & 2 deletions src/contexts/toasts-manager/toasts/DefaultToast.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Alert, AlertColor, AlertTitle } from '@mui/material'
import { Alert, AlertColor, AlertTitle, Typography } from '@mui/material'
import { CustomContentProps, SnackbarContent, useSnackbar } from 'notistack'
import { forwardRef, useMemo } from 'react'

Expand Down Expand Up @@ -46,7 +46,7 @@ const DefaultToast = forwardRef<HTMLDivElement, Props>((props: Props, ref) => {
onClose={() => closeSnackbar(id)}
>
<AlertTitle>{title}</AlertTitle>
{message}
<Typography variant={'body4'}>{message}</Typography>
</Alert>
</SnackbarContent>
)
Expand Down
41 changes: 40 additions & 1 deletion src/theme/components.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Components, Theme } from '@mui/material'
import { AlertColor, alpha, Components, Theme } from '@mui/material'

import { ICON_COMPONENTS } from '@/enums'

Expand Down Expand Up @@ -373,4 +373,43 @@ export const components: Components<Omit<Theme, 'components'>> = {
}),
},
},
MuiAlert: {
styleOverrides: {
root: ({ theme }) => ({
width: '100%',
borderRadius: theme.spacing(4),
backgroundColor: theme.palette.additional.pureBlack,
color: alpha(theme.palette.common.white, 0.7),
}),
icon: ({ ownerState, theme }) => {
const severityToBgColor: Record<AlertColor, string> = {
success: alpha(theme.palette.success.main, 0.2),
warning: alpha(theme.palette.warning.main, 0.2),
error: alpha(theme.palette.error.main, 0.2),
info: alpha(theme.palette.info.main, 0.2),
}

return {
backgroundColor: severityToBgColor[ownerState.severity ?? 'info'],
marginRight: theme.spacing(4),
marginTop: 'auto',
marginBottom: 'auto',
padding: theme.spacing(2),
borderRadius: theme.spacing(25),
}
},
message: ({ theme }) => ({
paddingTop: theme.spacing(4),
paddingBottom: theme.spacing(4),
}),
},
},
MuiAlertTitle: {
styleOverrides: {
root: ({ theme }) => ({
...typography.subtitle4,
color: theme.palette.common.white,
}),
},
},
}

0 comments on commit aec7573

Please sign in to comment.