Skip to content

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

[Feat] Animated Subscribe Button (#107)

Dipesh48a46fa231d9
diff --git a/config/docs.ts b/config/docs.ts
index e73d8736..dea111df 100644
--- a/config/docs.ts
+++ b/config/docs.ts
@@ -286,6 +286,12 @@ export const docsConfig: DocsConfig = {
items: [],
label: "",
},
+ {
+ title: "Animated Subscribe Button",
+ href: `/docs/components/animated-subscribe-button`,
+ items: [],
+ label: "New"
+ },
],
},
{
diff --git a/content/docs/components/animated-subscribe-button.mdx b/content/docs/components/animated-subscribe-button.mdx
new file mode 100644
index 00000000..ae5eabb8
--- /dev/null
+++ b/content/docs/components/animated-subscribe-button.mdx
@@ -0,0 +1,37 @@
+---
+title: Animated Subscribe Button
+date: 2024-05-30
+description: An animated subscribe button useful for showing a micro animation from intial to final result.
+author: pilladipesh33
+published: true
+---
+
+<ComponentPreview name="animated-subscribe-button-demo" />
+
+<Steps>
+
+### Installation
+
+Copy and paste the following code into your project.
+
+```text
+components/magicui/animated-subscribe-button.tsx
+```
+
+<ComponentSource name="animated-subscribe-button" />
+
+</Steps>
+
+## Props
+
+| Prop | Type | Description |
+| ------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| **brand** | string | The accent color for the button. This allows you to set a custom color that matches your brand's theme. |
+| **subscribeStatus** | boolean | A boolean flag to check the condition for the button. This property can be used to toggle the button's state, such as subscribed or unsubscribed. |
+| **buttonTextColor** | string | The color of the button text. This allows you to ensure the text is visible and matches your desired color scheme. |
+| **initialText** | string | The initial text displayed on the button. This is useful for setting a default label when the button first appears. |
+| **changeText** | string | The final text displayed on the button after an action has been taken. This can be used to indicate a state change, such as from "Subscribe" to "Subscribed". |
+
+## Credits
+
+- Credit to [@dipesh](https://github.com/pilladipesh33)
diff --git a/registry/components/example/animated-subscribe-button-demo.tsx b/registry/components/example/animated-subscribe-button-demo.tsx
new file mode 100644
index 00000000..93d6ae44
--- /dev/null
+++ b/registry/components/example/animated-subscribe-button-demo.tsx
@@ -0,0 +1,24 @@
+import { AnimatedSubscribeButton } from "@/registry/components/magicui/animated-subscribe-button";
+import { CheckIcon, ChevronRightIcon } from "lucide-react";
+
+export default function AnimatedSubscribeButtonDemo() {
+ return (
+ <AnimatedSubscribeButton
+ brand="#ffbd7a"
+ subscribeStatus={false}
+ buttonTextColor="#000009"
+ initialText={
+ <span className="group inline-flex items-center">
+ Subscribe{" "}
+ <ChevronRightIcon className="ml-1 h-4 w-4 transition-transform duration-300 group-hover:translate-x-1" />
+ </span>
+ }
+ changeText={
+ <span className="group inline-flex items-center">
+ <CheckIcon className="mr-2 h-4 w-4" />
+ Subscribed{" "}
+ </span>
+ }
+ />
+ );
+}
diff --git a/registry/components/magicui/animated-subscribe-button.tsx b/registry/components/magicui/animated-subscribe-button.tsx
new file mode 100644
index 00000000..f0d9dde4
--- /dev/null
+++ b/registry/components/magicui/animated-subscribe-button.tsx
@@ -0,0 +1,60 @@
+"use client";
+
+import { AnimatePresence, motion } from "framer-motion";
+import React, { useState } from "react";
+
+interface AnimatedSubscribeButtonProps {
+ brand: string;
+ subscribeStatus: boolean;
+ buttonTextColor?: string;
+ initialText: React.ReactElement | string;
+ changeText: React.ReactElement | string;
+}
+
+export const AnimatedSubscribeButton: React.FC<
+ AnimatedSubscribeButtonProps
+> = ({ brand, subscribeStatus, buttonTextColor, changeText, initialText }) => {
+ const [isSubscribed, setIsSubscribed] = useState<boolean>(subscribeStatus);
+
+ return (
+ <AnimatePresence mode="wait">
+ {isSubscribed ? (
+ <motion.button
+ className="relative flex w-[200px] items-center justify-center bg-white p-[10px]"
+ onClick={() => setIsSubscribed(false)}
+ initial={{ opacity: 0 }}
+ animate={{ opacity: 1 }}
+ exit={{ opacity: 0 }}
+ >
+ <motion.span
+ key="action"
+ className="relative block h-full w-full font-semibold"
+ initial={{ y: -50 }}
+ animate={{ y: 0 }}
+ style={{ color: brand }}
+ >
+ {changeText}
+ </motion.span>
+ </motion.button>
+ ) : (
+ <motion.button
+ className="relative flex w-[200px] cursor-pointer items-center justify-center rounded-md border-none p-[10px]"
+ style={{ backgroundColor: brand, color: buttonTextColor }}
+ onClick={() => setIsSubscribed(true)}
+ initial={{ opacity: 0 }}
+ animate={{ opacity: 1 }}
+ exit={{ opacity: 0 }}
+ >
+ <motion.span
+ key="reaction"
+ className="relative block font-semibold"
+ initial={{ x: 0 }}
+ exit={{ x: 50, transition: { duration: 0.1 } }}
+ >
+ {initialText}
+ </motion.span>
+ </motion.button>
+ )}
+ </AnimatePresence>
+ );
+};
diff --git a/registry/index.tsx b/registry/index.tsx
index d3b27c72..c6f0b6af 100644
--- a/registry/index.tsx
+++ b/registry/index.tsx
@@ -237,6 +237,11 @@ const ui: Registry = {
type: "components:ui",
files: ["registry/components/magicui/confetti.tsx"],
},
+ "animated-subscribe-button": {
+ name: "animated-subscribe-button",
+ type: "components:ui",
+ files: ["registry/components/magicui/animated-subscribe-button.tsx"],
+ },
};
const example: Registry = {
@@ -868,6 +873,15 @@ const example: Registry = {
() => import("@/registry/components/example/confetti-emoji"),
),
},
+ "animated-subscribe-button-demo": {
+ name: "animated-subscribe-button-demo",
+ type: "components:example",
+ files: ["registry/components/example/animated-subscribe-button-demo.tsx"],
+ component: React.lazy(
+ () =>
+ import("@/registry/components/example/animated-subscribe-button-demo"),
+ ),
+ },
};
export const registry: Registry = {
...ui,