Skip to content

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

feat: shine border component (#94)

Adebayo Anuoluwa Success7e85ef1d2c8c
diff --git a/config/docs.ts b/config/docs.ts
index bc856540..3096f19a 100644
--- a/config/docs.ts
+++ b/config/docs.ts
@@ -115,6 +115,12 @@ export const docsConfig: DocsConfig = {
href: `/docs/components/border-beam`,
items: [],
},
+ {
+ title: "Shine Border",
+ href: `/docs/components/shine-border`,
+ items: [],
+ label: "New",
+ },
{
title: "Magic Card",
href: `/docs/components/magic-card`,
diff --git a/content/docs/components/shine-border.mdx b/content/docs/components/shine-border.mdx
new file mode 100644
index 00000000..89f7424e
--- /dev/null
+++ b/content/docs/components/shine-border.mdx
@@ -0,0 +1,68 @@
+---
+title: Shine Border
+date: 2024-05-25
+description: Shine border is an animated background border effect.
+author: unnamed-lab
+published: true
+---
+
+<ComponentPreview name="shine-border-demo" />
+
+<Steps>
+
+### Installation
+
+Copy and paste the following code into your project.
+
+```js
+// tailwind.config.js
+module.exports = {
+ theme: {
+ extend: {
+ keyframes: {
+ "shine-pulse": {
+ "0%": {
+ "background-position": "0% 0%",
+ },
+ "50%": {
+ "background-position": "100% 100%",
+ },
+ to: {
+ "background-position": "0% 0%",
+ },
+ },
+ },
+ },
+ },
+};
+```
+
+```text
+components/magicui/shine-border.tsx
+```
+
+<ComponentSource name="shine-border" />
+
+</Steps>
+
+## Examples
+
+### Silver
+
+<ComponentPreview name="shine-border-demo-2" />
+
+## Props
+
+| Prop | Type | Description | Default |
+| ------------ | ------------------------------ | --------------------------------------------------- | ---------- |
+| className | string | The class name to be applied to the component | |
+| duration | number | The class name to be applied to the shining border. | 14 seconds |
+| color | `#${string}` OR `#${string}`[] | A string or string array to define border color. | #FFBD7A |
+| borderRadius | number | Defines the radius of the border. | 8px |
+| borderWidth | number | Defines the width of the border. | 2px |
+| children | React.ReactNode | Contains react node elements. | {} |
+
+## Credits
+
+- Credits to [Matthew Goshman](https://codepen.io/matthewgoshman/pen/bGMpKZy) for this fantastic component.
+- Credits to [Anu Adebayo](https://twitter.com/unnamedcodes) for improving and customizing the component.
diff --git a/registry/components/example/shine-border-demo-2.tsx b/registry/components/example/shine-border-demo-2.tsx
new file mode 100644
index 00000000..7b1c276f
--- /dev/null
+++ b/registry/components/example/shine-border-demo-2.tsx
@@ -0,0 +1,9 @@
+import ShineBorder from "@/registry/components/magicui/shine-border";
+
+export default function ShineBorderDemo() {
+ return (
+ <ShineBorder className="text-center text-2xl font-bold capitalize">
+ Shine Border
+ </ShineBorder>
+ );
+}
diff --git a/registry/components/example/shine-border-demo.tsx b/registry/components/example/shine-border-demo.tsx
new file mode 100644
index 00000000..77d0e5fc
--- /dev/null
+++ b/registry/components/example/shine-border-demo.tsx
@@ -0,0 +1,12 @@
+import ShineBorder from "@/registry/components/magicui/shine-border";
+
+export default function ShineBorderDemo() {
+ return (
+ <ShineBorder
+ className="text-center text-2xl font-bold capitalize"
+ color={["#A07CFE", "#FE8FB5", "#FFBE7B"]}
+ >
+ Shine Border
+ </ShineBorder>
+ );
+}
diff --git a/registry/components/magicui/shine-border.tsx b/registry/components/magicui/shine-border.tsx
new file mode 100644
index 00000000..3626e349
--- /dev/null
+++ b/registry/components/magicui/shine-border.tsx
@@ -0,0 +1,53 @@
+"use client";
+
+import { cn } from "@/lib/utils";
+
+type TColorProp = `#${string}` | `#${string}`[];
+interface ShineBorderProps {
+ borderRadius?: number;
+ borderWidth?: number;
+ duration?: number;
+ color?: TColorProp;
+ className?: string;
+ children: React.ReactNode;
+}
+
+export default function ShineBorder({
+ borderRadius = 8,
+ borderWidth = 1,
+ duration = 14,
+ color = "#fff",
+ className,
+ children,
+}: ShineBorderProps) {
+ return (
+ <div
+ style={
+ {
+ "--border-radius": `${borderRadius}px`,
+ } as React.CSSProperties
+ }
+ className={cn(
+ "relative grid min-h-[60px] w-fit min-w-[300px] place-items-center rounded-[--border-radius] bg-white p-3 text-black dark:bg-black dark:text-white",
+ className,
+ )}
+ >
+ <div
+ style={
+ {
+ "--border-width": `${borderWidth}px`,
+ "--border-radius": `${borderRadius}px`,
+ "--border-radius-child": `${borderRadius * 0.2}px`,
+ "--shine-pulse-duration": `${duration}s`,
+ "--mask-linear-gradient": `linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0)`,
+ "--background-radial-gradient": `radial-gradient(transparent,transparent, ${!(color instanceof Array) ? color : color.join(",")},transparent,transparent)`,
+ } as React.CSSProperties
+ }
+ className={`before:bg-shine-size before:absolute before:inset-[0] before:aspect-square before:h-full before:w-full before:rounded-[--border-radius] before:p-[--border-width] before:will-change-[background-position] before:content-[""] before:![-webkit-mask-composite:xor] before:![mask-composite:exclude] before:[background-image:var(--background-radial-gradient)] before:[background-size:300%_300%] before:[mask:var(--mask-linear-gradient)] motion-safe:before:animate-[shine-pulse_var(--shine-pulse-duration)_infinite_linear]`}
+ ></div>
+ <div className={"z-[1] h-full w-full rounded-[--border-radius-child]"}>
+ {children}
+ </div>
+ </div>
+ );
+}
diff --git a/registry/index.tsx b/registry/index.tsx
index 1098d730..0fac1487 100644
--- a/registry/index.tsx
+++ b/registry/index.tsx
@@ -222,6 +222,11 @@ const ui: Registry = {
type: "components:ui",
files: ["registry/components/magicui/box-reveal.tsx"],
},
+ "shine-border": {
+ name: "shine-border",
+ type: "components:ui",
+ files: ["registry/components/magicui/shine-border.tsx"],
+ },
};
const example: Registry = {
@@ -773,6 +778,22 @@ const example: Registry = {
() => import("@/registry/components/example/box-reveal-demo"),
),
},
+ "shine-border-demo": {
+ name: "shine-border-demo",
+ type: "components:example",
+ files: ["registry/components/example/shine-border-demo.tsx"],
+ component: React.lazy(
+ () => import("@/registry/components/example/shine-border-demo"),
+ ),
+ },
+ "shine-border-demo-2": {
+ name: "shine-border-demo-2",
+ type: "components:example",
+ files: ["registry/components/example/shine-border-demo-2.tsx"],
+ component: React.lazy(
+ () => import("@/registry/components/example/shine-border-demo-2"),
+ ),
+ },
};
export const registry: Registry = {
...ui,
diff --git a/tailwind.config.ts b/tailwind.config.ts
index 36f73f2f..c2da4324 100644
--- a/tailwind.config.ts
+++ b/tailwind.config.ts
@@ -183,8 +183,22 @@ module.exports = {
"rotate(360deg) translateY(calc(var(--radius) * 1px)) rotate(-360deg)",
},
},
+ "shine-pulse": {
+ "0%": {
+ "background-position": "0% 0%",
+ },
+ "50%": {
+ "background-position": "100% 100%",
+ },
+ to: {
+ "background-position": "0% 0%",
+ },
+ },
},
},
},
- plugins: [require("tailwindcss-animate"), require("@tailwindcss/typography")],
+ plugins: [
+ require("tailwindcss-animate"),
+ require("@tailwindcss/typography"),
+ ],
};