A shared background that slides to the active item.
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/highlight.jsonnpx shadcn@latest add https://animate.prequelui.terravidhal.me/r/highlight.json
Turn on the motion
npx @prequelui/cli@latest animate highlightThe 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 { Highlight, HighlightItem } from "@/components/prequelui/effects/highlight";
export default function Demo() {
return (
<Highlight hover defaultValue="Weekly" className="inline-flex rounded-xl bg-accent p-1">
{["Daily", "Weekly", "Monthly"].map((item) => (
<HighlightItem key={item} value={item} className="rounded-lg px-4 py-2 text-[13px]">
{item}
</HighlightItem>
))}
</Highlight>
);
}import { Highlight } from "@/components/prequelui/highlight";
export function Variant() {
return (
<Highlight tempo={1.2}>
…
</Highlight>
);
}Animation
One background element is shared by every item in the group. When the active value changes, the background is re-parented to the new item and a layout animation carries its position, width and height across, so it glides instead of blinking.
- Highlight spring: stiffness 500, damping 40.
- Both hover and click can drive the value; hover is ignored on touch pointers.
- The value can be controlled, uncontrolled or changed from outside.
- Reduced motion moves the surface instantly and keeps the colour change.
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.
Highlight
| Prop | Type | Default |
|---|---|---|
| value | string | null | — |
| defaultValue | string | null | null |
| onValueChange | (value: string | null) => void | — |
| hover | boolean | false |
| click | boolean | true |
| disabled | boolean | false |
| activeClassName | string | "bg-background shadow-sm" |
| transition | Transition | component spring or tween |
| className | string | — |
HighlightItem
| Prop | Type | Default |
|---|---|---|
| value | string | — |
| children | ReactNode | — |
| disabled | boolean | false |
| activeClassName | string | — |
| className | string | — |