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