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>
  );
}

Install

Add it with the shadcn CLI, or copy the source manually.

$ bunx --bun shadcn add @beui/action-swap-cascade

API Reference

ActionSwapCascadeButton

defaultValue?
string

The initial item id when uncontrolled. Default: the first item.

Default—
className?
string

Classes merged onto the root element.

Default—
size?
"sm" | "md" | "lg" | "icon"

Button height and padding. Default: "md"

Default—
value?
string

The id of the shown item, for controlled use.

Default—
items
ActionSwapItem[]

States the button steps through, each with a label and optional icon.

Default—
onValueChange?
((value: string, item: ActionSwapItem) => void)

Called with the next item's id and the item when a press advances it.

Default—
variant?
"outline" | "ghost" | "primary" | "secondary"

Visual style of the button. Default: "secondary"

Default—
iconOnly?
boolean

Show only the icon and use the label as the accessible name. Default: true for size "icon"

Default—
cycle?
boolean

Advance to the next item on each press, wrapping at the end. Default: true

Default—

ActionSwapCascadeText

className?
string

Classes merged onto the root element.

Default—
value
string

Key for the current text; a new value plays the swap.

Default—

ActionSwapCascadeIcon

className?
string

Classes merged onto the root element.

Default—
value
string

Key for the current icon; a new value plays the swap.

Default—

More in Action Swap

Updated