ag-common 0.0.665 → 0.0.667
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/dist/ui/components/Modal/Modal.d.ts +1 -1
- package/dist/ui/components/Modal/Modal.js +16 -2
- package/dist/ui/components/Modal/types.d.ts +2 -0
- package/dist/ui/components/Toast/base.d.ts +5 -3
- package/dist/ui/components/Toast/base.js +44 -31
- package/dist/ui/components/Toast/types.d.ts +16 -4
- package/package.json +1 -1
|
@@ -4,4 +4,4 @@ export declare const ModalItem: import("@emotion/styled").StyledComponent<{
|
|
|
4
4
|
theme?: import("@emotion/react").Theme | undefined;
|
|
5
5
|
as?: React.ElementType<any, keyof React.JSX.IntrinsicElements> | undefined;
|
|
6
6
|
}, React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
|
|
7
|
-
export declare const Modal: ({ open, setOpen, children, position, topPosition, showCloseButton, closeOnMoveMouseOutside, className, closeOnClickOutside, }: IModal) => React.JSX.Element;
|
|
7
|
+
export declare const Modal: ({ open, setOpen, children, position, topPosition, showCloseButton, closeOnMoveMouseOutside, className, closeOnClickOutside, portalId, }: IModal) => React.JSX.Element | null;
|
|
@@ -30,6 +30,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
30
30
|
exports.Modal = exports.ModalItem = void 0;
|
|
31
31
|
const styled_1 = __importDefault(require("@emotion/styled"));
|
|
32
32
|
const react_1 = __importStar(require("react"));
|
|
33
|
+
const react_dom_1 = require("react-dom");
|
|
33
34
|
const useOnClickOutside_1 = require("../../helpers/useOnClickOutside");
|
|
34
35
|
const styles_1 = require("../../styles");
|
|
35
36
|
const Close_1 = require("../Close");
|
|
@@ -83,7 +84,8 @@ exports.ModalItem = styled_1.default.div `
|
|
|
83
84
|
const CloseStyled = (0, styled_1.default)(Close_1.Close) `
|
|
84
85
|
z-index: 1;
|
|
85
86
|
`;
|
|
86
|
-
const Modal = ({ open, setOpen, children, position = 'left', topPosition = 'top', showCloseButton = true, closeOnMoveMouseOutside = false, className, closeOnClickOutside = true, }) => {
|
|
87
|
+
const Modal = ({ open, setOpen, children, position = 'left', topPosition = 'top', showCloseButton = true, closeOnMoveMouseOutside = false, className, closeOnClickOutside = true, portalId, }) => {
|
|
88
|
+
const [elem, setElem] = (0, react_1.useState)();
|
|
87
89
|
(0, react_1.useEffect)(() => {
|
|
88
90
|
const originalStyle = window.getComputedStyle(document.body).overflow || '';
|
|
89
91
|
if (open) {
|
|
@@ -110,12 +112,24 @@ const Modal = ({ open, setOpen, children, position = 'left', topPosition = 'top'
|
|
|
110
112
|
setBounced(true);
|
|
111
113
|
}
|
|
112
114
|
}, [open, bounced]);
|
|
115
|
+
(0, react_1.useEffect)(() => {
|
|
116
|
+
if (elem === undefined && portalId) {
|
|
117
|
+
setElem(document.getElementById(portalId));
|
|
118
|
+
}
|
|
119
|
+
}, [elem, portalId]);
|
|
113
120
|
if (!open) {
|
|
114
121
|
return react_1.default.createElement(react_1.default.Fragment, null);
|
|
115
122
|
}
|
|
116
|
-
|
|
123
|
+
const Content = (react_1.default.createElement(FixedBackground, null,
|
|
117
124
|
react_1.default.createElement(ModalBase, { "data-bounced": bounced, "data-position": position, "data-topposition": topPosition, ref: ref, className: className },
|
|
118
125
|
showCloseButton && (react_1.default.createElement(CloseStyled, { "data-type": "modal-close", onClick: () => setOpen(false) })),
|
|
119
126
|
children)));
|
|
127
|
+
if (portalId && elem === undefined) {
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
if (portalId && elem) {
|
|
131
|
+
return (0, react_dom_1.createPortal)(Content, elem);
|
|
132
|
+
}
|
|
133
|
+
return Content;
|
|
120
134
|
};
|
|
121
135
|
exports.Modal = Modal;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type {
|
|
2
|
+
import type { IVarStyles } from '../../styles/common';
|
|
3
|
+
import type { IToastInt, IToastProviderOptions, TAddToast, TAddToastDetailed } from './types';
|
|
3
4
|
export declare const ToastContext: React.Context<{
|
|
4
5
|
addToast: TAddToast;
|
|
6
|
+
addToastDetailed: TAddToastDetailed;
|
|
5
7
|
}>;
|
|
6
|
-
export declare const Toast: ({ toast, close,
|
|
8
|
+
export declare const Toast: ({ toast, close, style, }: {
|
|
7
9
|
toast: IToastInt;
|
|
8
|
-
|
|
10
|
+
style: IVarStyles;
|
|
9
11
|
close: (s: string) => void;
|
|
10
12
|
}) => React.JSX.Element;
|
|
11
13
|
export declare const ToastProvider: ({ children, providerOptions, }: {
|
|
@@ -32,6 +32,9 @@ const styled_1 = __importDefault(require("@emotion/styled"));
|
|
|
32
32
|
const react_1 = __importStar(require("react"));
|
|
33
33
|
const random_1 = require("../../../common/helpers/random");
|
|
34
34
|
const Warning_1 = require("../../icons/Warning");
|
|
35
|
+
const common_1 = require("../../styles/common");
|
|
36
|
+
const FlexColumn_1 = require("../FlexColumn");
|
|
37
|
+
const FlexRow_1 = require("../FlexRow");
|
|
35
38
|
const ProgressBar_1 = require("../ProgressBar");
|
|
36
39
|
const Cross_1 = require("./Cross");
|
|
37
40
|
const Tick_1 = require("./Tick");
|
|
@@ -42,6 +45,11 @@ const ToastContainerStyle = styled_1.default.div `
|
|
|
42
45
|
right: 0;
|
|
43
46
|
margin: 0.5rem;
|
|
44
47
|
z-index: 10000;
|
|
48
|
+
|
|
49
|
+
display: flex;
|
|
50
|
+
flex-flow: column;
|
|
51
|
+
align-items: flex-end;
|
|
52
|
+
max-width: 50vw;
|
|
45
53
|
`;
|
|
46
54
|
const ToastStyle = styled_1.default.div `
|
|
47
55
|
display: flex;
|
|
@@ -49,19 +57,12 @@ const ToastStyle = styled_1.default.div `
|
|
|
49
57
|
align-items: center;
|
|
50
58
|
padding: 0.5rem;
|
|
51
59
|
position: relative;
|
|
52
|
-
color: white;
|
|
53
60
|
font-size: 1.2rem;
|
|
54
61
|
&:not(:last-of-type) {
|
|
55
62
|
margin-bottom: 8px;
|
|
56
63
|
}
|
|
57
64
|
|
|
58
65
|
border-radius: 6px;
|
|
59
|
-
background-color: rgba(0, 0, 0, 0.8);
|
|
60
|
-
color: white;
|
|
61
|
-
&[data-dark='false'] {
|
|
62
|
-
background-color: rgba(255, 255, 255, 0.8);
|
|
63
|
-
color: black;
|
|
64
|
-
}
|
|
65
66
|
`;
|
|
66
67
|
const CloseStyle = styled_1.default.span `
|
|
67
68
|
position: absolute;
|
|
@@ -77,15 +78,9 @@ const CloseStyle = styled_1.default.span `
|
|
|
77
78
|
justify-content: center;
|
|
78
79
|
align-items: center;
|
|
79
80
|
color: white;
|
|
81
|
+
z-index: 1;
|
|
80
82
|
&:hover {
|
|
81
|
-
background-color:
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
&[data-dark='false'] {
|
|
85
|
-
color: #000;
|
|
86
|
-
&:hover {
|
|
87
|
-
background-color: #eee;
|
|
88
|
-
}
|
|
83
|
+
background-color: var(--bg);
|
|
89
84
|
}
|
|
90
85
|
`;
|
|
91
86
|
const Icon = styled_1.default.div `
|
|
@@ -97,15 +92,14 @@ const ProgressBarStyled = (0, styled_1.default)(ProgressBar_1.ProgressBar) `
|
|
|
97
92
|
height: 0.75rem;
|
|
98
93
|
margin-top: 0.5rem;
|
|
99
94
|
`;
|
|
100
|
-
const Toast = ({ toast, close,
|
|
101
|
-
var _a, _b, _c, _d, _e
|
|
102
|
-
const darkMode = (_a = providerOptions === null || providerOptions === void 0 ? void 0 : providerOptions.darkMode) !== null && _a !== void 0 ? _a : false;
|
|
95
|
+
const Toast = ({ toast, close, style, }) => {
|
|
96
|
+
var _a, _b, _c, _d, _e;
|
|
103
97
|
let closeMs;
|
|
104
|
-
if ((
|
|
105
|
-
closeMs = (
|
|
98
|
+
if ((_a = toast.options) === null || _a === void 0 ? void 0 : _a.autoClose) {
|
|
99
|
+
closeMs = (_b = toast.options) === null || _b === void 0 ? void 0 : _b.autoClose;
|
|
106
100
|
}
|
|
107
|
-
else if (((
|
|
108
|
-
if (((
|
|
101
|
+
else if (((_c = toast.options) === null || _c === void 0 ? void 0 : _c.autoClose) === undefined) {
|
|
102
|
+
if (((_d = toast === null || toast === void 0 ? void 0 : toast.options) === null || _d === void 0 ? void 0 : _d.appearance) === 'success') {
|
|
109
103
|
closeMs = 5000;
|
|
110
104
|
}
|
|
111
105
|
else {
|
|
@@ -113,7 +107,7 @@ const Toast = ({ toast, close, providerOptions, }) => {
|
|
|
113
107
|
}
|
|
114
108
|
}
|
|
115
109
|
let icon = react_1.default.createElement(Tick_1.Tick, null);
|
|
116
|
-
switch ((
|
|
110
|
+
switch ((_e = toast === null || toast === void 0 ? void 0 : toast.options) === null || _e === void 0 ? void 0 : _e.appearance) {
|
|
117
111
|
case 'error': {
|
|
118
112
|
icon = react_1.default.createElement(Cross_1.Cross, null);
|
|
119
113
|
break;
|
|
@@ -131,24 +125,43 @@ const Toast = ({ toast, close, providerOptions, }) => {
|
|
|
131
125
|
return () => clearTimeout(timeout);
|
|
132
126
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
133
127
|
}, []);
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
react_1.default.createElement(
|
|
137
|
-
|
|
128
|
+
if (toast.type === 'standard') {
|
|
129
|
+
const st = { color: style.color, '--bg': style.borderColor };
|
|
130
|
+
return (react_1.default.createElement(ToastStyle, { style: style },
|
|
131
|
+
react_1.default.createElement(CloseStyle, { onClick: () => close(toast.id), style: st }, "\u00D7"),
|
|
132
|
+
react_1.default.createElement(Icon, { style: { fill: style.color } }, icon),
|
|
133
|
+
toast.message,
|
|
134
|
+
closeMs !== undefined && (react_1.default.createElement(ProgressBarStyled, { max: 100, min: 0, dotPercentages: null, transitionToMs: closeMs }))));
|
|
135
|
+
}
|
|
136
|
+
const st = { color: style.color, '--bg': style.borderColor };
|
|
137
|
+
return (react_1.default.createElement(ToastStyle, { style: style },
|
|
138
|
+
react_1.default.createElement(CloseStyle, { onClick: () => close(toast.id), style: st }, "\u00D7"),
|
|
139
|
+
react_1.default.createElement(FlexRow_1.FlexRow, { noWrap: true, center: true },
|
|
140
|
+
toast.icon === undefined && react_1.default.createElement(Icon, null, icon),
|
|
141
|
+
toast.icon,
|
|
142
|
+
react_1.default.createElement(FlexColumn_1.FlexColumn, { style: { marginLeft: toast.icon === null ? '0' : '0.5rem' } },
|
|
143
|
+
react_1.default.createElement("b", null, toast.title),
|
|
144
|
+
toast.content)),
|
|
138
145
|
closeMs !== undefined && (react_1.default.createElement(ProgressBarStyled, { max: 100, min: 0, dotPercentages: null, transitionToMs: closeMs }))));
|
|
139
146
|
};
|
|
140
147
|
exports.Toast = Toast;
|
|
141
148
|
const ToastProvider = ({ children, providerOptions, }) => {
|
|
142
149
|
const [toasts, setToasts] = (0, react_1.useState)([]);
|
|
143
150
|
const addToast = (message, options) => setToasts((currentToasts) => [
|
|
144
|
-
...currentToasts.filter((ct) => ct.
|
|
151
|
+
...currentToasts.filter((ct) => ct.type === 'detailed' ||
|
|
152
|
+
ct.message !== message ||
|
|
145
153
|
JSON.stringify(ct.options) !== JSON.stringify(options)),
|
|
146
|
-
{ id: (0, random_1.random)(10000).toString(), message, options },
|
|
154
|
+
{ id: (0, random_1.random)(10000).toString(), message, options, type: 'standard' },
|
|
155
|
+
]);
|
|
156
|
+
const addToastDetailed = (p, options) => setToasts((currentToasts) => [
|
|
157
|
+
...currentToasts,
|
|
158
|
+
Object.assign(Object.assign({ id: (0, random_1.random)(10000).toString() }, p), { options, type: 'detailed' }),
|
|
147
159
|
]);
|
|
148
160
|
const close = (id) => setToasts((currentToasts) => currentToasts.filter((toast) => toast.id !== id));
|
|
149
|
-
const contextValue = (0, react_1.useMemo)(() => ({ addToast }), []);
|
|
161
|
+
const contextValue = (0, react_1.useMemo)(() => ({ addToast, addToastDetailed }), []);
|
|
162
|
+
const style = (0, common_1.getVarStyles)(providerOptions === null || providerOptions === void 0 ? void 0 : providerOptions.style);
|
|
150
163
|
return (react_1.default.createElement(exports.ToastContext.Provider, { value: contextValue },
|
|
151
164
|
children,
|
|
152
|
-
react_1.default.createElement(ToastContainerStyle, null, toasts.map((toast) => (react_1.default.createElement(exports.Toast, { key: toast.id, toast: toast, close: close,
|
|
165
|
+
react_1.default.createElement(ToastContainerStyle, null, toasts.map((toast) => (react_1.default.createElement(exports.Toast, { key: toast.id, toast: toast, close: close, style: style }))))));
|
|
153
166
|
};
|
|
154
167
|
exports.ToastProvider = ToastProvider;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { IVarStyles } from '../../styles';
|
|
1
3
|
export type TToastAppearance = 'error' | 'warning' | 'success';
|
|
2
4
|
export type TToastOptions = {
|
|
3
5
|
appearance: TToastAppearance;
|
|
@@ -5,14 +7,24 @@ export type TToastOptions = {
|
|
|
5
7
|
autoClose?: number | null;
|
|
6
8
|
} | undefined;
|
|
7
9
|
export type TAddToast = (m: string, options?: TToastOptions) => void;
|
|
10
|
+
export type TAddToastDetailed = (p: Omit<IToastDetailed, 'id' | 'type' | 'options'>, options?: TToastOptions) => void;
|
|
8
11
|
export interface IToastProviderOptions {
|
|
9
|
-
|
|
10
|
-
darkMode?: boolean;
|
|
12
|
+
style?: Partial<IVarStyles>;
|
|
11
13
|
}
|
|
12
|
-
|
|
14
|
+
interface IToastStandard {
|
|
15
|
+
type: 'standard';
|
|
13
16
|
message: string;
|
|
14
17
|
options?: TToastOptions;
|
|
18
|
+
id: string;
|
|
15
19
|
}
|
|
16
|
-
|
|
20
|
+
interface IToastDetailed {
|
|
21
|
+
type: 'detailed';
|
|
22
|
+
title?: string;
|
|
23
|
+
content: JSX.Element;
|
|
17
24
|
id: string;
|
|
25
|
+
options?: TToastOptions;
|
|
26
|
+
/** if provided will show. undef will show default icon. null wont show */
|
|
27
|
+
icon?: JSX.Element | null;
|
|
18
28
|
}
|
|
29
|
+
export type IToastInt = IToastStandard | IToastDetailed;
|
|
30
|
+
export {};
|
package/package.json
CHANGED