The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 23, 18:00 UTC
feat(web): quote chips show what you said about the quote (#15703)
oliver committed
Oct 7, 2026 at 22:49 UTC
12865b4a73c23bb402717d5f592dcd954ed196e5
2 files changed
+60
-26
apps/web/src/components/chat/AssistantCitationChip.test.tsx
+1
-5
@@ -19,11 +19,6 @@ vi.mock("@tanstack/react-router", () => ({
19
Link: ({ children }: { children: ReactNode }) => <a>{children}</a>,
20
}));
21
// Keep the real chip/editor lifecycle while replacing DOM positioning and floating layers.
22
-vi.mock("../ui/tooltip", () => ({
23
- Tooltip: ({ children }: { children: ReactNode }) => <>{children}</>,
24
- TooltipTrigger: ({ render }: { render: ReactNode }) => render,
25
- TooltipPopup: ({ children }: { children: ReactNode }) => <>{children}</>,
26
-}));
22
vi.mock("../ui/popover", () => ({
23
Popover: ({ children }: { children: ReactNode }) => <>{children}</>,
24
PopoverTrigger: ({ children }: { children: ReactNode }) => <button>{children}</button>,
@@ -62,6 +57,7 @@ function mount(onSave = vi.fn(() => true)) {
57
return (
58
<AssistantCitationChip
59
citation={citation}
60
+ composer
61
commentEditor={{ open, sourceAnchor, onOpenChange: setOpen, onSave }}
62
/>
63
);
apps/web/src/components/chat/AssistantCitationChip.tsx
+59
-21
@@ -4,7 +4,7 @@ import {
4
serializeAssistantCitation,
5
} from "@t3tools/shared/assistantCitations";
6
import { Link, useNavigate } from "@tanstack/react-router";
7
-import { PencilIcon, QuoteIcon } from "lucide-react";
7
+import { ArrowUpRightIcon, PencilIcon, QuoteIcon } from "lucide-react";
8
import {
9
useEffect,
10
useEffectEvent,
@@ -20,9 +20,12 @@ import {
20
assistantCitationHash,
21
assistantCitationNavigation,
22
} from "../../lib/assistantCitationNavigation";
23
+import { cn } from "~/lib/utils";
24
import { ContextChip, ContextChipAction, ContextChipLabel } from "../ContextChip";
24
-import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
25
-import { Popover, PopoverPopup, PopoverTrigger } from "../ui/popover";
25
+import { ContextChipPopover } from "../contextChipParts";
26
+import { Button } from "../ui/button";
27
+import { Popover, PopoverClose, PopoverPopup, PopoverTrigger } from "../ui/popover";
28
+import { getVirtualizedScrollFadeClassName } from "../ui/scroll-area";
29
import { AssistantCitationCommentEditor } from "./AssistantCitationCommentEditor";
30
import { resolveAssistantCitationCommentDismissal } from "./assistantCitationCommentDismissal";
31
import { observeAssistantCitationCommentSource } from "./AssistantCitationSource";
@@ -122,16 +125,27 @@ export function AssistantCitationChip({
125
<ContextChipLabel className="max-w-[16em]">{label}</ContextChipLabel>
126
</Link>
127
);
125
- const chatSourceLink = (
126
- <Link
127
- {...sourceLinkProps}
128
- className="inline-flex h-full min-w-0 items-center gap-[0.33em] rounded-sm text-inherit no-underline hover:bg-(--context-chip-accent)/17 focus-visible:outline-2 focus-visible:outline-foreground"
129
- aria-label={`View cited assistant text: ${label}`}
130
- >
131
- <QuoteIcon aria-hidden="true" />
132
- <ContextChipLabel className="max-w-[16em]">{label}</ContextChipLabel>
133
- </Link>
134
- );
128
+ if (!composer) {
129
+ return (
130
+ <ContextChipPopover
131
+ kind="citation"
132
+ icon={<QuoteIcon />}
133
+ label={label}
134
+ accessibleLabel={`Quoted assistant text: ${label}`}
135
+ copyMarkdown={serializeAssistantCitation(citation)}
136
+ >
137
+ <div className="flex max-h-[calc(var(--available-height)_-_1rem_-_2px)] flex-col items-start gap-3 p-1 text-sm">
138
+ <AssistantCitationQuote citation={citation} />
139
+ <PopoverClose
140
+ render={<Button variant="outline" size="sm" render={<Link {...sourceLinkProps} />} />}
141
+ >
142
+ <ArrowUpRightIcon aria-hidden="true" />
143
+ Go to source
144
+ </PopoverClose>
145
+ </div>
146
+ </ContextChipPopover>
147
+ );
148
+ }
149
return (
150
<ContextChip
151
kind="citation"
@@ -139,14 +153,7 @@ export function AssistantCitationChip({
153
data-assistant-citation-chip="true"
154
data-markdown-copy={serializeAssistantCitation(citation)}
155
>
142
- {composer ? (
143
- composerSourceLink
144
- ) : (
145
- <Tooltip>
146
- <TooltipTrigger render={chatSourceLink} />
147
- <TooltipPopup side="top">View source</TooltipPopup>
148
- </Tooltip>
149
- )}
156
+ {composerSourceLink}
157
{commentEditor ? (
158
<Popover
159
open={commentEditor.open}
@@ -232,3 +239,34 @@ export function AssistantCitationChip({
239
</ContextChip>
240
);
241
}
242
+
243
+function AssistantCitationQuote({ citation }: { citation: AssistantCitation }) {
244
+ const [fade, setFade] = useState({ top: false, bottom: false });
245
+ const updateFade = (element: HTMLElement) => {
246
+ const top = element.scrollTop > 1;
247
+ const bottom = element.scrollHeight - element.clientHeight - element.scrollTop > 1;
248
+ setFade((current) =>
249
+ current.top === top && current.bottom === bottom ? current : { top, bottom },
250
+ );
251
+ };
252
+ return (
253
+ <div
254
+ ref={(element) => {
255
+ if (!element) return;
256
+ const observer = new ResizeObserver(() => updateFade(element));
257
+ observer.observe(element);
258
+ return () => observer.disconnect();
259
+ }}
260
+ onScroll={(event) => updateFade(event.currentTarget)}
261
+ className={cn(
262
+ "max-h-64 min-h-0 space-y-3 self-stretch overflow-y-auto whitespace-pre-wrap wrap-break-word",
263
+ getVirtualizedScrollFadeClassName(fade),
264
+ )}
265
+ >
266
+ <blockquote className="border-l-2 border-border pl-3 text-muted-foreground">
267
+ {citation.text}
268
+ </blockquote>
269
+ {citation.comment ? <p>{citation.comment}</p> : null}
270
+ </div>
271
+ );
272
+}