resizable.tsx 1.8 KB

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