Cascade Action Swap
Button labels that change letter by letter, old ones dropping as new land.
Preview
"use client";
import { Check, Copy } from "lucide-react";
import {
ActionSwapCascadeButton,
type ActionSwapItem,
} from "@/components/motion/action-swap-cascade";
const CTA_ITEMS: ActionSwapItem[] = [
{
id: "copy",
label: "Copy link",
icon: <Copy className="h-4 w-4" />,
ariaLabel: "Copy link",
},
{
id: "copied",
label: "Copied!",
icon: <Check className="h-4 w-4" />,
ariaLabel: "Copied",
},
];
export function ActionSwapCascadePreview() {
return (
<div className="flex w-full justify-center">
<ActionSwapCascadeButton items={CTA_ITEMS} variant="primary" />
</div>
);
}
components/motion/action-swap-cascade.tsx
34 lines"use client";
// beui.dev/components/motion/action-swap/cascade
import {
ActionSwapButton,
ActionSwapIcon,
ActionSwapText,
type ActionSwapButtonProps,
type ActionSwapIconProps,
type ActionSwapTextProps,
} from "./action-swap";
export type {
ActionSwapButtonSize,
ActionSwapButtonVariant,
ActionSwapItem,
} from "./action-swap";
export type ActionSwapCascadeButtonProps = Omit<ActionSwapButtonProps, "animation">;
export type ActionSwapCascadeTextProps = Omit<ActionSwapTextProps, "animation">;
export type ActionSwapCascadeIconProps = Omit<ActionSwapIconProps, "animation">;
export function ActionSwapCascadeButton(props: ActionSwapCascadeButtonProps) {
return <ActionSwapButton {...props} animation="cascade" />;
}
export function ActionSwapCascadeText(props: ActionSwapCascadeTextProps) {
return <ActionSwapText {...props} animation="cascade" />;
}
export function ActionSwapCascadeIcon(props: ActionSwapCascadeIconProps) {
return <ActionSwapIcon {...props} animation="cascade" />;
}
Add it with the shadcn CLI, or copy the source manually.
npx shadcn add https://beui.dev/r/theme.json. Theme setupInstall dependencies
npm i clsx lucide-react motion tailwind-mergeAdd 4 files
Put each file at the same path in your project. Read or copy them one at a time in the Code tab above.
- components/motion/action-swap-cascade.tsx34
- components/motion/action-swap.tsx395
- lib/ease.ts68
- lib/utils.ts7
defaultValue?stringThe initial item id when uncontrolled. Default: the first item.
className?stringClasses merged onto the root element.
size?"sm" | "md" | "lg" | "icon"Button height and padding. Default: "md"
value?stringThe id of the shown item, for controlled use.
itemsActionSwapItem[]States the button steps through, each with a label and optional icon.
onValueChange?((value: string, item: ActionSwapItem) => void)Called with the next item's id and the item when a press advances it.
variant?"outline" | "ghost" | "primary" | "secondary"Visual style of the button. Default: "secondary"
iconOnly?booleanShow only the icon and use the label as the accessible name. Default: true for size "icon"
cycle?booleanAdvance to the next item on each press, wrapping at the end. Default: true
className?stringClasses merged onto the root element.
valuestringKey for the current text; a new value plays the swap.
Text Animation
Animated text primitives for spring reveals, chromatic sweeps, shimmer loading states, letter-cascade swaps and character scrambles.
Number Animation
Animated number primitives for count-up values, rolling tickers, and fixed-slot digit swaps.
Animated Badge
Status badge with animated state icons, pulse feedback and compact size variants.
Updated