Beams Background
kokonut-ui/beams-backgroundFreeComponent
Animated Beams in the background that are customizable.
Live preview
live · rendered by the registry
Rendered by kokonut-ui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://kokonutui.com/r/beams-background.jsonSource
1"use client";23/**4 * @author: @dorianbaffier5 * @description: Beams Background6 * @version: 1.0.07 * @date: 2025-06-268 * @license: MIT9 * @website: https://kokonutui.com10 * @github: https://github.com/kokonut-labs/kokonutui11 */1213import { motion } from "motion/react";14import { useEffect, useRef } from "react";15import { cn } from "@/lib/utils";1617interface AnimatedGradientBackgroundProps {18 className?: string;19 children?: React.ReactNode;20 intensity?: "subtle" | "medium" | "strong";21}2223interface Beam {24 x: number;25 y: number;26 width: number;27 length: number;28 angle: number;29 speed: number;30 opacity: number;31 hue: number;32 pulse: number;33 pulseSpeed: number;34}3536function createBeam(width: number, height: number, isDarkMode: boolean): Beam {37 const angle = -35 + Math.random() * 10;38 const hueBase = isDarkMode ? 190 : 210;39 const hueRange = isDarkMode ? 70 : 50;4041 return {42 x: Math.random() * width * 1.5 - width * 0.25,43 y: Math.random() * height * 1.5 - height * 0.25,44 width: 30 + Math.random() * 60,45 length: height * 2.5,46 angle,47 speed: 0.6 + Math.random() * 1.2,48 opacity: 0.12 + Math.random() * 0.16,49 hue: hueBase + Math.random() * hueRange,50 pulse: Math.random() * Math.PI * 2,51 pulseSpeed: 0.02 + Math.random() * 0.03,52 };53}5455export default function BeamsBackground({56 className,57 intensity = "strong",58}: AnimatedGradientBackgroundProps) {59 const canvasRef = useRef<HTMLCanvasElement>(null);60 const beamsRef = useRef<Beam[]>([]);61 const animationFrameRef = useRef<number>(0);62 const MINIMUM_BEAMS = 20;63 const isDarkModeRef = useRef<boolean>(false);6465 const opacityMap = {66 subtle: 0.7,67 medium: 0.85,68 strong: 1,69 };7071 useEffect(() => {72 const canvas = canvasRef.current;73 if (!canvas) return;7475 const ctx = canvas.getContext("2d");76 if (!ctx) return;7778 // Check for dark mode79 const updateDarkMode = () => {80 isDarkModeRef.current =81 document.documentElement.classList.contains("dark");82 };8384 const observer = new MutationObserver(updateDarkMode);85 observer.observe(document.documentElement, {86 attributes: true,87 attributeFilter: ["class"],88 });8990 updateDarkMode();9192 const updateCanvasSize = () => {93 const dpr = window.devicePixelRatio || 1;94 canvas.width = window.innerWidth * dpr;95 canvas.height = window.innerHeight * dpr;96 canvas.style.width = `${window.innerWidth}px`;97 canvas.style.height = `${window.innerHeight}px`;98// … truncated
What it pulls in
npm packages
Files it writes
More from kokonut-ui
All 40 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Action Search Baraction-search-bar | kokonut-ui | Components | Free | 2 deps · 2 files | |
| AI Input Searchai-input-search | kokonut-ui | Components | Free | 1 dep · 2 files | |
| AI State Loadingai-loading | kokonut-ui | Components | Free | 1 dep | |
| AI Input Selectorai-prompt | kokonut-ui | Components | Free | 2 deps · 4 files | |
| AI Text Loadingai-text-loading | kokonut-ui | Components | Free | 1 dep | |
| AI Voiceai-voice | kokonut-ui | Components | Free | 2 deps | |
| Apple Activity Cardapple-activity-card | kokonut-ui | Components | Free | 1 dep | |
| Magnet Buttonattract-button | kokonut-ui | Components | Free | 2 deps |
