@loomhq/lens 10.88.0 → 10.89.0
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,16 +1,18 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
declare const ToastWrapper: import("@emotion/styled-base").StyledComponent<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, ToastWrapperProps, object>;
|
|
3
|
-
declare const Toast: ({ children, isOpen, onCloseClick, zIndex, duration, }: ToastProps & React.ComponentProps<typeof ToastWrapper>) => JSX.Element;
|
|
3
|
+
declare const Toast: ({ children, isOpen, onCloseClick, zIndex, duration, platform, }: ToastProps & React.ComponentProps<typeof ToastWrapper>) => JSX.Element;
|
|
4
4
|
declare type ToastProps = {
|
|
5
5
|
children?: React.ReactNode;
|
|
6
6
|
isOpen?: boolean;
|
|
7
7
|
onCloseClick?: () => void;
|
|
8
8
|
zIndex?: number;
|
|
9
9
|
duration?: 'short' | 'long';
|
|
10
|
+
platform: 'web-app' | 'chrome-extension';
|
|
10
11
|
};
|
|
11
12
|
declare type ToastWrapperProps = {
|
|
12
13
|
zIndex?: number;
|
|
13
14
|
isOpen?: boolean;
|
|
14
15
|
toastDuration?: number;
|
|
16
|
+
platform: 'web-app' | 'chrome-extension';
|
|
15
17
|
};
|
|
16
18
|
export default Toast;
|
|
@@ -4,11 +4,13 @@ import IconButton from '../icon-button/icon-button';
|
|
|
4
4
|
import { SvgClose } from '../icon/available-icons';
|
|
5
5
|
import { keyframes } from '@emotion/core';
|
|
6
6
|
import styled from '@emotion/styled';
|
|
7
|
+
const WEBAPP = 'web-app';
|
|
8
|
+
const CHROME_EXTENSION = 'chrome-extension';
|
|
7
9
|
const toastDurations = { short: 3000, long: 8000 };
|
|
8
|
-
const enter = toastDuration => keyframes `
|
|
10
|
+
const enter = (toastDuration, platform) => keyframes `
|
|
9
11
|
0% {
|
|
10
12
|
opacity: 0;
|
|
11
|
-
transform: translate(-50%, ${u(8)});
|
|
13
|
+
transform: translate(-50%, ${u(platform === CHROME_EXTENSION ? -8 : 8)});
|
|
12
14
|
}
|
|
13
15
|
// (300 / toastDuration) * 100 evaluates to 10% for short. Longer durations will have the same speed of animation
|
|
14
16
|
${(300 / toastDuration) * 100}% {
|
|
@@ -23,12 +25,33 @@ const enter = toastDuration => keyframes `
|
|
|
23
25
|
opacity: 0;
|
|
24
26
|
}
|
|
25
27
|
`;
|
|
28
|
+
const getTop = platform => {
|
|
29
|
+
switch (platform) {
|
|
30
|
+
case WEBAPP:
|
|
31
|
+
return 'unset';
|
|
32
|
+
case CHROME_EXTENSION:
|
|
33
|
+
return u(4);
|
|
34
|
+
default:
|
|
35
|
+
return 'unset';
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
const getBottom = platform => {
|
|
39
|
+
switch (platform) {
|
|
40
|
+
case WEBAPP:
|
|
41
|
+
return u(4);
|
|
42
|
+
case CHROME_EXTENSION:
|
|
43
|
+
return 'unset';
|
|
44
|
+
default:
|
|
45
|
+
return u(4);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
26
48
|
const ToastWrapper = styled.div `
|
|
27
|
-
animation: ${props => enter(props.toastDuration)}
|
|
49
|
+
animation: ${props => enter(props.toastDuration, props.platform)}
|
|
28
50
|
${props => props.toastDuration}ms forwards;
|
|
29
51
|
background-color: ${getColorValue('background')};
|
|
30
52
|
border-radius: 1.75rem; // Height of single line toast (56px) divided by 2 so one line toasts appear fully rounded
|
|
31
|
-
|
|
53
|
+
top: ${props => getTop(props.platform)};
|
|
54
|
+
bottom: ${props => getBottom(props.platform)};
|
|
32
55
|
${getShadow('large')};
|
|
33
56
|
color: ${getColorValue('body')};
|
|
34
57
|
display: grid;
|
|
@@ -47,7 +70,7 @@ const ToastWrapper = styled.div `
|
|
|
47
70
|
const ChildrenSection = styled.div `
|
|
48
71
|
align-self: center;
|
|
49
72
|
`;
|
|
50
|
-
const Toast = ({ children, isOpen, onCloseClick, zIndex = 1100, duration = 'short', }) => {
|
|
73
|
+
const Toast = ({ children, isOpen, onCloseClick, zIndex = 1100, duration = 'short', platform = 'web-app', }) => {
|
|
51
74
|
const toastDuration = toastDurations[duration];
|
|
52
75
|
useEffect(() => {
|
|
53
76
|
const timer = setTimeout(() => {
|
|
@@ -57,7 +80,7 @@ const Toast = ({ children, isOpen, onCloseClick, zIndex = 1100, duration = 'shor
|
|
|
57
80
|
}, toastDuration);
|
|
58
81
|
return () => clearTimeout(timer);
|
|
59
82
|
}, [isOpen]);
|
|
60
|
-
return (React.createElement(React.Fragment, null, isOpen && (React.createElement(ToastWrapper, { "data-lens-theme": "dark", onClick: e => e.stopPropagation(), zIndex: zIndex, isOpen: isOpen, toastDuration: toastDuration },
|
|
83
|
+
return (React.createElement(React.Fragment, null, isOpen && (React.createElement(ToastWrapper, { "data-lens-theme": "dark", onClick: e => e.stopPropagation(), zIndex: zIndex, isOpen: isOpen, toastDuration: toastDuration, platform: platform },
|
|
61
84
|
React.createElement(ChildrenSection, { "aria-live": "polite" }, children),
|
|
62
85
|
onCloseClick && (React.createElement(IconButton, { altText: "Close", icon: React.createElement(SvgClose, null), onClick: onCloseClick }))))));
|
|
63
86
|
};
|