Action swap
A button that cycles through a few labelled states, swapping label and icon in place.
48 postsBerlin · joined 2023
When to use
- Copy to Copied, or Follow to Following, where the next state is the result.
- A control that steps through a short list of modes.
When not to use
- The states are unrelated actions; use separate buttons.
Installation
terminal
pnpm dlx shadcn@latest add @caliper/action-swap
Adds its 3 files to components/ui/, each with its own stylesheet, and installs their packages. Pro installs with your access token, set up once per project. See Pro access. The first part also adds Caliper UI’s tokens; import them once as in Installation.
API reference
ActionSwap
7 props
PropTypeDefault
items *readonly ActionSwapItem[]—
valuestring—
defaultValuestring—
onValueChange((value: string, item: ActionSwapItem) => void)—
variant"default" | "secondary" | "ghost" | "destructive""default"
iconOnlybooleanfalse
cyclebooleantrue
Keyboard
- No custom key handling; Tab and the native activation keys do the work.
Accessibility
It is built on native elements and keeps aria-label and aria-hidden in step with state.
Notes for AI
Give your coding assistant this page as Markdown instead of screenshots: the props, keyboard and examples in one file.
/docs/components/action-swap.mdThe index of every part is at /llms.txt.