Primitives
AutoHeight
Wrapper component that automatically animates height changes when content updates.
AutoHeight
A wrapper component that automatically measures and animates height changes when its content updates, creating smooth expand/collapse transitions.
Import
import { AutoHeight } from '@mks2508/mks-ui/react';Basic Usage
Basic Usage
.tsx
<AutoHeight className="border border-white/10 rounded-lg p-4">
<p className="mb-2">This content animates smoothly.</p>
<p>Add or remove content to see the height transition.</p>
</AutoHeight>How It Works
AutoHeightwraps your dynamic content- It uses
ResizeObserverinternally (viauseAutoHeighthook) - When children change size, the wrapper animates to the new height
- The animation uses Motion for smooth spring-based transitions
With Transition
Customize the animation transition:
<AutoHeight transition={{ duration: 0.5, ease: 'easeInOut' }}>
{/* Content with longer transition */}
</AutoHeight>With Dependencies
Re-measure height when specific values change:
const [items, setItems] = useState([]);
<AutoHeight deps={[items.length]}>
{items.map(item => <div key={item.id}>{item.name}</div>)}
</AutoHeight>API Reference
| Prop | Type | Default | Description |
|---|---|---|---|
transition | Transition | { duration: 0.3, ease: 'easeInOut' } | Motion transition config |
deps | unknown[] | [] | Dependencies that trigger re-measure |
className | string | — | Additional CSS classes |
children | ReactNode | — | Content to wrap |