Files
t3code/apps/web/src/components/ContextChip.tsx
T
+36 de34391427 feat(orchestrator): introduce new orchestrator (#2829)
Co-authored-by: maria-rcks <[email protected]>
Co-authored-by: Bilal Bakr <[email protected]>
Co-authored-by: shivam <[email protected]>
Co-authored-by: Vitalii Yehorov <[email protected]>
Co-authored-by: Jake Leventhal <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Co-authored-by: Alex Southwell <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Nicholas Wasmiller <[email protected]>
Co-authored-by: PB <[email protected]>
Co-authored-by: Exotic <[email protected]>
Co-authored-by: Yash Singh <[email protected]>
Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Theo Browne <[email protected]>
Co-authored-by: Gabriel De Andrade <[email protected]>
Co-authored-by: Dara Adedeji <[email protected]>
Co-authored-by: scratchyone <[email protected]>
Co-authored-by: Dominic Roy <[email protected]>
Co-authored-by: chukfinley <[email protected]>
Co-authored-by: Primož Ajdišek <[email protected]>
Co-authored-by: benthecarman <[email protected]>
Co-authored-by: NaveDanan <[email protected]>
Co-authored-by: aaditagrawal <[email protected]>
Co-authored-by: Aditya Garud <[email protected]>
Co-authored-by: Nick Anisimov <[email protected]>
Co-authored-by: MacKinley Smith <[email protected]>
Co-authored-by: Yordis Prieto <[email protected]>
Co-authored-by: t3-code[bot] <269035359+t3-code[bot]@users.noreply.github.com>
Co-authored-by: AKolenda <[email protected]>
Co-authored-by: Guillermo Casanova <[email protected]>
Co-authored-by: Otavio Salvador <[email protected]>
Co-authored-by: Shirish Pothi <[email protected]>
Co-authored-by: Ishaan Kothari <[email protected]>
Co-authored-by: Bob Fowler <[email protected]>
Co-authored-by: Anton Bezdenezhnykh <[email protected]>
Co-authored-by: ValeraZSD <[email protected]>
Co-authored-by: Ephraim <[email protected]>
Co-authored-by: Ryan Ilano <[email protected]>
Co-authored-by: Alex <[email protected]>
Co-authored-by: maco <[email protected]>
Co-authored-by: Cursor <[email protected]>
Co-authored-by: Tristan Knight <[email protected]>
Co-authored-by: PR Batch Tester <[email protected]>
Co-authored-by: oliver <[email protected]>
Co-authored-by: kamkm <[email protected]>
Signed-off-by: Yordis Prieto <[email protected]>
2026-10-02 12:22:22 -07:00

134 lines
6.0 KiB
TypeScript

import { mergeProps } from "@base-ui/react/merge-props";
import { useRender } from "@base-ui/react/use-render";
import { cva, type VariantProps } from "class-variance-authority";
import type * as React from "react";
import { cn } from "~/lib/utils";
/**
* The inline pill for one piece of chat context. It lives with the chat components rather than
* in components/ui because it is one feature's look, not a generic primitive.
*
* An inline pill for one piece of context (a file, mention, terminal excerpt, pull request,
* skill…) that sits in running text, both in the composer and in sent messages.
*
* Metrics are in em so the chip scales with the text around it (the composer honors the
* prompt font-size preference). Each kind keeps one restrained color identity: every accent
* shares a lightness so no kind reads heavier than another, and only hue carries identity.
* A consumer may override `--context-chip-accent` through `style` for a color that comes
* from content, such as an image's average color.
*
* Renders a span by default. Render it as a button, link or popover/tooltip trigger to make it
* interactive; the hover tint follows from that, not from a prop. Anything focusable (including a
* span with tabIndex for a tooltip) gets the focus outline.
*/
const contextChipVariants = cva(
"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",
{
defaultVariants: { kind: "neutral" },
variants: {
kind: {
neutral: "border-border/70 bg-accent/40 text-foreground",
image: "[--context-chip-accent:oklch(0.62_0.16_16)]",
video: "[--context-chip-accent:oklch(0.62_0.16_48)]",
file: "[--context-chip-accent:oklch(0.62_0.136_237)]",
mention: "[--context-chip-accent:oklch(0.62_0.11_215)]",
terminal: "[--context-chip-accent:oklch(0.62_0.134_163)]",
element: "[--context-chip-accent:oklch(0.62_0.134_70)]",
"preview-annotation": "[--context-chip-accent:oklch(0.62_0.134_70)]",
"review-comment": "[--context-chip-accent:oklch(0.62_0.16_292)]",
"pull-request": "[--context-chip-accent:oklch(0.62_0.16_277)]",
"pr-open": "[--context-chip-accent:oklch(0.62_0.134_163)]",
"pr-draft": "[--context-chip-accent:oklch(0.62_0.02_259)]",
"pr-merged": "[--context-chip-accent:oklch(0.62_0.16_292)]",
"pr-closed": "[--context-chip-accent:oklch(0.62_0.16_16)]",
skill: "[--context-chip-accent:oklch(0.62_0.16_322)]",
thread: "[--context-chip-accent:oklch(0.62_0.12_190)]",
citation: "[--context-chip-accent:oklch(0.62_0.16_259)]",
},
// Colors live in compoundVariants below so they come after the kind colors.
state: {
unresolved: "border-dashed",
invalid: "",
},
},
compoundVariants: [
{
kind: [
"image",
"video",
"file",
"mention",
"terminal",
"element",
"preview-annotation",
"review-comment",
"pull-request",
"pr-open",
"pr-draft",
"pr-merged",
"pr-closed",
"skill",
"thread",
"citation",
],
className:
"[--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",
},
// State colors win over any kind.
{ state: "unresolved", className: "text-foreground" },
{ state: "invalid", className: "border-destructive/35 bg-destructive/8 text-destructive" },
],
},
);
type ContextChipKind = NonNullable<VariantProps<typeof contextChipVariants>["kind"]>;
interface ContextChipProps extends useRender.ComponentProps<"span"> {
kind?: ContextChipKind;
state?: "unresolved" | "invalid";
}
function ContextChip({ className, kind, state, render, ...props }: ContextChipProps) {
const defaultProps = {
className: cn(contextChipVariants({ kind, state }), className),
"data-slot": "context-chip",
"data-state": state,
};
return useRender({
defaultTagName: "span",
props: mergeProps<"span">(defaultProps, props),
render,
});
}
/** The chip's text. Truncates to the chip's width. */
function ContextChipLabel({ className, ...props }: React.ComponentProps<"span">) {
return (
<span
className={cn("block min-w-0 self-center truncate leading-tight", className)}
data-slot="context-chip-label"
{...props}
/>
);
}
/** An icon action inside a chip, such as editing a citation's comment. Tints with the chip's kind. */
function ContextChipAction({ className, render, ...props }: useRender.ComponentProps<"button">) {
const defaultProps = {
className: cn(
"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-ring motion-reduce:transition-none [&_svg]:size-[0.85em]",
className,
),
"data-slot": "context-chip-action",
type: render ? undefined : ("button" as const),
};
return useRender({
defaultTagName: "button",
props: mergeProps<"button">(defaultProps, props),
render,
});
}
export { ContextChip, ContextChipAction, ContextChipLabel, type ContextChipKind };