@soul-refiner/design-system 0.2.83 → 0.2.85

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,8 @@ 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
+ animationDuration?: number;
7
8
  }
8
- export declare const AnimatedToast: ({ message, type, onClose, }: AnimatedToastProps) => React.JSX.Element;
9
+ export declare const AnimatedToast: ({ message, type, onClose, animationDuration, }: AnimatedToastProps) => React.JSX.Element;
@@ -2,27 +2,32 @@
2
2
  import React from 'react';
3
3
  import { styled } from 'styled-components';
4
4
  import { Toast } from '../toast';
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 }))));
5
+ export const AnimatedToast = ({ message, type, onClose, animationDuration = 4, }) => {
6
+ const [toastIsClosed, setToastIsClosed] = React.useState(false);
7
+ const timer = React.useRef(null);
8
+ React.useEffect(() => {
9
+ timer.current = setTimeout(() => {
10
+ setToastIsClosed(true);
11
+ !!onClose && onClose();
12
+ }, animationDuration * 1000);
13
+ return () => {
14
+ clearTimeout(timer.current);
15
+ };
16
+ }, [animationDuration, onClose]);
17
+ return (React.createElement(Container, null,
18
+ React.createElement(ToastAnimation, { className: `${toastIsClosed ? 'toast-closed' : ''}` },
19
+ React.createElement(Toast, { content: message, type: type, isAnimated: true, animationDuration: animationDuration }))));
13
20
  };
14
- const Wrapper = styled.div `
15
- display: flex;
16
- row-gap: 12px;
21
+ const Container = styled.div `
17
22
  position: fixed;
18
23
  z-index: 9999;
19
24
  bottom: 16px;
20
25
  right: 16px;
21
26
  `;
22
- const Container = styled.div `
27
+ const ToastAnimation = styled.div `
23
28
  animation: slide-in 0.4s ease-in-out forwards;
24
29
 
25
- .toast-dismissed {
30
+ &.toast-closed {
26
31
  animation: slide-out 0.4s ease-in-out forwards;
27
32
  }
28
33
 
@@ -3,8 +3,9 @@ export type ToastTypes = 'error' | 'info' | 'success' | 'warning';
3
3
  export interface ToastProps {
4
4
  content: string;
5
5
  href?: string;
6
- onClose: () => void;
6
+ onClose?: () => void;
7
7
  type: ToastTypes;
8
- handleDismiss?: () => void;
8
+ isAnimated?: boolean;
9
+ animationDuration?: number;
9
10
  }
10
- export declare const Toast: ({ content, href, onClose, type, handleDismiss, }: ToastProps) => React.JSX.Element;
11
+ export declare const Toast: ({ content, href, onClose, type, isAnimated, animationDuration, }: 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, animationDuration, }) => {
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
+ !isAnimated && (React.createElement(Button, { icon: React.createElement(Close, { size: 24 }), onClick: onClose, type: "special" })),
19
+ isAnimated && (React.createElement(ToastProgress, { "$animationDuration": animationDuration || 4 },
23
20
  React.createElement("div", { className: `toast-progress-bar ${type}` })))));
24
21
  };
25
22
  const ToastProgress = styled.div `
@@ -32,7 +29,7 @@ const ToastProgress = styled.div `
32
29
 
33
30
  .toast-progress-bar {
34
31
  height: 100%;
35
- animation: progress-bar 4s linear forwards;
32
+ ${({ $animationDuration }) => `animation: progress-bar ${$animationDuration}s linear forwards`};
36
33
  }
37
34
 
38
35
  .toast-progress-bar.success {
@@ -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.85",
4
4
  "main": "dist/index.js",
5
5
  "license": "MIT",
6
6
  "publishConfig": {