---
title: "Roll Action Swap"
description: "Free React action swap: the next button label or icon rolls up from below with a blur as the old one leaves. For send and save states. shadcn install."
category: "Components"
parent: "https://beui.dev/components/motion/action-swap"
publishedAt: "2026-06-10"
updatedAt: "2026-10-18"
documentation: "https://beui.dev/components/motion/action-swap/roll"
markdown: "https://beui.dev/components/motion/action-swap/roll.md"
license: "MIT"
---

# Roll Action Swap

> Free React action swap: the next button label or icon rolls up from below with a blur as the old one leaves. For send and save states. shadcn install.

## Install

```bash
npx shadcn@latest add @beui/action-swap-roll
```

## Dependencies

- `clsx`
- `lucide-react`
- `motion`
- `react`
- `tailwind-merge`

## Usage

### Roll usage

The next text or icon rolls in from below with blur.

```tsx
"use client";

import { Moon, Send, Sparkles, Sun } from "lucide-react";
import { useState } from "react";
import {
  type ActionSwapItem,
  ActionSwapRollButton,
} from "@/components/motion/action-swap-roll";

const TEXT_ITEMS: ActionSwapItem[] = [
  { id: "idle", label: "Save" },
  { id: "done", label: "Saved" },
];

const ICON_ITEMS: ActionSwapItem[] = [
  {
    id: "light",
    label: "Light",
    icon: <Sun className="h-4 w-4" />,
    ariaLabel: "Use light theme",
  },
  {
    id: "dark",
    label: "Dark",
    icon: <Moon className="h-4 w-4" />,
    ariaLabel: "Use dark theme",
  },
];

const CTA_ITEMS: ActionSwapItem[] = [
  {
    id: "send",
    label: "Send invite",
    icon: <Send className="h-4 w-4" />,
    ariaLabel: "Send invite",
  },
  {
    id: "sent",
    label: "Invite sent",
    icon: <Sparkles className="h-4 w-4" />,
    ariaLabel: "Invite sent",
  },
];

export function ActionSwapRollPreview() {
  const [textValue, setTextValue] = useState(TEXT_ITEMS[0]?.id);
  const [iconValue, setIconValue] = useState(ICON_ITEMS[0]?.id);
  const [ctaValue, setCtaValue] = useState(CTA_ITEMS[0]?.id);

  return (
    <div className="flex flex-wrap items-center justify-center gap-3">
      <ActionSwapRollButton
        items={TEXT_ITEMS}
        value={textValue}
        onValueChange={setTextValue}
        variant="secondary"
      />
      <ActionSwapRollButton
        items={ICON_ITEMS}
        value={iconValue}
        onValueChange={setIconValue}
        variant="outline"
        size="icon"
        iconOnly
      />
      <ActionSwapRollButton
        items={CTA_ITEMS}
        value={ctaValue}
        onValueChange={setCtaValue}
        variant="primary"
      />
    </div>
  );
}
```

## API Reference

### ActionSwapRollButton

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `className` | `string` | — | No | Classes merged onto the root element. |
| `defaultValue` | `string` | — | No | The initial item id when uncontrolled. Default: the first item. |
| `value` | `string` | — | No | The id of the shown item, for controlled use. |
| `size` | `"sm" \| "md" \| "lg" \| "icon"` | — | No | Button height and padding. Default: "md" |
| `onValueChange` | `((value: string, item: ActionSwapItem) => void)` | — | No | Called with the next item's id and the item when a press advances it. |
| `variant` | `"outline" \| "primary" \| "secondary" \| "ghost"` | — | No | Visual style of the button. Default: "secondary" |
| `items` | `ActionSwapItem[]` | — | Yes | States the button steps through, each with a label and optional icon. |
| `iconOnly` | `boolean` | — | No | Show only the icon and use the label as the accessible name. Default: true for size "icon" |
| `cycle` | `boolean` | — | No | Advance to the next item on each press, wrapping at the end. Default: true |

### ActionSwapRollText

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `className` | `string` | — | No | Classes merged onto the root element. |
| `value` | `string` | — | Yes | Key for the current text; a new value plays the swap. |

### ActionSwapRollIcon

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `className` | `string` | — | No | Classes merged onto the root element. |
| `value` | `string` | — | Yes | Key for the current icon; a new value plays the swap. |

## Types

### ActionSwapItem

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | `string` | Yes | Unique key, used as the button's value. |
| `label` | `ReactNode` | Yes | Text shown on the button while this item is active. Hidden when `iconOnly`. |
| `icon` | `ReactNode` | No | Icon shown before the label while this item is active. |
| `ariaLabel` | `string` | No | Accessible name while active. Falls back to a string label when `iconOnly`. |

## More in Action Swap

- [Cascade Action Swap](https://beui.dev/components/motion/action-swap/cascade.md)
- [Blur Action Swap](https://beui.dev/components/motion/action-swap/blur.md)

## Source

- Registry detail: https://beui.dev/r/action-swap-roll
- Raw source: https://beui.dev/r/action-swap-roll/raw
- GitHub: https://github.com/starc007/ui-components
