UI Library for Design Engineers. Animated components and effects you can copy and paste into your apps. Free. Open Source.
✨ feat: Add border beam component
Dillion Verma6e4beb5e0e55
diff --git a/content/components/border-beam-demo.mdx b/content/components/border-beam-demo.mdxnew file mode 100644index 00000000..bd4aa420--- /dev/null+++ b/content/components/border-beam-demo.mdx@@ -0,0 +1,94 @@+---+title: Border Beam+date: 2024-02-05+summary: An animated beam of light which travels along the border of its container.+author: dillionverma+published: true+video: https://cdn.magicui.design/border-beam.mp4+---++<ComponentPreview name="border-beam-demo" />++<Steps>++<Step>++## Installation++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: {+ "border-beam": "border-beam calc(var(--duration)*1s) infinite linear",+ },+ keyframes: {+ "border-beam": {+ "100%": {+ "offset-distance": "100%",+ },+ },+ },+ },+ },+};+```++```text+components/magicui/border-beam.tsx+```++<ComponentSource name="border-beam" />++</Step>++</Steps>++## Usage++Just place the border beam component inside a div with relative positioning, width, and height. You will notice the beam automatically moves around the perimeter of it's container.++```tsx+import { BorderBeam } from "@/components/magicui/border-beam.tsx";++export default async function App() {+ return (+ <div className="relative h-[200px] w-[200px] rounded-xl">+ <BorderBeam />+ </div>+ );+}+```++## Props++### Border Beam++| Prop | Type | Description | Default |+| ----------- | ------ | -------------------------------------- | ------- |+| className | string | Custom class to apply to the component | - |+| size | number | Size of the beam | 300 |+| duration | number | Duration of the animation | 15 |+| anchor | number | Anchor point of the beam | 90 |+| borderWidth | number | Width of the beam | 1.5 |+| colorFrom | string | Start color of the beam | #ffaa40 |+| colorTo | string | End color of the beam | #9c40ff |+| delay | number | Delay before the animation starts | 0 |++## Credits++- Credit to [@linear](https://linear.app/) where I first saw this effect.+- Credit to [@jh3yy](https://twitter.com/jh3yy) for the inspiration to create this component.diff --git a/public/dashboard-dark.png b/public/dashboard-dark.pngnew file mode 100644index 00000000..cc6cfc15Binary files /dev/null and b/public/dashboard-dark.png differdiff --git a/public/dashboard-light.png b/public/dashboard-light.pngnew file mode 100644index 00000000..48f75e69Binary files /dev/null and b/public/dashboard-light.png differdiff --git a/registry/components/example/border-beam-demo.tsx b/registry/components/example/border-beam-demo.tsxnew file mode 100644index 00000000..f5edebe0--- /dev/null+++ b/registry/components/example/border-beam-demo.tsx@@ -0,0 +1,20 @@+import { BorderBeam } from "@/registry/components/magicui/border-beam";++export default function BorderBeamDemo() {+ return (+ <div className="relative rounded-xl">+ <img+ src="/dashboard-dark.png"+ alt="Hero Image"+ className="hidden max-w-[700px] rounded-[inherit] border object-contain shadow-lg dark:block"+ />+ <img+ src="/dashboard-light.png"+ alt="Hero Image"+ className="block max-w-[700px] rounded-[inherit] border object-contain shadow-lg dark:hidden"+ />++ <BorderBeam size={250} duration={12} delay={9} />+ </div>+ );+}diff --git a/registry/components/magicui/border-beam.tsx b/registry/components/magicui/border-beam.tsxnew file mode 100644index 00000000..fff0fcdc--- /dev/null+++ b/registry/components/magicui/border-beam.tsx@@ -0,0 +1,49 @@+import { cn } from "@/lib/utils";++interface BorderBeamProps {+ className?: string;+ size?: number;+ duration?: number;+ borderWidth?: number;+ anchor?: number;+ colorFrom?: string;+ colorTo?: string;+ delay?: number;+}++export const BorderBeam = ({+ className,+ size = 300,+ duration = 15,+ anchor = 90,+ borderWidth = 1.5,+ colorFrom = "#ffaa40",+ colorTo = "#9c40ff",+ delay = 0,+}: BorderBeamProps) => {+ return (+ <div+ style={+ {+ "--size": size,+ "--duration": duration,+ "--anchor": anchor,+ "--border-width": borderWidth,+ "--color-from": colorFrom,+ "--color-to": colorTo,+ "--delay": `-${delay}s`,+ } as React.CSSProperties+ }+ className={cn(+ "absolute inset-[0] rounded-[inherit] [border:calc(var(--border-width)*1px)_solid_transparent]",++ // mask styles+ "![mask-clip:padding-box,border-box] ![mask-composite:intersect] [mask:linear-gradient(transparent,transparent),linear-gradient(white,white)]",++ // pseudo styles+ "after:absolute after:aspect-square after:w-[calc(var(--size)*1px)] after:animate-border-beam after:[animation-delay:var(--delay)] after:[background:linear-gradient(to_left,var(--color-from),var(--color-to),transparent)] after:[offset-anchor:calc(var(--anchor)*1%)_50%] after:[offset-path:rect(0_auto_auto_0_round_calc(var(--size)*1px))]",+ className,+ )}+ />+ );+};diff --git a/registry/index.tsx b/registry/index.tsxindex 8c309d3e..ca9a5ecd 100644--- a/registry/index.tsx+++ b/registry/index.tsx@@ -102,6 +102,16 @@ const ui: Registry = {type: "components:ui",files: ["registry/components/magicui/text-shimmer.tsx"],},+ "animated-grid-pattern": {+ name: "animated-grid-pattern",+ type: "components:ui",+ files: ["registry/components/magicui/animated-grid-pattern.tsx"],+ },+ "border-beam": {+ name: "border-beam",+ type: "components:ui",+ files: ["registry/components/magicui/border-beam.tsx"],+ },};const example: Registry = {@@ -346,6 +356,22 @@ const example: Registry = {() => import("@/registry/components/example/particles-demo"),),},+ "animated-grid-pattern-demo": {+ name: "animated-grid-pattern-demo",+ type: "components:example",+ files: ["registry/components/example/animated-grid-pattern-demo.tsx"],+ component: React.lazy(+ () => import("@/registry/components/example/animated-grid-pattern-demo"),+ ),+ },+ "border-beam-demo": {+ name: "border-beam-demo",+ type: "components:example",+ files: ["registry/components/example/border-beam-demo.tsx"],+ component: React.lazy(+ () => import("@/registry/components/example/border-beam-demo"),+ ),+ },};export const registry: Registry = {diff --git a/tailwind.config.ts b/tailwind.config.tsindex 41c263b0..0c7dbca0 100644--- a/tailwind.config.ts+++ b/tailwind.config.ts@@ -74,6 +74,7 @@ module.exports = {ripple: "ripple 3400ms ease infinite",line: "line 2s linear infinite",shimmer: "shimmer 8s infinite",+ "border-beam": "border-beam calc(var(--duration)*1s) infinite linear",},keyframes: {"accordion-down": {@@ -148,6 +149,11 @@ module.exports = {"0%": { "mask-position-x": "0%" },"100%": { "mask-position-x": "100%" },},+ "border-beam": {+ "100%": {+ "offset-distance": "100%",+ },+ },shimmer: {"0%, 90%, 100%": {"background-position": "calc(-100% - var(--shimmer-width)) 0",