Text-animated buttons
Five takes on kinetic text: a letter bounce, a wave, a reveal, a flip and a whole-label slide. Each is sized and token-driven; per-letter effects apply to string labels.
Installation
The styled layer is free and installs like any other ai2 component.
Run the following command
npx shadcn@latest add @ai2/buttons-text-animatedDependencies, the @ai2/tokens theme and the component file are installed together.
Install dependencies
npm install motionCopy the source
components/ui/buttons-text-animated.tsx"use client"
import type * as React from "react"
import { motion, useReducedMotion, type HTMLMotionProps, type Variants } from "motion/react"
import { cn } from "@/lib/utils"
/* Text-animated button family: 5 variations on kinetic text. Letter splitting happens only for string children; otherwise it renders plainly. framer-motion parent/child variants plus stagger. All are sized, take colour ONLY from tokens and are static under reduced-motion. */
export type StyledSize = "sm" | "md" | "lg" | "xl"
const sizes: Record<StyledSize, string> = {
sm: "h-8 gap-1.5 rounded-md px-3 text-sm",
md: "h-9 gap-2 rounded-lg px-4 text-sm",
lg: "h-10 gap-2 rounded-lg px-5 text-sm",
xl: "h-12 gap-2.5 rounded-xl px-6 text-base",
}
const base =
"relative inline-flex shrink-0 select-none items-center justify-center overflow-hidden bg-brand font-medium whitespace-nowrap text-brand-foreground outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0 [&_i]:text-base [&_i]:leading-none"
type Props = HTMLMotionProps<"button"> & { size?: StyledSize }
/* Shared: splits string children into per-letter spans that take a variant. */
function Letters({ text, variants }: { text: string; variants: Variants }) {
return (
<>
{text.split("").map((char, i) => (
<motion.span
key={`${char}-${i}`}
variants={variants}
className="inline-block"
style={{ whiteSpace: "pre" }}
>
{char}
</motion.span>
))}
</>
)
}
/* Bounce: the letters bounce upwards in sequence on hover. */
export function BounceTextButton({ className, size = "md", children, ...props }: Props) {
const reduce = useReducedMotion()
const text = typeof children === "string" ? children : null
return (
<motion.button
data-slot="styled-button"
initial="rest"
animate="rest"
whileHover={reduce || !text ? undefined : "hover"}
whileTap={reduce ? undefined : { scale: 0.97 }}
variants={text ? { rest: {}, hover: { transition: { staggerChildren: 0.03 } } } : undefined}
className={cn(base, sizes[size], "gap-0.5", className)}
{...props}
>
{text ? <Letters text={text} variants={{ rest: { y: 0 }, hover: { y: -3 } }} /> : (children as React.ReactNode)}
</motion.button>
)
}
/* Wave: the letters rise and fall in sequence like a wave on hover. */
export function WaveTextButton({ className, size = "md", children, ...props }: Props) {
const reduce = useReducedMotion()
const text = typeof children === "string" ? children : null
return (
<motion.button
data-slot="styled-button"
initial="rest"
animate="rest"
whileHover={reduce || !text ? undefined : "hover"}
whileTap={reduce ? undefined : { scale: 0.97 }}
variants={text ? { rest: {}, hover: { transition: { staggerChildren: 0.06 } } } : undefined}
className={cn(base, sizes[size], "gap-0.5", className)}
{...props}
>
{text ? (
<Letters
text={text}
variants={{ rest: { y: 0 }, hover: { y: [0, -4, 0], transition: { duration: 0.5, ease: "easeInOut" } } }}
/>
) : (
children as React.ReactNode
)}
</motion.button>
)
}
/* Reveal: the letters slide up into place on hover. */
export function RevealTextButton({ className, size = "md", children, ...props }: Props) {
const reduce = useReducedMotion()
const text = typeof children === "string" ? children : null
return (
<motion.button
data-slot="styled-button"
initial="rest"
animate="rest"
whileHover={reduce || !text ? undefined : "hover"}
whileTap={reduce ? undefined : { scale: 0.97 }}
variants={text ? { rest: {}, hover: { transition: { staggerChildren: 0.03 } } } : undefined}
className={cn(base, sizes[size], "gap-0.5", className)}
{...props}
>
{text ? (
<Letters text={text} variants={{ rest: { y: 0, opacity: 1 }, hover: { y: [8, 0], opacity: [0.3, 1] } }} />
) : (
children as React.ReactNode
)}
</motion.button>
)
}
/* Flip: the letters rotate on the X axis in sequence on hover. */
export function FlipTextButton({ className, size = "md", children, ...props }: Props) {
const reduce = useReducedMotion()
const text = typeof children === "string" ? children : null
return (
<motion.button
data-slot="styled-button"
initial="rest"
animate="rest"
whileHover={reduce || !text ? undefined : "hover"}
whileTap={reduce ? undefined : { scale: 0.97 }}
variants={text ? { rest: {}, hover: { transition: { staggerChildren: 0.04 } } } : undefined}
className={cn(base, sizes[size], "gap-0.5", className)}
style={{ transformPerspective: 400 }}
{...props}
>
{text ? (
<Letters text={text} variants={{ rest: { rotateX: 0 }, hover: { rotateX: [0, 360] } }} />
) : (
children as React.ReactNode
)}
</motion.button>
)
}
/* Slide: the label slides up on hover and a copy of the same label comes from below. */
export function SlideTextButton({ className, size = "md", children, ...props }: Props) {
const reduce = useReducedMotion()
return (
<motion.button
data-slot="styled-button"
whileTap={reduce ? undefined : { scale: 0.97 }}
transition={{ type: "spring", stiffness: 400, damping: 20 }}
className={cn(base, sizes[size], "group", className)}
{...props}
>
<span className="pointer-events-none flex items-center gap-2 opacity-0">{children as React.ReactNode}</span>
<span className="absolute inset-0 flex items-center justify-center gap-2 transition-transform duration-(--motion-base) ease-(--motion-ease) group-hover:-translate-y-full motion-reduce:transition-none">
{children as React.ReactNode}
</span>
<span className="absolute inset-0 flex translate-y-full items-center justify-center gap-2 transition-transform duration-(--motion-base) ease-(--motion-ease) group-hover:translate-y-0 motion-reduce:hidden">
{children as React.ReactNode}
</span>
</motion.button>
)
}Manual installs skip the @ai2/tokens theme, so add the token CSS from the theming guide or the tone colors will be missing.
Variations
5 takes on the same idea. Each is its own export, and every one accepts a size prop (sm, md, lg, xl) aligned to the base Button scale.
Bounce
Letters hop up in sequence on hover.
import { BounceTextButton } from "@/components/ui/buttons-text-animated"
<BounceTextButton>Bounce</BounceTextButton>Wave
Letters ripple up and down like a wave on hover.
import { WaveTextButton } from "@/components/ui/buttons-text-animated"
<WaveTextButton>Wave</WaveTextButton>Reveal
Letters slide up into place in sequence on hover.
import { RevealTextButton } from "@/components/ui/buttons-text-animated"
<RevealTextButton>Reveal</RevealTextButton>Flip
Letters flip on the X axis in sequence on hover.
import { FlipTextButton } from "@/components/ui/buttons-text-animated"
<FlipTextButton>Flip</FlipTextButton>Slide
The whole label slides up and a copy rises in from below.
import { SlideTextButton } from "@/components/ui/buttons-text-animated"
<SlideTextButton>Slide</SlideTextButton>ai2 Text-animated buttons: 5 styled variations on the token system
The ai2 Text-animated buttons are a set of 5 decorative button variations from the styled layer of the @ai2 design system, built around kinetic labels. They are free and MIT licensed, and every color comes from a semantic token, so they theme with the rest of ai2 in light and dark.
Motion runs on framer-motion: framer-motion staggers per-letter motion for the bounce, wave, reveal and flip, and slides the label for the slide. The styled layer is opt-in, so the dependency only lands if you use it; the base components stay lean. Under reduced motion, the letters stay put and the labels do not animate.
What is in the ai2 Text-animated buttons?
5 exports in one file: Bounce, Wave, Reveal, Flip and Slide. Each renders a native button and takes a size prop (sm, md, lg, xl) aligned to the base Button. They are separate from the base Button on purpose: the base keeps its clean variant, tone and size axes, while the styled layer carries the effects.
You own the file. Copy the one category file and you have all 5 variations, with no runtime dependency on ai2 itself.
Why use it
- On-system by construction: Every color resolves to an ai2 semantic token, so the buttons follow your theme in light and dark with no extra work.
- Effect without the sprawl: The decorations live in a dedicated styled file, so the base Button keeps its clean, predictable API.
- Accessible and honest: Each renders a real button element, keeps a visible focus ring, and respects prefers-reduced-motion.
Features
- Token-driven color: No hardcoded hex or oklch; the look recolors with your theme tokens.
- framer-motion: framer-motion staggers per-letter motion for the bounce, wave, reveal and flip, and slides the label for the slide.
- Reduced-motion aware: Under prefers-reduced-motion, the letters stay put and the labels do not animate.
- Size aligned to the base: Every variation takes sm, md, lg and xl matching the base Button height scale, so styled and base buttons line up in a row.
Production tips
- Use it for emphasis, not everywhere: Styled buttons draw the eye. Reserve them for the one action you want people to take on a screen, and use the base Button for the rest.
- Keep labels as verbs: The decoration adds weight, so a clear action label keeps the button scannable.
- Pick one variation per surface: The variations share a family; using two different ones in the same view competes for attention.
Works with the rest of ai2
The Text-animated buttons sit alongside the base Button and the rest of the @ai2 registry. They share the same token file, so a styled action next to a base button or a badge stays visually consistent in both modes.