Skip to content

UI Library for Design Engineers. Animated components and effects you can copy and paste into your apps. Free. Open Source.

feat: add new rainbow button

Dillion Vermaac284142e2c5
diff --git a/config/docs.ts b/config/docs.ts
index 1912b131..481c69f1 100644
--- a/config/docs.ts
+++ b/config/docs.ts
@@ -104,6 +104,12 @@ export const docsConfig: DocsConfig = {
href: `/docs/components/marquee`,
items: [],
},
+ {
+ title: "Rainbow Button",
+ href: `/docs/components/rainbow-button`,
+ items: [],
+ label: "New",
+ },
{
title: "Hero Video Dialog",
href: `/docs/components/hero-video-dialog`,
diff --git a/content/docs/components/rainbow-button.mdx b/content/docs/components/rainbow-button.mdx
new file mode 100644
index 00000000..da4802bb
--- /dev/null
+++ b/content/docs/components/rainbow-button.mdx
@@ -0,0 +1,97 @@
+---
+title: Rainbow Button
+date: 2024-09-19
+description: An animated button with a rainbow effect.
+author: dillionverma
+published: true
+---
+
+<ComponentPreview name="rainbow-button-demo" />
+
+## Installation
+
+<Tabs defaultValue="cli">
+
+<TabsList>
+ <TabsTrigger value="cli">CLI</TabsTrigger>
+ <TabsTrigger value="manual">Manual</TabsTrigger>
+</TabsList>
+<TabsContent value="cli">
+
+<Steps>
+
+<Step>Run the following command:</Step>
+
+```bash
+npx magicui-cli add rainbow-button
+```
+
+<Step>Update `globals.css`</Step>
+
+Add the following to your `globals.css` file:
+
+```css
+:root {
+ --color-1: 0 100% 63%;
+ --color-2: 270 100% 63%;
+ --color-3: 210 100% 63%;
+ --color-4: 195 100% 63%;
+ --color-5: 90 100% 63%;
+}
+```
+
+<Step>Update `tailwind.config.js`</Step>
+
+Add the following animations to your `tailwind.config.js` file:
+
+```js title="tailwind.config.js" {5-20}
+/** @type {import('tailwindcss').Config} */
+module.exports = {
+ theme: {
+ extend: {
+ colors: {
+ "color-1": "hsl(var(--color-1))",
+ "color-2": "hsl(var(--color-2))",
+ "color-3": "hsl(var(--color-3))",
+ "color-4": "hsl(var(--color-4))",
+ "color-5": "hsl(var(--color-5))",
+ },
+ animation: {
+ rainbow: "rainbow var(--speed, 2s) infinite linear",
+ },
+ keyframes: {
+ rainbow: {
+ "0%": { "background-position": "0%" },
+ "100%": { "background-position": "200%" },
+ },
+ },
+ },
+ },
+};
+```
+
+</Steps>
+
+</TabsContent>
+
+<TabsContent value="manual">
+
+<Steps>
+
+<Step>Copy and paste the following code into your project.</Step>
+
+<ComponentSource name="rainbow-button" />
+
+<Step>Update the import paths to match your project setup.</Step>
+
+</Steps>
+
+</TabsContent>
+
+</Tabs>
+
+## Props
+
+| Prop | Type | Description |
+| -------- | --------------- | ---------------------------------------------- |
+| children | React.ReactNode | The content to be displayed inside the button. |
diff --git a/registry/components/example/rainbow-button-demo.tsx b/registry/components/example/rainbow-button-demo.tsx
new file mode 100644
index 00000000..d5b01102
--- /dev/null
+++ b/registry/components/example/rainbow-button-demo.tsx
@@ -0,0 +1,5 @@
+import { RainbowButton } from "@/components/magicui/rainbow-button";
+
+export default function RainbowButtonDemo() {
+ return <RainbowButton>Get Unlimited Access</RainbowButton>;
+}
diff --git a/registry/components/magicui/rainbow-button.tsx b/registry/components/magicui/rainbow-button.tsx
new file mode 100644
index 00000000..fefdc503
--- /dev/null
+++ b/registry/components/magicui/rainbow-button.tsx
@@ -0,0 +1,28 @@
+import React from "react";
+
+import { cn } from "@/lib/utils";
+
+interface RainbowButtonProps
+ extends React.ButtonHTMLAttributes<HTMLButtonElement> {}
+
+export function RainbowButton({ children, ...props }: RainbowButtonProps) {
+ return (
+ <button
+ className={cn(
+ "h-11 px-8 py-2 inline-flex items-center justify-center rounded-xl font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 relative group animate-rainbow cursor-pointer border-0 bg-[length:200%] text-primary-foreground [background-clip:padding-box,border-box,border-box] [background-origin:border-box] [border:calc(0.08*1rem)_solid_transparent]",
+
+ // before styles
+ "before:absolute before:bottom-[-20%] before:left-1/2 before:z-0 before:h-1/5 before:w-3/5 before:-translate-x-1/2 before:animate-rainbow before:bg-[linear-gradient(90deg,hsl(var(--color-1)),hsl(var(--color-5)),hsl(var(--color-3)),hsl(var(--color-4)),hsl(var(--color-2)))] before:bg-[length:200%] before:[filter:blur(calc(0.8*1rem))]",
+
+ // light mode colors
+ "bg-[linear-gradient(#121213,#121213),linear-gradient(#121213_50%,rgba(18,18,19,0.6)_80%,rgba(18,18,19,0)),linear-gradient(90deg,hsl(var(--color-1)),hsl(var(--color-5)),hsl(var(--color-3)),hsl(var(--color-4)),hsl(var(--color-2)))]",
+
+ // dark mode colors
+ " dark:bg-[linear-gradient(#fff,#fff),linear-gradient(#fff_50%,rgba(255,255,255,0.6)_80%,rgba(0,0,0,0)),linear-gradient(90deg,hsl(var(--color-1)),hsl(var(--color-5)),hsl(var(--color-3)),hsl(var(--color-4)),hsl(var(--color-2)))]",
+ )}
+ {...props}
+ >
+ {children}
+ </button>
+ );
+}
diff --git a/registry/index.tsx b/registry/index.tsx
index c920669b..8a5be1a2 100644
--- a/registry/index.tsx
+++ b/registry/index.tsx
@@ -270,6 +270,11 @@ const ui: Registry = {
type: "components:magicui",
files: ["registry/components/magicui/iphone-15-pro.tsx"],
},
+ "rainbow-button": {
+ name: "rainbow-button",
+ type: "components:magicui",
+ files: ["registry/components/magicui/rainbow-button.tsx"],
+ },
};
const example: Registry = {
@@ -996,6 +1001,14 @@ const example: Registry = {
() => import("@/registry/components/example/iphone-15-pro-demo-2"),
),
},
+ "rainbow-button-demo": {
+ name: "rainbow-button-demo",
+ type: "components:example",
+ files: ["registry/components/example/rainbow-button-demo.tsx"],
+ component: React.lazy(
+ () => import("@/registry/components/example/rainbow-button-demo"),
+ ),
+ },
};
export const registry: Registry = {
...ui,
diff --git a/styles/globals.css b/styles/globals.css
index ae75b415..b7b7f5f6 100644
--- a/styles/globals.css
+++ b/styles/globals.css
@@ -6,34 +6,30 @@
:root {
--background: 0 0% 100%;
--foreground: 240 10% 3.9%;
-
--muted: 240 4.8% 95.9%;
--muted-foreground: 240 3.8% 46.1%;
-
--popover: 0 0% 100%;
--popover-foreground: 240 10% 3.9%;
-
--card: 0 0% 100%;
--card-foreground: 240 10% 3.9%;
-
--border: 240 5.9% 90%;
--input: 240 5.9% 90%;
-
--primary: 240 5.9% 10%;
--primary-foreground: 0 0% 98%;
-
--secondary: 240 4.8% 95.9%;
--secondary-foreground: 240 5.9% 10%;
-
--accent: 240 4.8% 95.9%;
--accent-foreground: 240 5.9% 10%;
-
--destructive: 0 84.2% 60.2%;
--destructive-foreground: 0 0% 98%;
-
--ring: 240 5% 64.9%;
-
--radius: 0.5rem;
+
+ --color-1: 0 100% 63%;
+ --color-2: 270 100% 63%;
+ --color-3: 210 100% 63%;
+ --color-4: 195 100% 63%;
+ --color-5: 90 100% 63%;
}
.dark {
diff --git a/tailwind.config.ts b/tailwind.config.ts
index c721e108..2adac6d2 100644
--- a/tailwind.config.ts
+++ b/tailwind.config.ts
@@ -83,6 +83,7 @@ module.exports = {
backgroundPositionSpin:
"background-position-spin 3000ms infinite alternate",
pulse: "pulse var(--duration) ease-out infinite",
+ rainbow: "rainbow var(--speed, 2s) infinite linear",
},
keyframes: {
"accordion-down": {
@@ -199,6 +200,10 @@ module.exports = {
"0%, 100%": { boxShadow: "0 0 0 0 var(--pulse-color)" },
"50%": { boxShadow: "0 0 0 8px var(--pulse-color)" },
},
+ rainbow: {
+ "0%": { "background-position": "0%" },
+ "100%": { "background-position": "200%" },
+ },
},
},
},