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