Skip to content

Commit c5cdcb6

Browse files
refactor(web): context chips render through one ContextChip component
Button variant="chip" was an escape hatch: it skipped buttonVariants entirely and let each call site assemble the chip look from exported class-name constants (CHAT_INLINE_CHIP_CLASS_NAME, the tone maps, the interactive and dismiss classes). Every chip surface re-derived the same pill slightly differently. ContextChip (components/ContextChip.tsx) now owns that look. It is a chat feature component, not a components/ui primitive: nothing outside chat context uses it. ContextChip takes a kind (neutral, file, mention, terminal, skill, pull request states, …) and a state (unresolved, invalid). Interactivity follows from what it renders as: render={<button/>} or a link gets the hover tint, focus outline and pointer, and media kinds zoom. ContextChipLabel truncates the text and ContextChipAction is the in-chip icon button. The composer, sent messages, the markdown file link, skills, terminal excerpts and citations all use it, and variant="chip" plus the class-name exports are gone. The markdown file link drops its own color and focus ring from index.css so the chip's apply alone. The background worktree setup pill is a Button ghost-muted micro now; it is a control, not context. no-restyle findings: 624 -> 604. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent e22e7ca commit c5cdcb6

14 files changed

Lines changed: 330 additions & 576 deletions

‎apps/web/src/components/ChatMarkdown.tsx‎

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ import { markdownImageGallery, markdownImageItems } from "./chat/markdownImageGa
105105
import { MediaVideoPlayer } from "./media/MediaVideoPlayer";
106106
import { MediaActions, type MediaActionSource } from "./media/MediaActions";
107107
import { resolveProtocolRelativeMediaUrl } from "./media/mediaContent";
108-
import { CHAT_FILE_TAG_CHIP_CLASS_NAME, FileTagChipContent } from "./chat/FileTagChip";
108+
import { FileTagChipContent } from "./chat/FileTagChip";
109109
import { PierreEntryIcon } from "./chat/PierreEntryIcon";
110110
import {
111111
revealInFileExplorerLabelForKind,
@@ -118,6 +118,7 @@ import {
118118
import { hasSpecificPierreIconForFileName, syntheticFileNameForLanguageId } from "../pierre-icons";
119119
import { Tooltip, TooltipPopup, TooltipTrigger } from "./ui/tooltip";
120120
import { Button } from "./ui/button";
121+
import { ContextChip } from "./ContextChip";
121122
import { Collapsible, CollapsiblePanel, CollapsibleTrigger } from "./ui/collapsible";
122123
import { ScrollArea } from "./ui/scroll-area";
123124
import { Menu, MenuItem, MenuPopup, MenuTrigger } from "./ui/menu";
@@ -1156,11 +1157,9 @@ interface MarkdownFileLinkProps {
11561157
/** Platform-specific menu label ("Reveal in Finder", ...); required for the
11571158
reveal item to show. */
11581159
revealLabel?: string | undefined;
1159-
className?: string | undefined;
11601160
}
11611161

1162-
const MARKDOWN_FILE_CHIP_CLASS_NAME = "chat-markdown-file-link";
1163-
const MARKDOWN_FILE_LINK_CLASS_NAME = `${MARKDOWN_FILE_CHIP_CLASS_NAME} cursor-pointer transition-colors hover:bg-accent/70 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70`;
1162+
const MARKDOWN_FILE_LINK_CLASS_NAME = "chat-markdown-file-link";
11641163

11651164
function pathParentSegments(path: string): string[] {
11661165
const normalized = path.replaceAll("\\", "/");
@@ -1895,7 +1894,6 @@ const MarkdownFileLink = memo(function MarkdownFileLink({
18951894
onOpenMedia,
18961895
onReveal,
18971896
revealLabel,
1898-
className,
18991897
}: MarkdownFileLinkProps) {
19001898
const handleOpenInEditor = useCallback(() => {
19011899
if (!onOpen) {
@@ -2165,13 +2163,10 @@ const MarkdownFileLink = memo(function MarkdownFileLink({
21652163
<TooltipTrigger
21662164
render={
21672165
hasPrimaryAction ? (
2168-
<a
2169-
href={href}
2170-
className={cn(
2171-
CHAT_FILE_TAG_CHIP_CLASS_NAME,
2172-
MARKDOWN_FILE_LINK_CLASS_NAME,
2173-
className,
2174-
)}
2166+
<ContextChip
2167+
kind="mention"
2168+
render={<a href={href} />}
2169+
className={MARKDOWN_FILE_LINK_CLASS_NAME}
21752170
data-markdown-copy={copyMarkdown}
21762171
onClick={(event) => {
21772172
event.preventDefault();
@@ -2188,25 +2183,21 @@ const MarkdownFileLink = memo(function MarkdownFileLink({
21882183
}}
21892184
onContextMenu={handleContextMenu}
21902185
>
2191-
<FileTagChipContent path={iconPath} label={label} theme={theme} selectable />
2192-
</a>
2186+
<FileTagChipContent path={iconPath} label={label} theme={theme} />
2187+
</ContextChip>
21932188
) : (
2194-
<button
2195-
type="button"
2189+
<ContextChip
2190+
kind="mention"
2191+
render={<button type="button" />}
21962192
aria-label={`File options for ${label}`}
21972193
aria-haspopup="menu"
2198-
className={cn(
2199-
CHAT_FILE_TAG_CHIP_CLASS_NAME,
2200-
MARKDOWN_FILE_LINK_CLASS_NAME,
2201-
"select-text",
2202-
className,
2203-
)}
2194+
className={cn(MARKDOWN_FILE_LINK_CLASS_NAME, "select-text")}
22042195
data-markdown-copy={copyMarkdown}
22052196
onClick={handleContextMenu}
22062197
onContextMenu={handleContextMenu}
22072198
>
2208-
<FileTagChipContent path={iconPath} label={label} theme={theme} selectable />
2209-
</button>
2199+
<FileTagChipContent path={iconPath} label={label} theme={theme} />
2200+
</ContextChip>
22102201
)
22112202
}
22122203
/>
@@ -2242,8 +2233,7 @@ function areMarkdownFileLinkPropsEqual(
22422233
previous.onOpenInBrowser === next.onOpenInBrowser &&
22432234
previous.onOpenMedia === next.onOpenMedia &&
22442235
previous.onReveal === next.onReveal &&
2245-
previous.revealLabel === next.revealLabel &&
2246-
previous.className === next.className
2236+
previous.revealLabel === next.revealLabel
22472237
);
22482238
}
22492239

@@ -2571,12 +2561,7 @@ function useChatMarkdownState({
25712561
[cwd, findWorkspaceBasenameMatch, revealFileInFileManager],
25722562
);
25732563
const fileLinkChip = useCallback(
2574-
(
2575-
fileLinkMeta: MarkdownFileLinkMeta,
2576-
copyMarkdown: string,
2577-
className?: string,
2578-
mediaSource?: string,
2579-
) => {
2564+
(fileLinkMeta: MarkdownFileLinkMeta, copyMarkdown: string, mediaSource?: string) => {
25802565
const parentSuffix = fileLinkParentSuffixByPath.get(
25812566
fileLinkMeta.filePath.replaceAll("\\", "/"),
25822567
);
@@ -2633,7 +2618,6 @@ function useChatMarkdownState({
26332618
? () => openMarkdownFileInPreview(fileLinkMeta.filePath)
26342619
: undefined
26352620
}
2636-
className={className}
26372621
/>
26382622
);
26392623
},
@@ -3068,7 +3052,6 @@ const CHAT_MARKDOWN_COMPONENTS = {
30683052
return fileLinkChip(
30693053
fileLinkMeta,
30703054
`[${fileLinkMeta.basename}](${normalizedHref})`,
3071-
props.className,
30723055
normalizedHref,
30733056
);
30743057
},
@@ -3085,7 +3068,6 @@ const CHAT_MARKDOWN_COMPONENTS = {
30853068
return fileLinkChip(
30863069
fileLinkMeta,
30873070
`\`${codeText}\``,
3088-
undefined,
30893071
inlineCodeFilePathCandidate(codeText) ?? codeText.trim(),
30903072
);
30913073
}

‎apps/web/src/components/ComposerPromptEditorTiptap.tsx‎

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,13 @@ import {
5858
import { collectInlineContextIds } from "~/lib/composerContextReferences";
5959
import { cn, isMacPlatform } from "~/lib/utils";
6060
import { basenameOfPath } from "~/pierre-icons";
61-
import {
62-
COMPOSER_INLINE_CHIP_DECORATOR_CLASS_NAME,
63-
COMPOSER_INLINE_CHIP_ICON_CLASS_NAME,
64-
COMPOSER_INLINE_CHIP_LABEL_CLASS_NAME,
65-
COMPOSER_INLINE_SKILL_CHIP_CLASS_NAME,
66-
SKILL_CHIP_ICON_SVG,
67-
} from "./composerInlineChip";
68-
import { FILE_TAG_CHIP_CLASS_NAME, FileTagChipContent } from "./chat/FileTagChip";
61+
import { FileTagChipContent } from "./chat/FileTagChip";
62+
import { SkillChipIcon } from "./chat/SkillInlineText";
6963
import { AssistantCitationChip } from "./chat/AssistantCitationChip";
7064
import { getTimelinePageScrollKey } from "./chat/pageScrollController";
7165
import { ContextChipPopover } from "./contextChipParts";
7266
import { Button } from "./ui/button";
67+
import { ContextChip } from "./ContextChip";
7368
import {
7469
ComposerContextActionsContext,
7570
ComposerContextReferenceChip,
@@ -190,6 +185,13 @@ function resolvedThemeFromDocument(): "light" | "dark" {
190185

191186
// ── Inline atom nodes (chips) ─────────────────────────────────────────────
192187

188+
/**
189+
* Wraps an inline chip node view: keeps the caret and text selection out of the chip and
190+
* paints the editor's node selection over it.
191+
*/
192+
const CHIP_NODE_SELECTION_CLASS_NAME =
193+
"relative inline-flex select-none items-center align-middle leading-none data-[composer-chip-selected]:after:pointer-events-none data-[composer-chip-selected]:after:absolute data-[composer-chip-selected]:after:inset-0 data-[composer-chip-selected]:after:rounded-[6px] data-[composer-chip-selected]:after:bg-[Highlight] data-[composer-chip-selected]:after:opacity-30 data-[composer-chip-selected]:after:content-['']";
194+
193195
const ComposerMentionExtension = Node.create({
194196
name: "composer-mention",
195197
group: "inline",
@@ -217,11 +219,11 @@ function ComposerMentionNodeView({ node }: NodeViewProps) {
217219
const actions = use(ComposerContextActionsContext);
218220
const path = (node.attrs.path as string) ?? "";
219221
const chip = (
220-
<Button
221-
variant="chip"
222+
<ContextChip
223+
kind="mention"
224+
render={<button type="button" />}
222225
onClick={() => actions.openMention(path)}
223226
aria-label={`Preview ${path}`}
224-
className={`${FILE_TAG_CHIP_CLASS_NAME} cursor-pointer focus-visible:outline-2`}
225227
contentEditable={false}
226228
spellCheck={false}
227229
data-composer-mention-chip="true"
@@ -231,10 +233,10 @@ function ComposerMentionNodeView({ node }: NodeViewProps) {
231233
label={basenameOfPath(path)}
232234
theme={resolvedThemeFromDocument()}
233235
/>
234-
</Button>
236+
</ContextChip>
235237
);
236238
return (
237-
<NodeViewWrapper as="span" className={COMPOSER_INLINE_CHIP_DECORATOR_CLASS_NAME}>
239+
<NodeViewWrapper as="span" className={CHIP_NODE_SELECTION_CLASS_NAME}>
238240
<Tooltip>
239241
<TooltipTrigger render={chip} />
240242
<TooltipPopup side="top">{path}</TooltipPopup>
@@ -275,20 +277,12 @@ function ComposerSkillNodeView({ node }: NodeViewProps) {
275277
const skillDescription = (node.attrs.skillDescription as string | null) ?? null;
276278
const skill = skills.find((candidate) => candidate.name === skillName);
277279
return (
278-
<NodeViewWrapper as="span" className={COMPOSER_INLINE_CHIP_DECORATOR_CLASS_NAME}>
280+
<NodeViewWrapper as="span" className={CHIP_NODE_SELECTION_CLASS_NAME}>
279281
<ContextChipPopover
282+
kind="skill"
283+
icon={<SkillChipIcon />}
284+
label={skillLabel}
280285
accessibleLabel={`Skill ${skillLabel}`}
281-
triggerClassName={COMPOSER_INLINE_SKILL_CHIP_CLASS_NAME}
282-
chip={
283-
<>
284-
<span
285-
aria-hidden="true"
286-
className={COMPOSER_INLINE_CHIP_ICON_CLASS_NAME}
287-
dangerouslySetInnerHTML={{ __html: SKILL_CHIP_ICON_SVG }}
288-
/>
289-
<span className={COMPOSER_INLINE_CHIP_LABEL_CLASS_NAME}>{skillLabel}</span>
290-
</>
291-
}
292286
>
293287
<div className="space-y-3 p-2 text-sm">
294288
<p className="font-medium">{skillLabel}</p>
@@ -380,7 +374,7 @@ function ComposerCitationNodeView({ node, editor, getPos }: NodeViewProps) {
380374
return (
381375
<NodeViewWrapper
382376
as="span"
383-
className="inline-flex min-w-0 max-w-full"
377+
className="inline-flex min-w-0 max-w-full select-none"
384378
contentEditable={false}
385379
spellCheck={false}
386380
data-composer-citation-chip="true"
@@ -435,7 +429,7 @@ const ComposerContextReferenceExtension = Node.create({
435429

436430
function ComposerContextReferenceNodeView({ node }: NodeViewProps) {
437431
return (
438-
<NodeViewWrapper as="span" className={COMPOSER_INLINE_CHIP_DECORATOR_CLASS_NAME}>
432+
<NodeViewWrapper as="span" className={CHIP_NODE_SELECTION_CLASS_NAME}>
439433
<ComposerContextReferenceChip
440434
kind={(node.attrs.kind as string) ?? ""}
441435
contextId={(node.attrs.contextId as string) ?? ""}
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
import { mergeProps } from "@base-ui/react/merge-props";
2+
import { useRender } from "@base-ui/react/use-render";
3+
import { cva, type VariantProps } from "class-variance-authority";
4+
import type * as React from "react";
5+
6+
import { cn } from "~/lib/utils";
7+
8+
/**
9+
* The inline pill for one piece of chat context. It lives with the chat components rather than
10+
* in components/ui because it is one feature's look, not a generic primitive.
11+
*
12+
* An inline pill for one piece of context (a file, mention, terminal excerpt, pull request,
13+
* skill…) that sits in running text, both in the composer and in sent messages.
14+
*
15+
* Metrics are in em so the chip scales with the text around it (the composer honors the
16+
* prompt font-size preference). Each kind keeps one restrained color identity: every accent
17+
* shares a lightness so no kind reads heavier than another, and only hue carries identity.
18+
* A consumer may override `--context-chip-accent` through `style` for a color that comes
19+
* from content, such as an image's average color.
20+
*
21+
* Renders a span by default. Render it as a button, link or popover/tooltip trigger to make it
22+
* interactive; the hover tint follows from that, not from a prop. Anything focusable (including a
23+
* span with tabIndex for a tooltip) gets the focus outline.
24+
*/
25+
const contextChipVariants = cva(
26+
"inline-flex h-[1.41em] max-w-full items-center gap-[0.33em] rounded-[0.5em] border px-[0.5em] align-middle font-medium text-[0.86em] leading-none [&_svg]:block [&_svg]:size-[1.17em] [&_svg]:shrink-0 [&_svg]:self-center [button&,a&,[data-popup-open]&]:cursor-pointer [button&,a&]:transition-colors [button&,a&]:motion-reduce:transition-none focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[var(--contrast-foreground)] disabled:cursor-default",
27+
{
28+
defaultVariants: { kind: "neutral" },
29+
variants: {
30+
kind: {
31+
neutral: "border-border/70 bg-accent/40 text-foreground",
32+
image: "[--context-chip-accent:oklch(0.62_0.16_16)]",
33+
video: "[--context-chip-accent:oklch(0.62_0.16_48)]",
34+
file: "[--context-chip-accent:oklch(0.62_0.136_237)]",
35+
mention: "[--context-chip-accent:oklch(0.62_0.11_215)]",
36+
terminal: "[--context-chip-accent:oklch(0.62_0.134_163)]",
37+
element: "[--context-chip-accent:oklch(0.62_0.134_70)]",
38+
"preview-annotation": "[--context-chip-accent:oklch(0.62_0.134_70)]",
39+
"review-comment": "[--context-chip-accent:oklch(0.62_0.16_292)]",
40+
"pull-request": "[--context-chip-accent:oklch(0.62_0.16_277)]",
41+
"pr-open": "[--context-chip-accent:oklch(0.62_0.134_163)]",
42+
"pr-draft": "[--context-chip-accent:oklch(0.62_0.02_259)]",
43+
"pr-merged": "[--context-chip-accent:oklch(0.62_0.16_292)]",
44+
"pr-closed": "[--context-chip-accent:oklch(0.62_0.16_16)]",
45+
skill: "[--context-chip-accent:oklch(0.62_0.16_322)]",
46+
citation: "[--context-chip-accent:oklch(0.62_0.16_259)]",
47+
},
48+
// Colors live in compoundVariants below so they come after the kind colors.
49+
state: {
50+
unresolved: "border-dashed",
51+
invalid: "",
52+
},
53+
},
54+
compoundVariants: [
55+
{
56+
kind: [
57+
"image",
58+
"video",
59+
"file",
60+
"mention",
61+
"terminal",
62+
"element",
63+
"preview-annotation",
64+
"review-comment",
65+
"pull-request",
66+
"pr-open",
67+
"pr-draft",
68+
"pr-merged",
69+
"pr-closed",
70+
"skill",
71+
"citation",
72+
],
73+
className:
74+
"border-[color-mix(in_oklab,var(--context-chip-accent)_34%,var(--contrast-border))] bg-[color-mix(in_oklab,var(--context-chip-accent)_11%,transparent)] text-[color-mix(in_oklab,var(--context-chip-accent)_22%,var(--contrast-foreground))] [button:enabled&,a&]:hover:border-[color-mix(in_oklab,var(--context-chip-accent)_48%,var(--contrast-border))] [button:enabled&,a&]:hover:bg-[color-mix(in_oklab,var(--context-chip-accent)_17%,transparent)]",
75+
},
76+
// State colors win over any kind.
77+
{ state: "unresolved", className: "text-foreground" },
78+
{ state: "invalid", className: "border-destructive/35 bg-destructive/8 text-destructive" },
79+
],
80+
},
81+
);
82+
83+
type ContextChipKind = NonNullable<VariantProps<typeof contextChipVariants>["kind"]>;
84+
85+
interface ContextChipProps extends useRender.ComponentProps<"span"> {
86+
kind?: ContextChipKind;
87+
state?: "unresolved" | "invalid";
88+
}
89+
90+
function ContextChip({ className, kind, state, render, ...props }: ContextChipProps) {
91+
const defaultProps = {
92+
className: cn(contextChipVariants({ kind, state }), className),
93+
"data-slot": "context-chip",
94+
"data-state": state,
95+
};
96+
return useRender({
97+
defaultTagName: "span",
98+
props: mergeProps<"span">(defaultProps, props),
99+
render,
100+
});
101+
}
102+
103+
/** The chip's text. Truncates to the chip's width. */
104+
function ContextChipLabel({ className, ...props }: React.ComponentProps<"span">) {
105+
return (
106+
<span
107+
className={cn("block min-w-0 self-center truncate leading-tight", className)}
108+
data-slot="context-chip-label"
109+
{...props}
110+
/>
111+
);
112+
}
113+
114+
/** An icon action inside a chip, such as editing a citation's comment. Tints with the chip's kind. */
115+
function ContextChipAction({ className, render, ...props }: useRender.ComponentProps<"button">) {
116+
const defaultProps = {
117+
className: cn(
118+
"ml-[0.17em] inline-flex size-[1.17em] shrink-0 cursor-pointer items-center justify-center rounded-sm text-current transition-colors hover:bg-[color-mix(in_oklab,var(--context-chip-accent,var(--color-foreground))_17%,transparent)] focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring motion-reduce:transition-none [&_svg]:size-[0.85em]",
119+
className,
120+
),
121+
"data-slot": "context-chip-action",
122+
type: render ? undefined : ("button" as const),
123+
};
124+
return useRender({
125+
defaultTagName: "button",
126+
props: mergeProps<"button">(defaultProps, props),
127+
render,
128+
});
129+
}
130+
131+
export { ContextChip, ContextChipAction, ContextChipLabel, type ContextChipKind };

0 commit comments

Comments
 (0)