@devries-cameron20 / composio Mirror · read-only
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 04:45 UTC

next
tsx 72 lines 1.46 KB
Raw
1 "use client"
2
3 import * as React from "react"
4
5 import { cn } from "@/lib/utils"
6
7 type TerminalBodyScrollProps = {
8 fill?: boolean
9 pinBottom?: boolean
10 stickToBottom?: boolean
11 children: React.ReactNode
12 }
13
14 function pinScrollElement(element: HTMLElement) {
15 element.scrollTop = element.scrollHeight
16 }
17
18 function pinScrollElementSoon(element: HTMLElement) {
19 pinScrollElement(element)
20 requestAnimationFrame(() => {
21 pinScrollElement(element)
22 requestAnimationFrame(() => pinScrollElement(element))
23 })
24 }
25
26 export function TerminalBodyScroll({
27 fill,
28 pinBottom = false,
29 stickToBottom = false,
30 children,
31 }: TerminalBodyScrollProps) {
32 const scrollRef = React.useRef<HTMLDivElement>(null)
33
34 React.useEffect(() => {
35 if (!stickToBottom) return
36
37 const el = scrollRef.current
38 if (!el) return
39
40 const pin = () => pinScrollElementSoon(el)
41
42 pin()
43
44 const observer = new ResizeObserver(pin)
45 observer.observe(el)
46 if (el.firstElementChild) {
47 observer.observe(el.firstElementChild)
48 }
49
50 return () => observer.disconnect()
51 }, [stickToBottom, children])
52
53 return (
54 <div
55 className={cn(
56 "terminal-body-scroll-host",
57 fill && "min-h-0 flex-1 overflow-hidden"
58 )}
59 >
60 <div
61 ref={scrollRef}
62 className={cn(
63 "terminal-body-scroll",
64 fill && "min-h-0 flex-1",
65 pinBottom && "terminal-body-scroll-pin-bottom"
66 )}
67 >
68 {children}
69 </div>
70 </div>
71 )
72 }