|
| 1 | +"use client" |
| 2 | + |
| 3 | +import { GripVerticalIcon } from "lucide-react" |
| 4 | +import type { GroupProps, PanelProps, SeparatorProps } from "react-resizable-panels" |
| 5 | +import { Group, Panel, Separator } from "react-resizable-panels" |
| 6 | + |
| 7 | +import { cn } from "@/lib/utils" |
| 8 | + |
| 9 | +// Map 'direction' prop to 'orientation' for backward compatibility |
| 10 | +type ResizablePanelGroupProps = Omit<GroupProps, 'orientation'> & { |
| 11 | + direction?: 'horizontal' | 'vertical' |
| 12 | +} |
| 13 | + |
| 14 | +function ResizablePanelGroup({ |
| 15 | + className, |
| 16 | + direction = 'horizontal', |
| 17 | + ...props |
| 18 | +}: ResizablePanelGroupProps) { |
| 19 | + return ( |
| 20 | + <Group |
| 21 | + data-slot="resizable-panel-group" |
| 22 | + data-panel-group-direction={direction} |
| 23 | + orientation={direction} |
| 24 | + className={cn( |
| 25 | + "flex h-full w-full data-[panel-group-direction=vertical]:flex-col", |
| 26 | + className |
| 27 | + )} |
| 28 | + {...props} |
| 29 | + /> |
| 30 | + ) |
| 31 | +} |
| 32 | + |
| 33 | +function ResizablePanel({ |
| 34 | + className, |
| 35 | + ...props |
| 36 | +}: PanelProps & { className?: string }) { |
| 37 | + return <Panel data-slot="resizable-panel" className={className} {...props} /> |
| 38 | +} |
| 39 | + |
| 40 | +function ResizableHandle({ |
| 41 | + withHandle, |
| 42 | + className, |
| 43 | + ...props |
| 44 | +}: SeparatorProps & { |
| 45 | + withHandle?: boolean |
| 46 | +}) { |
| 47 | + return ( |
| 48 | + <Separator |
| 49 | + data-slot="resizable-handle" |
| 50 | + className={cn( |
| 51 | + "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-[panel-group-direction=vertical]:h-px data-[panel-group-direction=vertical]:w-full data-[panel-group-direction=vertical]:after:left-0 data-[panel-group-direction=vertical]:after:h-1 data-[panel-group-direction=vertical]:after:w-full data-[panel-group-direction=vertical]:after:translate-x-0 data-[panel-group-direction=vertical]:after:-translate-y-1/2 [&[data-panel-group-direction=vertical]>div]:rotate-90", |
| 52 | + className |
| 53 | + )} |
| 54 | + {...props} |
| 55 | + > |
| 56 | + {withHandle && ( |
| 57 | + <div className="bg-border z-10 flex h-4 w-3 items-center justify-center rounded-xs border"> |
| 58 | + <GripVerticalIcon className="size-2.5" /> |
| 59 | + </div> |
| 60 | + )} |
| 61 | + </Separator> |
| 62 | + ) |
| 63 | +} |
| 64 | + |
| 65 | +export { ResizableHandle, ResizablePanel, ResizablePanelGroup } |
| 66 | + |
0 commit comments