@dt-dds/react-toast 1.0.0-beta.100
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 +896 -0
- package/LICENSE.md +21 -0
- package/README.md +218 -0
- package/dist/index.d.mts +50 -0
- package/dist/index.d.ts +50 -0
- package/dist/index.js +401 -0
- package/dist/index.mjs +391 -0
- package/package.json +59 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __defProps = Object.defineProperties;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
10
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
+
var __spreadValues = (a, b) => {
|
|
14
|
+
for (var prop in b || (b = {}))
|
|
15
|
+
if (__hasOwnProp.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
if (__getOwnPropSymbols)
|
|
18
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
19
|
+
if (__propIsEnum.call(b, prop))
|
|
20
|
+
__defNormalProp(a, prop, b[prop]);
|
|
21
|
+
}
|
|
22
|
+
return a;
|
|
23
|
+
};
|
|
24
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
+
var __objRest = (source, exclude) => {
|
|
26
|
+
var target = {};
|
|
27
|
+
for (var prop in source)
|
|
28
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
29
|
+
target[prop] = source[prop];
|
|
30
|
+
if (source != null && __getOwnPropSymbols)
|
|
31
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
32
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
33
|
+
target[prop] = source[prop];
|
|
34
|
+
}
|
|
35
|
+
return target;
|
|
36
|
+
};
|
|
37
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
38
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
39
|
+
};
|
|
40
|
+
var __export = (target, all) => {
|
|
41
|
+
for (var name in all)
|
|
42
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
43
|
+
};
|
|
44
|
+
var __copyProps = (to, from, except, desc) => {
|
|
45
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
46
|
+
for (let key of __getOwnPropNames(from))
|
|
47
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
48
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
49
|
+
}
|
|
50
|
+
return to;
|
|
51
|
+
};
|
|
52
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
53
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
54
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
55
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
56
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
57
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
58
|
+
mod
|
|
59
|
+
));
|
|
60
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
61
|
+
|
|
62
|
+
// ../box/dist/index.js
|
|
63
|
+
var require_dist = __commonJS({
|
|
64
|
+
"../box/dist/index.js"(exports2, module2) {
|
|
65
|
+
"use strict";
|
|
66
|
+
var __create2 = Object.create;
|
|
67
|
+
var __defProp2 = Object.defineProperty;
|
|
68
|
+
var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
|
|
69
|
+
var __getOwnPropNames2 = Object.getOwnPropertyNames;
|
|
70
|
+
var __getProtoOf2 = Object.getPrototypeOf;
|
|
71
|
+
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
72
|
+
var __export2 = (target, all) => {
|
|
73
|
+
for (var name in all)
|
|
74
|
+
__defProp2(target, name, { get: all[name], enumerable: true });
|
|
75
|
+
};
|
|
76
|
+
var __copyProps2 = (to, from, except, desc) => {
|
|
77
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
78
|
+
for (let key of __getOwnPropNames2(from))
|
|
79
|
+
if (!__hasOwnProp2.call(to, key) && key !== except)
|
|
80
|
+
__defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
|
|
81
|
+
}
|
|
82
|
+
return to;
|
|
83
|
+
};
|
|
84
|
+
var __toESM2 = (mod, isNodeMode, target) => (target = mod != null ? __create2(__getProtoOf2(mod)) : {}, __copyProps2(
|
|
85
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
86
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
87
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
88
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
89
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp2(target, "default", { value: mod, enumerable: true }) : target,
|
|
90
|
+
mod
|
|
91
|
+
));
|
|
92
|
+
var __toCommonJS2 = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
|
|
93
|
+
var index_exports2 = {};
|
|
94
|
+
__export2(index_exports2, {
|
|
95
|
+
Box: () => Box2
|
|
96
|
+
});
|
|
97
|
+
module2.exports = __toCommonJS2(index_exports2);
|
|
98
|
+
var import_styled2 = __toESM2(require("@emotion/styled"));
|
|
99
|
+
var BoxStyled = import_styled2.default.div`
|
|
100
|
+
display: flex;
|
|
101
|
+
flex-direction: column;
|
|
102
|
+
align-items: center;
|
|
103
|
+
`;
|
|
104
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
105
|
+
var Box2 = ({
|
|
106
|
+
dataTestId,
|
|
107
|
+
children,
|
|
108
|
+
element = "div",
|
|
109
|
+
style
|
|
110
|
+
}) => {
|
|
111
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(BoxStyled, { as: element, "data-testid": dataTestId, style, children });
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
// index.ts
|
|
117
|
+
var index_exports = {};
|
|
118
|
+
__export(index_exports, {
|
|
119
|
+
Toast: () => Toast_default,
|
|
120
|
+
ToastPosition: () => ToastPosition,
|
|
121
|
+
ToastType: () => ToastType,
|
|
122
|
+
Toaster: () => Toaster_default,
|
|
123
|
+
dismissToast: () => dismissToast,
|
|
124
|
+
emitToast: () => emitToast
|
|
125
|
+
});
|
|
126
|
+
module.exports = __toCommonJS(index_exports);
|
|
127
|
+
|
|
128
|
+
// src/Toast.tsx
|
|
129
|
+
var import_react_box = __toESM(require_dist());
|
|
130
|
+
var import_react_icon = require("@dt-dds/react-icon");
|
|
131
|
+
var import_react_typography = require("@dt-dds/react-typography");
|
|
132
|
+
var import_react2 = require("@emotion/react");
|
|
133
|
+
|
|
134
|
+
// src/constants/enums.ts
|
|
135
|
+
var ToastPosition = /* @__PURE__ */ ((ToastPosition2) => {
|
|
136
|
+
ToastPosition2["TopLeft"] = "top-left";
|
|
137
|
+
ToastPosition2["TopCenter"] = "top-center";
|
|
138
|
+
ToastPosition2["TopRight"] = "top-right";
|
|
139
|
+
ToastPosition2["BottomLeft"] = "bottom-left";
|
|
140
|
+
ToastPosition2["BottomCenter"] = "bottom-center";
|
|
141
|
+
ToastPosition2["BottomRight"] = "bottom-right";
|
|
142
|
+
return ToastPosition2;
|
|
143
|
+
})(ToastPosition || {});
|
|
144
|
+
var ToastType = /* @__PURE__ */ ((ToastType2) => {
|
|
145
|
+
ToastType2["Success"] = "success";
|
|
146
|
+
ToastType2["Error"] = "error";
|
|
147
|
+
ToastType2["Info"] = "informative";
|
|
148
|
+
ToastType2["Warning"] = "warning";
|
|
149
|
+
return ToastType2;
|
|
150
|
+
})(ToastType || {});
|
|
151
|
+
|
|
152
|
+
// src/Toast.styled.ts
|
|
153
|
+
var import_react = require("@emotion/react");
|
|
154
|
+
var import_styled = __toESM(require("@emotion/styled"));
|
|
155
|
+
var fadeIn = import_react.keyframes`
|
|
156
|
+
from { opacity: 0; }
|
|
157
|
+
to { opacity: 1; }
|
|
158
|
+
`;
|
|
159
|
+
var ToastStyled = import_styled.default.div`
|
|
160
|
+
display: flex;
|
|
161
|
+
flex-direction: column;
|
|
162
|
+
width: 360px;
|
|
163
|
+
animation: ${fadeIn} 0.75s ease-in;
|
|
164
|
+
transition: all 0.75s ease-in-out;
|
|
165
|
+
overflow: hidden;
|
|
166
|
+
${({ theme, isVisible, type }) => `
|
|
167
|
+
border: 1px solid ${theme.palette[type].default};
|
|
168
|
+
border-left: 6px solid ${theme.palette[type].default};
|
|
169
|
+
background-color: ${theme.palette[type].light};
|
|
170
|
+
opacity: ${isVisible ? 1 : 0};
|
|
171
|
+
border-radius: ${theme.shape.toast};
|
|
172
|
+
padding: ${theme.spacing.spacing_50} ${theme.spacing.spacing_50} ${theme.spacing.spacing_50} ${theme.spacing.spacing_30};
|
|
173
|
+
`}
|
|
174
|
+
`;
|
|
175
|
+
var ToastMessageStyled = import_styled.default.div`
|
|
176
|
+
${({ theme, type }) => `
|
|
177
|
+
${theme.fontStyles.bodyMdRegular};
|
|
178
|
+
color: ${theme.palette[type].dark};
|
|
179
|
+
overflow: hidden;
|
|
180
|
+
word-break: break-word;
|
|
181
|
+
hyphens: auto;
|
|
182
|
+
display: -webkit-box;
|
|
183
|
+
-webkit-line-clamp: 6;
|
|
184
|
+
-webkit-box-orient: vertical;
|
|
185
|
+
margin-inline: calc(24px + ${theme.spacing.spacing_30})
|
|
186
|
+
`}
|
|
187
|
+
`;
|
|
188
|
+
var ToastButtonCloseStyled = import_styled.default.button`
|
|
189
|
+
${({ theme, toastType }) => `
|
|
190
|
+
color: ${theme.palette[toastType].dark};
|
|
191
|
+
border: 0;
|
|
192
|
+
cursor: pointer;
|
|
193
|
+
background: transparent;
|
|
194
|
+
align-self: flex-start;
|
|
195
|
+
margin-left: auto;
|
|
196
|
+
font-size: 0;
|
|
197
|
+
line-height: 0;
|
|
198
|
+
|
|
199
|
+
&:focus-visible {
|
|
200
|
+
outline: 2px solid ${theme.palette.primary.default};
|
|
201
|
+
outline-offset: 1px;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
&:hover {
|
|
205
|
+
background-color: ${theme.palette[toastType].medium};
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
`}
|
|
209
|
+
`;
|
|
210
|
+
var ActionsContainer = import_styled.default.div`
|
|
211
|
+
${({ theme, type }) => `
|
|
212
|
+
display: flex;
|
|
213
|
+
flex-direction: row;
|
|
214
|
+
justify-content: flex-end;
|
|
215
|
+
gap: ${theme.spacing.spacing_20};
|
|
216
|
+
margin-top: ${theme.spacing.spacing_30};
|
|
217
|
+
|
|
218
|
+
button {
|
|
219
|
+
color: ${theme.palette[type].dark};
|
|
220
|
+
|
|
221
|
+
&:hover {
|
|
222
|
+
background-color: ${theme.palette[type].medium};
|
|
223
|
+
color: ${theme.palette[type].dark};
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
`}
|
|
227
|
+
`;
|
|
228
|
+
|
|
229
|
+
// src/Toast.tsx
|
|
230
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
231
|
+
var ToastIcons = {
|
|
232
|
+
["success" /* Success */]: "check_circle",
|
|
233
|
+
["error" /* Error */]: "error",
|
|
234
|
+
["informative" /* Info */]: "info",
|
|
235
|
+
["warning" /* Warning */]: "warning"
|
|
236
|
+
};
|
|
237
|
+
var Toast = ({
|
|
238
|
+
id,
|
|
239
|
+
dataTestId,
|
|
240
|
+
title,
|
|
241
|
+
message,
|
|
242
|
+
onClose,
|
|
243
|
+
type,
|
|
244
|
+
isVisible = true,
|
|
245
|
+
dismissible = true,
|
|
246
|
+
children
|
|
247
|
+
}) => {
|
|
248
|
+
const dataTest = dataTestId != null ? dataTestId : `toast-${id}`;
|
|
249
|
+
const theme = (0, import_react2.useTheme)();
|
|
250
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
251
|
+
ToastStyled,
|
|
252
|
+
{
|
|
253
|
+
"data-testid": dataTest,
|
|
254
|
+
isVisible,
|
|
255
|
+
type,
|
|
256
|
+
children: [
|
|
257
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
258
|
+
import_react_box.Box,
|
|
259
|
+
{
|
|
260
|
+
style: {
|
|
261
|
+
alignSelf: "start",
|
|
262
|
+
flexDirection: "row",
|
|
263
|
+
width: "100%",
|
|
264
|
+
gap: theme.spacing.spacing_30
|
|
265
|
+
},
|
|
266
|
+
children: [
|
|
267
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_icon.Icon, { code: ToastIcons[type], color: theme.palette[type].dark }),
|
|
268
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
269
|
+
import_react_typography.Typography,
|
|
270
|
+
{
|
|
271
|
+
color: `${type}.dark`,
|
|
272
|
+
element: "span",
|
|
273
|
+
fontStyles: "bodyLgBold",
|
|
274
|
+
children: title
|
|
275
|
+
}
|
|
276
|
+
),
|
|
277
|
+
dismissible ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
278
|
+
ToastButtonCloseStyled,
|
|
279
|
+
{
|
|
280
|
+
"data-testId": "close-button",
|
|
281
|
+
onClick: onClose,
|
|
282
|
+
toastType: type,
|
|
283
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_icon.Icon, { code: "close", color: theme.palette[type].dark })
|
|
284
|
+
}
|
|
285
|
+
) : null
|
|
286
|
+
]
|
|
287
|
+
}
|
|
288
|
+
),
|
|
289
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(ToastMessageStyled, { type, children: message }),
|
|
290
|
+
Boolean(children) ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ActionsContainer, { type, children }) : null
|
|
291
|
+
]
|
|
292
|
+
},
|
|
293
|
+
id
|
|
294
|
+
);
|
|
295
|
+
};
|
|
296
|
+
var Toast_default = Toast;
|
|
297
|
+
|
|
298
|
+
// src/Toaster.tsx
|
|
299
|
+
var import_react_button = require("@dt-dds/react-button");
|
|
300
|
+
var import_react_core = require("@dt-dds/react-core");
|
|
301
|
+
var import_react3 = require("@emotion/react");
|
|
302
|
+
var import_react4 = __toESM(require("react"));
|
|
303
|
+
var import_react_hot_toast = require("react-hot-toast");
|
|
304
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
305
|
+
var TOAST_DEFAULT_DURATION = 4e3;
|
|
306
|
+
var TOAST_ERROR_DURATION = Infinity;
|
|
307
|
+
var smallPosition = "bottom-center" /* BottomCenter */;
|
|
308
|
+
var defaultPosition = "bottom-right" /* BottomRight */;
|
|
309
|
+
var dismissToast = (id) => {
|
|
310
|
+
import_react_hot_toast.toast.dismiss(id);
|
|
311
|
+
};
|
|
312
|
+
var processChildren = (children) => {
|
|
313
|
+
return import_react4.default.Children.map(children, (child) => {
|
|
314
|
+
if (!import_react4.default.isValidElement(child)) {
|
|
315
|
+
return child;
|
|
316
|
+
}
|
|
317
|
+
if (child.type === import_react_button.Button) {
|
|
318
|
+
return import_react4.default.cloneElement(child, __spreadProps(__spreadValues({}, child.props), {
|
|
319
|
+
size: "small",
|
|
320
|
+
variant: "text"
|
|
321
|
+
}));
|
|
322
|
+
}
|
|
323
|
+
if (child.props.children) {
|
|
324
|
+
return import_react4.default.cloneElement(
|
|
325
|
+
child,
|
|
326
|
+
__spreadValues({}, child.props),
|
|
327
|
+
processChildren(child.props.children)
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
return child;
|
|
331
|
+
});
|
|
332
|
+
};
|
|
333
|
+
var emitToast = (_a) => {
|
|
334
|
+
var _b = _a, {
|
|
335
|
+
type,
|
|
336
|
+
title,
|
|
337
|
+
message,
|
|
338
|
+
children,
|
|
339
|
+
dismissible
|
|
340
|
+
} = _b, props = __objRest(_b, [
|
|
341
|
+
"type",
|
|
342
|
+
"title",
|
|
343
|
+
"message",
|
|
344
|
+
"children",
|
|
345
|
+
"dismissible"
|
|
346
|
+
]);
|
|
347
|
+
const duration = type === "error" /* Error */ ? TOAST_ERROR_DURATION : TOAST_DEFAULT_DURATION;
|
|
348
|
+
import_react_hot_toast.toast.custom(
|
|
349
|
+
(t) => {
|
|
350
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
351
|
+
Toast_default,
|
|
352
|
+
{
|
|
353
|
+
dismissible,
|
|
354
|
+
id: t.id,
|
|
355
|
+
isVisible: t.visible,
|
|
356
|
+
message,
|
|
357
|
+
onClose: () => import_react_hot_toast.toast.dismiss(t.id),
|
|
358
|
+
title,
|
|
359
|
+
type,
|
|
360
|
+
children: processChildren(children)
|
|
361
|
+
}
|
|
362
|
+
);
|
|
363
|
+
},
|
|
364
|
+
__spreadValues({
|
|
365
|
+
duration
|
|
366
|
+
}, props)
|
|
367
|
+
);
|
|
368
|
+
};
|
|
369
|
+
var Toaster = (_a) => {
|
|
370
|
+
var _b = _a, { gutter = 8 } = _b, props = __objRest(_b, ["gutter"]);
|
|
371
|
+
const theme = (0, import_react3.useTheme)();
|
|
372
|
+
const small = (0, import_react_core.useMedia)(`(max-width: ${theme.breakpoints.mq2}px)`);
|
|
373
|
+
const position = small ? smallPosition : defaultPosition;
|
|
374
|
+
const margin = small ? 8 : 16;
|
|
375
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
376
|
+
import_react_hot_toast.Toaster,
|
|
377
|
+
__spreadProps(__spreadValues({
|
|
378
|
+
gutter,
|
|
379
|
+
position
|
|
380
|
+
}, props), {
|
|
381
|
+
containerStyle: __spreadProps(__spreadValues({
|
|
382
|
+
bottom: 16,
|
|
383
|
+
right: margin,
|
|
384
|
+
top: margin,
|
|
385
|
+
left: margin
|
|
386
|
+
}, props.containerStyle), {
|
|
387
|
+
zIndex: import_react_core.TOAST_Z_INDEX
|
|
388
|
+
})
|
|
389
|
+
})
|
|
390
|
+
);
|
|
391
|
+
};
|
|
392
|
+
var Toaster_default = Toaster;
|
|
393
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
394
|
+
0 && (module.exports = {
|
|
395
|
+
Toast,
|
|
396
|
+
ToastPosition,
|
|
397
|
+
ToastType,
|
|
398
|
+
Toaster,
|
|
399
|
+
dismissToast,
|
|
400
|
+
emitToast
|
|
401
|
+
});
|