Skip to content

shadcn.io is not affiliated with official shadcn/ui

Shadcn Swap for React Radix UI

Animate between two visual states with smooth transitions.

Framework
UI library

Radix UI does not include this primitive, so this page uses the Ark UI component. The visuals match the Ark UI version.

Installation

bunx --bun shadcn@latest add https://kit.dev/r/radix/swap.json

Usage

import { MoonIcon, SunIcon } from "lucide-react";
import React from "react";
import { Button } from "@/components/ui/button";
import { Swap, SwapIndicator } from "@/components/ui/swap";
const SwapDemo = () => {
  const [swap, setSwap] = React.useState(false);

  return (
    <Button onClick={() => setSwap(!swap)} size="icon-lg" variant="outline">
      <Swap swap={swap} variant="fade">
        <SwapIndicator type="on">
          <MoonIcon />
        </SwapIndicator>
        <SwapIndicator type="off">
          <SunIcon />
        </SwapIndicator>
      </Swap>
    </Button>
  );
};

Accessibility

KeyDescription
Enter
Activate the focused control.
Space
Activate the focused control.

Demos

Blur

Flip

Rotate

Scale

API Reference

Swap

span

PropType
AttributeType

SwapIndicator

span

PropType
AttributeType

useSwap

PropType