Sliding Text

Text slides out of its box while a copy slides in.

sliding-text.tsx

Installation

1

Install the packages

npm install @prequelui/react motion

@prequelui/react reuses the primitive library your components already depend on.

2

Add the component

npx shadcn@latest add https://animate.prequelui.terravidhal.me/r/sliding-text.json

npx shadcn@latest add https://animate.prequelui.terravidhal.me/r/sliding-text.json

3

Turn on the motion

npx @prequelui/cli@latest animate sliding-text

The 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.

sliding-text.tsx
import { SlidingText } from "@/components/prequelui/sliding-text";

export default function Demo() {
  return (
    <button className="rounded-lg bg-accent px-5 py-2 text-[15px] font-medium">
      <SlidingText text="Read the story" />
    </button>
  );
}
import { SlidingText } from "@/components/prequelui/sliding-text";

export function Variant() {
  return (
    <SlidingText tempo={1.2}>
      …
    </SlidingText>
  );
}

Animation

The label and an identical copy sit in a clipped box. Hovering slides both by exactly one line plus a 0.6 em gap, so the copy lands where the original was; the motion is a single continuous value that can be interrupted at any time.

  • Slide: 250 ms with a fill curve, on a retargetable motion value.
  • Gap between the two copies: 0.6 em; bleed: 0.25 em.
  • Inside a link or a button, the whole host drives the slide.
  • Reduced motion jumps between the two positions.
250 ms fillgap 0.6 emcontinuous valuehost aware

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.

SlidingText

PropTypeDefault
textstring—
direction"up" | "down""down"
trigger"hover" | "click""hover"
transitionTransitioncomponent spring or tween

Built by Vidhal. The source is available on GitHub.

Last updated: 11/17/2026