@choice-ui/react 1.6.9 → 1.7.1
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.
|
@@ -78,12 +78,20 @@ interface ToastData {
|
|
|
78
78
|
id: string;
|
|
79
79
|
type: ToastType;
|
|
80
80
|
variant?: ToastVariant;
|
|
81
|
+
/**
|
|
82
|
+
* Title content. Supports:
|
|
83
|
+
* - Plain string: rendered as text
|
|
84
|
+
* - HTML string (containing tags like `<b>`, `<strong>`, etc.): rendered as HTML
|
|
85
|
+
* - ReactNode: rendered as React component
|
|
86
|
+
*/
|
|
81
87
|
title?: React.ReactNode;
|
|
82
|
-
/**
|
|
83
|
-
|
|
88
|
+
/**
|
|
89
|
+
* Description content. Supports:
|
|
90
|
+
* - Plain string: rendered as text
|
|
91
|
+
* - HTML string (containing tags like `<b>`, `<strong>`, etc.): rendered as HTML
|
|
92
|
+
* - ReactNode: rendered as React component
|
|
93
|
+
*/
|
|
84
94
|
description?: React.ReactNode;
|
|
85
|
-
/** HTML string for description - rendered with dangerouslySetInnerHTML */
|
|
86
|
-
descriptionHtml?: string;
|
|
87
95
|
duration?: number;
|
|
88
96
|
icon?: React.ReactNode;
|
|
89
97
|
action?: {
|
|
@@ -105,9 +113,13 @@ interface ToastData {
|
|
|
105
113
|
interface ToastOptions {
|
|
106
114
|
id?: string;
|
|
107
115
|
variant?: ToastVariant;
|
|
116
|
+
/**
|
|
117
|
+
* Description content. Supports:
|
|
118
|
+
* - Plain string: rendered as text
|
|
119
|
+
* - HTML string (containing tags like `<b>`, `<strong>`, etc.): rendered as HTML
|
|
120
|
+
* - ReactNode: rendered as React component
|
|
121
|
+
*/
|
|
108
122
|
description?: React.ReactNode;
|
|
109
|
-
/** HTML string for description - rendered with dangerouslySetInnerHTML */
|
|
110
|
-
descriptionHtml?: string;
|
|
111
123
|
duration?: number;
|
|
112
124
|
icon?: React.ReactNode;
|
|
113
125
|
action?: {
|
|
@@ -45,6 +45,10 @@ const TOAST_ICONS = {
|
|
|
45
45
|
function getToastIcon(type) {
|
|
46
46
|
return TOAST_ICONS[type] ?? null;
|
|
47
47
|
}
|
|
48
|
+
const HTML_TAG_REGEX = /<[a-z][\s\S]*>/i;
|
|
49
|
+
function isHtmlString(content) {
|
|
50
|
+
return typeof content === "string" && HTML_TAG_REGEX.test(content);
|
|
51
|
+
}
|
|
48
52
|
const ToasterItem = memo(
|
|
49
53
|
forwardRef(function ToasterItem2({
|
|
50
54
|
toast,
|
|
@@ -172,7 +176,7 @@ const ToasterItem = memo(
|
|
|
172
176
|
setSwipeOffset({ x: 0, y: 0 });
|
|
173
177
|
setSwipeDirection(null);
|
|
174
178
|
});
|
|
175
|
-
const displayIcon = getToastIcon(toast.type);
|
|
179
|
+
const displayIcon = toast.icon ?? getToastIcon(toast.type);
|
|
176
180
|
const isBehind = index > 0 && !expanded;
|
|
177
181
|
const isTop = position.startsWith("top");
|
|
178
182
|
const scale = expanded ? 1 : Math.max(0, 1 - index * 0.05);
|
|
@@ -208,7 +212,7 @@ const ToasterItem = memo(
|
|
|
208
212
|
type: toast.type,
|
|
209
213
|
position,
|
|
210
214
|
hasActions: !!toast.action || !!toast.cancel,
|
|
211
|
-
hasDescription: !!
|
|
215
|
+
hasDescription: !!toast.description,
|
|
212
216
|
hasIcon: !!displayIcon,
|
|
213
217
|
behind: isBehind,
|
|
214
218
|
expanded,
|
|
@@ -221,7 +225,6 @@ const ToasterItem = memo(
|
|
|
221
225
|
toast.action,
|
|
222
226
|
toast.cancel,
|
|
223
227
|
toast.description,
|
|
224
|
-
toast.descriptionHtml,
|
|
225
228
|
displayIcon,
|
|
226
229
|
isBehind,
|
|
227
230
|
expanded,
|
|
@@ -278,29 +281,22 @@ const ToasterItem = memo(
|
|
|
278
281
|
id: titleId,
|
|
279
282
|
className: tcx(tv.title(), slotProps.titleClassName),
|
|
280
283
|
style: slotProps.titleStyle,
|
|
281
|
-
children: toast.title
|
|
284
|
+
...isHtmlString(toast.title) ? { dangerouslySetInnerHTML: { __html: toast.title } } : { children: toast.title }
|
|
282
285
|
}
|
|
283
286
|
);
|
|
284
287
|
}, [toast.title, titleId, tv, slotProps.titleClassName, slotProps.titleStyle]);
|
|
285
288
|
const descriptionContent = useMemo(() => {
|
|
286
|
-
if (!toast.description
|
|
289
|
+
if (!toast.description) return null;
|
|
287
290
|
return /* @__PURE__ */ jsx(
|
|
288
291
|
"div",
|
|
289
292
|
{
|
|
290
293
|
id: descriptionId,
|
|
291
294
|
className: tcx(tv.description(), slotProps.descriptionClassName),
|
|
292
295
|
style: slotProps.descriptionStyle,
|
|
293
|
-
...toast.
|
|
296
|
+
...isHtmlString(toast.description) ? { dangerouslySetInnerHTML: { __html: toast.description } } : { children: toast.description }
|
|
294
297
|
}
|
|
295
298
|
);
|
|
296
|
-
}, [
|
|
297
|
-
toast.description,
|
|
298
|
-
toast.descriptionHtml,
|
|
299
|
-
descriptionId,
|
|
300
|
-
tv,
|
|
301
|
-
slotProps.descriptionClassName,
|
|
302
|
-
slotProps.descriptionStyle
|
|
303
|
-
]);
|
|
299
|
+
}, [toast.description, descriptionId, tv, slotProps.descriptionClassName, slotProps.descriptionStyle]);
|
|
304
300
|
const actionsContent = useMemo(() => {
|
|
305
301
|
var _a;
|
|
306
302
|
if (!toast.action && !toast.cancel) return null;
|
|
@@ -3,12 +3,20 @@ export interface ToastData {
|
|
|
3
3
|
id: string;
|
|
4
4
|
type: ToastType;
|
|
5
5
|
variant?: ToastVariant;
|
|
6
|
+
/**
|
|
7
|
+
* Title content. Supports:
|
|
8
|
+
* - Plain string: rendered as text
|
|
9
|
+
* - HTML string (containing tags like `<b>`, `<strong>`, etc.): rendered as HTML
|
|
10
|
+
* - ReactNode: rendered as React component
|
|
11
|
+
*/
|
|
6
12
|
title?: React.ReactNode;
|
|
7
|
-
/**
|
|
8
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Description content. Supports:
|
|
15
|
+
* - Plain string: rendered as text
|
|
16
|
+
* - HTML string (containing tags like `<b>`, `<strong>`, etc.): rendered as HTML
|
|
17
|
+
* - ReactNode: rendered as React component
|
|
18
|
+
*/
|
|
9
19
|
description?: React.ReactNode;
|
|
10
|
-
/** HTML string for description - rendered with dangerouslySetInnerHTML */
|
|
11
|
-
descriptionHtml?: string;
|
|
12
20
|
duration?: number;
|
|
13
21
|
icon?: React.ReactNode;
|
|
14
22
|
action?: {
|
|
@@ -30,9 +38,13 @@ export interface ToastData {
|
|
|
30
38
|
export interface ToastOptions {
|
|
31
39
|
id?: string;
|
|
32
40
|
variant?: ToastVariant;
|
|
41
|
+
/**
|
|
42
|
+
* Description content. Supports:
|
|
43
|
+
* - Plain string: rendered as text
|
|
44
|
+
* - HTML string (containing tags like `<b>`, `<strong>`, etc.): rendered as HTML
|
|
45
|
+
* - ReactNode: rendered as React component
|
|
46
|
+
*/
|
|
33
47
|
description?: React.ReactNode;
|
|
34
|
-
/** HTML string for description - rendered with dangerouslySetInnerHTML */
|
|
35
|
-
descriptionHtml?: string;
|
|
36
48
|
duration?: number;
|
|
37
49
|
icon?: React.ReactNode;
|
|
38
50
|
action?: {
|
|
@@ -74,7 +74,6 @@ function addToast(title, type, options = {}, toasterId = DEFAULT_TOASTER_ID) {
|
|
|
74
74
|
variant: options.variant,
|
|
75
75
|
title,
|
|
76
76
|
description: options.description,
|
|
77
|
-
descriptionHtml: options.descriptionHtml,
|
|
78
77
|
duration: options.duration,
|
|
79
78
|
icon: options.icon,
|
|
80
79
|
action: options.action,
|
package/package.json
CHANGED