@rango-dev/ui 0.27.0 → 0.27.1-next.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.
- package/CHANGELOG.md +25 -0
- package/dist/index.js +2 -2
- package/dist/index.js.map +4 -4
- package/dist/widget/ui/src/components/Alert/Alert.styles.d.ts +1 -0
- package/dist/widget/ui/src/components/Alert/Alert.styles.d.ts.map +1 -1
- package/dist/widget/ui/src/components/Toast/Toast.Provider.d.ts +6 -0
- package/dist/widget/ui/src/components/Toast/Toast.Provider.d.ts.map +1 -0
- package/dist/widget/ui/src/components/Toast/Toast.d.ts +4 -0
- package/dist/widget/ui/src/components/Toast/Toast.d.ts.map +1 -0
- package/dist/widget/ui/src/components/Toast/Toast.helpers.d.ts +2 -0
- package/dist/widget/ui/src/components/Toast/Toast.helpers.d.ts.map +1 -0
- package/dist/widget/ui/src/components/Toast/Toast.stories.d.ts +7 -0
- package/dist/widget/ui/src/components/Toast/Toast.stories.d.ts.map +1 -0
- package/dist/widget/ui/src/components/Toast/Toast.styles.d.ts +977 -0
- package/dist/widget/ui/src/components/Toast/Toast.styles.d.ts.map +1 -0
- package/dist/widget/ui/src/components/Toast/Toast.types.d.ts +31 -0
- package/dist/widget/ui/src/components/Toast/Toast.types.d.ts.map +1 -0
- package/dist/widget/ui/src/components/Toast/index.d.ts +3 -0
- package/dist/widget/ui/src/components/Toast/index.d.ts.map +1 -0
- package/dist/widget/ui/src/components/index.d.ts +1 -0
- package/dist/widget/ui/src/components/index.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/components/Alert/Alert.styles.ts +5 -0
- package/src/components/Toast/Toast.Provider.tsx +87 -0
- package/src/components/Toast/Toast.helpers.ts +7 -0
- package/src/components/Toast/Toast.stories.tsx +71 -0
- package/src/components/Toast/Toast.styles.ts +113 -0
- package/src/components/Toast/Toast.tsx +59 -0
- package/src/components/Toast/Toast.types.ts +31 -0
- package/src/components/Toast/index.ts +2 -0
- package/src/components/index.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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;+DAa3B,CAAC;AAEH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;+DAI9B,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { Type } from '../Alert/Alert.types';
|
|
3
|
+
import type { CSSProperties } from '@stitches/react';
|
|
4
|
+
export interface ProviderPropTypes {
|
|
5
|
+
container: HTMLElement;
|
|
6
|
+
anchorOrigin?: {
|
|
7
|
+
horizontal: 'left' | 'right';
|
|
8
|
+
vertical: 'bottom' | 'top';
|
|
9
|
+
};
|
|
10
|
+
containerStyle?: CSSProperties;
|
|
11
|
+
}
|
|
12
|
+
export type ToastType = {
|
|
13
|
+
autoHideDuration?: number;
|
|
14
|
+
id?: number | string;
|
|
15
|
+
} & ({
|
|
16
|
+
title: string;
|
|
17
|
+
type: Type;
|
|
18
|
+
titleColor?: string;
|
|
19
|
+
style?: CSSProperties;
|
|
20
|
+
} | {
|
|
21
|
+
component: React.ReactNode;
|
|
22
|
+
});
|
|
23
|
+
export type ToastProps = ToastType & {
|
|
24
|
+
id: number | string;
|
|
25
|
+
horizontal: 'left' | 'right';
|
|
26
|
+
};
|
|
27
|
+
export type ProviderContext = {
|
|
28
|
+
addToast: (content: ToastType) => void;
|
|
29
|
+
removeToast: (id: number | string) => void;
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=Toast.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Toast.types.d.ts","sourceRoot":"","sources":["../../../../../../src/components/Toast/Toast.types.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErD,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,WAAW,CAAC;IACvB,YAAY,CAAC,EAAE;QACb,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC;QAC7B,QAAQ,EAAE,QAAQ,GAAG,KAAK,CAAC;KAC5B,CAAC;IACF,cAAc,CAAC,EAAE,aAAa,CAAC;CAChC;AAED,MAAM,MAAM,SAAS,GAAG;IAAE,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAAC,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,GAAG,CAC1E;IACE,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,IAAI,CAAC;IACX,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,aAAa,CAAC;CACvB,GACD;IAAE,SAAS,EAAE,KAAK,CAAC,SAAS,CAAA;CAAE,CACjC,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG;IACnC,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC;CAC9B,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,EAAE,CAAC,OAAO,EAAE,SAAS,KAAK,IAAI,CAAC;IACvC,WAAW,EAAE,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,KAAK,IAAI,CAAC;CAC5C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/components/Toast/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -29,6 +29,7 @@ export * from './SwapListItem';
|
|
|
29
29
|
export * from './SwapDetailsPlaceholder';
|
|
30
30
|
export * from './Switch';
|
|
31
31
|
export * from './TextField';
|
|
32
|
+
export * from './Toast';
|
|
32
33
|
export * from './TokenList';
|
|
33
34
|
export * from './TokenPreview';
|
|
34
35
|
export * from './Tooltip';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC;AACxB,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,wBAAwB,CAAC;AACvC,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC;AACvC,cAAc,UAAU,CAAC;AACzB,cAAc,0BAA0B,CAAC;AACzC,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,0BAA0B,CAAC;AACzC,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc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CAAC;AACzC,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ProviderContext,
|
|
3
|
+
ProviderPropTypes,
|
|
4
|
+
ToastProps,
|
|
5
|
+
ToastType,
|
|
6
|
+
} from './Toast.types';
|
|
7
|
+
import type { PropsWithChildren } from 'react';
|
|
8
|
+
|
|
9
|
+
import React, { createContext, useContext, useMemo, useState } from 'react';
|
|
10
|
+
import { createPortal } from 'react-dom';
|
|
11
|
+
|
|
12
|
+
import { Toast } from './Toast';
|
|
13
|
+
import { idGenerator } from './Toast.helpers';
|
|
14
|
+
import { ToastContainer } from './Toast.styles';
|
|
15
|
+
|
|
16
|
+
const ToastContext = createContext<ProviderContext | undefined>(undefined);
|
|
17
|
+
|
|
18
|
+
export const ToastProvider = (props: PropsWithChildren<ProviderPropTypes>) => {
|
|
19
|
+
const generateId = useMemo(() => idGenerator(), []);
|
|
20
|
+
|
|
21
|
+
const {
|
|
22
|
+
children,
|
|
23
|
+
anchorOrigin = {
|
|
24
|
+
horizontal: 'right',
|
|
25
|
+
vertical: 'bottom',
|
|
26
|
+
},
|
|
27
|
+
container,
|
|
28
|
+
containerStyle = {},
|
|
29
|
+
} = props;
|
|
30
|
+
const [toasts, setToasts] = useState<ToastProps[]>([]);
|
|
31
|
+
|
|
32
|
+
// eslint-disable-next-line react/jsx-no-constructed-context-values
|
|
33
|
+
const api: ProviderContext = {
|
|
34
|
+
addToast(content: ToastType) {
|
|
35
|
+
setToasts((toasts) => {
|
|
36
|
+
const isToastExistById = toasts.find(
|
|
37
|
+
(toast) => toast.id === content.id
|
|
38
|
+
);
|
|
39
|
+
if (isToastExistById) {
|
|
40
|
+
console.warn(
|
|
41
|
+
'Trying to send a toast with an existing ID. Please update the toast ID or use it after the toast is hidden'
|
|
42
|
+
);
|
|
43
|
+
return toasts;
|
|
44
|
+
}
|
|
45
|
+
return [
|
|
46
|
+
...toasts,
|
|
47
|
+
{
|
|
48
|
+
...content,
|
|
49
|
+
id: content.id || generateId(),
|
|
50
|
+
horizontal: anchorOrigin.horizontal,
|
|
51
|
+
},
|
|
52
|
+
];
|
|
53
|
+
});
|
|
54
|
+
},
|
|
55
|
+
removeToast(id: number | string) {
|
|
56
|
+
setToasts((toasts) => toasts.filter((t) => t.id !== id));
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
return (
|
|
61
|
+
<ToastContext.Provider value={api}>
|
|
62
|
+
{children}
|
|
63
|
+
{container &&
|
|
64
|
+
createPortal(
|
|
65
|
+
<ToastContainer
|
|
66
|
+
style={containerStyle}
|
|
67
|
+
horizontal={anchorOrigin.horizontal}
|
|
68
|
+
vertical={anchorOrigin.vertical}>
|
|
69
|
+
{toasts.map((toast) => (
|
|
70
|
+
<Toast {...toast} key={toast.id} />
|
|
71
|
+
))}
|
|
72
|
+
</ToastContainer>,
|
|
73
|
+
container
|
|
74
|
+
)}
|
|
75
|
+
</ToastContext.Provider>
|
|
76
|
+
);
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export function useToast(): ProviderContext {
|
|
80
|
+
const context = useContext(ToastContext);
|
|
81
|
+
if (!context) {
|
|
82
|
+
throw new Error(
|
|
83
|
+
'useToast can only be used within the ToastProvider component'
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
return context;
|
|
87
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { ToastProps } from './Toast.types';
|
|
2
|
+
import type { Meta } from '@storybook/react';
|
|
3
|
+
|
|
4
|
+
import React from 'react';
|
|
5
|
+
|
|
6
|
+
import { Button } from '../Button';
|
|
7
|
+
|
|
8
|
+
import { ToastStoryContainer } from './Toast.styles';
|
|
9
|
+
|
|
10
|
+
import { Toast, ToastProvider, useToast } from '.';
|
|
11
|
+
|
|
12
|
+
export default {
|
|
13
|
+
title: 'Components/Toast',
|
|
14
|
+
component: Toast,
|
|
15
|
+
args: {
|
|
16
|
+
type: 'success',
|
|
17
|
+
title: 'Please change your wallet network to Polygon',
|
|
18
|
+
autoHideDuration: 5_000,
|
|
19
|
+
horizontal: 'right',
|
|
20
|
+
},
|
|
21
|
+
argTypes: {
|
|
22
|
+
type: {
|
|
23
|
+
name: 'type',
|
|
24
|
+
control: {
|
|
25
|
+
type: 'select',
|
|
26
|
+
options: ['success', 'warning', 'error', 'info', 'loading'],
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
} as Meta<typeof Toast>;
|
|
31
|
+
|
|
32
|
+
export const TopToasts = (props: ToastProps) => {
|
|
33
|
+
return (
|
|
34
|
+
<ToastProvider
|
|
35
|
+
container={document.body}
|
|
36
|
+
anchorOrigin={{
|
|
37
|
+
horizontal: props.horizontal,
|
|
38
|
+
vertical: 'top',
|
|
39
|
+
}}>
|
|
40
|
+
<ToastComponent {...props} />
|
|
41
|
+
</ToastProvider>
|
|
42
|
+
);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const BottomToasts = (props: ToastProps) => {
|
|
46
|
+
return (
|
|
47
|
+
<ToastProvider
|
|
48
|
+
container={document.body}
|
|
49
|
+
anchorOrigin={{
|
|
50
|
+
horizontal: props.horizontal,
|
|
51
|
+
vertical: 'bottom',
|
|
52
|
+
}}>
|
|
53
|
+
<ToastComponent {...props} />
|
|
54
|
+
</ToastProvider>
|
|
55
|
+
);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const ToastComponent = (props: ToastProps) => {
|
|
59
|
+
const { addToast } = useToast();
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<ToastStoryContainer>
|
|
63
|
+
<Button
|
|
64
|
+
variant="contained"
|
|
65
|
+
type="success"
|
|
66
|
+
onClick={() => addToast(props)}>
|
|
67
|
+
Show Toast
|
|
68
|
+
</Button>
|
|
69
|
+
</ToastStoryContainer>
|
|
70
|
+
);
|
|
71
|
+
};
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { darkTheme, keyframes, lightTheme, styled } from '../../theme';
|
|
2
|
+
import { Typography } from '../Typography';
|
|
3
|
+
|
|
4
|
+
const toastOpacity = keyframes({
|
|
5
|
+
from: { opacity: 0 },
|
|
6
|
+
to: { opacity: 1 },
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
export const ToastContentContainer = styled('div', {
|
|
10
|
+
variants: {
|
|
11
|
+
horizontal: {
|
|
12
|
+
right: {
|
|
13
|
+
right: 12,
|
|
14
|
+
animation: `${toastOpacity} .7s`,
|
|
15
|
+
},
|
|
16
|
+
left: {
|
|
17
|
+
left: 12,
|
|
18
|
+
animation: `${toastOpacity} .7s`,
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export const ToastContainer = styled('div', {
|
|
25
|
+
position: 'absolute',
|
|
26
|
+
zIndex: 9999,
|
|
27
|
+
display: 'flex',
|
|
28
|
+
gap: '$4',
|
|
29
|
+
flexDirection: 'column',
|
|
30
|
+
variants: {
|
|
31
|
+
horizontal: {
|
|
32
|
+
right: {
|
|
33
|
+
right: 12,
|
|
34
|
+
},
|
|
35
|
+
left: {
|
|
36
|
+
left: 12,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
vertical: {
|
|
41
|
+
top: {
|
|
42
|
+
top: 2,
|
|
43
|
+
},
|
|
44
|
+
bottom: {
|
|
45
|
+
bottom: 2,
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
export const AlertBox = styled('div', {
|
|
52
|
+
display: 'flex',
|
|
53
|
+
borderRadius: '$sm',
|
|
54
|
+
width: '292px',
|
|
55
|
+
minHeight: '52px',
|
|
56
|
+
backgroundColor: '$background',
|
|
57
|
+
borderRight: '1px solid',
|
|
58
|
+
[`.${darkTheme} &`]: {
|
|
59
|
+
backgroundColor: '#070917',
|
|
60
|
+
},
|
|
61
|
+
'&:hover': {
|
|
62
|
+
backgroundColor: '$info100',
|
|
63
|
+
[`.${darkTheme} &`]: {
|
|
64
|
+
backgroundColor: '#111733',
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
variants: {
|
|
68
|
+
type: {
|
|
69
|
+
error: {
|
|
70
|
+
borderRightColor: '$error500',
|
|
71
|
+
},
|
|
72
|
+
success: {
|
|
73
|
+
borderRightColor: '$success500',
|
|
74
|
+
},
|
|
75
|
+
warning: {
|
|
76
|
+
borderRightColor: '$warning500',
|
|
77
|
+
},
|
|
78
|
+
info: {
|
|
79
|
+
borderRightColor: '$info500',
|
|
80
|
+
},
|
|
81
|
+
loading: {
|
|
82
|
+
borderRightColor: '$info500',
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
export const AlertFlexContainer = styled('div', {
|
|
89
|
+
display: 'flex',
|
|
90
|
+
padding: '$10',
|
|
91
|
+
alignItems: 'center',
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
export const StyledTypography = styled(Typography, {
|
|
95
|
+
variants: {
|
|
96
|
+
hasColor: {
|
|
97
|
+
false: {
|
|
98
|
+
[`.${lightTheme} &`]: {
|
|
99
|
+
color: '$neutral700',
|
|
100
|
+
},
|
|
101
|
+
[`.${darkTheme} &`]: {
|
|
102
|
+
color: '$neutral900',
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
export const ToastStoryContainer = styled('div', {
|
|
110
|
+
display: 'flex',
|
|
111
|
+
justifyContent: 'center',
|
|
112
|
+
alignItems: 'center',
|
|
113
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { ToastProps } from './Toast.types';
|
|
2
|
+
|
|
3
|
+
import React, { useEffect } from 'react';
|
|
4
|
+
|
|
5
|
+
import { IconHighlight } from '../Alert/Alert.styles';
|
|
6
|
+
import AlertIcon from '../Alert/AlertIcon';
|
|
7
|
+
import { Divider } from '../Divider';
|
|
8
|
+
|
|
9
|
+
import { useToast } from './Toast.Provider';
|
|
10
|
+
import {
|
|
11
|
+
AlertBox,
|
|
12
|
+
AlertFlexContainer,
|
|
13
|
+
StyledTypography,
|
|
14
|
+
ToastContentContainer,
|
|
15
|
+
} from './Toast.styles';
|
|
16
|
+
|
|
17
|
+
const DEFAULT_HIDE_DURATION = 3_000;
|
|
18
|
+
|
|
19
|
+
export const Toast = (props: ToastProps) => {
|
|
20
|
+
const { id, horizontal, autoHideDuration = DEFAULT_HIDE_DURATION } = props;
|
|
21
|
+
const { removeToast } = useToast();
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
const timer = setTimeout(() => {
|
|
24
|
+
removeToast(id);
|
|
25
|
+
}, autoHideDuration);
|
|
26
|
+
|
|
27
|
+
return () => {
|
|
28
|
+
clearTimeout(timer);
|
|
29
|
+
};
|
|
30
|
+
}, [id]);
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<ToastContentContainer horizontal={horizontal}>
|
|
34
|
+
{'component' in props ? (
|
|
35
|
+
props.component
|
|
36
|
+
) : (
|
|
37
|
+
<AlertBox
|
|
38
|
+
onClick={() => removeToast(id)}
|
|
39
|
+
type={props.type}
|
|
40
|
+
style={props.style}>
|
|
41
|
+
<AlertFlexContainer>
|
|
42
|
+
<IconHighlight type={props.type} align="center">
|
|
43
|
+
<AlertIcon type={props.type} />
|
|
44
|
+
</IconHighlight>
|
|
45
|
+
<Divider direction="horizontal" size={10} />
|
|
46
|
+
<StyledTypography
|
|
47
|
+
variant="body"
|
|
48
|
+
size="small"
|
|
49
|
+
color={props.titleColor}
|
|
50
|
+
hasColor={!!props.titleColor}
|
|
51
|
+
align="left">
|
|
52
|
+
{props.title}
|
|
53
|
+
</StyledTypography>
|
|
54
|
+
</AlertFlexContainer>
|
|
55
|
+
</AlertBox>
|
|
56
|
+
)}
|
|
57
|
+
</ToastContentContainer>
|
|
58
|
+
);
|
|
59
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Type } from '../Alert/Alert.types';
|
|
2
|
+
import type { CSSProperties } from '@stitches/react';
|
|
3
|
+
|
|
4
|
+
export interface ProviderPropTypes {
|
|
5
|
+
container: HTMLElement;
|
|
6
|
+
anchorOrigin?: {
|
|
7
|
+
horizontal: 'left' | 'right';
|
|
8
|
+
vertical: 'bottom' | 'top';
|
|
9
|
+
};
|
|
10
|
+
containerStyle?: CSSProperties;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type ToastType = { autoHideDuration?: number; id?: number | string } & (
|
|
14
|
+
| {
|
|
15
|
+
title: string;
|
|
16
|
+
type: Type;
|
|
17
|
+
titleColor?: string;
|
|
18
|
+
style?: CSSProperties;
|
|
19
|
+
}
|
|
20
|
+
| { component: React.ReactNode }
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
export type ToastProps = ToastType & {
|
|
24
|
+
id: number | string;
|
|
25
|
+
horizontal: 'left' | 'right';
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export type ProviderContext = {
|
|
29
|
+
addToast: (content: ToastType) => void;
|
|
30
|
+
removeToast: (id: number | string) => void;
|
|
31
|
+
};
|
package/src/components/index.ts
CHANGED
|
@@ -29,6 +29,7 @@ export * from './SwapListItem';
|
|
|
29
29
|
export * from './SwapDetailsPlaceholder';
|
|
30
30
|
export * from './Switch';
|
|
31
31
|
export * from './TextField';
|
|
32
|
+
export * from './Toast';
|
|
32
33
|
export * from './TokenList';
|
|
33
34
|
export * from './TokenPreview';
|
|
34
35
|
export * from './Tooltip';
|