Text switcher
A reusable component that creates an engaging animation effect by smoothly transitioning between a list of phrases. The animation, driven by a moving dot, makes it ideal for dynamically completing a sentence or tagline.
Current Theme:
As someone who styles divs and
solves backend
nightmares, I write
code that
solves backend
nightmares, I write
code that
c
o
m
p
i
l
e
s
.
API usage
components/text-switcher.demo.tsx
import { TextSwitcher } from "./text-switcher";
export function TextSwitcherDemo() {
return (
<div className="text-sm sm:text-base md:text-xl lg:text-2xl">
As someone who styles divs and <br className="md:hidden" /> solves
backend
<br className="max-md:hidden" />
nightmares, I write <br className="md:hidden" />
code that
<TextSwitcher
phrases={["compiles", "ships", "breaks", "runs anyway"]}
className="font-medium"
/>
</div>
);
}Installation
CLI (recommended)
1
Run the command below to add the component to your project.
It will also generate the required base stylesheet if one doesn't already exist and guide you through setting up the import alias
@/components/... if it isn't already configured.pnpm dlx shadcn@latest add https://100xui.com/components/text-switcher.jsonManual
1
pnpm add clsx motion tailwind-merge2
100xui
components/text-switcher.tsx
3
API reference
<TextSwitcher/>
| Props | Type | Description | Default value |
|---|---|---|---|
phrases | | An array of strings that the component will cycle through. | |
animationDurationInSec? | | The duration, in seconds, of the enter and exit animations for each phrase. | |
readTimeInSec? | | The display duration, in seconds, for each phrase before its exit animation starts. | |
style? | | Optional inline styles to apply to the component's root element. | |
className? | | Optional class names to apply to the component's root element. | |