UNPKG

@vectara/vectara-ui

Version:

Vectara's design system, codified as a React and Sass component library

55 lines (54 loc) 2.45 kB
var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import classNames from "classnames"; import Markdown from "markdown-to-jsx"; import { extractCitations } from "../../utils/citations/extractCitations"; import { VuiText } from "../typography/Text"; const markDownCitations = (summary) => { const citations = extractCitations(summary); return citations .reduce((accum, { text, references }) => { if (references) { accum.push(text); const marginBefore = text ? text[text.length - 1] !== " " : false; if (marginBefore) { accum.push(" "); } references.forEach((reference, referenceIndex) => { if (referenceIndex > 0) { accum.push(" "); } accum.push(`<SummaryCitation reference={${reference}} />`); }); } else { accum.push(text); } return accum; }, []) .join(""); }; export const VuiSummary = (_a) => { var { summary, className, SummaryCitation, statusIndicator } = _a, rest = __rest(_a, ["summary", "className", "SummaryCitation", "statusIndicator"]); // Protect users' privacy in FullStory. // https://help.fullstory.com/hc/en-us/articles/360020623574-How-do-I-protect-my-users-privacy-in-FullStory-#01F5DPW1AJHZHR8TBM9YQEDRMH const classes = classNames("vuiSummary", "fs-mask", className); const parsedSummary = summary && (_jsx(Markdown, { children: markDownCitations(summary), options: { overrides: { SummaryCitation: { component: SummaryCitation } } } })); return (_jsx("div", Object.assign({ className: classes, dir: "auto" }, rest, { children: summary ? (_jsx(VuiText, Object.assign({ size: "m" }, { children: _jsxs("p", { children: [parsedSummary, statusIndicator] }) }))) : (statusIndicator) }))); };