@dt-dds/react-toast 1.0.0-beta.72 → 1.0.0-beta.74
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 +16 -0
- package/README.md +15 -9
- package/dist/index.d.mts +5 -14
- package/dist/index.d.ts +5 -14
- package/dist/index.js +43 -47
- package/dist/index.mjs +41 -45
- package/package.json +2 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @dt-ui/react-toast
|
|
2
2
|
|
|
3
|
+
## 1.0.0-beta.74
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- @dt-dds/react-button@1.0.0-beta.57
|
|
8
|
+
|
|
9
|
+
## 1.0.0-beta.73
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- feat: pass children instead of actions
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- @dt-dds/react-button@1.0.0-beta.56
|
|
18
|
+
|
|
3
19
|
## 1.0.0-beta.72
|
|
4
20
|
|
|
5
21
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -12,6 +12,12 @@ const notify = () =>
|
|
|
12
12
|
title: 'success',
|
|
13
13
|
message: 'myMEssage' + count,
|
|
14
14
|
type: ToastType.Success,
|
|
15
|
+
children: (
|
|
16
|
+
<Tooltip>
|
|
17
|
+
<Button onClick={() => console.log('clicked')}>Action 2</Button>
|
|
18
|
+
<Tooltip.Content>Some tooltip</Tooltip.Content>
|
|
19
|
+
</Tooltip>
|
|
20
|
+
),
|
|
15
21
|
});
|
|
16
22
|
|
|
17
23
|
const App = () => {
|
|
@@ -116,14 +122,14 @@ const MyComponent = () => {
|
|
|
116
122
|
|
|
117
123
|
### Toaster
|
|
118
124
|
|
|
119
|
-
| Property | Type
|
|
120
|
-
| -------------------- |
|
|
121
|
-
| `toastOptions` | `DefaultToastOptions`
|
|
122
|
-
| `reverseOrder` | `boolean`
|
|
123
|
-
| `gutter` | `number`
|
|
124
|
-
| `containerStyle` | `React.CSSProperties`
|
|
125
|
-
| `containerClassName` | `string`
|
|
126
|
-
| `
|
|
125
|
+
| Property | Type | Default | Description |
|
|
126
|
+
| -------------------- | :------------------------------ | :-------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
127
|
+
| `toastOptions` | `DefaultToastOptions` | - | These will act as default options for all toasts. See the documentation [here](https://react-hot-toast.com/docs/toast). |
|
|
128
|
+
| `reverseOrder` | `boolean` | - | Toasts spawn at top by default. Set to true if you want new toasts at the end. |
|
|
129
|
+
| `gutter` | `number` | 8 | Changes the gap between each toast. |
|
|
130
|
+
| `containerStyle` | `React.CSSProperties` | - | Customize the style of toaster div. This can be used to change the offset of all toasts |
|
|
131
|
+
| `containerClassName` | `string` | undefined | Add a custom CSS class name to toaster div. |
|
|
132
|
+
| `children` | `(toast: Toast) => JSX.Element` | - | You can customize how each toast is displayed by passing your own render function to the Toaster as its children. This function will be called for every toast, allowing you to render any component based on the toast’s state. Note: If the rendered component is a button, its styles will be overridden by the default styles. |
|
|
127
133
|
|
|
128
134
|
### emitToast
|
|
129
135
|
|
|
@@ -133,7 +139,7 @@ const MyComponent = () => {
|
|
|
133
139
|
| `title` | `string` | - | The title to be displayed |
|
|
134
140
|
| `message` | `string` | - | The message to be displayed |
|
|
135
141
|
| `dismissable` | `boolean` | true | Sets the visibility of a close button that will fire the onClose callback |
|
|
136
|
-
| `
|
|
142
|
+
| `children` | `ReactNode` | - | A child that will be rendered at the end of the content section |
|
|
137
143
|
|
|
138
144
|
The emitToast extends from ToastOptions. They will overwrite all options received from `<Toaster />`. For example:
|
|
139
145
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CustomTheme } from '@dt-dds/themes';
|
|
2
2
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
3
|
import { BaseProps } from '@dt-dds/react-core';
|
|
4
|
-
import {
|
|
4
|
+
import { ReactNode } from 'react';
|
|
5
5
|
import { ToasterProps, ToastOptions } from 'react-hot-toast';
|
|
6
6
|
|
|
7
7
|
declare enum ToastPosition {
|
|
@@ -19,15 +19,6 @@ declare enum ToastType {
|
|
|
19
19
|
Warning = "warning"
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
interface Action extends Pick<BaseProps, 'dataTestId'> {
|
|
23
|
-
onClick: () => void;
|
|
24
|
-
label: string;
|
|
25
|
-
tooltip?: {
|
|
26
|
-
message: string;
|
|
27
|
-
background?: TooltipBackground;
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
22
|
interface ToastProps extends Pick<BaseProps, 'dataTestId'> {
|
|
32
23
|
id: string;
|
|
33
24
|
type: ToastType;
|
|
@@ -36,19 +27,19 @@ interface ToastProps extends Pick<BaseProps, 'dataTestId'> {
|
|
|
36
27
|
onClose: () => void;
|
|
37
28
|
isVisible?: boolean;
|
|
38
29
|
dismissible?: boolean;
|
|
39
|
-
|
|
30
|
+
children?: ReactNode;
|
|
40
31
|
}
|
|
41
|
-
declare const Toast: ({ id, dataTestId, title, message, onClose, type, isVisible, dismissible,
|
|
32
|
+
declare const Toast: ({ id, dataTestId, title, message, onClose, type, isVisible, dismissible, children, }: ToastProps) => react_jsx_runtime.JSX.Element;
|
|
42
33
|
|
|
43
34
|
interface EmitToastProps extends ToastOptions {
|
|
44
35
|
type: ToastType;
|
|
45
36
|
title: string;
|
|
46
37
|
message: string;
|
|
47
|
-
|
|
38
|
+
children?: ReactNode;
|
|
48
39
|
dismissible?: boolean;
|
|
49
40
|
}
|
|
50
41
|
declare const dismissToast: (id: string) => void;
|
|
51
|
-
declare const emitToast: ({ type, title, message,
|
|
42
|
+
declare const emitToast: ({ type, title, message, children, dismissible, ...props }: EmitToastProps) => void;
|
|
52
43
|
declare const Toaster: ({ gutter, ...props }: ToasterProps) => react_jsx_runtime.JSX.Element;
|
|
53
44
|
|
|
54
45
|
declare module '@emotion/react' {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CustomTheme } from '@dt-dds/themes';
|
|
2
2
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
3
|
import { BaseProps } from '@dt-dds/react-core';
|
|
4
|
-
import {
|
|
4
|
+
import { ReactNode } from 'react';
|
|
5
5
|
import { ToasterProps, ToastOptions } from 'react-hot-toast';
|
|
6
6
|
|
|
7
7
|
declare enum ToastPosition {
|
|
@@ -19,15 +19,6 @@ declare enum ToastType {
|
|
|
19
19
|
Warning = "warning"
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
interface Action extends Pick<BaseProps, 'dataTestId'> {
|
|
23
|
-
onClick: () => void;
|
|
24
|
-
label: string;
|
|
25
|
-
tooltip?: {
|
|
26
|
-
message: string;
|
|
27
|
-
background?: TooltipBackground;
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
22
|
interface ToastProps extends Pick<BaseProps, 'dataTestId'> {
|
|
32
23
|
id: string;
|
|
33
24
|
type: ToastType;
|
|
@@ -36,19 +27,19 @@ interface ToastProps extends Pick<BaseProps, 'dataTestId'> {
|
|
|
36
27
|
onClose: () => void;
|
|
37
28
|
isVisible?: boolean;
|
|
38
29
|
dismissible?: boolean;
|
|
39
|
-
|
|
30
|
+
children?: ReactNode;
|
|
40
31
|
}
|
|
41
|
-
declare const Toast: ({ id, dataTestId, title, message, onClose, type, isVisible, dismissible,
|
|
32
|
+
declare const Toast: ({ id, dataTestId, title, message, onClose, type, isVisible, dismissible, children, }: ToastProps) => react_jsx_runtime.JSX.Element;
|
|
42
33
|
|
|
43
34
|
interface EmitToastProps extends ToastOptions {
|
|
44
35
|
type: ToastType;
|
|
45
36
|
title: string;
|
|
46
37
|
message: string;
|
|
47
|
-
|
|
38
|
+
children?: ReactNode;
|
|
48
39
|
dismissible?: boolean;
|
|
49
40
|
}
|
|
50
41
|
declare const dismissToast: (id: string) => void;
|
|
51
|
-
declare const emitToast: ({ type, title, message,
|
|
42
|
+
declare const emitToast: ({ type, title, message, children, dismissible, ...props }: EmitToastProps) => void;
|
|
52
43
|
declare const Toaster: ({ gutter, ...props }: ToasterProps) => react_jsx_runtime.JSX.Element;
|
|
53
44
|
|
|
54
45
|
declare module '@emotion/react' {
|
package/dist/index.js
CHANGED
|
@@ -128,10 +128,8 @@ module.exports = __toCommonJS(index_exports);
|
|
|
128
128
|
// src/Toast.tsx
|
|
129
129
|
var import_react_box = __toESM(require_dist());
|
|
130
130
|
var import_react_icon = require("@dt-dds/react-icon");
|
|
131
|
-
var import_react_tooltip = require("@dt-dds/react-tooltip");
|
|
132
131
|
var import_react_typography = require("@dt-dds/react-typography");
|
|
133
132
|
var import_react2 = require("@emotion/react");
|
|
134
|
-
var import_react3 = __toESM(require("react"));
|
|
135
133
|
|
|
136
134
|
// src/constants/enums.ts
|
|
137
135
|
var ToastPosition = /* @__PURE__ */ ((ToastPosition2) => {
|
|
@@ -152,7 +150,6 @@ var ToastType = /* @__PURE__ */ ((ToastType2) => {
|
|
|
152
150
|
})(ToastType || {});
|
|
153
151
|
|
|
154
152
|
// src/Toast.styled.ts
|
|
155
|
-
var import_react_button = require("@dt-dds/react-button");
|
|
156
153
|
var import_react = require("@emotion/react");
|
|
157
154
|
var import_styled = __toESM(require("@emotion/styled"));
|
|
158
155
|
var fadeIn = import_react.keyframes`
|
|
@@ -206,13 +203,21 @@ var ToastButtonCloseStyled = import_styled.default.button`
|
|
|
206
203
|
|
|
207
204
|
`}
|
|
208
205
|
`;
|
|
209
|
-
var
|
|
206
|
+
var ActionsContainer = import_styled.default.div`
|
|
210
207
|
${({ theme, toastType }) => `
|
|
211
|
-
|
|
208
|
+
display: flex;
|
|
209
|
+
flex-direction: row;
|
|
210
|
+
justify-content: flex-end;
|
|
211
|
+
gap: ${theme.spacing.spacing_20};
|
|
212
|
+
margin-top: ${theme.spacing.spacing_30};
|
|
212
213
|
|
|
213
|
-
|
|
214
|
-
background-color: ${theme.palette[toastType].medium};
|
|
214
|
+
button {
|
|
215
215
|
color: ${theme.palette[toastType].dark};
|
|
216
|
+
|
|
217
|
+
&:hover {
|
|
218
|
+
background-color: ${theme.palette[toastType].medium};
|
|
219
|
+
color: ${theme.palette[toastType].dark};
|
|
220
|
+
}
|
|
216
221
|
}
|
|
217
222
|
`}
|
|
218
223
|
`;
|
|
@@ -234,7 +239,7 @@ var Toast = ({
|
|
|
234
239
|
type,
|
|
235
240
|
isVisible = true,
|
|
236
241
|
dismissible = true,
|
|
237
|
-
|
|
242
|
+
children
|
|
238
243
|
}) => {
|
|
239
244
|
const dataTest = dataTestId != null ? dataTestId : `toast-${id}`;
|
|
240
245
|
const theme = (0, import_react2.useTheme)();
|
|
@@ -262,9 +267,6 @@ var Toast = ({
|
|
|
262
267
|
color: `${type}.dark`,
|
|
263
268
|
element: "span",
|
|
264
269
|
fontStyles: "bodyLgBold",
|
|
265
|
-
style: {
|
|
266
|
-
textTransform: "capitalize"
|
|
267
|
-
},
|
|
268
270
|
children: title
|
|
269
271
|
}
|
|
270
272
|
),
|
|
@@ -281,36 +283,7 @@ var Toast = ({
|
|
|
281
283
|
}
|
|
282
284
|
),
|
|
283
285
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(ToastMessageStyled, { toastType: type, children: message }),
|
|
284
|
-
|
|
285
|
-
import_react_box.Box,
|
|
286
|
-
{
|
|
287
|
-
style: {
|
|
288
|
-
flexDirection: "row",
|
|
289
|
-
justifyContent: "flex-end",
|
|
290
|
-
gap: theme.spacing.spacing_20,
|
|
291
|
-
marginTop: theme.spacing.spacing_30
|
|
292
|
-
},
|
|
293
|
-
children: actions.map(({ label, onClick, dataTestId: dataTestId2, tooltip }, index) => {
|
|
294
|
-
var _a;
|
|
295
|
-
if (index > 1) return null;
|
|
296
|
-
const actionButtonElement = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
297
|
-
ActionButtonStyled,
|
|
298
|
-
{
|
|
299
|
-
"data-testid": dataTestId2,
|
|
300
|
-
onClick,
|
|
301
|
-
size: "small",
|
|
302
|
-
toastType: type,
|
|
303
|
-
variant: "text",
|
|
304
|
-
children: label
|
|
305
|
-
}
|
|
306
|
-
);
|
|
307
|
-
return (tooltip == null ? void 0 : tooltip.message) ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_tooltip.Tooltip, { children: [
|
|
308
|
-
actionButtonElement,
|
|
309
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_tooltip.Tooltip.Content, { background: (_a = tooltip == null ? void 0 : tooltip.background) != null ? _a : "full", children: tooltip == null ? void 0 : tooltip.message })
|
|
310
|
-
] }, label) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react3.default.Fragment, { children: actionButtonElement }, label);
|
|
311
|
-
})
|
|
312
|
-
}
|
|
313
|
-
) : null
|
|
286
|
+
Boolean(children) ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ActionsContainer, { toastType: type, children }) : null
|
|
314
287
|
]
|
|
315
288
|
},
|
|
316
289
|
id
|
|
@@ -319,8 +292,10 @@ var Toast = ({
|
|
|
319
292
|
var Toast_default = Toast;
|
|
320
293
|
|
|
321
294
|
// src/Toaster.tsx
|
|
295
|
+
var import_react_button = require("@dt-dds/react-button");
|
|
322
296
|
var import_react_core = require("@dt-dds/react-core");
|
|
323
|
-
var
|
|
297
|
+
var import_react3 = require("@emotion/react");
|
|
298
|
+
var import_react4 = __toESM(require("react"));
|
|
324
299
|
var import_react_hot_toast = require("react-hot-toast");
|
|
325
300
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
326
301
|
var TOAST_DEFAULT_DURATION = 4e3;
|
|
@@ -330,18 +305,39 @@ var defaultPosition = "bottom-right" /* BottomRight */;
|
|
|
330
305
|
var dismissToast = (id) => {
|
|
331
306
|
import_react_hot_toast.toast.dismiss(id);
|
|
332
307
|
};
|
|
308
|
+
var processChildren = (children) => {
|
|
309
|
+
return import_react4.default.Children.map(children, (child) => {
|
|
310
|
+
if (!import_react4.default.isValidElement(child)) {
|
|
311
|
+
return child;
|
|
312
|
+
}
|
|
313
|
+
if (child.type === import_react_button.Button) {
|
|
314
|
+
return import_react4.default.cloneElement(child, __spreadProps(__spreadValues({}, child.props), {
|
|
315
|
+
size: "small",
|
|
316
|
+
variant: "text"
|
|
317
|
+
}));
|
|
318
|
+
}
|
|
319
|
+
if (child.props.children) {
|
|
320
|
+
return import_react4.default.cloneElement(
|
|
321
|
+
child,
|
|
322
|
+
__spreadValues({}, child.props),
|
|
323
|
+
processChildren(child.props.children)
|
|
324
|
+
);
|
|
325
|
+
}
|
|
326
|
+
return child;
|
|
327
|
+
});
|
|
328
|
+
};
|
|
333
329
|
var emitToast = (_a) => {
|
|
334
330
|
var _b = _a, {
|
|
335
331
|
type,
|
|
336
332
|
title,
|
|
337
333
|
message,
|
|
338
|
-
|
|
334
|
+
children,
|
|
339
335
|
dismissible
|
|
340
336
|
} = _b, props = __objRest(_b, [
|
|
341
337
|
"type",
|
|
342
338
|
"title",
|
|
343
339
|
"message",
|
|
344
|
-
"
|
|
340
|
+
"children",
|
|
345
341
|
"dismissible"
|
|
346
342
|
]);
|
|
347
343
|
const duration = type === "error" /* Error */ ? TOAST_ERROR_DURATION : TOAST_DEFAULT_DURATION;
|
|
@@ -350,14 +346,14 @@ var emitToast = (_a) => {
|
|
|
350
346
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
351
347
|
Toast_default,
|
|
352
348
|
{
|
|
353
|
-
actions,
|
|
354
349
|
dismissible,
|
|
355
350
|
id: t.id,
|
|
356
351
|
isVisible: t.visible,
|
|
357
352
|
message,
|
|
358
353
|
onClose: () => import_react_hot_toast.toast.dismiss(t.id),
|
|
359
354
|
title,
|
|
360
|
-
type
|
|
355
|
+
type,
|
|
356
|
+
children: processChildren(children)
|
|
361
357
|
}
|
|
362
358
|
);
|
|
363
359
|
},
|
|
@@ -368,7 +364,7 @@ var emitToast = (_a) => {
|
|
|
368
364
|
};
|
|
369
365
|
var Toaster = (_a) => {
|
|
370
366
|
var _b = _a, { gutter = 8 } = _b, props = __objRest(_b, ["gutter"]);
|
|
371
|
-
const theme = (0,
|
|
367
|
+
const theme = (0, import_react3.useTheme)();
|
|
372
368
|
const small = (0, import_react_core.useMedia)(`(max-width: ${theme.breakpoints.mq2}px)`);
|
|
373
369
|
const position = small ? smallPosition : defaultPosition;
|
|
374
370
|
const margin = small ? 8 : 16;
|
package/dist/index.mjs
CHANGED
|
@@ -116,10 +116,8 @@ var require_dist = __commonJS({
|
|
|
116
116
|
// src/Toast.tsx
|
|
117
117
|
var import_react_box = __toESM(require_dist());
|
|
118
118
|
import { Icon } from "@dt-dds/react-icon";
|
|
119
|
-
import { Tooltip } from "@dt-dds/react-tooltip";
|
|
120
119
|
import { Typography } from "@dt-dds/react-typography";
|
|
121
120
|
import { useTheme } from "@emotion/react";
|
|
122
|
-
import React from "react";
|
|
123
121
|
|
|
124
122
|
// src/constants/enums.ts
|
|
125
123
|
var ToastPosition = /* @__PURE__ */ ((ToastPosition2) => {
|
|
@@ -140,7 +138,6 @@ var ToastType = /* @__PURE__ */ ((ToastType2) => {
|
|
|
140
138
|
})(ToastType || {});
|
|
141
139
|
|
|
142
140
|
// src/Toast.styled.ts
|
|
143
|
-
import { Button } from "@dt-dds/react-button";
|
|
144
141
|
import { keyframes } from "@emotion/react";
|
|
145
142
|
import styled from "@emotion/styled";
|
|
146
143
|
var fadeIn = keyframes`
|
|
@@ -194,13 +191,21 @@ var ToastButtonCloseStyled = styled.button`
|
|
|
194
191
|
|
|
195
192
|
`}
|
|
196
193
|
`;
|
|
197
|
-
var
|
|
194
|
+
var ActionsContainer = styled.div`
|
|
198
195
|
${({ theme, toastType }) => `
|
|
199
|
-
|
|
196
|
+
display: flex;
|
|
197
|
+
flex-direction: row;
|
|
198
|
+
justify-content: flex-end;
|
|
199
|
+
gap: ${theme.spacing.spacing_20};
|
|
200
|
+
margin-top: ${theme.spacing.spacing_30};
|
|
200
201
|
|
|
201
|
-
|
|
202
|
-
background-color: ${theme.palette[toastType].medium};
|
|
202
|
+
button {
|
|
203
203
|
color: ${theme.palette[toastType].dark};
|
|
204
|
+
|
|
205
|
+
&:hover {
|
|
206
|
+
background-color: ${theme.palette[toastType].medium};
|
|
207
|
+
color: ${theme.palette[toastType].dark};
|
|
208
|
+
}
|
|
204
209
|
}
|
|
205
210
|
`}
|
|
206
211
|
`;
|
|
@@ -222,7 +227,7 @@ var Toast = ({
|
|
|
222
227
|
type,
|
|
223
228
|
isVisible = true,
|
|
224
229
|
dismissible = true,
|
|
225
|
-
|
|
230
|
+
children
|
|
226
231
|
}) => {
|
|
227
232
|
const dataTest = dataTestId != null ? dataTestId : `toast-${id}`;
|
|
228
233
|
const theme = useTheme();
|
|
@@ -250,9 +255,6 @@ var Toast = ({
|
|
|
250
255
|
color: `${type}.dark`,
|
|
251
256
|
element: "span",
|
|
252
257
|
fontStyles: "bodyLgBold",
|
|
253
|
-
style: {
|
|
254
|
-
textTransform: "capitalize"
|
|
255
|
-
},
|
|
256
258
|
children: title
|
|
257
259
|
}
|
|
258
260
|
),
|
|
@@ -269,36 +271,7 @@ var Toast = ({
|
|
|
269
271
|
}
|
|
270
272
|
),
|
|
271
273
|
/* @__PURE__ */ jsx(ToastMessageStyled, { toastType: type, children: message }),
|
|
272
|
-
|
|
273
|
-
import_react_box.Box,
|
|
274
|
-
{
|
|
275
|
-
style: {
|
|
276
|
-
flexDirection: "row",
|
|
277
|
-
justifyContent: "flex-end",
|
|
278
|
-
gap: theme.spacing.spacing_20,
|
|
279
|
-
marginTop: theme.spacing.spacing_30
|
|
280
|
-
},
|
|
281
|
-
children: actions.map(({ label, onClick, dataTestId: dataTestId2, tooltip }, index) => {
|
|
282
|
-
var _a;
|
|
283
|
-
if (index > 1) return null;
|
|
284
|
-
const actionButtonElement = /* @__PURE__ */ jsx(
|
|
285
|
-
ActionButtonStyled,
|
|
286
|
-
{
|
|
287
|
-
"data-testid": dataTestId2,
|
|
288
|
-
onClick,
|
|
289
|
-
size: "small",
|
|
290
|
-
toastType: type,
|
|
291
|
-
variant: "text",
|
|
292
|
-
children: label
|
|
293
|
-
}
|
|
294
|
-
);
|
|
295
|
-
return (tooltip == null ? void 0 : tooltip.message) ? /* @__PURE__ */ jsxs(Tooltip, { children: [
|
|
296
|
-
actionButtonElement,
|
|
297
|
-
/* @__PURE__ */ jsx(Tooltip.Content, { background: (_a = tooltip == null ? void 0 : tooltip.background) != null ? _a : "full", children: tooltip == null ? void 0 : tooltip.message })
|
|
298
|
-
] }, label) : /* @__PURE__ */ jsx(React.Fragment, { children: actionButtonElement }, label);
|
|
299
|
-
})
|
|
300
|
-
}
|
|
301
|
-
) : null
|
|
274
|
+
Boolean(children) ? /* @__PURE__ */ jsx(ActionsContainer, { toastType: type, children }) : null
|
|
302
275
|
]
|
|
303
276
|
},
|
|
304
277
|
id
|
|
@@ -307,8 +280,10 @@ var Toast = ({
|
|
|
307
280
|
var Toast_default = Toast;
|
|
308
281
|
|
|
309
282
|
// src/Toaster.tsx
|
|
283
|
+
import { Button } from "@dt-dds/react-button";
|
|
310
284
|
import { TOAST_Z_INDEX, useMedia } from "@dt-dds/react-core";
|
|
311
285
|
import { useTheme as useTheme2 } from "@emotion/react";
|
|
286
|
+
import React from "react";
|
|
312
287
|
import {
|
|
313
288
|
toast,
|
|
314
289
|
Toaster as ToastProvider
|
|
@@ -321,18 +296,39 @@ var defaultPosition = "bottom-right" /* BottomRight */;
|
|
|
321
296
|
var dismissToast = (id) => {
|
|
322
297
|
toast.dismiss(id);
|
|
323
298
|
};
|
|
299
|
+
var processChildren = (children) => {
|
|
300
|
+
return React.Children.map(children, (child) => {
|
|
301
|
+
if (!React.isValidElement(child)) {
|
|
302
|
+
return child;
|
|
303
|
+
}
|
|
304
|
+
if (child.type === Button) {
|
|
305
|
+
return React.cloneElement(child, __spreadProps(__spreadValues({}, child.props), {
|
|
306
|
+
size: "small",
|
|
307
|
+
variant: "text"
|
|
308
|
+
}));
|
|
309
|
+
}
|
|
310
|
+
if (child.props.children) {
|
|
311
|
+
return React.cloneElement(
|
|
312
|
+
child,
|
|
313
|
+
__spreadValues({}, child.props),
|
|
314
|
+
processChildren(child.props.children)
|
|
315
|
+
);
|
|
316
|
+
}
|
|
317
|
+
return child;
|
|
318
|
+
});
|
|
319
|
+
};
|
|
324
320
|
var emitToast = (_a) => {
|
|
325
321
|
var _b = _a, {
|
|
326
322
|
type,
|
|
327
323
|
title,
|
|
328
324
|
message,
|
|
329
|
-
|
|
325
|
+
children,
|
|
330
326
|
dismissible
|
|
331
327
|
} = _b, props = __objRest(_b, [
|
|
332
328
|
"type",
|
|
333
329
|
"title",
|
|
334
330
|
"message",
|
|
335
|
-
"
|
|
331
|
+
"children",
|
|
336
332
|
"dismissible"
|
|
337
333
|
]);
|
|
338
334
|
const duration = type === "error" /* Error */ ? TOAST_ERROR_DURATION : TOAST_DEFAULT_DURATION;
|
|
@@ -341,14 +337,14 @@ var emitToast = (_a) => {
|
|
|
341
337
|
return /* @__PURE__ */ jsx2(
|
|
342
338
|
Toast_default,
|
|
343
339
|
{
|
|
344
|
-
actions,
|
|
345
340
|
dismissible,
|
|
346
341
|
id: t.id,
|
|
347
342
|
isVisible: t.visible,
|
|
348
343
|
message,
|
|
349
344
|
onClose: () => toast.dismiss(t.id),
|
|
350
345
|
title,
|
|
351
|
-
type
|
|
346
|
+
type,
|
|
347
|
+
children: processChildren(children)
|
|
352
348
|
}
|
|
353
349
|
);
|
|
354
350
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dt-dds/react-toast",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.74",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dist/index.js"
|
|
@@ -20,10 +20,9 @@
|
|
|
20
20
|
"test:update:snapshot": "jest -u"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@dt-dds/react-button": "1.0.0-beta.
|
|
23
|
+
"@dt-dds/react-button": "1.0.0-beta.57",
|
|
24
24
|
"@dt-dds/react-core": "1.0.0-beta.49",
|
|
25
25
|
"@dt-dds/react-icon": "1.0.0-beta.50",
|
|
26
|
-
"@dt-dds/react-tooltip": "1.0.0-beta.57",
|
|
27
26
|
"@dt-dds/react-typography": "1.0.0-beta.40",
|
|
28
27
|
"@dt-dds/themes": "1.0.0-beta.8",
|
|
29
28
|
"react-hot-toast": "^2.3.0"
|