@vectara/vectara-ui 18.4.0 → 19.0.0

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.
Files changed (35) hide show
  1. package/lib/components/card/SimpleCard.d.ts +1 -1
  2. package/lib/components/card/_index.scss +5 -30
  3. package/lib/components/composer/Composer.d.ts +41 -0
  4. package/lib/components/composer/Composer.js +148 -0
  5. package/lib/components/composer/_index.scss +4 -0
  6. package/lib/components/composer/useComposerHistory.d.ts +34 -0
  7. package/lib/components/composer/useComposerHistory.js +127 -0
  8. package/lib/components/context/Theme.d.ts +24 -0
  9. package/lib/components/context/Theme.js +78 -2
  10. package/lib/components/fileDropTarget/FileDropTarget.d.ts +8 -0
  11. package/lib/components/fileDropTarget/FileDropTarget.js +69 -0
  12. package/lib/components/fileDropTarget/_index.scss +34 -0
  13. package/lib/components/index.d.ts +5 -2
  14. package/lib/components/index.js +4 -1
  15. package/lib/components/patch/VuiPatch.d.ts +10 -0
  16. package/lib/components/patch/VuiPatch.js +32 -0
  17. package/lib/components/patch/_index.scss +30 -0
  18. package/lib/styles/index.css +122 -28
  19. package/package.json +1 -1
  20. package/src/docs/pages/card/SimpleCard.tsx +72 -6
  21. package/src/docs/pages/colorPalette/CategoricalColors.tsx +89 -0
  22. package/src/docs/pages/colorPalette/NeutralColors.tsx +42 -0
  23. package/src/docs/pages/colorPalette/SemanticColors.tsx +64 -0
  24. package/src/docs/pages/colorPalette/Swatch.tsx +59 -0
  25. package/src/docs/pages/colorPalette/TextAndBorderColors.tsx +37 -0
  26. package/src/docs/pages/colorPalette/Usage.tsx +72 -0
  27. package/src/docs/pages/colorPalette/index.tsx +43 -0
  28. package/src/docs/pages/composer/Composer.tsx +130 -0
  29. package/src/docs/pages/composer/index.tsx +11 -0
  30. package/src/docs/pages/fileDropTarget/FileDropTarget.tsx +80 -0
  31. package/src/docs/pages/fileDropTarget/index.tsx +11 -0
  32. package/src/docs/pages/patch/Icons.tsx +16 -0
  33. package/src/docs/pages/patch/Sizes.tsx +20 -0
  34. package/src/docs/pages/patch/index.tsx +22 -0
  35. package/src/docs/pages.tsx +9 -3
@@ -0,0 +1,59 @@
1
+ import { VuiCopyButton, VuiFlexContainer, VuiFlexItem, VuiSpacer, VuiText, VuiTextColor } from "../../../lib";
2
+
3
+ type Props = {
4
+ // Friendly name for the color.
5
+ name: string;
6
+ // The CSS custom property exposed by the theme, e.g. "--vui-color-primary-shade".
7
+ cssVariable: string;
8
+ // The value resolved in the light theme, shown for reference.
9
+ value?: string;
10
+ };
11
+
12
+ // Renders a single theme color as a live swatch alongside its CSS variable and value.
13
+ // The swatch fills itself with var(cssVariable), so it always reflects the active theme.
14
+ export const Swatch = ({ name, cssVariable, value }: Props) => {
15
+ return (
16
+ <VuiFlexItem grow={false}>
17
+ <div style={{ width: 200 }}>
18
+ <div
19
+ style={{
20
+ height: 64,
21
+ borderRadius: 6,
22
+ backgroundColor: `var(${cssVariable})`,
23
+ border: "1px solid var(--vui-color-border-medium)"
24
+ }}
25
+ />
26
+
27
+ <VuiSpacer size="xs" />
28
+
29
+ <VuiText size="xs">
30
+ <p>
31
+ <strong>{name}</strong>
32
+ </p>
33
+ </VuiText>
34
+
35
+ <VuiFlexContainer alignItems="center" spacing="xs" justifyContent="spaceBetween">
36
+ <VuiFlexItem grow={false}>
37
+ <VuiText size="xs">
38
+ <p>
39
+ <code>{cssVariable}</code>
40
+ </p>
41
+ </VuiText>
42
+ </VuiFlexItem>
43
+
44
+ <VuiFlexItem grow={false}>
45
+ <VuiCopyButton size="xs" value={`var(${cssVariable})`} title={`Copy var(${cssVariable})`} />
46
+ </VuiFlexItem>
47
+ </VuiFlexContainer>
48
+
49
+ {value && (
50
+ <VuiText size="xs">
51
+ <p>
52
+ <VuiTextColor color="subdued">{value}</VuiTextColor>
53
+ </p>
54
+ </VuiText>
55
+ )}
56
+ </div>
57
+ </VuiFlexItem>
58
+ );
59
+ };
@@ -0,0 +1,37 @@
1
+ import { VuiFlexContainer } from "../../../lib";
2
+ import { Subsection } from "../../components/Subsection";
3
+ import { Swatch } from "./Swatch";
4
+
5
+ // Foreground colors for body copy and form labels.
6
+ const textSwatches = [
7
+ { name: "Text", cssVariable: "--vui-color-text", value: "#1c1d22" },
8
+ { name: "Label", cssVariable: "--vui-color-label", value: "#1c1d22" }
9
+ ];
10
+
11
+ // Border colors for dividers, inputs, and surfaces.
12
+ const borderSwatches = [
13
+ { name: "Border medium", cssVariable: "--vui-color-border-medium", value: "#cbd1de" },
14
+ { name: "Border light", cssVariable: "--vui-color-border-light", value: "#e3e4f3" }
15
+ ];
16
+
17
+ export const TextAndBorderColors = () => {
18
+ return (
19
+ <>
20
+ <Subsection title="Text">
21
+ <VuiFlexContainer spacing="l" wrap>
22
+ {textSwatches.map((swatch) => (
23
+ <Swatch key={swatch.cssVariable} {...swatch} />
24
+ ))}
25
+ </VuiFlexContainer>
26
+ </Subsection>
27
+
28
+ <Subsection title="Border">
29
+ <VuiFlexContainer spacing="l" wrap>
30
+ {borderSwatches.map((swatch) => (
31
+ <Swatch key={swatch.cssVariable} {...swatch} />
32
+ ))}
33
+ </VuiFlexContainer>
34
+ </Subsection>
35
+ </>
36
+ );
37
+ };
@@ -0,0 +1,72 @@
1
+ import { VuiSpacer, VuiText, VuiTitle } from "../../../lib";
2
+
3
+ // Demonstrates referencing theme colors from CSS, including the -rgb companion variables
4
+ // that let you compose translucent colors at any opacity.
5
+ export const Usage = () => {
6
+ return (
7
+ <>
8
+ <VuiText>
9
+ <p>
10
+ Every theme color is published as a CSS custom property prefixed with <code>--vui-color-</code>. Reference one
11
+ anywhere you write CSS with <code>var(...)</code>:
12
+ </p>
13
+ </VuiText>
14
+
15
+ <VuiSpacer size="s" />
16
+
17
+ <VuiText>
18
+ <pre>
19
+ <code>{`.myElement {\n color: var(--vui-color-primary-shade);\n border: 1px solid var(--vui-color-border-medium);\n}`}</code>
20
+ </pre>
21
+ </VuiText>
22
+
23
+ <VuiSpacer size="m" />
24
+
25
+ <VuiText>
26
+ <p>
27
+ Each color also has an <code>-rgb</code> companion that holds just the{" "}
28
+ <code>r, g, b</code> channels. Pair it with <code>rgba()</code> to build a translucent color at any opacity:
29
+ </p>
30
+ </VuiText>
31
+
32
+ <VuiSpacer size="s" />
33
+
34
+ <VuiText>
35
+ <pre>
36
+ <code>{`.myElement {\n background-color: rgba(var(--vui-color-primary-shade-rgb), 0.08);\n}`}</code>
37
+ </pre>
38
+ </VuiText>
39
+
40
+ <VuiSpacer size="m" />
41
+
42
+ <VuiTitle size="xs">
43
+ <h4>Live example</h4>
44
+ </VuiTitle>
45
+
46
+ <VuiSpacer size="s" />
47
+
48
+ <div
49
+ style={{
50
+ padding: 16,
51
+ borderRadius: 8,
52
+ color: "var(--vui-color-primary-shade)",
53
+ backgroundColor: "rgba(var(--vui-color-primary-shade-rgb), 0.08)",
54
+ border: "1px solid var(--vui-color-border-medium)"
55
+ }}
56
+ >
57
+ This panel's text, background, and border are all driven by theme color variables, so it adapts automatically
58
+ when the theme changes.
59
+ </div>
60
+
61
+ <VuiSpacer size="m" />
62
+
63
+ <VuiText>
64
+ <p>
65
+ To change these values, pass a <code>theme</code> to <code>VuiContextProvider</code> — see the Theme page. The
66
+ neutral, text, and border colors invert between the light and dark themes, so prefer the semantic name (for
67
+ example <code>--vui-color-empty-shade</code>) over a literal lightness.
68
+ </p>
69
+ </VuiText>
70
+ </>
71
+ );
72
+ };
@@ -0,0 +1,43 @@
1
+ import { Usage } from "./Usage";
2
+ import { SemanticColors } from "./SemanticColors";
3
+ import { CategoricalColors } from "./CategoricalColors";
4
+ import { NeutralColors } from "./NeutralColors";
5
+ import { TextAndBorderColors } from "./TextAndBorderColors";
6
+
7
+ const UsageSource = require("!!raw-loader!./Usage");
8
+ const SemanticColorsSource = require("!!raw-loader!./SemanticColors");
9
+ const CategoricalColorsSource = require("!!raw-loader!./CategoricalColors");
10
+ const NeutralColorsSource = require("!!raw-loader!./NeutralColors");
11
+ const TextAndBorderColorsSource = require("!!raw-loader!./TextAndBorderColors");
12
+
13
+ export const colorPalette = {
14
+ name: "Color palette",
15
+ path: "/colorPalette",
16
+ examples: [
17
+ {
18
+ name: "Using color variables",
19
+ component: <Usage />,
20
+ source: UsageSource.default.toString()
21
+ },
22
+ {
23
+ name: "Semantic colors",
24
+ component: <SemanticColors />,
25
+ source: SemanticColorsSource.default.toString()
26
+ },
27
+ {
28
+ name: "Categorical colors",
29
+ component: <CategoricalColors />,
30
+ source: CategoricalColorsSource.default.toString()
31
+ },
32
+ {
33
+ name: "Neutral and special colors",
34
+ component: <NeutralColors />,
35
+ source: NeutralColorsSource.default.toString()
36
+ },
37
+ {
38
+ name: "Text and border colors",
39
+ component: <TextAndBorderColors />,
40
+ source: TextAndBorderColorsSource.default.toString()
41
+ }
42
+ ]
43
+ };
@@ -0,0 +1,130 @@
1
+ import { useState } from "react";
2
+ import {
3
+ VuiButtonTertiary,
4
+ VuiComposer,
5
+ ComposerSubmission,
6
+ VuiFlexContainer,
7
+ VuiFlexItem,
8
+ VuiIcon,
9
+ VuiIconButton,
10
+ VuiSpacer,
11
+ VuiText,
12
+ VuiTextColor
13
+ } from "../../../lib";
14
+ import { BiBulb, BiError } from "react-icons/bi";
15
+
16
+ const MAX_FILE_SIZE_BYTES = 5 * 1024 * 1024;
17
+
18
+ type SentMessage = {
19
+ text: string;
20
+ fileNames: string[];
21
+ };
22
+
23
+ export const Composer = () => {
24
+ const [messages, setMessages] = useState<SentMessage[]>([]);
25
+ const [isRunning, setIsRunning] = useState(false);
26
+ const [rejectedFiles, setRejectedFiles] = useState<string[]>([]);
27
+ const [skillCount, setSkillCount] = useState(0);
28
+
29
+ const handleSubmit = ({ text, files }: ComposerSubmission) => {
30
+ setMessages((prev) => [...prev, { text, fileNames: files.map((file) => file.name) }]);
31
+ setRejectedFiles([]);
32
+
33
+ // Simulate a streaming response so the Send button toggles to Cancel.
34
+ setIsRunning(true);
35
+ window.setTimeout(() => setIsRunning(false), 2000);
36
+ };
37
+
38
+ return (
39
+ <>
40
+ {messages.length > 0 && (
41
+ <>
42
+ {messages.map((message, index) => (
43
+ <div key={index}>
44
+ <VuiText>
45
+ <p>{message.text || <VuiTextColor color="subdued">(no text)</VuiTextColor>}</p>
46
+ </VuiText>
47
+ {message.fileNames.length > 0 && (
48
+ <VuiText size="s">
49
+ <p>
50
+ <VuiTextColor color="subdued">Attached: {message.fileNames.join(", ")}</VuiTextColor>
51
+ </p>
52
+ </VuiText>
53
+ )}
54
+ <VuiSpacer size="xs" />
55
+ </div>
56
+ ))}
57
+ <VuiSpacer size="m" />
58
+ </>
59
+ )}
60
+
61
+ <VuiComposer
62
+ placeholder="Ask a question, attach files, or press / for skills"
63
+ isRunning={isRunning}
64
+ onCancel={() => setIsRunning(false)}
65
+ onSubmit={handleSubmit}
66
+ enableHistory
67
+ historyKey="vuiComposerDocs:history"
68
+ canUploadFiles
69
+ validateFile={(file) => (file.size > MAX_FILE_SIZE_BYTES ? "File exceeds 5 MB" : null)}
70
+ onFilesRejected={(errors) => setRejectedFiles(errors.map((error) => error.file.name))}
71
+ onShortcutKeys={{
72
+ "/": (event, { value }) => {
73
+ // Open the skill picker only when the composer is empty.
74
+ if (value === "") {
75
+ event.preventDefault();
76
+ setSkillCount((count) => count + 1);
77
+ }
78
+ }
79
+ }}
80
+ leadingActions={
81
+ <VuiFlexItem>
82
+ <VuiFlexContainer alignItems="center" spacing="xxs">
83
+ <VuiIconButton
84
+ color="neutral"
85
+ aria-label="Select skill"
86
+ onClick={() => setSkillCount((count) => count + 1)}
87
+ icon={
88
+ <VuiIcon>
89
+ <BiBulb />
90
+ </VuiIcon>
91
+ }
92
+ />
93
+ {skillCount > 0 && (
94
+ <VuiText size="s">
95
+ <VuiTextColor color="subdued">({skillCount})</VuiTextColor>
96
+ </VuiText>
97
+ )}
98
+ </VuiFlexContainer>
99
+ </VuiFlexItem>
100
+ }
101
+ footer={
102
+ rejectedFiles.length > 0 ? (
103
+ <>
104
+ <VuiSpacer size="s" />
105
+ <VuiFlexContainer alignItems="center" spacing="xs">
106
+ <VuiFlexItem>
107
+ <VuiIcon size="s" color="danger">
108
+ <BiError />
109
+ </VuiIcon>
110
+ </VuiFlexItem>
111
+ <VuiFlexItem>
112
+ <VuiText size="s">
113
+ <p>
114
+ <VuiTextColor color="subdued">Could not attach: {rejectedFiles.join(", ")}</VuiTextColor>
115
+ </p>
116
+ </VuiText>
117
+ </VuiFlexItem>
118
+ <VuiFlexItem>
119
+ <VuiButtonTertiary noPadding color="primary" size="s" onClick={() => setRejectedFiles([])}>
120
+ Dismiss
121
+ </VuiButtonTertiary>
122
+ </VuiFlexItem>
123
+ </VuiFlexContainer>
124
+ </>
125
+ ) : undefined
126
+ }
127
+ />
128
+ </>
129
+ );
130
+ };
@@ -0,0 +1,11 @@
1
+ import { Composer } from "./Composer";
2
+ const ComposerSource = require("!!raw-loader!./Composer");
3
+
4
+ export const composer = {
5
+ name: "Composer",
6
+ path: "/composer",
7
+ example: {
8
+ component: <Composer />,
9
+ source: ComposerSource.default.toString()
10
+ }
11
+ };
@@ -0,0 +1,80 @@
1
+ import { useRef, useState } from "react";
2
+ import { VuiFileDropTarget, VuiSpacer, VuiText, VuiTextColor, VuiToggle } from "../../../lib";
3
+
4
+ export const FileDropTarget = () => {
5
+ const [isScoped, setIsScoped] = useState(false);
6
+ const [droppedFiles, setDroppedFiles] = useState<string[]>([]);
7
+ const scopeRef = useRef<HTMLDivElement>(null);
8
+
9
+ // Only one target is mounted at a time: the global target listens on the whole
10
+ // document, so it would intercept drops meant for a scoped target.
11
+ return (
12
+ <>
13
+ <VuiToggle
14
+ label="Scope drop target to an element"
15
+ checked={isScoped}
16
+ onChange={(e) => {
17
+ setIsScoped(e.target.checked);
18
+ setDroppedFiles([]);
19
+ }}
20
+ />
21
+
22
+ <VuiSpacer size="m" />
23
+
24
+ <VuiText>
25
+ <p>
26
+ <VuiTextColor color="subdued">
27
+ {isScoped
28
+ ? "Drag a file over the box below. The overlay is scoped to the positioned container."
29
+ : "Drag a file anywhere over the page to reveal a full-screen overlay."}
30
+ </VuiTextColor>
31
+ </p>
32
+ </VuiText>
33
+
34
+ {droppedFiles.length > 0 && (
35
+ <>
36
+ <VuiSpacer size="xs" />
37
+ <VuiText size="s">
38
+ <p>Dropped: {droppedFiles.join(", ")}</p>
39
+ </VuiText>
40
+ </>
41
+ )}
42
+
43
+ <VuiSpacer size="s" />
44
+
45
+ {isScoped ? (
46
+ <div
47
+ ref={scopeRef}
48
+ style={{
49
+ position: "relative",
50
+ minHeight: 160,
51
+ display: "flex",
52
+ alignItems: "center",
53
+ justifyContent: "center",
54
+ padding: 16,
55
+ border: "1px dashed var(--vui-color-border)",
56
+ borderRadius: 8
57
+ }}
58
+ >
59
+ <VuiText>
60
+ <p>
61
+ <VuiTextColor color="subdued">Drop zone</VuiTextColor>
62
+ </p>
63
+ </VuiText>
64
+
65
+ <VuiFileDropTarget
66
+ scopeRef={scopeRef}
67
+ message={
68
+ <VuiText align="center" size="l">
69
+ <p>Release to drop here</p>
70
+ </VuiText>
71
+ }
72
+ onFilesDropped={(files) => setDroppedFiles(files.map((file) => file.name))}
73
+ />
74
+ </div>
75
+ ) : (
76
+ <VuiFileDropTarget onFilesDropped={(files) => setDroppedFiles(files.map((file) => file.name))} />
77
+ )}
78
+ </>
79
+ );
80
+ };
@@ -0,0 +1,11 @@
1
+ import { FileDropTarget } from "./FileDropTarget";
2
+ const FileDropTargetSource = require("!!raw-loader!./FileDropTarget");
3
+
4
+ export const fileDropTarget = {
5
+ name: "File drop target",
6
+ path: "/fileDropTarget",
7
+ example: {
8
+ component: <FileDropTarget />,
9
+ source: FileDropTargetSource.default.toString()
10
+ }
11
+ };
@@ -0,0 +1,16 @@
1
+ import { BiHelpCircle } from "react-icons/bi";
2
+ import { PATCH_COLOR, VuiIcon, VuiPatch, VuiFlexContainer } from "../../../lib";
3
+
4
+ export const Icons = () => {
5
+ return (
6
+ <VuiFlexContainer spacing="m" wrap>
7
+ {PATCH_COLOR.map((color) => (
8
+ <VuiPatch color={color}>
9
+ <VuiIcon size="m">
10
+ <BiHelpCircle />
11
+ </VuiIcon>
12
+ </VuiPatch>
13
+ ))}
14
+ </VuiFlexContainer>
15
+ );
16
+ };
@@ -0,0 +1,20 @@
1
+ import { BiCompass } from "react-icons/bi";
2
+ import { VuiPatch, VuiFlexContainer, VuiIcon } from "../../../lib";
3
+
4
+ const sizes = ["xs", "s", "m"] as const;
5
+
6
+ export const Sizes = () => {
7
+ return (
8
+ <VuiFlexContainer spacing="m" wrap>
9
+ {sizes.map((size) => (
10
+ <div>
11
+ <VuiPatch color="indigo" size={size}>
12
+ <VuiIcon>
13
+ <BiCompass />
14
+ </VuiIcon>
15
+ </VuiPatch>
16
+ </div>
17
+ ))}
18
+ </VuiFlexContainer>
19
+ );
20
+ };
@@ -0,0 +1,22 @@
1
+ import { Icons } from "./Icons";
2
+ import { Sizes } from "./Sizes";
3
+
4
+ const IconsSource = require("!!raw-loader!./Icons");
5
+ const SizesSource = require("!!raw-loader!./Sizes");
6
+
7
+ export const patch = {
8
+ name: "Patch",
9
+ path: "/patch",
10
+ examples: [
11
+ {
12
+ name: "Icons",
13
+ component: <Icons />,
14
+ source: IconsSource.default.toString()
15
+ },
16
+ {
17
+ name: "Sizes",
18
+ component: <Sizes />,
19
+ source: SizesSource.default.toString()
20
+ }
21
+ ]
22
+ };
@@ -11,12 +11,15 @@ import { checkbox } from "./pages/checkbox";
11
11
  import { chip } from "./pages/chip";
12
12
  import { code } from "./pages/code";
13
13
  import { codeEditor } from "./pages/codeEditor";
14
+ import { colorPalette } from "./pages/colorPalette";
14
15
  import { complexConfigurationButton } from "./pages/complexConfigurationButton";
16
+ import { composer } from "./pages/composer";
15
17
  import { copyButton } from "./pages/copyButton";
16
18
  import { datePicker } from "./pages/datePicker";
17
19
  import { drawer } from "./pages/drawer";
18
20
  import { durationBar } from "./pages/durationBar";
19
21
  import { errorBoundary } from "./pages/errorBoundary";
22
+ import { fileDropTarget } from "./pages/fileDropTarget";
20
23
  import { flex } from "./pages/flex";
21
24
  import { formGroup } from "./pages/formGroup";
22
25
  import { grid } from "./pages/grid";
@@ -40,6 +43,7 @@ import { optionsButton } from "./pages/optionsButton";
40
43
  import { optionsList } from "./pages/optionsList";
41
44
  import { pagination } from "./pages/pagination";
42
45
  import { panel } from "./pages/panel";
46
+ import { patch } from "./pages/patch";
43
47
  import { popover } from "./pages/popover";
44
48
  import { progressBar } from "./pages/progressBar";
45
49
  import { prompt } from "./pages/prompt";
@@ -84,11 +88,11 @@ type Example = { component: React.ReactNode; source: string };
84
88
  export const categories: Category[] = [
85
89
  {
86
90
  name: "Query",
87
- pages: [chat, prompt, searchInput, searchResult, summary]
91
+ pages: [chat, composer, prompt, searchInput, searchResult, summary]
88
92
  },
89
93
  {
90
94
  name: "Application",
91
- pages: [app, drawer, modal, portalContainer, notifications, accountButton, theme]
95
+ pages: [app, drawer, modal, portalContainer, notifications, accountButton, theme, colorPalette]
92
96
  },
93
97
  {
94
98
  name: "Info",
@@ -106,6 +110,7 @@ export const categories: Category[] = [
106
110
  name: "Content",
107
111
  pages: [
108
112
  badge,
113
+ patch,
109
114
  status,
110
115
  callout,
111
116
  code,
@@ -138,7 +143,8 @@ export const categories: Category[] = [
138
143
  radioButton,
139
144
  superCheckboxGroup,
140
145
  superRadioGroup,
141
- itemsInput
146
+ itemsInput,
147
+ fileDropTarget
142
148
  ]
143
149
  },
144
150
  {