GeezerVison is showing github.com — fix(web): chips drop their pill and stay readable on every theme (#25… · pingdotgg/t3code@4914cdd
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/ComposerPromptEditorTiptap.tsx +4-7Lines changed: 4 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -import { documentIconColorForFileName } from "~/pierre-icons"; | | 1 | +import { documentChipKindForFileName } from "~/pierre-icons"; | 2 | 2 | import { isProviderSkillUserInvocable } from "@t3tools/client-runtime/providerSkills"; | 3 | 3 | import { formatProviderSkillDisplayName } from "@t3tools/shared/inlineSkills"; | 4 | 4 | import { | @@ -46,7 +46,6 @@ import { | 46 | 46 | useLayoutEffect, | 47 | 47 | useRef, | 48 | 48 | useState, | 49 | | - type CSSProperties, | 50 | 49 | type KeyboardEvent as ReactKeyboardEvent, | 51 | 50 | type RefObject, | 52 | 51 | } from "react"; | @@ -232,7 +231,7 @@ function resolvedThemeFromDocument(): "light" | "dark" { | 232 | 231 | } | 233 | 232 |
| 234 | 233 | const CHIP_NODE_SELECTION_CLASS_NAME = | 235 | | - "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-sm data-[composer-chip-selected]:after:bg-[Highlight] data-[composer-chip-selected]:after:opacity-30 data-[composer-chip-selected]:after:content-['']"; | | 234 | + "relative inline-flex min-w-0 max-w-full select-none items-baseline 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-sm data-[composer-chip-selected]:after:bg-[Highlight] data-[composer-chip-selected]:after:opacity-30 data-[composer-chip-selected]:after:content-['']"; | 236 | 235 |
| 237 | 236 | const ComposerMentionExtension = Node.create({ | 238 | 237 | name: "composer-mention", | @@ -260,11 +259,9 @@ const ComposerMentionExtension = Node.create({ | 260 | 259 | function ComposerMentionNodeView({ node }: NodeViewProps) { | 261 | 260 | const actions = use(ComposerContextActionsContext); | 262 | 261 | const path = (node.attrs.path as string) ?? ""; | 263 | | - const accent = documentIconColorForFileName(path); | 264 | 262 | const chip = ( | 265 | 263 | <ContextChip | 266 | | - kind="mention" | 267 | | - style={accent ? ({ "--context-chip-accent": accent } as CSSProperties) : undefined} | | 264 | + kind={documentChipKindForFileName(path) ?? "mention"} | 268 | 265 | dir="ltr" | 269 | 266 | render={<button type="button" />} | 270 | 267 | onClick={() => actions.openMention(path)} | @@ -442,7 +439,7 @@ function ComposerCitationNodeView({ node, editor, getPos }: NodeViewProps) { | 442 | 439 | return ( | 443 | 440 | <NodeViewWrapper | 444 | 441 | as="span" | 445 | | - className={cn(CHIP_NODE_SELECTION_CLASS_NAME, "min-w-0 max-w-full")} | | 442 | + className={CHIP_NODE_SELECTION_CLASS_NAME} | 446 | 443 | contentEditable={false} | 447 | 444 | spellCheck={false} | 448 | 445 | data-composer-citation-chip="true" | |
Collapse file Copy file name to clipboard +42Lines changed: 42 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import { FileIcon } from "lucide-react"; | | 2 | +import { describe, expect, it } from "vite-plus/test"; | | 3 | + | | 4 | +import "~/index.css"; | | 5 | +import { render } from "../../test/render"; | | 6 | +import { ContextChip, ContextChipLabel } from "./ContextChip"; | | 7 | + | | 8 | +// An empty inline-block's bottom edge sits on the baseline of the line it is in. | | 9 | +function BaselineMarker(props: { id: string }) { | | 10 | + return <span data-baseline={props.id} className="inline-block size-0" />; | | 11 | +} | | 12 | + | | 13 | +describe("ContextChip", () => { | | 14 | + it("sets its label on the sentence baseline at the sentence size without growing the line", async () => { | | 15 | + await using screen = await render( | | 16 | + <p className="w-[60ch] text-sm leading-relaxed"> | | 17 | + Open | | 18 | + <BaselineMarker id="text" /> the{" "} | | 19 | + <ContextChip kind="mention" render={<button type="button" />}> | | 20 | + <FileIcon /> | | 21 | + <ContextChipLabel> | | 22 | + src/ | | 23 | + <BaselineMarker id="chip" /> | | 24 | + Typography.tsx | | 25 | + </ContextChipLabel> | | 26 | + </ContextChip>{" "} | | 27 | + file | | 28 | + </p>, | | 29 | + ); | | 30 | + const paragraph = screen.container.querySelector("p")!; | | 31 | + const label = screen.container.querySelector<HTMLElement>('[data-slot="context-chip-label"]')!; | | 32 | + const baseline = (id: string) => | | 33 | + screen.container.querySelector(`[data-baseline="${id}"]`)!.getBoundingClientRect().bottom; | | 34 | + | | 35 | + expect(getComputedStyle(label).fontSize).toBe(getComputedStyle(paragraph).fontSize); | | 36 | + expect(Math.abs(baseline("chip") - baseline("text"))).toBeLessThanOrEqual(0.5); | | 37 | + expect(paragraph.getBoundingClientRect().height).toBeCloseTo( | | 38 | + Number.parseFloat(getComputedStyle(paragraph).lineHeight), | | 39 | + 0, | | 40 | + ); | | 41 | + }); | | 42 | +}); |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/ContextChip.tsx +31-48Lines changed: 31 additions & 48 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -6,60 +6,40 @@ import type * as React from "react"; | 6 | 6 | import { cn } from "~/lib/utils"; | 7 | 7 |
| 8 | 8 | const contextChipVariants = cva( | 9 | | - "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-foreground disabled:cursor-default", | | 9 | + "inline-flex max-w-full items-center gap-[0.2em] font-medium leading-[normal] text-(--context-chip-ink) [--context-chip-ink:var(--context-chip-accent)] [--document-icon-stroke:var(--context-chip-ink)] [&_svg]:block [&_svg]:size-[1em] [&_svg]:shrink-0 [&_svg]:self-center [button&,a&,[data-popup-open]&]:cursor-pointer focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-current rounded-sm disabled:cursor-default", | 10 | 10 | { | 11 | 11 | defaultVariants: { kind: "neutral" }, | 12 | 12 | variants: { | 13 | 13 | kind: { | 14 | | - neutral: "border-border/70 bg-accent/40 text-foreground", | 15 | | - image: "[--context-chip-accent:oklch(0.62_0.16_16)]", | 16 | | - video: "[--context-chip-accent:oklch(0.62_0.16_48)]", | 17 | | - file: "[--context-chip-accent:oklch(0.62_0.136_237)]", | 18 | | - mention: "[--context-chip-accent:oklch(0.62_0.11_215)]", | 19 | | - terminal: "[--context-chip-accent:oklch(0.62_0.134_163)]", | 20 | | - element: "[--context-chip-accent:oklch(0.62_0.134_70)]", | 21 | | - "preview-annotation": "[--context-chip-accent:oklch(0.62_0.134_70)]", | 22 | | - "review-comment": "[--context-chip-accent:oklch(0.62_0.16_292)]", | 23 | | - "pull-request": "[--context-chip-accent:oklch(0.62_0.16_277)]", | 24 | | - "pr-open": "[--context-chip-accent:oklch(0.62_0.134_163)]", | 25 | | - "pr-draft": "[--context-chip-accent:oklch(0.62_0.02_259)]", | 26 | | - "pr-merged": "[--context-chip-accent:oklch(0.62_0.16_292)]", | 27 | | - "pr-closed": "[--context-chip-accent:oklch(0.62_0.16_16)]", | 28 | | - skill: "[--context-chip-accent:oklch(0.62_0.16_322)]", | 29 | | - thread: "[--context-chip-accent:oklch(0.62_0.12_190)]", | 30 | | - citation: "[--context-chip-accent:oklch(0.62_0.16_259)]", | | 14 | + neutral: "[--context-chip-accent:currentColor]", | | 15 | + image: "[--context-chip-accent:var(--context-chip-image)]", | | 16 | + video: "[--context-chip-accent:var(--context-chip-video)]", | | 17 | + file: "[--context-chip-accent:var(--context-chip-file)]", | | 18 | + mention: "[--context-chip-accent:var(--context-chip-mention)]", | | 19 | + terminal: "[--context-chip-accent:var(--context-chip-terminal)]", | | 20 | + element: "[--context-chip-accent:var(--context-chip-element)]", | | 21 | + "preview-annotation": "[--context-chip-accent:var(--context-chip-preview-annotation)]", | | 22 | + "review-comment": "[--context-chip-accent:var(--context-chip-review-comment)]", | | 23 | + "pull-request": "[--context-chip-accent:var(--context-chip-pull-request)]", | | 24 | + "pr-open": "[--context-chip-accent:var(--context-chip-pr-open)]", | | 25 | + "pr-draft": "[--context-chip-accent:var(--context-chip-pr-draft)]", | | 26 | + "pr-merged": "[--context-chip-accent:var(--context-chip-pr-merged)]", | | 27 | + "pr-closed": "[--context-chip-accent:var(--context-chip-pr-closed)]", | | 28 | + skill: "[--context-chip-accent:var(--context-chip-skill)]", | | 29 | + thread: "[--context-chip-accent:var(--context-chip-thread)]", | | 30 | + citation: "[--context-chip-accent:var(--context-chip-citation)]", | | 31 | + "doc-pdf": "[--context-chip-accent:var(--context-chip-doc-pdf)]", | | 32 | + "doc-word": "[--context-chip-accent:var(--context-chip-doc-word)]", | | 33 | + "doc-spreadsheet": "[--context-chip-accent:var(--context-chip-doc-spreadsheet)]", | | 34 | + "doc-slides": "[--context-chip-accent:var(--context-chip-doc-slides)]", | | 35 | + "doc-epub": "[--context-chip-accent:var(--context-chip-doc-epub)]", | 31 | 36 | }, | 32 | 37 | state: { | 33 | | - unresolved: "border-dashed", | 34 | | - invalid: "", | | 38 | + unresolved: "data-[state=unresolved]:[--context-chip-accent:currentColor]", | | 39 | + invalid: | | 40 | + "data-[state=invalid]:[--context-chip-accent:var(--context-chip-invalid,var(--destructive-foreground))]", | 35 | 41 | }, | 36 | 42 | }, | 37 | | - compoundVariants: [ | 38 | | - { | 39 | | - kind: [ | 40 | | - "image", | 41 | | - "video", | 42 | | - "file", | 43 | | - "mention", | 44 | | - "terminal", | 45 | | - "element", | 46 | | - "preview-annotation", | 47 | | - "review-comment", | 48 | | - "pull-request", | 49 | | - "pr-open", | 50 | | - "pr-draft", | 51 | | - "pr-merged", | 52 | | - "pr-closed", | 53 | | - "skill", | 54 | | - "thread", | 55 | | - "citation", | 56 | | - ], | 57 | | - className: | 58 | | - "[--context-chip-border:color-mix(in_oklab,var(--context-chip-accent)_34%,var(--contrast-border))] [--context-chip-border-hover:color-mix(in_oklab,var(--context-chip-accent)_48%,var(--contrast-border))] [--context-chip-foreground:color-mix(in_oklab,var(--context-chip-accent)_22%,var(--contrast-foreground))] border-(--context-chip-border) bg-(--context-chip-accent)/11 text-(--context-chip-foreground) [button:enabled&,a&]:hover:border-(--context-chip-border-hover) [button:enabled&,a&]:hover:bg-(--context-chip-accent)/17", | 59 | | - }, | 60 | | - { state: "unresolved", className: "text-foreground" }, | 61 | | - { state: "invalid", className: "border-destructive/35 bg-destructive/8 text-destructive" }, | 62 | | - ], | 63 | 43 | }, | 64 | 44 | ); | 65 | 45 |
| @@ -86,7 +66,10 @@ function ContextChip({ className, kind, state, render, ...props }: ContextChipPr | 86 | 66 | function ContextChipLabel({ className, ...props }: React.ComponentProps<"span">) { | 87 | 67 | return ( | 88 | 68 | <span | 89 | | - className={cn("block min-w-0 self-center truncate leading-tight", className)} | | 69 | + className={cn( | | 70 | + "block min-w-0 self-baseline overflow-x-clip text-ellipsis whitespace-nowrap underline decoration-transparent decoration-1 underline-offset-[0.2em] transition-colors motion-reduce:transition-none [:is(button:enabled,a):hover>&]:decoration-current", | | 71 | + className, | | 72 | + )} | 90 | 73 | data-slot="context-chip-label" | 91 | 74 | {...props} | 92 | 75 | /> | @@ -96,7 +79,7 @@ function ContextChipLabel({ className, ...props }: React.ComponentProps<"span">) | 96 | 79 | function ContextChipAction({ className, render, ...props }: useRender.ComponentProps<"button">) { | 97 | 80 | const defaultProps = { | 98 | 81 | className: cn( | 99 | | - "ml-[0.17em] inline-flex size-[1.17em] shrink-0 cursor-pointer items-center justify-center rounded-sm text-current transition-colors hover:bg-(--context-chip-accent,var(--color-foreground))/17 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring motion-reduce:transition-none [&_svg]:size-[0.85em]", | | 82 | + "ml-[0.17em] inline-flex size-[1em] shrink-0 cursor-pointer items-center justify-center rounded-sm text-current transition-colors hover:bg-(--context-chip-accent,var(--color-foreground))/17 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring motion-reduce:transition-none [&_svg]:size-[0.85em]", | 100 | 83 | className, | 101 | 84 | ), | 102 | 85 | "data-slot": "context-chip-action", | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/ThreadContextChip.tsx +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -30,7 +30,7 @@ export function ThreadContextChip(props: { | 30 | 30 | className="no-underline" | 31 | 31 | > | 32 | 32 | {project ? ( | 33 | | - <ProjectFavicon project={project} className="size-[1.17em] self-center" /> | | 33 | + <ProjectFavicon project={project} className="size-[1em] self-center" /> | 34 | 34 | ) : ( | 35 | 35 | <MessagesSquareIcon /> | 36 | 36 | )} | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/chat/AssistantCitationChip.tsx +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -124,7 +124,7 @@ export function AssistantCitationChip({ | 124 | 124 | const composerSourceLink = ( | 125 | 125 | <Link | 126 | 126 | {...sourceLinkProps} | 127 | | - className="inline-flex h-full min-w-0 items-center gap-[0.33em] rounded-sm text-inherit no-underline focus-visible:outline-2 focus-visible:outline-foreground" | | 127 | + className="inline-flex min-w-0 items-center gap-[0.2em] self-baseline text-inherit no-underline focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-current rounded-sm" | 128 | 128 | aria-label={`View cited assistant text: ${label}`} | 129 | 129 | > | 130 | 130 | <QuoteIcon aria-hidden="true" /> | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/chat/MarkdownFileLink.tsx +5-8Lines changed: 5 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -5,13 +5,13 @@ import { | 5 | 5 | type AtomCommandResult, | 6 | 6 | } from "@t3tools/client-runtime/state/runtime"; | 7 | 7 | import type { EnvironmentId, ScopedThreadRef } from "@t3tools/contracts"; | 8 | | -import { memo, type CSSProperties, type MouseEvent as ReactMouseEvent } from "react"; | | 8 | +import { memo, type MouseEvent as ReactMouseEvent } from "react"; | 9 | 9 |
| 10 | 10 | import { readLocalApi } from "../../localApi"; | 11 | 11 | import { cn } from "../../lib/utils"; | 12 | 12 | import { shouldOpenMarkdownFileLinkInEditor } from "../../markdown-links"; | 13 | 13 | import type { markdownFileCopyPaths } from "../../markdownFileHostPath"; | 14 | | -import { documentIconColorForFileName } from "../../pierre-icons"; | | 14 | +import { documentChipKindForFileName } from "../../pierre-icons"; | 15 | 15 | import { ContextChip } from "../ContextChip"; | 16 | 16 | import { stackedThreadToast, toastManager } from "../ui/toast"; | 17 | 17 | import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip"; | @@ -321,20 +321,18 @@ export const MarkdownFileLink = memo(function MarkdownFileLink({ | 321 | 321 | canOpenInBrowser, | 322 | 322 | canOpenInPanel, | 323 | 323 | }); | 324 | | - const accent = documentIconColorForFileName(iconPath); | 325 | | - const chipStyle = accent ? ({ "--context-chip-accent": accent } as CSSProperties) : undefined; | | 324 | + const chipKind = documentChipKindForFileName(iconPath) ?? "mention"; | 326 | 325 |
| 327 | 326 | return ( | 328 | 327 | <Tooltip> | 329 | 328 | <TooltipTrigger | 330 | 329 | render={ | 331 | 330 | hasPrimaryAction ? ( | 332 | 331 | <ContextChip | 333 | | - kind="mention" | | 332 | + kind={chipKind} | 334 | 333 | dir="ltr" | 335 | 334 | render={<a href={href} />} | 336 | 335 | className={MARKDOWN_FILE_LINK_CLASS_NAME} | 337 | | - style={chipStyle} | 338 | 336 | data-markdown-copy={copyMarkdown} | 339 | 337 | onClick={(event) => { | 340 | 338 | event.preventDefault(); | @@ -360,13 +358,12 @@ export const MarkdownFileLink = memo(function MarkdownFileLink({ | 360 | 358 | </ContextChip> | 361 | 359 | ) : ( | 362 | 360 | <ContextChip | 363 | | - kind="mention" | | 361 | + kind={chipKind} | 364 | 362 | dir="ltr" | 365 | 363 | render={<button type="button" />} | 366 | 364 | aria-label={`File options for ${label}`} | 367 | 365 | aria-haspopup="menu" | 368 | 366 | className={cn(MARKDOWN_FILE_LINK_CLASS_NAME, "select-text")} | 369 | | - style={chipStyle} | 370 | 367 | data-markdown-copy={copyMarkdown} | 371 | 368 | onClick={handleContextMenu} | 372 | 369 | onContextMenu={handleContextMenu} | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/chat/TimelineUserMessageRow.tsx +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -75,6 +75,9 @@ import { | 75 | 75 | import { UserMessageContextReferenceChip } from "./UserMessageContextChips"; | 76 | 76 | import { resolvePreviewAnnotationImage } from "./TimelineUserMessageRow.logic"; | 77 | 77 |
| | 78 | +const BUBBLE_CHIP_CLASS_NAME = | | 79 | + "[&_[data-slot=context-chip]]:[--context-chip-ink:var(--context-chip-message,var(--context-chip-accent))]"; | | 80 | + | 78 | 81 | function UserVideoAttachment({ file }: { readonly file: ChatFileAttachment }) { | 79 | 82 | const ctx = use(TimelineRowCtx); | 80 | 83 | // Row updates rebuild attachment objects, so the asset follows only the | @@ -165,6 +168,7 @@ function AutomationMessageRow({ row }: { row: Extract<TimelineRow, { kind: "mess | 165 | 168 | <div | 166 | 169 | className={cn( | 167 | 170 | "min-w-0 max-w-[80%] rounded-2xl bg-message text-message-foreground", | | 171 | + BUBBLE_CHIP_CLASS_NAME, | 168 | 172 | expanded && "w-full", | 169 | 173 | )} | 170 | 174 | > | @@ -454,6 +458,7 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message" | 454 | 458 | <div | 455 | 459 | className={cn( | 456 | 460 | "relative min-w-0 max-w-[80%] rounded-2xl text-message-foreground", | | 461 | + BUBBLE_CHIP_CLASS_NAME, | 457 | 462 | userMessage.attribution === "guest" ? guestBubbleClassName(false) : "bg-message", | 458 | 463 | !folded && "p-3", | 459 | 464 | folded && expanded && "w-full", | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/chat/UserMessageContextChips.tsx +3-5Lines changed: 3 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -import { documentIconColorForFileName } from "~/pierre-icons"; | | 1 | +import { documentChipKindForFileName } from "~/pierre-icons"; | 2 | 2 | import { isSvgAttachment } from "@t3tools/shared/image"; | 3 | 3 | import { useRenderedAppearance } from "../../hooks/useTheme"; | 4 | 4 | import { PullRequestGlyph } from "../pullRequest/pullRequestIcons"; | 5 | 5 | import { ReadOnlySourcePreview } from "../files/AttachmentFilePreview"; | 6 | 6 | import { useRightPanelStore } from "~/rightPanelStore"; | 7 | 7 | import { COMPOSER_CONTEXT_KINDS } from "@t3tools/contracts"; | 8 | 8 | import { formatAttachmentSize } from "@t3tools/client-runtime/state/attachments"; | 9 | | -import { use, type CSSProperties, type ReactNode } from "react"; | | 9 | +import { use, type ReactNode } from "react"; | 10 | 10 | import { FileDiff } from "@pierre/diffs/react"; | 11 | 11 | import { DiffWorkerPoolProvider } from "../DiffWorkerPoolProvider"; | 12 | 12 | import { | @@ -65,14 +65,12 @@ function UserMessageMentionChip(props: { | 65 | 65 | copyMarkdown: string; | 66 | 66 | }) { | 67 | 67 | const ctx = use(TimelineRowCtx); | 68 | | - const accent = documentIconColorForFileName(props.record.path); | 69 | 68 | return ( | 70 | 69 | <Tooltip> | 71 | 70 | <TooltipTrigger | 72 | 71 | render={ | 73 | 72 | <ContextChip | 74 | | - kind="mention" | 75 | | - style={accent ? ({ "--context-chip-accent": accent } as CSSProperties) : undefined} | | 73 | + kind={documentChipKindForFileName(props.record.path) ?? "mention"} | 76 | 74 | render={<button type="button" />} | 77 | 75 | aria-label={`Preview ${props.record.path}`} | 78 | 76 | data-markdown-copy={props.copyMarkdown} | |
|