mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-18 23:46:03 +01:00
refactor(web/notifications): improve notification transitions
This commit is contained in:
@@ -3,7 +3,7 @@ import { IconProp } from '@fortawesome/fontawesome-svg-core';
|
|||||||
import { toast, Toaster, ToastPosition } from 'react-hot-toast';
|
import { toast, Toaster, ToastPosition } from 'react-hot-toast';
|
||||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||||
import ReactMarkdown from 'react-markdown';
|
import ReactMarkdown from 'react-markdown';
|
||||||
import { Avatar, createStyles, Group, Stack, Box, Text } from '@mantine/core';
|
import { Avatar, createStyles, Group, Stack, Box, Text, keyframes } from '@mantine/core';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
export interface NotificationProps {
|
export interface NotificationProps {
|
||||||
@@ -49,6 +49,73 @@ const useStyles = createStyles((theme) => ({
|
|||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
// I hate this
|
||||||
|
const enterAnimationTop = keyframes({
|
||||||
|
from: {
|
||||||
|
opacity: 0,
|
||||||
|
transform: 'translateY(-30px)',
|
||||||
|
},
|
||||||
|
to: {
|
||||||
|
opacity: 1,
|
||||||
|
transform: 'translateY(0px)',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const enterAnimationBottom = keyframes({
|
||||||
|
from: {
|
||||||
|
opacity: 0,
|
||||||
|
transform: 'translateY(30px)',
|
||||||
|
},
|
||||||
|
to: {
|
||||||
|
opacity: 1,
|
||||||
|
transform: 'translateY(0px)',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const exitAnimationTop = keyframes({
|
||||||
|
from: {
|
||||||
|
opacity: 1,
|
||||||
|
transform: 'translateY(0px)',
|
||||||
|
},
|
||||||
|
to: {
|
||||||
|
opacity: 0,
|
||||||
|
transform: 'translateY(-100%)',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const exitAnimationRight = keyframes({
|
||||||
|
from: {
|
||||||
|
opacity: 1,
|
||||||
|
transform: 'translateX(0px)',
|
||||||
|
},
|
||||||
|
to: {
|
||||||
|
opacity: 0,
|
||||||
|
transform: 'translateX(100%)',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const exitAnimationLeft = keyframes({
|
||||||
|
from: {
|
||||||
|
opacity: 1,
|
||||||
|
transform: 'translateX(0px)',
|
||||||
|
},
|
||||||
|
to: {
|
||||||
|
opacity: 0,
|
||||||
|
transform: 'translateX(-100%)',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const exitAnimationBottom = keyframes({
|
||||||
|
from: {
|
||||||
|
opacity: 1,
|
||||||
|
transform: 'translateY(0px)',
|
||||||
|
},
|
||||||
|
to: {
|
||||||
|
opacity: 0,
|
||||||
|
transform: 'translateY(100%)',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
const Notifications: React.FC = () => {
|
const Notifications: React.FC = () => {
|
||||||
const { classes } = useStyles();
|
const { classes } = useStyles();
|
||||||
|
|
||||||
@@ -68,8 +135,29 @@ const Notifications: React.FC = () => {
|
|||||||
data.icon = data.type === 'error' ? 'xmark' : data.type === 'success' ? 'check' : 'info';
|
data.icon = data.type === 'error' ? 'xmark' : data.type === 'success' ? 'check' : 'info';
|
||||||
}
|
}
|
||||||
|
|
||||||
toast(
|
toast.custom(
|
||||||
<Box style={data.style} className={`${classes.container}`}>
|
(t) => (
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
animation: t.visible
|
||||||
|
? `${position?.includes('bottom') ? enterAnimationBottom : enterAnimationTop} 0.2s ease-out forwards`
|
||||||
|
: `${
|
||||||
|
position?.includes('right')
|
||||||
|
? exitAnimationRight
|
||||||
|
: position?.includes('left')
|
||||||
|
? exitAnimationLeft
|
||||||
|
: position === 'top-center'
|
||||||
|
? exitAnimationTop
|
||||||
|
: position
|
||||||
|
? exitAnimationBottom
|
||||||
|
: exitAnimationRight
|
||||||
|
} 0.4s ease-in forwards`,
|
||||||
|
}}
|
||||||
|
style={{
|
||||||
|
...data.style,
|
||||||
|
}}
|
||||||
|
className={`${classes.container}`}
|
||||||
|
>
|
||||||
<Group noWrap spacing={12}>
|
<Group noWrap spacing={12}>
|
||||||
{data.icon && (
|
{data.icon && (
|
||||||
<>
|
<>
|
||||||
@@ -91,16 +179,12 @@ const Notifications: React.FC = () => {
|
|||||||
{data.description && <ReactMarkdown className={classes.description}>{data.description}</ReactMarkdown>}
|
{data.description && <ReactMarkdown className={classes.description}>{data.description}</ReactMarkdown>}
|
||||||
</Stack>
|
</Stack>
|
||||||
</Group>
|
</Group>
|
||||||
</Box>,
|
</Box>
|
||||||
|
),
|
||||||
{
|
{
|
||||||
id: data.id?.toString(),
|
id: data.id?.toString(),
|
||||||
duration: data.duration || 3000,
|
duration: data.duration || 3000,
|
||||||
position: position || 'top-right',
|
position: position || 'top-right',
|
||||||
style: {
|
|
||||||
padding: 0,
|
|
||||||
boxShadow: 'none',
|
|
||||||
backgroundColor: 'transparent',
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user