Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Make the quote chip above the composer solid

AdityaUmalec731fdb89114
diff --git a/src/components/CitationUI.tsx b/src/components/CitationUI.tsx
index d4da5ce368..965ad506e3 100644
--- a/src/components/CitationUI.tsx
+++ b/src/components/CitationUI.tsx
@@ -1,5 +1,6 @@
import { useEffect, useLayoutEffect, useRef, useState, type RefObject } from "react";
import { createPortal } from "react-dom";
+import { cn } from "@/lib/cn";
import { Quote, X } from "lucide-react";
import {
CITATION_MAX_COMMENT_LENGTH,
@@ -224,11 +225,14 @@ export function CitationBadge({
onChange,
onRemove,
onNavigate,
+ solid = false,
}: {
citation: CitationAttachment;
onChange?: (citation: CitationAttachment) => void;
onRemove?: () => void;
onNavigate?: () => Promise<boolean>;
+ /** Paint the tint on the thread colour: the composer floats over the transcript, and a see-through chip lets chat text show through it. */
+ solid?: boolean;
}) {
const triggerRef = useRef<HTMLButtonElement>(null);
const detailsRef = useRef<HTMLDivElement>(null);
@@ -269,13 +273,13 @@ export function CitationBadge({
onClick={() => { setUnavailable(false); setOpen((value) => !value); }}
aria-expanded={open}
aria-label={t("chat.citation.open", { quote: citation.quote.slice(0, 80) })}
- className="inline-flex max-w-64 items-center gap-1.5 rounded-full border border-accent/30 bg-accent/10 px-2.5 py-1 text-[11px] text-accent-text hover:border-accent/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus/60"
+ className={cn("inline-flex max-w-64 items-center gap-1.5 rounded-full border border-accent/30 px-2.5 py-1 text-[11px] text-accent-text hover:border-accent/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus/60", solid ? "bg-app bg-linear-to-r from-accent/10 to-accent/10" : "bg-accent/10")}
>
<Quote size={11} className="shrink-0" aria-hidden="true" />
<span className="truncate">{citation.quote.replace(/\s+/g, " ")}</span>
</button>
{onRemove && (
- <button type="button" onClick={onRemove} aria-label={t("chat.citation.remove")} className="flex size-5 items-center justify-center rounded-full text-ink-secondary hover:bg-raised hover:text-ink"><X size={11} /></button>
+ <button type="button" onClick={onRemove} aria-label={t("chat.citation.remove")} className={cn("flex size-5 items-center justify-center rounded-full text-ink-secondary hover:bg-raised hover:text-ink", solid && "bg-app")}><X size={11} /></button>
)}
{open && createPortal(
<div
diff --git a/src/components/ComposerAttachments.citation-chip.test.ts b/src/components/ComposerAttachments.citation-chip.test.ts
new file mode 100644
index 0000000000..59b8b13874
--- /dev/null
+++ b/src/components/ComposerAttachments.citation-chip.test.ts
@@ -0,0 +1,38 @@
+import { createElement } from "react";
+import { renderToStaticMarkup } from "react-dom/server";
+import { describe, expect, it } from "vitest";
+import type { CitationAttachment } from "@/lib/citations";
+import { ComposerAttachments } from "./ComposerAttachments";
+import { SentCitations } from "./CitationUI";
+
+const citation: CitationAttachment = {
+ kind: "citation", version: 1, id: "c1", quote: "Your request was not processed.", size: 31,
+ source: { ownerType: "bot", ownerId: "b1", threadId: "t1", messageId: "m1", start: 0, end: 31, prefix: "", suffix: "" },
+};
+const noop = () => {};
+const classesOf = (html: string, label: string) => {
+ const tag = html.match(new RegExp(`<button[^>]*aria-label="${label}[^"]*"[^>]*>`))?.[0] ?? "";
+ return tag.match(/class="([^"]*)"/)?.[1].split(/\s+/) ?? [];
+};
+
+describe("quote chip in the composer", () => {
+ // The composer floats over the transcript, so a see-through chip lets chat text show through it.
+ it("sits on the thread colour, so chat text scrolling under the composer does not show through", () => {
+ const html = renderToStaticMarkup(createElement(ComposerAttachments, {
+ items: [citation], onAdd: noop, onRemove: noop, onChangeCitation: noop, onDisplayInChatBox: noop,
+ notice: null, onNotice: noop, uploadImage: async () => null,
+ }));
+ const chip = classesOf(html, "Open citation");
+ const remove = classesOf(html, "Remove citation");
+ expect(chip).toContain("bg-app");
+ expect(chip).not.toContain("bg-accent/10");
+ expect(remove).toContain("bg-app");
+ });
+
+ it("keeps the see-through tint on a sent message's quote, which sits on its own surface", () => {
+ const html = renderToStaticMarkup(createElement(SentCitations, { citations: [citation], onNavigate: async () => true }));
+ const chip = classesOf(html, "Open citation");
+ expect(chip).toContain("bg-accent/10");
+ expect(chip).not.toContain("bg-app");
+ });
+});
diff --git a/src/components/ComposerAttachments.tsx b/src/components/ComposerAttachments.tsx
index 0fc981e342..ca23a77e31 100644
--- a/src/components/ComposerAttachments.tsx
+++ b/src/components/ComposerAttachments.tsx
@@ -140,6 +140,7 @@ export function ComposerAttachments({
citation={a}
onChange={onChangeCitation}
onRemove={() => onRemove(a.id)}
+ solid
/>
) : a.kind === "paste" ? (
<Chip