Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Shadcn Swap for React and Tailwind

Animate between two visual states with smooth transitions.

Installation

bunx --bun shadcn@latest add https://kit.dev/r/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