2025-04-17 14:26:41 +08:00
|
|
|
// Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
|
2025-04-17 12:02:23 +08:00
|
|
|
import { useStickToBottom } from "use-stick-to-bottom";
|
|
|
|
|
|
2025-04-17 20:36:11 +08:00
|
|
|
import { ScrollArea } from "~/components/ui/scroll-area";
|
2025-04-17 12:02:23 +08:00
|
|
|
import { cn } from "~/lib/utils";
|
|
|
|
|
|
|
|
|
|
export function ScrollContainer({
|
|
|
|
|
className,
|
|
|
|
|
children,
|
|
|
|
|
scrollShadow = true,
|
2025-04-20 11:18:05 +08:00
|
|
|
scrollShadowColor = "var(--background)",
|
2025-04-17 12:02:23 +08:00
|
|
|
}: {
|
|
|
|
|
className?: string;
|
|
|
|
|
children: React.ReactNode;
|
|
|
|
|
scrollShadow?: boolean;
|
|
|
|
|
scrollShadowColor?: string;
|
|
|
|
|
}) {
|
|
|
|
|
const { scrollRef, contentRef } = useStickToBottom({
|
|
|
|
|
initial: "instant",
|
|
|
|
|
});
|
|
|
|
|
return (
|
|
|
|
|
<div className={cn("relative", className)}>
|
|
|
|
|
{scrollShadow && (
|
|
|
|
|
<>
|
|
|
|
|
<div
|
|
|
|
|
className={cn(
|
2025-04-20 11:48:24 +08:00
|
|
|
"absolute top-[-1px] right-0 left-0 z-10 h-10 bg-gradient-to-b",
|
2025-04-17 12:02:23 +08:00
|
|
|
`from-[var(--scroll-shadow-color)] to-transparent`,
|
|
|
|
|
)}
|
|
|
|
|
style={
|
|
|
|
|
{
|
|
|
|
|
"--scroll-shadow-color": scrollShadowColor,
|
|
|
|
|
} as React.CSSProperties
|
|
|
|
|
}
|
|
|
|
|
></div>
|
|
|
|
|
<div
|
|
|
|
|
className={cn(
|
|
|
|
|
"absolute right-0 bottom-0 left-0 z-10 h-10 bg-gradient-to-b",
|
|
|
|
|
`from-transparent to-[var(--scroll-shadow-color)]`,
|
|
|
|
|
)}
|
|
|
|
|
style={
|
|
|
|
|
{
|
|
|
|
|
"--scroll-shadow-color": scrollShadowColor,
|
|
|
|
|
} as React.CSSProperties
|
|
|
|
|
}
|
|
|
|
|
></div>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
2025-04-17 20:36:11 +08:00
|
|
|
<ScrollArea ref={scrollRef} className="h-full w-full">
|
2025-04-17 12:02:23 +08:00
|
|
|
<div className="h-fit w-full" ref={contentRef}>
|
|
|
|
|
{children}
|
|
|
|
|
</div>
|
2025-04-17 20:36:11 +08:00
|
|
|
</ScrollArea>
|
2025-04-17 12:02:23 +08:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|