shadcn Resizeable组件因为react-resizable-panels v4.0.15,API 已变更导致失效报错 #9214
JG1848244690
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
项目使用的是 react-resizable-panels v4.0.15,API 已变更
shadcn/ui 的 resizable 组件仍使用旧 API(PanelGroup、PanelResizeHandle)
新 API 使用 Group、Separator,属性名从 direction 改为 orientation
已完成的修复:
更新了 resizable.tsx:
将 PanelGroup 改为 Group
将 PanelResizeHandle 改为 Separator
将 data-[panel-group-direction=vertical] 改为 data-[orientation=vertical]
使用命名导入而不是命名空间导入
`"use client"
import * as React from "react"
import { GripVerticalIcon } from "lucide-react"
import { Group, Panel, Separator } from "react-resizable-panels"
import { cn } from "@/lib/utils"
function ResizablePanelGroup({
className,
...props
}: React.ComponentProps) {
return (
<Group
data-slot="resizable-panel-group"
className={cn(
"flex h-full w-full data-[orientation=vertical]:flex-col",
className
)}
{...props}
/>
)
}
function ResizablePanel({
...props
}: React.ComponentProps) {
return <Panel data-slot="resizable-panel" {...props} />
}
function ResizableHandle({
withHandle,
className,
...props
}: React.ComponentProps & {
withHandle?: boolean
}) {
return (
<Separator
data-slot="resizable-handle"
className={cn(
"bg-border focus-visible:ring-ring relative flex w-px items-center justify-center after:absolute after:inset-y-0 after:left-1/2 after:w-1 after:-translate-x-1/2 focus-visible:ring-1 focus-visible:ring-offset-1 focus-visible:outline-hidden data-[orientation=vertical]:h-px data-[orientation=vertical]:w-full data-[orientation=vertical]:after:left-0 data-[orientation=vertical]:after:h-1 data-[orientation=vertical]:after:w-full data-[orientation=vertical]:after:translate-x-0 data-[orientation=vertical]:after:-translate-y-1/2 [&[data-orientation=vertical]>div]:rotate-90",
className
)}
{...props}
>
{withHandle && (
)}
)
}
export { ResizablePanelGroup, ResizablePanel, ResizableHandle }
`
Beta Was this translation helpful? Give feedback.
All reactions