shadcn.io is an independent project built on shadcn/ui
On this page6 sections
Installation
Usage
<script setup lang="ts">
import { MoonIcon, SunIcon } from "lucide-vue-next";
import React from "react";
import { Button } from "@/components/ui/button";
import { Swap, SwapIndicator } from "@/components/ui/swap";
</script>
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
- Enter
- Activate the focused control.
- Space
- Activate the focused control.
Demos
Blur
Flip
Rotate
Scale
FAQ
Which transitions can Swap use?
Five: fade (the default), blur, flip, rotate and scale. Pass variant on Swap. Each has its own enter and exit animation, shown in the demos on this page.
How do I put two icons in a Swap?
Wrap them in SwapIndicator with type="on" and type="off", and control the state with the swap prop on Swap. When swap is true the "on" indicator shows.
Does Swap respect reduced motion?
Yes. The indicators carry motion-reduce:animate-none, so with the system's reduced-motion setting on, the icon changes without animation.
How do I make a Swap button accessible?
Swap draws the icons only, so the control around it needs a name. Put it in a button with an aria-label, and use aria-pressed if it is a toggle. Keyboard use comes from that button: Enter and Space.
Are both icons in the page at once?
Not by default. lazyMount and unmountOnExit default to true, so an indicator is mounted when it is shown and unmounted after its exit animation.
API Reference
Swap
lazyMount?boolean
Mount an indicator only once it first shows.
- Default
true
swap?boolean
Whether the on indicator shows.
- Default
false
unmountOnExit?boolean
Unmount an indicator once it has animated out.
- Default
true
variant?"blur" | "fade" | "flip" | "rotate" | "scale"
The visual style.
- Type
"blur" | "fade" | "flip" | "rotate" | "scale"- Default
"fade"
#render?{ props, state, children }
A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.
class?string
Merged with the part's classes.
SwapIndicator
typeSwapSide
on shows while swap is true, off while it's false.
#render?{ props, state, children }
A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.
class?string
Merged with the part's classes.