Components/AI
Resizable Separator
Interactive resizable separator component for managing layout space between elements
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
Prop | Type | Default | Description |
---|---|---|---|
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) => void | required | Callback when size changes |
minSize | number | 100 | Minimum size in pixels |
maxSize | number | 600 | Maximum size in pixels |
className | string | undefined | Additional CSS classes for styling |
parentRef | RefObject<HTMLElement> | required | Reference to parent element |
showIndicator | boolean | false | Whether to show visual indicator |
animated | boolean | true | Enable animations |
zIndex | number | 20 | Z-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