A container whose height glides to fit whatever is inside.
Installation
Install the packages
npm install @prequelui/react motion@prequelui/react reuses the primitive library your components already depend on.
Add the component
npx shadcn@latest add https://animate.prequelui.terravidhal.me/r/auto-height.jsonnpx shadcn@latest add https://animate.prequelui.terravidhal.me/r/auto-height.json
Turn on the motion
npx @prequelui/cli@latest animate auto-heightThe CLI finds the component through components.json, swaps the import and removes the CSS animation classes that Motion replaces.
Usage
Import the component and compose it exactly like the primitive it wraps. Motion is enabled by default; the tempo prop scales every duration and softens every spring.
import { AutoHeight } from "@/components/prequelui/effects/auto-height";
export default function Demo() {
const [open, setOpen] = useState(false);
return (
<AutoHeight deps={[open]} className="w-[320px] overflow-hidden rounded-xl border">
<p className="p-4 text-[13px] font-medium">Deployment summary</p>
{open && <p className="px-4 pb-4 text-[13px] text-muted-foreground">…</p>}
</AutoHeight>
);
}import { AutoHeight } from "@/components/prequelui/auto-height";
export function Variant() {
return (
<AutoHeight tempo={1.2}>
…
</AutoHeight>
);
}Animation
The container measures its child instead of guessing at a height. Every time the content, the font metrics or the parent box changes, a ResizeObserver reports the new size and the outer motion element springs to it with overflow hidden.
- Height spring: stiffness 300, damping 30, bounce 0, restDelta 0.01.
- The measured height is rounded to the device pixel ratio so text stays crisp.
- The observer watches the child and the parent box, not only the root.
- Reduced motion applies the new height instantly.
API Reference
Each part accepts the usual HTML props in addition to the motion props below. No accessibility prop is hidden behind the animation layer.
AutoHeight
| Prop | Type | Default |
|---|---|---|
| children | ReactNode | — |
| deps | DependencyList | [] |
| animate | TargetAndTransition | — |
| transition | Transition | component spring or tween |
| asChild | boolean | false |
| className | string | — |
useAutoHeight
| Prop | Type | Default |
|---|---|---|
| deps | DependencyList | [] |
| includeParentBox | boolean | true |
| includeSelfBox | boolean | false |