@vectara/vectara-ui 13.11.1 → 13.11.3
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.
|
@@ -19,7 +19,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
19
19
|
return t;
|
|
20
20
|
};
|
|
21
21
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
22
|
-
import { useEffect, useState } from "react";
|
|
22
|
+
import { useEffect, useRef, useState } from "react";
|
|
23
23
|
import { FocusOn } from "react-focus-on";
|
|
24
24
|
import { BiClipboard, BiFullscreen, BiX } from "react-icons/bi";
|
|
25
25
|
import classNames from "classnames";
|
|
@@ -45,8 +45,15 @@ import { VuiText } from "../typography/Text";
|
|
|
45
45
|
export const VuiCode = (_a) => {
|
|
46
46
|
var { onCopy, isFullscreenEnabled = true, isCopyEnabled = true, language = "none", fullHeight, children = "" } = _a, rest = __rest(_a, ["onCopy", "isFullscreenEnabled", "isCopyEnabled", "language", "fullHeight", "children"]);
|
|
47
47
|
const [isFullscreen, setIsFullscreen] = useState(false);
|
|
48
|
+
const codeRef = useRef(null);
|
|
48
49
|
useEffect(() => {
|
|
49
|
-
|
|
50
|
+
if (codeRef.current) {
|
|
51
|
+
// Skip highlighting for very large code blocks to avoid performance issues.
|
|
52
|
+
const contentLength = children.trim().length;
|
|
53
|
+
if (contentLength > 20000)
|
|
54
|
+
return;
|
|
55
|
+
Prism.highlightElement(codeRef.current);
|
|
56
|
+
}
|
|
50
57
|
}, [children, language, isFullscreen]);
|
|
51
58
|
const containerClasses = classNames("vuiCodeContainer", {
|
|
52
59
|
"vuiCodeContainer--fullHeight": fullHeight
|
|
@@ -62,7 +69,7 @@ export const VuiCode = (_a) => {
|
|
|
62
69
|
if (onCopy)
|
|
63
70
|
onCopy();
|
|
64
71
|
}) }))] })));
|
|
65
|
-
const code = (_jsx("pre", Object.assign({ className: "vuiCodePre" }, { children: _jsx("code", Object.assign({ className: classes }, { children: children })) })));
|
|
72
|
+
const code = (_jsx("pre", Object.assign({ className: "vuiCodePre" }, { children: _jsx("code", Object.assign({ className: classes, ref: codeRef }, { children: children })) })));
|
|
66
73
|
return (_jsxs("div", Object.assign({ className: containerClasses }, rest, { children: [code, actions, testId && (_jsx("div", Object.assign({ "data-testid": `${testId}-hidden`, hidden: true }, { children: children }))), _jsx(VuiPortal, { children: isFullscreen && (_jsx(VuiScreenBlock, { children: _jsx(FocusOn, Object.assign({ onEscapeKey: () => {
|
|
67
74
|
setIsFullscreen(false);
|
|
68
75
|
} }, { children: _jsxs("div", Object.assign({ className: "vuiCodeFullscreen" }, getOverlayProps("fullscreenCodeTitle"), { children: [_jsxs(VuiFlexContainer, Object.assign({ alignItems: "center", justifyContent: "spaceBetween", className: "vuiCodeFullscreen__actions" }, { children: [_jsx(VuiFlexItem, { children: _jsx(VuiText, { children: _jsx("p", Object.assign({ id: "fullscreenCodeTitle" }, { children: _jsx("strong", { children: "Code" }) })) }) }), _jsx(VuiFlexItem, { children: _jsxs(VuiFlexContainer, Object.assign({ spacing: "xxs" }, { children: [isCopyEnabled && (_jsx(VuiIconButton, { color: "neutral", size: "m", icon: _jsx(VuiIcon, { children: _jsx(BiClipboard, {}) }), "aria-label": "Copy to clipboard", onClick: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -18,5 +18,5 @@ import { VuiText } from "../../typography/Text";
|
|
|
18
18
|
export const VuiSuperRadioButton = (_a) => {
|
|
19
19
|
var { label, description, value, checked, onChange, groupName } = _a, rest = __rest(_a, ["label", "description", "value", "checked", "onChange", "groupName"]);
|
|
20
20
|
const id = createId();
|
|
21
|
-
return (_jsx("label", Object.assign({ className: "vuiSuperRadioButton", htmlFor: id }, { children: _jsxs(VuiFlexContainer, Object.assign({ spacing: "l", alignItems: "center" }, { children: [_jsx(VuiFlexItem, Object.assign({ grow: false, shrink:
|
|
21
|
+
return (_jsx("label", Object.assign({ className: "vuiSuperRadioButton", htmlFor: id }, { children: _jsxs(VuiFlexContainer, Object.assign({ spacing: "l", alignItems: "center" }, { children: [_jsx(VuiFlexItem, Object.assign({ grow: false, shrink: 0 }, { children: _jsx("input", Object.assign({ id: id, name: groupName, type: "radio", checked: checked, onChange: () => onChange(value) }, rest)) })), _jsxs(VuiFlexItem, Object.assign({ grow: false, shrink: 1 }, { children: [_jsx(VuiText, { children: _jsx("p", Object.assign({ className: "vuiSuperRadioButton__text" }, { children: label })) }), description && (_jsxs(_Fragment, { children: [_jsx(VuiSpacer, { size: "xxs" }), _jsx(VuiText, Object.assign({ size: "xs" }, { children: _jsx("p", Object.assign({ className: "vuiSuperRadioButton__text vuiSuperRadioButton__description" }, { children: description })) }))] }))] }))] })) })));
|
|
22
22
|
};
|
package/lib/styles/index.css
CHANGED