feat: integrate Radix UI scroll area component and update message list view

This commit is contained in:
Wang Chenxi
2025-04-17 20:36:11 +08:00
parent 211c4af256
commit b06a4a625b
5 changed files with 3621 additions and 2964 deletions

View File

@@ -18,6 +18,7 @@
},
"dependencies": {
"@ant-design/icons": "^6.0.0",
"@radix-ui/react-scroll-area": "^1.2.4",
"@radix-ui/react-slot": "^1.2.0",
"@radix-ui/react-tabs": "^1.1.4",
"@radix-ui/react-tooltip": "^1.2.0",

6516
web/pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -68,7 +68,7 @@ export function MessageListView({
return (
<ScrollContainer
className={cn(
"flex h-full w-full flex-col overflow-y-auto pt-4",
"flex h-full w-full flex-col overflow-hidden pt-4",
className,
)}
scrollShadowColor="#f7f5f3"

View File

@@ -3,6 +3,7 @@
import { useStickToBottom } from "use-stick-to-bottom";
import { ScrollArea } from "~/components/ui/scroll-area";
import { cn } from "~/lib/utils";
export function ScrollContainer({
@@ -47,11 +48,11 @@ export function ScrollContainer({
></div>
</>
)}
<div ref={scrollRef} className={"h-full w-full overflow-y-scroll"}>
<ScrollArea ref={scrollRef} className="h-full w-full">
<div className="h-fit w-full" ref={contentRef}>
{children}
</div>
</div>
</ScrollArea>
</div>
);
}

View File

@@ -0,0 +1,61 @@
"use client";
import * as ScrollAreaPrimitive from "@radix-ui/react-scroll-area";
import * as React from "react";
import { cn } from "~/lib/utils";
function ScrollArea({
className,
children,
ref,
...props
}: React.ComponentProps<typeof ScrollAreaPrimitive.Root>) {
return (
<ScrollAreaPrimitive.Root
data-slot="scroll-area"
className={cn("relative", className)}
{...props}
>
<ScrollAreaPrimitive.Viewport
data-slot="scroll-area-viewport"
className="focus-visible:ring-ring/50 size-full rounded-[inherit] transition-[color,box-shadow] outline-none focus-visible:ring-[3px] focus-visible:outline-1"
// https://github.com/stackblitz-labs/use-stick-to-bottom/issues/15
ref={ref}
>
{children}
</ScrollAreaPrimitive.Viewport>
<ScrollBar />
<ScrollAreaPrimitive.Corner />
</ScrollAreaPrimitive.Root>
);
}
function ScrollBar({
className,
orientation = "vertical",
...props
}: React.ComponentProps<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>) {
return (
<ScrollAreaPrimitive.ScrollAreaScrollbar
data-slot="scroll-area-scrollbar"
orientation={orientation}
className={cn(
"flex touch-none p-px transition-colors select-none",
orientation === "vertical" &&
"h-full w-2.5 border-l border-l-transparent",
orientation === "horizontal" &&
"h-2.5 flex-col border-t border-t-transparent",
className,
)}
{...props}
>
<ScrollAreaPrimitive.ScrollAreaThumb
data-slot="scroll-area-thumb"
className="bg-border relative flex-1 rounded-full"
/>
</ScrollAreaPrimitive.ScrollAreaScrollbar>
);
}
export { ScrollArea, ScrollBar };