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 pulsating button (#170)

Shikha Patel3efceffbcb1a
diff --git a/config/docs.ts b/config/docs.ts
index aedd038a..fb02e60d 100644
--- a/config/docs.ts
+++ b/config/docs.ts
@@ -350,6 +350,12 @@ export const docsConfig: DocsConfig = {
items: [],
label: "",
},
+ {
+ title: "Pulsating Button",
+ href:'/docs/components/pulsating-button',
+ items: [],
+ label: "New"
+ },
],
},
{
diff --git a/content/docs/components/pulsating-button.mdx b/content/docs/components/pulsating-button.mdx
new file mode 100644
index 00000000..46e2bb73
--- /dev/null
+++ b/content/docs/components/pulsating-button.mdx
@@ -0,0 +1,106 @@
+---
+title: Pulsating Button
+date: 2024-07-23
+description: An animated pulsating button useful for capturing attention of users.
+author: shikhap04
+published: true
+---
+
+<ComponentPreview name="pulsating-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 pulsating-button
+```
+
+<Step>Update `tailwind.config.js`</Step>
+
+Add the following animations to your `tailwind.config.js` file:
+
+```js title="tailwind.config.js" {5-13}
+/** @type {import('tailwindcss').Config} */
+module.exports = {
+ theme: {
+ extend: {
+ animation: {
+ pulse: "pulse var(--duration) ease-out infinite",
+ },
+ keyframes: {
+ pulse: {
+ "0%, 100%": { boxShadow: "0 0 0 0 var(--pulse-color)" },
+ "50%": { boxShadow: "0 0 0 8px var(--pulse-color)" },
+ },
+ },
+ },
+ },
+};
+```
+
+</Steps>
+
+</TabsContent>
+
+<TabsContent value="manual">
+
+<Steps>
+
+<Step>Copy and paste the following code into your project.</Step>
+
+<ComponentSource name="pulsating-button" />
+
+<Step>Update the import paths to match your project setup.</Step>
+
+<Step>Update `tailwind.config.js`</Step>
+
+Add the following animations to your `tailwind.config.js` file:
+
+```js title="tailwind.config.js" {5-13}
+/** @type {import('tailwindcss').Config} */
+module.exports = {
+ theme: {
+ extend: {
+ animation: {
+ pulse: "pulse var(--duration) ease-out infinite",
+ },
+ keyframes: {
+ pulse: {
+ "0%, 100%": { boxShadow: "0 0 0 0 var(--pulse-color)" },
+ "50%": { boxShadow: "0 0 0 8px var(--pulse-color)" },
+ },
+ },
+ },
+ },
+};
+```
+
+</Steps>
+
+</TabsContent>
+
+</Tabs>
+
+## Props
+
+| Prop | Type | Description |
+| ---------- | --------------- | -------------------------------------------------------- |
+| children | React.ReactNode | The content of the button. |
+| className | string | Additional class names for the button. |
+| pulseColor | string | The rbg numbers only for the color of the pulsing waves. |
+| duration | string | The time span of one pulse. |
+
+## Credits
+
+- Credit to [@shikhap04](https://github.com/shikhap04)
diff --git a/registry/components/example/pulsating-button-demo.tsx b/registry/components/example/pulsating-button-demo.tsx
new file mode 100644
index 00000000..92731a36
--- /dev/null
+++ b/registry/components/example/pulsating-button-demo.tsx
@@ -0,0 +1,5 @@
+import PulsatingButton from "@/registry/components/magicui/pulsating-button";
+
+export default function PulsatingButtonDemo() {
+ return <PulsatingButton>Join Affiliate Program</PulsatingButton>;
+}
diff --git a/registry/components/magicui/pulsating-button.tsx b/registry/components/magicui/pulsating-button.tsx
new file mode 100644
index 00000000..5cd0be09
--- /dev/null
+++ b/registry/components/magicui/pulsating-button.tsx
@@ -0,0 +1,38 @@
+"use client";
+
+import React from "react";
+
+import { cn } from "@/lib/utils";
+
+interface PulsatingButtonProps
+ extends React.ButtonHTMLAttributes<HTMLButtonElement> {
+ pulseColor?: string;
+ duration?: string;
+}
+
+export default function PulsatingButton({
+ className,
+ children,
+ pulseColor = "#0096ff",
+ duration = "1.5s",
+ ...props
+}: PulsatingButtonProps) {
+ return (
+ <button
+ className={cn(
+ "relative text-center cursor-pointer flex justify-center items-center rounded-lg text-white dark:text-black bg-blue-500 dark:bg-blue-500 px-4 py-2",
+ className,
+ )}
+ style={
+ {
+ "--pulse-color": pulseColor,
+ "--duration": duration,
+ } as React.CSSProperties
+ }
+ {...props}
+ >
+ <div className="relative z-10">{children}</div>
+ <div className="absolute top-1/2 left-1/2 size-full rounded-lg bg-inherit animate-pulse -translate-x-1/2 -translate-y-1/2" />
+ </button>
+ );
+}
diff --git a/registry/index.tsx b/registry/index.tsx
index 42818ace..a50d3bdd 100644
--- a/registry/index.tsx
+++ b/registry/index.tsx
@@ -229,6 +229,11 @@ const ui: Registry = {
type: "components:magicui",
files: ["registry/components/magicui/cool-mode.tsx"],
},
+ "pulsating-button": {
+ name: "pulsating-button",
+ type: "components:ui",
+ files: ["registry/components/magicui/pulsating-button.tsx"],
+ },
"file-tree": {
name: "file-tree",
type: "components:magicui",
@@ -854,6 +859,14 @@ const example: Registry = {
() => import("@/registry/components/example/cool-mode-custom"),
),
},
+ "pulsating-button-demo": {
+ name: "pulsating-button-demo",
+ type: "components:example",
+ files: ["registry/components/example/pulsating-button-demo.tsx"],
+ component: React.lazy(
+ () => import("@/registry/components/example/pulsating-button-demo"),
+ ),
+ },
"file-tree-demo": {
name: "file-tree-demo",
type: "components:example",
diff --git a/tailwind.config.ts b/tailwind.config.ts
index 13f4b8d4..c721e108 100644
--- a/tailwind.config.ts
+++ b/tailwind.config.ts
@@ -82,6 +82,7 @@ module.exports = {
orbit: "orbit calc(var(--duration)*1s) linear infinite",
backgroundPositionSpin:
"background-position-spin 3000ms infinite alternate",
+ pulse: "pulse var(--duration) ease-out infinite",
},
keyframes: {
"accordion-down": {
@@ -194,6 +195,10 @@ module.exports = {
"background-position": "0% 0%",
},
},
+ pulse: {
+ "0%, 100%": { boxShadow: "0 0 0 0 var(--pulse-color)" },
+ "50%": { boxShadow: "0 0 0 8px var(--pulse-color)" },
+ },
},
},
},