@soul-refiner/design-system 0.2.83 → 0.2.84

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.
@@ -2,7 +2,7 @@ import React from 'react';
2
2
  import { ToastTypes } from '../toast/toast';
3
3
  export interface AnimatedToastProps {
4
4
  message: string;
5
- onClose: () => void;
5
+ onClose?: () => void;
6
6
  type: ToastTypes;
7
7
  }
8
8
  export declare const AnimatedToast: ({ message, type, onClose, }: AnimatedToastProps) => React.JSX.Element;
@@ -3,15 +3,24 @@ import React from 'react';
3
3
  import { styled } from 'styled-components';
4
4
  import { Toast } from '../toast';
5
5
  export const AnimatedToast = ({ message, type, onClose, }) => {
6
- const [dismissed, setDismissed] = React.useState(false);
7
- const handleDismiss = () => {
8
- setDismissed(true);
9
- };
10
- return (React.createElement(Wrapper, null,
11
- React.createElement(Container, null,
12
- React.createElement(Toast, { content: message, type: type, onClose: onClose, handleDismiss: handleDismiss }))));
6
+ const [toastIsClosed, setToastIsClosed] = React.useState(false);
7
+ const timer = React.useRef(null);
8
+ React.useEffect(() => {
9
+ timer.current = setTimeout(() => {
10
+ setToastIsClosed(true);
11
+ }, 4000);
12
+ return () => {
13
+ clearTimeout(timer.current);
14
+ };
15
+ }, []);
16
+ return (React.createElement(Container, null,
17
+ React.createElement(ToastAnimation, { className: `${toastIsClosed ? 'toast-closed' : ''}` },
18
+ React.createElement(Toast, { content: message, type: type, onClose: () => {
19
+ !!onClose && onClose();
20
+ setToastIsClosed(true);
21
+ }, isAnimated: true }))));
13
22
  };
14
- const Wrapper = styled.div `
23
+ const Container = styled.div `
15
24
  display: flex;
16
25
  row-gap: 12px;
17
26
  position: fixed;
@@ -19,10 +28,10 @@ const Wrapper = styled.div `
19
28
  bottom: 16px;
20
29
  right: 16px;
21
30
  `;
22
- const Container = styled.div `
31
+ const ToastAnimation = styled.div `
23
32
  animation: slide-in 0.4s ease-in-out forwards;
24
33
 
25
- .toast-dismissed {
34
+ .toast-closed {
26
35
  animation: slide-out 0.4s ease-in-out forwards;
27
36
  }
28
37
 
@@ -5,6 +5,6 @@ export interface ToastProps {
5
5
  href?: string;
6
6
  onClose: () => void;
7
7
  type: ToastTypes;
8
- handleDismiss?: () => void;
8
+ isAnimated?: boolean;
9
9
  }
10
- export declare const Toast: ({ content, href, onClose, type, handleDismiss, }: ToastProps) => React.JSX.Element;
10
+ export declare const Toast: ({ content, href, onClose, type, isAnimated, }: ToastProps) => React.JSX.Element;
@@ -4,22 +4,19 @@ import styled from 'styled-components';
4
4
  import { Styles } from '../../../common';
5
5
  import { Button, P } from '../../';
6
6
  import { AlertCircle, AlertOctogon, AlertTriangle, Close, Information, } from '../../../icons';
7
- export const Toast = ({ content, href, onClose, type, handleDismiss, }) => {
7
+ export const Toast = ({ content, href, onClose, type, isAnimated = false, }) => {
8
8
  const iconLookup = {
9
9
  error: React.createElement(AlertOctogon, { size: 24 }),
10
10
  info: React.createElement(Information, { size: 24 }),
11
11
  success: React.createElement(AlertCircle, { size: 24 }),
12
12
  warning: React.createElement(AlertTriangle, { size: 24 }),
13
13
  };
14
- return (React.createElement(Wrapper, { as: "output", "$dir": "row", "$gap": 8, "$type": type },
14
+ return (React.createElement(Wrapper, { as: "output", "$align": "center", "$dir": "row", "$gap": 8, "$type": type, "$isAnimated": isAnimated },
15
15
  iconLookup[type],
16
16
  React.createElement(P, { as: "span" }, content),
17
17
  href && (React.createElement(P, { sx: "padding-left: 8px;", as: "a", href: href, "$color": "primary-blue-2" }, "View")),
18
- React.createElement(Button, { icon: React.createElement(Close, { size: 24 }), onClick: () => {
19
- !!handleDismiss && handleDismiss();
20
- onClose();
21
- }, type: "special" }),
22
- !!handleDismiss && (React.createElement(ToastProgress, null,
18
+ React.createElement(Button, { icon: React.createElement(Close, { size: 24 }), onClick: onClose, type: "special" }),
19
+ isAnimated && (React.createElement(ToastProgress, null,
23
20
  React.createElement("div", { className: `toast-progress-bar ${type}` })))));
24
21
  };
25
22
  const ToastProgress = styled.div `
@@ -61,6 +58,12 @@ const ToastProgress = styled.div `
61
58
  }
62
59
  `;
63
60
  const Wrapper = styled.output `
61
+ ${({ $isAnimated }) => !$isAnimated &&
62
+ `
63
+ position: fixed;
64
+ bottom: 24px;
65
+ right: 24px;`}
66
+
64
67
  width: 99vw;
65
68
  max-width: 476px;
66
69
  box-sizing: border-box;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soul-refiner/design-system",
3
- "version": "0.2.83",
3
+ "version": "0.2.84",
4
4
  "main": "dist/index.js",
5
5
  "license": "MIT",
6
6
  "publishConfig": {