fix: use native Snackbar positioning for NotificationStack instead of custom Stack wrapper
This commit is contained in:
@@ -1,9 +1,11 @@
|
|||||||
import CloseIcon from '@mui/icons-material/Close'
|
import CloseIcon from '@mui/icons-material/Close'
|
||||||
import { Snackbar, Alert, Stack, IconButton, Button } from '@mui/material'
|
import { Snackbar, Alert, IconButton, Button } from '@mui/material'
|
||||||
import { useUnit } from 'effector-react'
|
import { useUnit } from 'effector-react'
|
||||||
import { useNavigate } from 'react-router-dom'
|
import { useNavigate } from 'react-router-dom'
|
||||||
import { $notifications, dismissNotification as dismissNotificationEvent } from '../../model/notification'
|
import { $notifications, dismissNotification as dismissNotificationEvent } from '../../model/notification'
|
||||||
|
|
||||||
|
const GAP = 76
|
||||||
|
|
||||||
export function NotificationStack() {
|
export function NotificationStack() {
|
||||||
const notifications = useUnit($notifications)
|
const notifications = useUnit($notifications)
|
||||||
const dismissNotification = useUnit(dismissNotificationEvent)
|
const dismissNotification = useUnit(dismissNotificationEvent)
|
||||||
@@ -12,27 +14,18 @@ export function NotificationStack() {
|
|||||||
if (notifications.length === 0) return null
|
if (notifications.length === 0) return null
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack
|
<>
|
||||||
spacing={1.5}
|
{notifications.map((n, index) => (
|
||||||
sx={{
|
|
||||||
position: 'fixed',
|
|
||||||
bottom: 88,
|
|
||||||
left: '50%',
|
|
||||||
transform: 'translateX(-50%)',
|
|
||||||
zIndex: 2000,
|
|
||||||
width: 'auto',
|
|
||||||
minWidth: 360,
|
|
||||||
maxWidth: 440,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{notifications.map((n) => (
|
|
||||||
<Snackbar
|
<Snackbar
|
||||||
key={n.id}
|
key={n.id}
|
||||||
open
|
open
|
||||||
autoHideDuration={n.autoHideDuration}
|
autoHideDuration={n.autoHideDuration}
|
||||||
onClose={() => dismissNotification(n.id)}
|
onClose={() => dismissNotification(n.id)}
|
||||||
anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }}
|
anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }}
|
||||||
sx={{ position: 'static' }}
|
sx={{
|
||||||
|
bottom: `${88 + (notifications.length - 1 - index) * GAP}px !important`,
|
||||||
|
zIndex: 2000 + index,
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<Alert
|
<Alert
|
||||||
severity={n.type}
|
severity={n.type}
|
||||||
@@ -40,6 +33,8 @@ export function NotificationStack() {
|
|||||||
onClose={() => dismissNotification(n.id)}
|
onClose={() => dismissNotification(n.id)}
|
||||||
sx={{
|
sx={{
|
||||||
width: '100%',
|
width: '100%',
|
||||||
|
minWidth: 360,
|
||||||
|
maxWidth: 440,
|
||||||
px: 2,
|
px: 2,
|
||||||
py: 1.5,
|
py: 1.5,
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
@@ -100,6 +95,6 @@ export function NotificationStack() {
|
|||||||
</Alert>
|
</Alert>
|
||||||
</Snackbar>
|
</Snackbar>
|
||||||
))}
|
))}
|
||||||
</Stack>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user