Glitch Button
nyxui/glitch-buttonFreeComponent
Cyberpunk-inspired button with dynamic glitch effects that can be triggered on hover or click.
Live preview
live · rendered by the registry
Rendered by shadcn/ui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://nyxui.com/r/glitch-button.jsonSource
1"use client";2import React, { useState, useRef } from "react";3import { twMerge } from "tailwind-merge";45interface GlitchButtonProps6 extends React.ButtonHTMLAttributes<HTMLButtonElement> {7 children: React.ReactNode;8 className?: string;9 glitchOnHover?: boolean;10 glitchAlways?: boolean;11 glitchColors?: {12 primary?: string;13 secondary?: string;14 };15 borderColor?: string;16}1718export const GlitchButton: React.FC<GlitchButtonProps> = ({19 children,20 className = "",21 glitchOnHover = true,22 glitchAlways = false,23 glitchColors = {24 primary: "#ef00ef",25 secondary: "#00ffff",26 },27 borderColor = "white",28 ...props29}) => {30 const [isHovering, setIsHovering] = useState(false);31 const [isClicked, setIsClicked] = useState(false);32 const buttonRef = useRef<HTMLButtonElement>(null);33 const showGlitch = glitchAlways || (glitchOnHover && isHovering) || isClicked;34 const bgColorClass = className.match(/bg-[a-z0-9-]+/)?.[0] || "bg-gray-900";35 const textColorClass =36 className.match(/text-[a-z0-9-]+/)?.[0] || "text-white";37 const isRounded = /rounded(-[a-z]+)?/.test(className);3839 const borderStyle = {40 boxShadow: `inset ${borderColor} 5px 5px 0px, inset ${borderColor} -5px 5px 0px, inset ${borderColor} 5px -5px 0px, inset ${borderColor} -5px -5px 0px`,41 };4243 const textShadowStyle = {44 textShadow: `45 -1.5px -1.5px 0 ${glitchColors.primary},46 1.5px 1.5px 0 ${glitchColors.secondary}47 `,48 };4950 const handleMouseEnter = () => setIsHovering(true);51 const handleMouseLeave = () => setIsHovering(false);5253 const handleClick = () => {54 setIsClicked(true);55 setTimeout(() => setIsClicked(false), 500);56 };5758 const containerClasses = twMerge(59 "relative cursor-pointer font-mono overflow-hidden",60 "text-4xl",61 "bg-gray-900",62 "text-white",63 "p-4 m-1.5",64 "group",65 "hover:shadow-none",66 "hover:bg-gradient-to-r hover:from-fuchsia-600 hover:via-white hover:to-cyan-400",67 isClicked ? "click-glitch" : "",68 className,69 );7071 return (72 <button73 ref={buttonRef}74 onClick={handleClick}75 onMouseEnter={handleMouseEnter}76 onMouseLeave={handleMouseLeave}77 className={containerClasses}78 style={borderStyle}79 {...props}80 >81 <span82 className={`83 block84 ${showGlitch ? "opacity-0" : "opacity-100"}85 transition-opacity86 ${glitchAlways ? "flicker-animation" : ""}87 `}88 >89 {children}90 </span>9192// … truncated
Files it writes
More from shadcn/ui
All 68 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| 3D Layered Card3d-layered-card | shadcn/ui | Components | Free | 1 dep | |
| Animated Code Blockanimated-code-block | shadcn/ui | Components | Free | 3 deps | |
| Animated Grainy Backgroundanimated-grainy-bg | shadcn/ui | Components | Free | 1 dep | |
| Animated Textanimated-text | shadcn/ui | Components | Free | 1 dep | |
| Apple Glass Effectapple-glass-effect | shadcn/ui | Components | Free | 1 dep | |
| Bubble Backgroundbubble-background | shadcn/ui | Components | Free | no deps | |
| Custom Cursorcustom-cursor | shadcn/ui | Components | Free | 1 dep | |
| Cyberpunk Cardcyberpunk-card | shadcn/ui | Components | Free | no deps |
