@rango-dev/ui 0.28.2-next.6 → 0.28.2-next.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  import type { ToastProps } from './Toast.types';
2
2
 
3
- import React, { useEffect } from 'react';
3
+ import React, { useEffect, useState } from 'react';
4
4
 
5
5
  import { CloseIcon } from '../../icons';
6
6
  import { Alert } from '../Alert';
@@ -9,12 +9,14 @@ import AlertIcon from '../Alert/AlertIcon';
9
9
  import { Divider } from '../Divider';
10
10
  import { IconButton } from '../IconButton';
11
11
 
12
+ import { TOAST_HIDE_DELAY, TOAST_UNMOUNT_DELAY } from './Toast.helpers';
12
13
  import { useToast } from './Toast.Provider';
13
14
  import {
14
15
  AlertBox,
15
16
  AlertFlexContainer,
16
17
  StyledTypography,
17
18
  ToastContentContainer,
19
+ toastContentStyles,
18
20
  } from './Toast.styles';
19
21
 
20
22
  export const Toast = (props: ToastProps) => {
@@ -29,6 +31,8 @@ export const Toast = (props: ToastProps) => {
29
31
  hideOnTap = true,
30
32
  variant = 'standard',
31
33
  } = props;
34
+ const [isActive, setIsActive] = useState(false);
35
+ const [isVisible, setIsVisible] = useState(false);
32
36
  const { removeToast } = useToast();
33
37
  useEffect(() => {
34
38
  let cleanup;
@@ -45,42 +49,63 @@ export const Toast = (props: ToastProps) => {
45
49
  }, [id]);
46
50
 
47
51
  const handleClose = () => {
48
- removeToast(id, position);
49
- onClose?.();
52
+ setIsActive(false);
53
+ setTimeout(() => {
54
+ setIsVisible(false);
55
+ }, TOAST_HIDE_DELAY);
56
+ setTimeout(() => {
57
+ removeToast(id, position);
58
+ onClose?.();
59
+ }, TOAST_UNMOUNT_DELAY);
50
60
  };
51
61
 
62
+ useEffect(() => {
63
+ setIsVisible(true);
64
+ setTimeout(() => {
65
+ setIsActive(true);
66
+ }, 0);
67
+ }, []);
68
+
52
69
  return (
53
- <ToastContentContainer>
54
- <AlertBox
55
- onClick={hideOnTap ? handleClose : undefined}
56
- variant={variant}
57
- type={type}>
58
- {variant === 'custom' ? (
59
- <AlertFlexContainer>
60
- <IconHighlight type={type} align="center">
61
- <AlertIcon type={type} />
62
- </IconHighlight>
63
- <Divider direction="horizontal" size={10} />
64
- <StyledTypography variant="body" size="small" align="left">
65
- {props.title}
66
- </StyledTypography>
67
- </AlertFlexContainer>
68
- ) : (
69
- <Alert
70
- title={title}
71
- type={type}
72
- variant="alarm"
73
- titleAlign="left"
74
- action={
75
- hasCloseIcon ? (
76
- <IconButton variant="ghost" size="xsmall" onClick={handleClose}>
77
- <CloseIcon size={12} />
78
- </IconButton>
79
- ) : undefined
80
- }
81
- />
82
- )}
83
- </AlertBox>
70
+ <ToastContentContainer
71
+ isActive={isActive}
72
+ position={position}
73
+ isVisible={isVisible}>
74
+ <div className={toastContentStyles()}>
75
+ <AlertBox
76
+ onClick={hideOnTap ? handleClose : undefined}
77
+ variant={variant}
78
+ type={type}>
79
+ {variant === 'custom' ? (
80
+ <AlertFlexContainer>
81
+ <IconHighlight type={type} align="center">
82
+ <AlertIcon type={type} />
83
+ </IconHighlight>
84
+ <Divider direction="horizontal" size={10} />
85
+ <StyledTypography variant="body" size="small" align="left">
86
+ {props.title}
87
+ </StyledTypography>
88
+ </AlertFlexContainer>
89
+ ) : (
90
+ <Alert
91
+ title={title}
92
+ type={type}
93
+ variant="alarm"
94
+ titleAlign="left"
95
+ action={
96
+ hasCloseIcon ? (
97
+ <IconButton
98
+ variant="ghost"
99
+ size="xsmall"
100
+ onClick={handleClose}>
101
+ <CloseIcon size={12} />
102
+ </IconButton>
103
+ ) : undefined
104
+ }
105
+ />
106
+ )}
107
+ </AlertBox>
108
+ </div>
84
109
  </ToastContentContainer>
85
110
  );
86
111
  };