JGuang

Rainbow Button

Rainbow Button · Magic UI

Preview
npx shadcn@latest add https://jiguang132.com/r/magic-ui/rainbow-button.json

Some upstream demos use online images, videos or tweets. That content depends on network access and third-party services.

Rainbow Button

Install: npx shadcn@latest add https://jiguang132.com/r/magic-ui/rainbow-button.json

Use case

Render a native button with an animated rainbow border.

Native props used by the examples

Extracted from all local examples for this entry, grouped by imported module and native owner, including other Magic components used by compound demos. This is not an exhaustive API or a universal host variant. Inspect spread object declarations and the source types/defaults below.

Owning component propExplanationExample source
RainbowButton.children (rainbow-button)Native child content; keep the owning component's text/element constraints.examples/rainbow-button-demo.tsx、examples/rainbow-button-demo-2.tsx
RainbowButton.variant (rainbow-button)Owning component's style/shape union; never substitute a universal variant API.examples/rainbow-button-demo-2.tsx

Interaction and state checks

  • Rainbow Button Demo — rainbow-button-demo
  • Rainbow Button Demo 2 — rainbow-button-demo-2

These names identify real example entries, not new component props or extra components. Check pointer/keyboard behavior, themes, small screens and failures for the selected example. Decorative effects must not invent disabled/error/submission states. Complete example installation includes the actual dependency closure.

Business integration boundary

variant/size come from its own native style variants. asChild requires a valid child element; do not swap Base UI composition APIs into it.

Host and motion setup

Initialize Tailwind CSS v4, semantic CSS variables and the dark variant; import the independent local Registry namespace. Reuse an existing next-themes Provider without substituting JGuang UI/Base UI/HeroUI APIs. Mount effects in view and unmount offscreen; provide static alternatives for unavailable Canvas/WebGL or failed remote media. Respect prefers-reduced-motion and verify timer/RAF/observer/listener cleanup: stopping CSS alone does not prove the engine stopped. Examples provide no backend, login, payment or real AI stream. This practical guide is bilingual; detailed upstream references and demo text retain their original language.

Available examples

rainbow-button-demo, rainbow-button-demo-2

Demo state and mock data do not provide a backend service. Inspect the component props before wiring real data.

Installation

<Tabs defaultValue="cli"> <TabsList> <TabsTrigger value="cli">CLI</TabsTrigger> <TabsTrigger value="manual">Manual</TabsTrigger> </TabsList> <TabsContent value="cli">
npx shadcn@latest add @magicui/rainbow-button
</TabsContent> <TabsContent value="manual"> <Steps>

<Step>Copy and paste the following code into your project.</Step>

<Step>Update the import paths to match your project setup.</Step>

<Step>Update globals.css</Step>

Add the following to your globals.css file:

:root {
  --color-1: hsl(0 100% 63%);
  --color-2: hsl(270 100% 63%);
  --color-3: hsl(210 100% 63%);
  --color-4: hsl(195 100% 63%);
  --color-5: hsl(90 100% 63%);
}

<Step>Add the required CSS animations</Step>

Add the following animations to your global CSS file.

@theme inline {
  --animate-rainbow: rainbow var(--speed, 2s) infinite linear;

  @keyframes rainbow {
    0% {
      background-position: 0%;
    }
    100% {
      background-position: 200%;
    }
  }
}
</Steps> </TabsContent> </Tabs>

Examples

Outline Variant

Usage

import { RainbowButton } from "@/components/ui/rainbow-button"
<RainbowButton>Rainbow Button</RainbowButton>

Props

PropTypeDefaultDescription
childrenReact.ReactNode-The content to be displayed inside the button.
classNamestring-Additional CSS classes to be applied to the button.
variant"default" | "outline""default"The variant of the button.
size"default" | "sm" | "lg" | "icon""default"The size of the button.

Complete example installation

The component command installs the component. Each example command also includes its actual imported components, native support UI, utilities and pinned dependencies. Helpers are not additional catalog components.

Rainbow Button Demo

npx shadcn@latest add https://jiguang132.com/r/magic-ui/examples/rainbow-button/rainbow-button-demo.json

Default import: @/components/magicui/examples/rainbow-button-demo

Dependencies: @radix-ui/react-slot@1.3.0, class-variance-authority@0.7.1, clsx@2.1.1, tailwind-merge@3.6.0

Rainbow Button Demo 2

npx shadcn@latest add https://jiguang132.com/r/magic-ui/examples/rainbow-button/rainbow-button-demo-2.json

Default import: @/components/magicui/examples/rainbow-button-demo-2

Dependencies: @radix-ui/react-slot@1.3.0, class-variance-authority@0.7.1, clsx@2.1.1, tailwind-merge@3.6.0

Minimal usage and theme

import Demo from '@/components/magicui/examples/rainbow-button-demo';
import { ThemeProvider } from 'next-themes';
export default function Example() {
  return <ThemeProvider attribute="class" defaultTheme="system" enableSystem><Demo /></ThemeProvider>;
}

Initialize Tailwind CSS v4, semantic color variables and the dark variant first. Reuse an existing next-themes provider rather than nesting another. Next Link examples require a Next.js environment; in static Vite projects adapt the demo links to your router without changing the native component API. Some media and tweets require network access. Examples do not supply authentication or backend services.

Source-backed parameter reference

Implementation signatures and types are generated from the pinned local source. Optional props, native inherited types, union branches and never exclusions are preserved. A forwardRef implementation's ref is a React reference, not an additional business prop.

RainbowButton({ className, variant, size, asChild = false, ...props }, ref)
interface RainbowButtonProps
  extends
    React.ButtonHTMLAttributes<HTMLButtonElement>,
    VariantProps<typeof rainbowButtonVariants> {
  asChild?: boolean
}

Destructuring defaults in source

Only defaults written directly in parameter/props destructuring are listed. Conditional expressions, runtime theme and computed values require source inspection; this is not an exhaustive behavior-default list.

// RainbowButton
asChild = false

Native and external types

External types remain defined by React or native dependencies, not manually expanded into guessed props. The installed version's TypeScript definitions are authoritative.

HTMLButtonElement
React.ButtonHTMLAttributes<HTMLButtonElement>
VariantProps<typeof rainbowButtonVariants>