Skip to content

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

feat: neon gradient card component (#83)

William52c4af920dcf
diff --git a/config/docs.ts b/config/docs.ts
index ccca5e7d..bc856540 100644
--- a/config/docs.ts
+++ b/config/docs.ts
@@ -105,7 +105,6 @@ export const docsConfig: DocsConfig = {
href: `/docs/components/animated-beam`,
items: [],
},
-
// {
// title: "Animated Lines",
// href: `/docs/components/animated-lines`,
@@ -126,6 +125,12 @@ export const docsConfig: DocsConfig = {
href: `/docs/components/meteors`,
items: [],
},
+ {
+ title: "Neon Gradient Card",
+ href: `/docs/components/neon-gradient-card`,
+ items: [],
+ label: "New",
+ },
],
},
{
diff --git a/content/docs/components/neon-gradient-card.mdx b/content/docs/components/neon-gradient-card.mdx
new file mode 100644
index 00000000..d5d27df0
--- /dev/null
+++ b/content/docs/components/neon-gradient-card.mdx
@@ -0,0 +1,57 @@
+---
+title: Neon Gradient Card
+date: 2024-05-26
+description: A beautiful neon card effect
+author: Draxx0
+published: true
+---
+
+<ComponentPreview name="neon-gradient-card-demo" />
+
+<Steps>
+
+### Installation
+
+Copy and paste the following code into your project.
+
+```js
+// tailwind.config.js
+module.exports = {
+ theme: {
+ extend: {
+ animation: {
+ backgroundPositionSpin:
+ "background-position-spin 3000ms infinite alternate",
+ },
+ keyframes: {
+ "background-position-spin": {
+ "0%": { backgroundPosition: "top center" },
+ "100%": { backgroundPosition: "bottom center" },
+ },
+ },
+ },
+ },
+};
+```
+
+```text
+components/magicui/neon-gradient-card.tsx
+```
+
+<ComponentSource name="neon-gradient-card" />
+
+</Steps>
+
+## Props
+
+| Prop | Type | Description | Default |
+| ------------ | --------- | --------------------------------------------- | --------------------------------------------------- |
+| className | string | The class name to be applied to the component | - |
+| children | ReactNode | Children elements | - |
+| borderSize | number | The size of the border | 5 |
+| borderRadius | number | The size of the radius | 20 |
+| neonColors | object | The colors of the neon gradient | `{ firstColor: "#ff00aa", secondColor: "#00FFF1" }` |
+
+## Credits
+
+- Credit to [@Unleashed-Design](https://unleashed-design.de/)
diff --git a/registry/components/example/neon-gradient-card-demo.tsx b/registry/components/example/neon-gradient-card-demo.tsx
new file mode 100644
index 00000000..b51d4525
--- /dev/null
+++ b/registry/components/example/neon-gradient-card-demo.tsx
@@ -0,0 +1,11 @@
+import { NeonGradientCard } from "@/registry/components/magicui/neon-gradient-card";
+
+export default async function NeonGradientCardDemo() {
+ return (
+ <NeonGradientCard className="max-w-sm items-center justify-center text-center">
+ <span className="pointer-events-none z-10 whitespace-pre-wrap bg-gradient-to-br from-[#ff2975] from-35% to-[#00FFF1] bg-clip-text text-center text-7xl font-bold leading-none tracking-tighter text-transparent drop-shadow-[0_5px_5px_rgba(0,0,0,0.8)]">
+ Neon Gradient Card
+ </span>
+ </NeonGradientCard>
+ );
+}
diff --git a/registry/components/magicui/neon-gradient-card.tsx b/registry/components/magicui/neon-gradient-card.tsx
new file mode 100644
index 00000000..052f4c6d
--- /dev/null
+++ b/registry/components/magicui/neon-gradient-card.tsx
@@ -0,0 +1,143 @@
+"use client";
+
+import { cn } from "@/lib/utils";
+import {
+ CSSProperties,
+ ReactElement,
+ ReactNode,
+ useEffect,
+ useRef,
+ useState,
+} from "react";
+
+interface NeonColorsProps {
+ firstColor: string;
+ secondColor: string;
+}
+
+interface NeonGradientCardProps {
+ /**
+ * @default <div />
+ * @type ReactElement
+ * @description
+ * The component to be rendered as the card
+ * */
+ as?: ReactElement;
+ /**
+ * @default ""
+ * @type string
+ * @description
+ * The className of the card
+ */
+ className?: string;
+
+ /**
+ * @default ""
+ * @type ReactNode
+ * @description
+ * The children of the card
+ * */
+ children?: ReactNode;
+
+ /**
+ * @default 5
+ * @type number
+ * @description
+ * The size of the border in pixels
+ * */
+ borderSize?: number;
+
+ /**
+ * @default 20
+ * @type number
+ * @description
+ * The size of the radius in pixels
+ * */
+ borderRadius?: number;
+
+ /**
+ * @default "{ firstColor: '#ff00aa', secondColor: '#00FFF1' }"
+ * @type string
+ * @description
+ * The colors of the neon gradient
+ * */
+ neonColors?: NeonColorsProps;
+
+ [key: string]: any;
+}
+
+const NeonGradientCard: React.FC<NeonGradientCardProps> = ({
+ className,
+ children,
+ borderSize = 5,
+ borderRadius = 20,
+ neonColors = {
+ firstColor: "#ff00aa",
+ secondColor: "#00FFF1",
+ },
+ ...props
+}) => {
+ const containerRef = useRef<HTMLDivElement>(null);
+ const [dimensions, setDimensions] = useState({ width: 0, height: 0 });
+
+ useEffect(() => {
+ const updateDimensions = () => {
+ if (containerRef.current) {
+ const { offsetWidth, offsetHeight } = containerRef.current;
+ setDimensions({ width: offsetWidth, height: offsetHeight });
+ }
+ };
+
+ updateDimensions();
+ window.addEventListener("resize", updateDimensions);
+
+ return () => {
+ window.removeEventListener("resize", updateDimensions);
+ };
+ }, []);
+
+ return (
+ <div
+ ref={containerRef}
+ style={
+ {
+ "--border-size": `${borderSize}px`,
+ "--border-radius": `${borderRadius}px`,
+ "--neon-first-color": neonColors.firstColor,
+ "--neon-second-color": neonColors.secondColor,
+ "--card-width": `${dimensions.width}px`,
+ "--card-height": `${dimensions.height}px`,
+ "--card-content-radius": `${borderRadius - borderSize}px`,
+ "--pseudo-element-background-image": `linear-gradient(0deg, ${neonColors.firstColor}, ${neonColors.secondColor})`,
+ "--pseudo-element-width": `${dimensions.width + borderSize * 2}px`,
+ "--pseudo-element-height": `${dimensions.height + borderSize * 2}px`,
+ "--after-blur": `${dimensions.width / 2}px`,
+ } as CSSProperties
+ }
+ className={cn(
+ "relative z-10 h-full w-full rounded-[var(--border-radius)]",
+ className,
+ )}
+ {...props}
+ >
+ <div
+ className={cn(
+ "relative h-full min-h-[inherit] w-full rounded-[var(--card-content-radius)] bg-gray-100 p-6",
+ "before:absolute before:-left-[var(--border-size)] before:-top-[var(--border-size)] before:-z-10 before:block",
+ "before:h-[var(--pseudo-element-height)] before:w-[var(--pseudo-element-width)] before:rounded-[var(--border-radius)] before:content-['']",
+ "before:bg-[linear-gradient(0deg,var(--neon-first-color),var(--neon-second-color))] before:bg-[length:100%_200%]",
+ "before:animate-backgroundPositionSpin",
+ "after:absolute after:-left-[var(--border-size)] after:-top-[var(--border-size)] after:-z-10 after:block",
+ "after:h-[var(--pseudo-element-height)] after:w-[var(--pseudo-element-width)] after:rounded-[var(--border-radius)] after:blur-[var(--after-blur)] after:content-['']",
+ "after:bg-[linear-gradient(0deg,var(--neon-first-color),var(--neon-second-color))] after:bg-[length:100%_200%]",
+ "after:animate-backgroundPositionSpin",
+ "dark:bg-neutral-900",
+ )}
+ >
+ {children}
+ </div>
+ </div>
+ );
+};
+
+export { NeonGradientCard };
diff --git a/registry/index.tsx b/registry/index.tsx
index b2be9297..1098d730 100644
--- a/registry/index.tsx
+++ b/registry/index.tsx
@@ -7,6 +7,11 @@ const ui: Registry = {
type: "components:ui",
files: ["registry/components/magicui/magic-card.tsx"],
},
+ "neon-gradient-card": {
+ name: "neon-gradient-card",
+ type: "components:ui",
+ files: ["registry/components/magicui/neon-gradient-card.tsx"],
+ },
"linear-gradient": {
name: "linear-gradient",
type: "components:ui",
@@ -228,6 +233,14 @@ const example: Registry = {
() => import("@/registry/components/example/magic-card-demo"),
),
},
+ "neon-gradient-card-demo": {
+ name: "neon-gradient-card-demo",
+ type: "components:example",
+ files: ["registry/components/example/neon-gradient-card-demo.tsx"],
+ component: React.lazy(
+ () => import("@/registry/components/example/neon-gradient-card-demo"),
+ ),
+ },
"magic-card-gradient": {
name: "magic-card-gradient",
type: "components:example",
diff --git a/tailwind.config.ts b/tailwind.config.ts
index e547e755..2ef66c3e 100644
--- a/tailwind.config.ts
+++ b/tailwind.config.ts
@@ -76,6 +76,8 @@ module.exports = {
shimmer: "shimmer 8s infinite",
"border-beam": "border-beam calc(var(--duration)*1s) infinite linear",
orbit: "orbit calc(var(--duration)*1s) linear infinite",
+ backgroundPositionSpin:
+ "background-position-spin 3000ms infinite alternate",
},
keyframes: {
"accordion-down": {
@@ -86,6 +88,10 @@ module.exports = {
from: { height: "var(--radix-accordion-content-height)" },
to: { height: "0" },
},
+ "background-position-spin": {
+ "0%": { backgroundPosition: "top center" },
+ "100%": { backgroundPosition: "bottom center" },
+ },
gradient: {
to: {
backgroundPosition: "var(--bg-size) 0",