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 shimmer button

Dillion Vermaf1ea3d4edc56
diff --git a/content/components/shimmer-button.mdx b/content/components/shimmer-button.mdx
new file mode 100644
index 00000000..f02fd5fb
--- /dev/null
+++ b/content/components/shimmer-button.mdx
@@ -0,0 +1,88 @@
+---
+title: Shimmer Button
+date: 2023-08-10
+summary: A button with a rotating shimmering effect
+author: dillionverma
+published: true
+video: https://cdn.magicuikit.com/shimmer.mp4
+---
+
+<ComponentPreview name="shimmer-button-demo" />
+
+<Steps>
+
+<Step>
+
+## Prerequisites
+
+```bash
+npm install -D tailwindcss clsx tailwind-merge
+```
+
+Copy and paste the following code into your project.
+
+```typescript
+// lib/utils.ts
+import clsx, { ClassValue } from "clsx";
+import { twMerge } from "tailwind-merge";
+
+export function cn(...inputs: ClassValue[]) {
+ return twMerge(clsx(inputs));
+}
+```
+
+```js
+// tailwind.config.js
+module.exports = {
+ theme: {
+ extend: {
+ animation: {
+ flip: "flip calc(var(--spark) * 2) infinite steps(2, end)",
+ rotate: "rotate var(--spark) linear infinite both;",
+ },
+ keyframes: {
+ flip: {
+ to: { rotate: "360deg" },
+ },
+ rotate: {
+ to: {
+ transform: "rotate(90deg)",
+ },
+ },
+ },
+ },
+ },
+};
+```
+
+</Step>
+
+<Step>
+
+## Installation
+
+Copy and paste the following code into your project.
+
+```text
+components/magicui/shimmer-button.tsx
+```
+
+<ComponentSource name="shimmer-button" />
+
+</Step>
+
+</Steps>
+
+## Props
+
+| Prop Name | Type | Description | Default Value |
+| ------------- | --------------- | ----------------------------------- | ------------------------------------------------------------------------------- |
+| shadow | string | The shadow of the button | |
+| shadowEnabled | boolean | Whether the shadow is enabled | true |
+| shimmerColor | string | The color of the shimmer | #ffffff |
+| shimmerSize | string | The size of the shimmer | 0.1em |
+| borderRadius | string | The border radius of the button | 100px |
+| sparkDuration | string | The duration of the spark animation | 1.8s |
+| background | string | The background of the button | radial-gradient(ellipse 80% 50% at 50% 120%,rgba(62, 61, 117),rgba(13, 13, 33)) |
+| className | string | The class name of the button | undefined |
+| children | React.ReactNode | The children of the button | undefined |
diff --git a/registry/components/example/shimmer-button-demo.tsx b/registry/components/example/shimmer-button-demo.tsx
new file mode 100644
index 00000000..ebaf101e
--- /dev/null
+++ b/registry/components/example/shimmer-button-demo.tsx
@@ -0,0 +1,15 @@
+import LinearGradient from "@/registry/components/magicui/linear-gradient";
+import ShimmerButton from "@/registry/components/magicui/shimmer-button";
+
+export default function ShimmerButtonDemo() {
+ return (
+ <div className="relative flex h-full w-full items-center justify-center rounded-lg border bg-background p-20 shadow-2xl">
+ <ShimmerButton shadowEnabled={false}>
+ <span className="pointer-events-none z-[1] whitespace-pre-wrap bg-gradient-to-b from-black from-30% to-gray-300/80 bg-clip-text text-center text-2xl font-semibold leading-none tracking-tight text-transparent dark:from-white dark:to-slate-900/10">
+ Shimmer Button
+ </span>
+ </ShimmerButton>
+ <LinearGradient to="rgba(120,119,198,0.15)" />
+ </div>
+ );
+}
diff --git a/registry/components/magicui/shimmer-button.tsx b/registry/components/magicui/shimmer-button.tsx
new file mode 100644
index 00000000..41e0e0fc
--- /dev/null
+++ b/registry/components/magicui/shimmer-button.tsx
@@ -0,0 +1,59 @@
+import { cn } from "@/lib/utils";
+import { CSSProperties } from "react";
+
+interface ShimmerButtonProps {
+ shadow?: string;
+ shadowEnabled?: boolean;
+ shimmerColor?: string;
+ shimmerSize?: string;
+ borderRadius?: string;
+ sparkDuration?: string;
+ background?: string;
+ className?: string;
+ children?: React.ReactNode;
+}
+
+const ShimmerButton = ({
+ shadow = "0 0 calc(var(--active) * 4em) calc(var(--active) * 2em) hsl(260 97% 61% / 0.75),0 0.05em 0 0 hsl(260 calc(var(--active) * 97%) calc((var(--active) * 50%) + 30%)) inset,0 -0.05em 0 0 hsl(260 calc(var(--active) * 97%) calc(var(--active) * 60%)) inset",
+ shadowEnabled = true,
+ shimmerColor = "#ffffff",
+ shimmerSize = "0.1em",
+ borderRadius = "100px",
+ sparkDuration = "1.8s",
+ background = "radial-gradient(ellipse 80% 50% at 50% 120%,rgba(62, 61, 117),rgba(13, 13, 33))",
+ className,
+ children,
+}: ShimmerButtonProps) => {
+ return (
+ <button
+ style={
+ {
+ "--shimmer-color": shimmerColor,
+ "--radius": borderRadius,
+ "--spark": sparkDuration,
+ "--cut": shimmerSize,
+ "--bg": background,
+ "--shadow": shadow,
+ } as CSSProperties
+ }
+ className={cn(
+ "group relative grid cursor-pointer place-items-center overflow-hidden whitespace-nowrap px-6 py-4 [background:var(--bg)] [border-radius:var(--radius)] [box-shadow:var(--shadow)]",
+ "transition-all [--active:0] hover:scale-110",
+ { "hover:[--active:1]": shadowEnabled },
+ className,
+ )}
+ >
+ {/* spark container */}
+ <div className="absolute inset-0 rotate-0 animate-flip overflow-hidden [border-radius:var(--radius)] [container-type:size] [mask:linear-gradient(white,transparent_50%)] ">
+ {/* spark before */}
+ <div className="absolute -z-[1] w-[200%] rotate-0 animate-rotate transition-all [aspect-ratio:1] [background:conic-gradient(from_0deg,transparent_0_340deg,var(--shimmer-color)_360deg)] [inset:0_auto_auto_50%] [transform:rotate(-90deg)] [translate:-50%_-15%] group-hover:opacity-40" />
+ </div>
+ {/* backdrop */}
+ <div className="absolute [background:var(--bg)] [border-radius:var(--radius)] [inset:var(--cut)]" />
+ {/* content */}
+ {children}
+ </button>
+ );
+};
+
+export default ShimmerButton;
diff --git a/registry/index.tsx b/registry/index.tsx
index e8d231d4..95d1739b 100644
--- a/registry/index.tsx
+++ b/registry/index.tsx
@@ -48,6 +48,11 @@ const ui: Registry = {
type: "components:ui",
files: ["registry/components/magicui/tweet-card.tsx"],
},
+ "shimmer-button": {
+ name: "shimmer-button",
+ type: "components:ui",
+ files: ["registry/components/magicui/shimmer-button.tsx"],
+ },
};
const example: Registry = {
@@ -156,6 +161,14 @@ const example: Registry = {
() => import("@/registry/components/example/tweet-card-demo"),
),
},
+ "shimmer-button-demo": {
+ name: "shimmer-button-demo",
+ type: "components:example",
+ files: ["registry/components/example/shimmer-button-demo.tsx"],
+ component: React.lazy(
+ () => import("@/registry/components/example/shimmer-button-demo"),
+ ),
+ },
};
export const registry: Registry = {
diff --git a/tailwind.config.ts b/tailwind.config.ts
index ad699da1..5fb9510f 100644
--- a/tailwind.config.ts
+++ b/tailwind.config.ts
@@ -66,6 +66,8 @@ module.exports = {
meteor: "meteor 5s linear infinite",
grid: "grid 15s linear infinite",
marquee: "marquee var(--duration) linear infinite",
+ flip: "flip calc(var(--spark) * 2) infinite steps(2, end)",
+ rotate: "rotate var(--spark) linear infinite both;",
},
keyframes: {
"accordion-down": {
@@ -98,6 +100,14 @@ module.exports = {
from: { transform: "translateX(0)" },
to: { transform: "translateX(calc(-50% - var(--gap)/2))" },
},
+ flip: {
+ to: { rotate: "360deg" },
+ },
+ rotate: {
+ to: {
+ transform: "rotate(90deg)",
+ },
+ },
},
},
},