Components/AI

Resizable Separator

Interactive resizable separator component for managing layout space between elements

Live Preview
Open in
image part 1
image part 2

Example

import { useRef, useState } from 'react'
import ResizableSeparator from '@/components/LY UI/AI/resizableSeparator'

export default function ResizableSeparatorExample() {
  const containerRef = useRef<HTMLDivElement>(null)
  const [leftWidth, setLeftWidth] = useState(300)
  const [rightWidth, setRightWidth] = useState(400)

  const handleResize = (newSize: number) => {
    setLeftWidth(newSize)
    setRightWidth(containerRef.current ? containerRef.current.offsetWidth - newSize - 8 : 400)
  }

  return (
    <div 
      ref={containerRef}
      className="flex h-96 w-full border rounded-lg overflow-hidden"
    >
      {/* Left Panel */}
      <div 
        className="bg-neutral-50 dark:bg-neutral-800 p-4"
        style={{ width: leftWidth }}
      >
        <h3 className="font-semibold mb-2">Left Panel</h3>
        <p className="text-sm text-neutral-600 dark:text-neutral-300">
          This panel can be resized by dragging the separator. 
          The content adjusts automatically to the new size.
        </p>
      </div>

      {/* Resizable Separator */}
      <ResizableSeparator
        direction="vertical"
        variant="outline"
        size="medium"
        onResize={handleResize}
        minSize={150}
        maxSize={500}
        parentRef={containerRef}
        showIndicator={true}
        animated={true}
        className="bg-neutral-200 dark:bg-neutral-600"
      />

      {/* Right Panel */}
      <div 
        className="bg-neutral-50 dark:bg-neutral-800 p-4 flex-1"
        style={{ width: rightWidth }}
      >
        <h3 className="font-semibold mb-2">Right Panel</h3>
        <p className="text-sm text-neutral-600 dark:text-neutral-300">
          This panel automatically adjusts its width based on the separator position.
          The layout remains responsive and functional.
        </p>
      </div>
    </div>
  )
}

Documentation

PropTypeDefaultDescription
direction"vertical" | "horizontal""vertical"Direction of the separator
variant"ghost" | "outline""ghost"Visual style variant
size"small" | "medium" | "large""medium"Size of the separator
onResize(size: number) => voidrequiredCallback when size changes
minSizenumber100Minimum size in pixels
maxSizenumber600Maximum size in pixels
classNamestringundefinedAdditional CSS classes for styling
parentRefRefObject<HTMLElement>requiredReference to parent element
showIndicatorbooleanfalseWhether to show visual indicator
animatedbooleantrueEnable animations
zIndexnumber20Z-index of the separator

Types

type ResizableSeparatorDirection = "vertical" | "horizontal"
type ResizableSeparatorVariant = "ghost" | "outline"
type ResizableSeparatorSize = "small" | "medium" | "large"

interface ResizableSeparatorProps {
  direction?: ResizableSeparatorDirection
  variant?: ResizableSeparatorVariant
  size?: ResizableSeparatorSize
  onResize: (size: number) => void
  minSize?: number
  maxSize?: number
  className?: string
  parentRef: RefObject<HTMLElement | null>
  showIndicator?: boolean
  animated?: boolean
  zIndex?: number
}

Features

  • Bidirectional Resizing: Support for both vertical and horizontal resizing
  • Size Constraints: Configurable minimum and maximum size limits
  • Visual Variants: Ghost and outline styles for different use cases
  • Size Options: Small, medium, and large separator sizes
  • Visual Indicator: Optional drag handle indicator
  • Touch Support: Full touch device compatibility
  • Responsive Design: Adapts to different screen sizes and orientations
  • Dark Mode Support: Full dark mode compatibility with appropriate styling
  • Accessibility Focused: Proper ARIA labels and keyboard navigation support