The best way to control Claude Code, Codex and more from any computer or phone

main
tsx 61 lines 1.83 KB
Raw
1 import { useGT } from "gt-react";
2 import { useId, useRef, useState, type ComponentProps } from "react";
3
4 import { cn } from "~/lib/utils";
5 import { Button } from "../ui/button";
6 import { PullRequestMarkdown } from "./PullRequestMarkdown";
7 import { observeResize } from "~/lib/observeResize";
8
9 export function PullRequestCommentBody({
10 className,
11 ...props
12 }: ComponentProps<typeof PullRequestMarkdown>) {
13 const gt = useGT();
14 const [expanded, setExpanded] = useState(false);
15 const [overflowing, setOverflowing] = useState(false);
16 const clip = useRef<HTMLDivElement>(null);
17 const id = useId();
18
19 return (
20 <div className={cn("min-w-0", className)}>
21 <div
22 ref={clip}
23 id={id}
24 className={cn("relative", !expanded && "max-h-[240px] overflow-hidden")}
25 onFocusCapture={() => setExpanded(true)}
26 >
27 <div
28 ref={(element) => {
29 if (element === null) return;
30 return observeResize(element, ([entry]) => {
31 if (entry) setOverflowing(entry.contentRect.height > 240);
32 });
33 }}
34 >
35 <PullRequestMarkdown {...props} />
36 </div>
37 {overflowing && !expanded ? (
38 <div
39 aria-hidden
40 className="pointer-events-none absolute inset-x-0 bottom-0 h-10 bg-gradient-to-t from-background to-transparent"
41 />
42 ) : null}
43 </div>
44 {overflowing ? (
45 <Button
46 size="xs"
47 variant="ghost-muted"
48 className="mt-2"
49 aria-expanded={expanded}
50 aria-controls={id}
51 onClick={() => {
52 if (expanded) clip.current?.scrollIntoView({ block: "nearest" });
53 setExpanded(!expanded);
54 }}
55 >
56 {expanded ? gt("Show less") : gt("Show full comment")}
57 </Button>
58 ) : null}
59 </div>
60 );
61 }