Pixel Icon
bucharitesh/pixel-iconFreeComponent
A pixel icon component for Next.js apps with next-themes and Tailwind CSS, supporting system, light, and dark modes.
Install it
npx shadcn@latest add https://bucharitesh.in/r/pixel-icon.jsonSource
1'use client';23import type React from 'react';4import { useCallback, useEffect, useMemo, useRef, useState } from 'react';56interface PixelIconProps {7 icon: number[][];8 baseColor: string;9 flickerColor: string;10 secondaryColor?: string;11 size?: number;12 flickerChance?: number;13 pixelShape?: 'circle' | 'square';14 className?: string;15}1617const PixelIcon: React.FC<PixelIconProps> = ({18 icon,19 baseColor,20 flickerColor,21 secondaryColor = 'gray',22 size = 80,23 flickerChance = 0.3,24 pixelShape = 'circle',25 className,26}) => {27 const canvasRef = useRef<HTMLCanvasElement>(null);28 const [isHovering, setIsHovering] = useState(false);29 const [isInView, setIsInView] = useState(false);3031 const memoizedColors = useMemo(() => {32 const toRGB = (color: string): [number, number, number] => {33 if (typeof window === 'undefined') {34 return [0, 0, 0];35 }36 const canvas = document.createElement('canvas');37 canvas.width = canvas.height = 1;38 const ctx = canvas.getContext('2d');39 if (!ctx) return [255, 0, 0];40 ctx.fillStyle = color;41 ctx.fillRect(0, 0, 1, 1);42 const [r, g, b] = ctx.getImageData(0, 0, 1, 1).data;43 return [r, g, b];44 };4546 const createShades = (47 color: [number, number, number],48 isDarker: boolean49 ) => {50 const shades: any = [];51 if (isDarker) {52 // Create more distinct dark shades53 const darkFactors = [0.7, 0.8, 0.9, 1.0];54 for (const factor of darkFactors) {55 shades.push(56 color.map((c) => Math.floor(c * factor)) as [number, number, number]57 );58 }59 } else {60 // Keep the original logic for lighter shades61 for (let i = 0; i < 4; i++) {62 const factor = 0.7 + (0.6 * i) / 3; // Range from 0.7 to 1.363 shades.push(64 color.map((c) => Math.min(255, Math.floor(c * factor))) as [65 number,66 number,67 number,68 ]69 );70 }71 }72 return shades;73 };7475 const baseRGB = toRGB(baseColor);76 const flickerRGB = toRGB(flickerColor);77 const secondaryRGB = toRGB(secondaryColor);7879 return {80 base: `rgb(${baseRGB.join(',')})`,81 flickerDark: createShades(flickerRGB, true),82 flickerLight: createShades(flickerRGB, false),83 secondary: `rgb(${secondaryRGB.join(',')})`,84 };85 }, [baseColor, flickerColor, secondaryColor]);8687 const setupCanvas = useCallback(88// … truncated
Files it writes
More from bucharitesh
All 26 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Bookbook | bucharitesh | Components | Free | 1 dep · 2 files | |
| Game of Lifegame-of-life | bucharitesh | Components | Free | no deps | |
| Magical Mousemagical-mouse | bucharitesh | Components | Free | 1 dep | |
| Metallic Buttonmetallic-button | bucharitesh | Components | Free | 2 deps | |
| Modern Progressmodern-progress | bucharitesh | Components | Free | 1 dep | |
| Split Text Effectsplit-text-effect | bucharitesh | Components | Free | 1 dep | |
| Text Highlighttext-highlight | bucharitesh | Components | Free | 1 dep | |
| View Magnifierview-magnifier | bucharitesh | Components | Free | 1 dep |
