resizable.tsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. "use client"
  2. import * as React from "react"
  3. import { GripVerticalIcon } from "lucide-react"
  4. import * as ResizablePrimitive from "react-resizable-panels"
  5. import { cn } from "@/lib/utils"
  6. function ResizablePanelGroup({
  7. className,
  8. ...props
  9. }: React.ComponentProps<typeof ResizablePrimitive.PanelGroup>) {
  10. return (
  11. <ResizablePrimitive.PanelGroup
  12. data-slot="resizable-panel-group"
  13. className={cn(
  14. "flex h-full w-full data-[panel-group-direction=vertical]:flex-col",
  15. className
  16. )}
  17. {...props}
  18. />
  19. )
  20. }
  21. function ResizablePanel({
  22. ...props
  23. }: React.ComponentProps<typeof ResizablePrimitive.Panel>) {
  24. return <ResizablePrimitive.Panel data-slot="resizable-panel" {...props} />
  25. }
  26. function ResizableHandle({
  27. withHandle,
  28. className,
  29. ...props
  30. }: React.ComponentProps<typeof ResizablePrimitive.PanelResizeHandle> & {
  31. withHandle?: boolean
  32. }) {
  33. return (
  34. <ResizablePrimitive.PanelResizeHandle
  35. data-slot="resizable-handle"
  36. className={cn(
  37. "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",
  38. className
  39. )}
  40. {...props}
  41. >
  42. {withHandle && (
  43. <div className="bg-border z-10 flex h-4 w-3 items-center justify-center rounded-xs border">
  44. <GripVerticalIcon className="size-2.5" />
  45. </div>
  46. )}
  47. </ResizablePrimitive.PanelResizeHandle>
  48. )
  49. }
  50. export { ResizablePanelGroup, ResizablePanel, ResizableHandle }