@vectara/vectara-ui 15.7.1 → 15.7.2
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.
|
@@ -44,8 +44,17 @@ export const VuiDrawer = (_a) => {
|
|
|
44
44
|
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
45
45
|
}, 0);
|
|
46
46
|
};
|
|
47
|
+
// Handle outside clicks, but ignore clicks on notifications.
|
|
48
|
+
const handleClickOutside = (event) => {
|
|
49
|
+
const target = event.target;
|
|
50
|
+
// Check if the click is within a notification.
|
|
51
|
+
if (target.closest("[data-awareness='notification']")) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
onCloseDelayed();
|
|
55
|
+
};
|
|
47
56
|
const classes = classNames("vuiDrawer", `vuiDrawer--${color}`, className);
|
|
48
|
-
return (_jsx(VuiPortal, { children: isOpen && (_jsx(VuiScreenBlock, { children: _jsx(FocusOn, Object.assign({ onEscapeKey: onCloseDelayed, onClickOutside:
|
|
57
|
+
return (_jsx(VuiPortal, { children: isOpen && (_jsx(VuiScreenBlock, { children: _jsx(FocusOn, Object.assign({ onEscapeKey: onCloseDelayed, onClickOutside: handleClickOutside,
|
|
49
58
|
// Enable manual focus return to work.
|
|
50
59
|
returnFocus: false,
|
|
51
60
|
// Enable focus on contents when it's open,
|
|
@@ -37,5 +37,7 @@ export const VuiNotification = ({ color, message, onDismiss, children, hasCopyBu
|
|
|
37
37
|
icon = null;
|
|
38
38
|
}
|
|
39
39
|
const copyValue = code ? `${message}\n\n${code.content}` : message;
|
|
40
|
-
|
|
40
|
+
// data-awareness="notification" enables notifications to be closed when a drawer is open,
|
|
41
|
+
// without triggering the drawer to close.
|
|
42
|
+
return (_jsx("div", Object.assign({ className: classes, "data-testid": `notification-${color}`, "data-awareness": "notification" }, { children: _jsxs(VuiFlexContainer, Object.assign({ alignItems: "start", spacing: "s" }, { children: [_jsx(VuiFlexItem, Object.assign({ grow: 1 }, { children: _jsxs(VuiFlexContainer, Object.assign({ alignItems: "start", spacing: "xs" }, { children: [icon, _jsxs("div", { children: [_jsx(VuiText, Object.assign({ preserveWhiteSpace: true }, { children: _jsx(VuiTextColor, Object.assign({ color: color }, { children: message })) })), code && (_jsxs(_Fragment, { children: [_jsx(VuiSpacer, { size: "s" }), _jsx(VuiCode, Object.assign({ language: code.language }, { children: code.content }))] })), hasCopyButton && (_jsxs(_Fragment, { children: [_jsx(VuiSpacer, { size: "s" }), _jsx(VuiCopyButton, { value: copyValue, size: "s", label: "Copy notification" })] })), children && (_jsxs(_Fragment, { children: [_jsx(VuiSpacer, { size: "s" }), children] })), link && (_jsxs(_Fragment, { children: [_jsx(VuiSpacer, { size: "s" }), _jsx(VuiLink, Object.assign({}, link))] }))] })] })) })), _jsx(VuiFlexItem, Object.assign({ grow: false, shrink: false }, { children: _jsx(VuiIconButton, { "aria-label": "Dismiss message", size: "xs", color: "neutral", icon: _jsx(VuiIcon, { children: _jsx(BiX, {}) }), onClick: () => onDismiss(), "data-testid": `dismissNotificationButton-${color}` }) }))] })) })));
|
|
41
43
|
};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Toaster } from "sonner";
|
|
3
|
+
import { VuiPortal } from "../portal/Portal";
|
|
3
4
|
export const VuiNotifications = (props) => {
|
|
4
5
|
const finalProps = Object.assign({ position: "top-right" }, props);
|
|
5
|
-
|
|
6
|
+
// Render inside portal so notifications can appear above everything else, including drawers.
|
|
7
|
+
return (_jsx(VuiPortal, { children: _jsx(Toaster, Object.assign({}, finalProps)) }));
|
|
6
8
|
};
|
package/package.json
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { useState } from "react";
|
|
2
2
|
import {
|
|
3
|
+
addNotification,
|
|
3
4
|
VuiButtonPrimary,
|
|
4
5
|
VuiButtonSecondary,
|
|
5
6
|
VuiDrawer,
|
|
6
7
|
VuiFlexContainer,
|
|
8
|
+
VuiNotifications,
|
|
7
9
|
VuiSpacer,
|
|
8
10
|
VuiText,
|
|
9
11
|
VuiToggle
|
|
@@ -51,6 +53,20 @@ export const PrimaryDrawer = () => {
|
|
|
51
53
|
)
|
|
52
54
|
}
|
|
53
55
|
>
|
|
56
|
+
<VuiButtonSecondary
|
|
57
|
+
color="primary"
|
|
58
|
+
onClick={() => {
|
|
59
|
+
addNotification({
|
|
60
|
+
color: "primary",
|
|
61
|
+
message: "Just some information, FYI"
|
|
62
|
+
});
|
|
63
|
+
}}
|
|
64
|
+
>
|
|
65
|
+
Add notification
|
|
66
|
+
</VuiButtonSecondary>
|
|
67
|
+
|
|
68
|
+
<VuiSpacer size="m" />
|
|
69
|
+
|
|
54
70
|
<VuiText>
|
|
55
71
|
<p>I just thought you should know that your drawer is showing.</p>
|
|
56
72
|
</VuiText>
|
|
@@ -186,6 +202,8 @@ export const PrimaryDrawer = () => {
|
|
|
186
202
|
<FormGroup />
|
|
187
203
|
<VuiSpacer size="l" />
|
|
188
204
|
</VuiDrawer>
|
|
205
|
+
|
|
206
|
+
<VuiNotifications />
|
|
189
207
|
</>
|
|
190
208
|
);
|
|
191
209
|
};
|