resizable.tsx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. "use client";
  2. import * as React from "react";
  3. import { GripVerticalIcon } from "lucide-react";
  4. import { Group, Panel, Separator } from "react-resizable-panels";
  5. import { cn } from "@/lib/utils";
  6. function ResizablePanelGroup({
  7. className,
  8. ...props
  9. }: React.ComponentProps<typeof Group>) {
  10. return (
  11. <Group
  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({ ...props }: React.ComponentProps<typeof Panel>) {
  22. return <Panel data-slot="resizable-panel" {...props} />;
  23. }
  24. function ResizableHandle({
  25. withHandle,
  26. className,
  27. ...props
  28. }: React.ComponentProps<typeof Separator> & {
  29. withHandle?: boolean;
  30. }) {
  31. return (
  32. <Separator
  33. data-slot="resizable-handle"
  34. className={cn(
  35. "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",
  36. className,
  37. )}
  38. {...props}
  39. >
  40. {withHandle && (
  41. <div className="bg-border z-10 flex h-4 w-3 items-center justify-center rounded-xs border">
  42. <GripVerticalIcon className="size-2.5" />
  43. </div>
  44. )}
  45. </Separator>
  46. );
  47. }
  48. export { ResizablePanelGroup, ResizablePanel, ResizableHandle };