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 21, 04:45 UTC
| 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 | const contextChipVariants = cva( |
| 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-message-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 | { |
| 11 | defaultVariants: { kind: "neutral" }, |
| 12 | variants: { |
| 13 | kind: { |
| 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 | model: "[--context-chip-accent:var(--context-chip-model)]", |
| 30 | thread: "[--context-chip-accent:var(--context-chip-thread)]", |
| 31 | environment: "[--context-chip-accent:var(--context-chip-environment)]", |
| 32 | citation: "[--context-chip-accent:var(--context-chip-citation)]", |
| 33 | // PDF red reads as the invalid state, so only the icon carries it. |
| 34 | "doc-pdf": |
| 35 | "[--context-chip-accent:var(--context-chip-doc-pdf)] [--context-chip-ink:var(--context-chip-message-ink,currentColor)] [--document-icon-stroke:var(--context-chip-message-ink,var(--context-chip-accent))]", |
| 36 | "doc-word": "[--context-chip-accent:var(--context-chip-doc-word)]", |
| 37 | "doc-spreadsheet": "[--context-chip-accent:var(--context-chip-doc-spreadsheet)]", |
| 38 | "doc-slides": "[--context-chip-accent:var(--context-chip-doc-slides)]", |
| 39 | "doc-epub": "[--context-chip-accent:var(--context-chip-doc-epub)]", |
| 40 | }, |
| 41 | shape: { |
| 42 | inline: "", |
| 43 | bubble: "w-64 gap-2 rounded-2xl bg-message px-3 py-2 text-sm text-message-foreground", |
| 44 | }, |
| 45 | state: { |
| 46 | unresolved: "data-[state=unresolved]:[--context-chip-accent:currentColor]", |
| 47 | invalid: |
| 48 | "data-[state=invalid]:[--context-chip-accent:var(--context-chip-invalid,var(--destructive-foreground))] data-[state=invalid]:[--context-chip-ink:var(--context-chip-message-ink,var(--context-chip-accent))]", |
| 49 | }, |
| 50 | }, |
| 51 | }, |
| 52 | ); |
| 53 | |
| 54 | type ContextChipKind = NonNullable<VariantProps<typeof contextChipVariants>["kind"]>; |
| 55 | |
| 56 | interface ContextChipProps extends useRender.ComponentProps<"span"> { |
| 57 | kind?: ContextChipKind; |
| 58 | state?: "unresolved" | "invalid"; |
| 59 | shape?: "inline" | "bubble"; |
| 60 | } |
| 61 | |
| 62 | function ContextChip({ className, kind, state, shape, render, ...props }: ContextChipProps) { |
| 63 | const defaultProps = { |
| 64 | className: cn(contextChipVariants({ kind, state, shape }), className), |
| 65 | "data-slot": "context-chip", |
| 66 | "data-state": state, |
| 67 | }; |
| 68 | return useRender({ |
| 69 | defaultTagName: "span", |
| 70 | props: mergeProps<"span">(defaultProps, props), |
| 71 | render, |
| 72 | }); |
| 73 | } |
| 74 | |
| 75 | function ContextChipLabel({ className, ...props }: React.ComponentProps<"span">) { |
| 76 | return ( |
| 77 | <span |
| 78 | className={cn( |
| 79 | "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", |
| 80 | className, |
| 81 | )} |
| 82 | data-slot="context-chip-label" |
| 83 | {...props} |
| 84 | /> |
| 85 | ); |
| 86 | } |
| 87 | |
| 88 | function ContextChipAction({ className, render, ...props }: useRender.ComponentProps<"button">) { |
| 89 | const defaultProps = { |
| 90 | className: cn( |
| 91 | "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]", |
| 92 | className, |
| 93 | ), |
| 94 | "data-slot": "context-chip-action", |
| 95 | type: render ? undefined : ("button" as const), |
| 96 | }; |
| 97 | return useRender({ |
| 98 | defaultTagName: "button", |
| 99 | props: mergeProps<"button">(defaultProps, props), |
| 100 | render, |
| 101 | }); |
| 102 | } |
| 103 | |
| 104 | export { ContextChip, ContextChipAction, ContextChipLabel, type ContextChipKind }; |