Skip to content

feat: add pulsating button #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 46 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
fb86cb5
testing update
shikhap04 May 31, 2024
b616d0e
reverting test
shikhap04 May 31, 2024
7490ccf
updating registery
shikhap04 Jun 4, 2024
81fd958
creating page outline
shikhap04 Jun 4, 2024
878a71a
updating index
shikhap04 Jun 4, 2024
85519cb
demo attempt (not working)
shikhap04 Jun 4, 2024
5991665
pulsating button
shikhap04 Jun 4, 2024
a74197d
reduced redundant code
shikhap04 Jun 4, 2024
b11de42
syntax error fixed
shikhap04 Jun 5, 2024
fddbf86
argument interface
shikhap04 Jun 5, 2024
e426b4c
variable descriptions added
shikhap04 Jun 5, 2024
93a0249
updated button name
shikhap04 Jun 10, 2024
1c5ecf7
removed old document object
shikhap04 Jun 10, 2024
9f8d16a
updated description
shikhap04 Jun 10, 2024
17023c5
removed video tag
shikhap04 Jun 10, 2024
4b14369
fixed rounded edges
shikhap04 Jun 20, 2024
b11074d
removing extra code
shikhap04 Jun 20, 2024
98ba4a7
Merge branch 'main' of https://github.com/shikhap04/magicui_OSC into …
shikhap04 Jun 20, 2024
5a16282
code style update for uniformity
shikhap04 Jun 21, 2024
135b3d1
removed bold, changed rounded edges size
shikhap04 Jun 21, 2024
eabd4fa
Merge branch 'Open-source-Contribution' of https://github.com/shikhap…
shikhap04 Jun 21, 2024
5e7f7b7
testing update
shikhap04 May 31, 2024
ed2006e
reverting test
shikhap04 May 31, 2024
cbc8caf
updating registery
shikhap04 Jun 4, 2024
f08b651
creating page outline
shikhap04 Jun 4, 2024
123525f
updating index
shikhap04 Jun 4, 2024
052f534
demo attempt (not working)
shikhap04 Jun 4, 2024
0edeefc
pulsating button
shikhap04 Jun 4, 2024
35e3518
reduced redundant code
shikhap04 Jun 4, 2024
2b3ea38
syntax error fixed
shikhap04 Jun 5, 2024
f2fd048
argument interface
shikhap04 Jun 5, 2024
d4ce157
variable descriptions added
shikhap04 Jun 5, 2024
181e1c1
updated button name
shikhap04 Jun 10, 2024
375e1a3
removed old document object
shikhap04 Jun 10, 2024
7f4b640
updated description
shikhap04 Jun 10, 2024
4a85785
removed video tag
shikhap04 Jun 10, 2024
e7f1b7f
fixed rounded edges
shikhap04 Jun 20, 2024
564cbcf
removing extra code
shikhap04 Jun 20, 2024
ffa4a15
code style update for uniformity
shikhap04 Jun 21, 2024
a2849a1
removed bold, changed rounded edges size
shikhap04 Jun 21, 2024
df6ead5
fix: remove husky
dillionverma Jul 1, 2024
9f0034c
Merge branch 'main' into Open-source-Contribution
shikhap04 Jul 18, 2024
3ec01c4
fix: update button code
dillionverma Jul 23, 2024
b23772c
fix: update button date
dillionverma Jul 23, 2024
cc026bf
Merge branch 'main' of https://github.com/shikhap04/magicui_OSC into …
shikhap04 Sep 24, 2024
ae8f2ab
Merge branch 'Open-source-Contribution' of https://github.com/shikhap…
shikhap04 Sep 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: update button code
  • Loading branch information
dillionverma committed Jul 23, 2024
commit 3ec01c49e1918e429f4752a81419c1fbe3a769f4
98 changes: 82 additions & 16 deletions content/docs/components/pulsating-button.mdx
Original file line number Diff line number Diff line change
@@ -1,40 +1,106 @@
---
title: Pulsating Button
date: 2024-06-20
description: An animated pulsating button useful for capturing attention of users.
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>

### Installation
<Step>Run the following command:</Step>

```bash
npx magicui-cli add pulsating-button
```

<Step>Update `tailwind.config.js`</Step>

Copy and paste the following code into your project.
Add the following animations to your `tailwind.config.js` file:

```text
components/magicui/pulsating-button.tsx
```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>

## Props
</TabsContent>

| Prop | Type | Description |
|-------------------|---------|-----------------------------------------------------------|
| text | string | The text displayed on the button. |
| backgroundColor | string | The hex color for the color of the button. |
| pulseColor | string | The rbg numbers only for the color of the pulsing waves. |
| textColor | string | The color of the text displayed on the button. |
| animationDuration | string | The time span of one pulse. |
| buttonWidth | string | The width of the button. |
| buttonHeight | string | The height of the button. |
</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)
- Credit to [@shikhap04](https://github.com/shikhap04)
18 changes: 3 additions & 15 deletions registry/components/example/pulsating-button-demo.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
import PulsatingButton from "@/registry/components/magicui/pulsating-button";

import { PulsatingButton } from "@/registry/components/magicui/pulsating-button"
import { constants } from "zlib";

const PulsatingButtonDemo = () => {
return <PulsatingButton
text = 'Join Affiliate Program'
pulseColor = '0, 150, 255'
backgroundColor= '#0096FF'
textColor = '#ffffff'
animationDuration = '1.5s'
buttonWidth = '200px'
buttonHeight = '50px'
/>;
export default function PulsatingButtonDemo() {
return <PulsatingButton>Join Affiliate Program</PulsatingButton>;
}

export default PulsatingButtonDemo;
97 changes: 29 additions & 68 deletions registry/components/magicui/pulsating-button.tsx
Original file line number Diff line number Diff line change
@@ -1,77 +1,38 @@

"use client";

import React from "react";

interface PulsatingButtonProps {
text: string;
pulseColor: string;
backgroundColor: string;
textColor: string;
animationDuration: string;
buttonWidth: string;
buttonHeight: string;
}
import { cn } from "@/lib/utils";

export const PulsatingButton: React.FC<PulsatingButtonProps> = ({
text,
pulseColor,
backgroundColor,
textColor,
animationDuration,
buttonWidth,
buttonHeight
}) => {
const pulseKeyframes = {
'--tw-pulse-color': pulseColor,
animation: `pulse ${animationDuration} linear infinite`,
};
interface PulsatingButtonProps
extends React.ButtonHTMLAttributes<HTMLButtonElement> {
pulseColor?: string;
duration?: string;
}

export default function PulsatingButton({
className,
children,
pulseColor = "#0096ff",
duration = "1.5s",
...props
}: PulsatingButtonProps) {
return (
<div
className="flex justify-center items-center"
<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}
>
<button
className="relative block text-center cursor-pointer flex justify-center items-center"
style={{
color: textColor,
backgroundColor: backgroundColor,
width: buttonWidth,
height: buttonHeight,
borderRadius: '12px',
...pulseKeyframes,
}}
>
<div>{text}</div>
<style jsx>{`
@keyframes pulse {
0% {
box-shadow: 0 0 0 0 rgba(var(--tw-pulse-color), 0);
}
50% {
box-shadow: 0 0 0 8px rgba(var(--tw-pulse-color), 0.5);
}
100% {
box-shadow: 0 0 0 0 rgba(var(--tw-pulse-color), 0);
}
}
button::before {
content: '';
position: absolute;
top: 50%;
left: 50%;
width: 100%;
height: 100%;
border-radius: 20px;
background: inherit;
animation: inherit;
transform: translate(-50%, -50%);
z-index: -1;
}
`}</style>
</button>
</div>
<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>
);
};

export default PulsatingButton;
}
3 changes: 3 additions & 0 deletions registry/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ const ui: Registry = {
name: "pulsating-button",
type: "components:ui",
files: ["registry/components/magicui/pulsating-button.tsx"],
},
"file-tree": {
name: "file-tree",
type: "components:magicui",
Expand Down Expand Up @@ -864,6 +865,8 @@ const example: Registry = {
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",
Expand Down
5 changes: 5 additions & 0 deletions tailwind.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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)" },
},
},
},
},
Expand Down
Loading