Emerald Glass Button
Smoked-emerald optical Liquid Glass button with 1px specular bezel, lower-right prismatic refraction, hover mineral dust, and 3D lake-water wave refraction.
Hover for mineral dust · Click anywhere for lake-water ripple
1. Install Dependencies
$npm install lucide-react
2. Copy Component Code
components/ui/EmeraldLiquidGlassButton.tsx
1"use client";2
3import React, { useEffect, useId, useRef, type CSSProperties } from "react";4import Link from "next/link";5
6export type EmeraldLiquidGlassShape = "pill" | "machined";7
8export interface EmeraldLiquidGlassButtonProps {9 href?: string;10 shape?: EmeraldLiquidGlassShape;11 onClick?: React.MouseEventHandler<HTMLElement>;12 onPointerDown?: React.PointerEventHandler<HTMLElement>;13 onPointerMove?: React.PointerEventHandler<HTMLElement>;14 type?: "button" | "submit" | "reset";15 disabled?: boolean;16 target?: string;17 rel?: string;18 className?: string;19 ariaLabel?: string;20 children: React.ReactNode;21}22
23interface MineralSpeck {24 cx: number;25 cy: number;26 r: number;27 opacity: number;28 cool: boolean;29}30
31const PATTERN_WIDTH = 180;32const PATTERN_HEIGHT = 48;33
34const MINERAL_SPECKS: readonly MineralSpeck[] = Array.from(35 { length: 160 },36 (_, index) => {37 const seedA = Math.sin(index * 17.137 + 2.719) * 41293.8173;38 const seedB = Math.sin(index * 63.913 + 11.423) * 28471.3917;39 const seedC = Math.sin(index * 41.287 + 5.839) * 19583.6241;40 const u = seedA - Math.floor(seedA);41 const v = seedB - Math.floor(seedB);42 const w = seedC - Math.floor(seedC);43
44 return {45 cx: Number((u * PATTERN_WIDTH).toFixed(2)),46 cy: Number((v * PATTERN_HEIGHT).toFixed(2)),47 // ~0.75px sub-pixel diameter range (radius ~0.35-0.42px)48 r: Number((0.34 + w * 0.09).toFixed(2)),49 opacity: Number((0.14 + Math.pow(w, 1.5) * 0.52).toFixed(2)),50 cool: w > 0.65,51 };52 },53);54
55const SHAPE_RADIUS: Record<EmeraldLiquidGlassShape, string> = {56 pill: "rounded-full",57 machined: "rounded-xl",58};59
60const RIM_MASK_STYLE: CSSProperties = {61 padding: "1px",62 mask: "linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0)",63 WebkitMask: "linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0)",64 maskComposite: "exclude",65 WebkitMaskComposite: "xor",66};67
68const SVG_NS = "http://www.w3.org/2000/svg";69const WAVE_DURATION_MS = 1200;70
71interface ActiveSingleWave {72 x: number;73 y: number;74 maxCrestRadius: number;75 boundRadius: number;76 startTime: number;77 el: HTMLSpanElement;78 maskCircle: SVGCircleElement;79}80
81function clamp01(value: number): number {82 return Math.max(0, Math.min(1, value));83}84
85function smoothstep01(t: number): number {86 const x = clamp01(t);87 return x * x * (3 - 2 * x);88}89
90/** Evaluates cubic-bezier(0.22, 1, 0.36, 1) at normalized time t in [0, 1]. */91function easeLiquidWave(t: number): number {92 if (t <= 0) return 0;93 if (t >= 1) return 1;94 const cx1 = 0.22;95 const cy1 = 1.0;96 const cx2 = 0.36;97 const cy2 = 1.0;98
99 let u = t;100 for (let i = 0; i < 6; i++) {101 const inv = 1 - u;102 const x =103 3 * inv * inv * u * cx1 + 3 * inv * u * u * cx2 + u * u * u - t;104 const dx =105 3 * inv * inv * cx1 +106 6 * inv * u * (cx2 - cx1) +107 3 * u * u * (1 - cx2);108 if (Math.abs(dx) < 1e-5) break;109 u = clamp01(u - x / dx);110 }111 const inv = 1 - u;112 return 3 * inv * inv * u * cy1 + 3 * inv * u * u * cy2 + u * u * u;113}114
115const BASE_SURFACE_CLASSES =116 "group relative inline-flex items-center justify-center gap-2 select-none " +117 "bg-[linear-gradient(155deg,rgba(6,78,55,0.58)_0%,rgba(2,28,20,0.78)_52%,rgba(1,16,11,0.88)_100%)] " +118 "backdrop-blur-xl shadow-[inset_0_1px_0.5px_rgba(236,253,245,0.28)] " +119 "font-medium tracking-[-0.01em] text-white " +120 "transition-transform duration-200 motion-safe:active:scale-[0.99] " +121 "focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-emerald-500 dark:focus-visible:outline-emerald-400 " +122 "disabled:pointer-events-none disabled:opacity-50";123
124function prefersReducedMotion(): boolean {125 return (126 typeof window !== "undefined" &&127 window.matchMedia("(prefers-reduced-motion: reduce)").matches128 );129}130
131function createRippleNode(x: number, y: number): HTMLSpanElement {132 const wave = document.createElement("span");133 wave.setAttribute("aria-hidden", "true");134 wave.style.position = "absolute";135 wave.style.left = `${x}px`;136 wave.style.top = `${y}px`;137 wave.style.width = "0px";138 wave.style.height = "0px";139 wave.style.borderRadius = "9999px";140 wave.style.pointerEvents = "none";141 wave.style.transform = "translate(-50%, -50%)";142 wave.style.opacity = "0";143 wave.style.willChange = "width, height, opacity";144 return wave;145}146
147/** Smoked-emerald optical Liquid Glass button with 1px specular bezel, prismatic edge glint, mineral dust, and a single propagating 3D water swell illuminating starlight. */148export function EmeraldLiquidGlassButton({149 href,150 shape = "pill",151 onClick,152 onPointerDown,153 onPointerMove,154 type = "button",155 disabled = false,156 target,157 rel,158 className = "",159 ariaLabel,160 children,161}: EmeraldLiquidGlassButtonProps) {162 const controlRef = useRef<HTMLElement | null>(null);163 const opticsLayerRef = useRef<HTMLSpanElement | null>(null);164 const rippleLayerRef = useRef<HTMLSpanElement | null>(null);165 const displaceRef = useRef<SVGFEDisplacementMapElement | null>(null);166 const waveDustRectRef = useRef<SVGRectElement | null>(null);167 const waveMaskGroupRef = useRef<SVGGElement | null>(null);168 const activeWavesRef = useRef<Set<ActiveSingleWave>>(new Set());169 const physicsRafRef = useRef<number | null>(null);170 const lastPointerRippleAtRef = useRef(-Infinity);171
172 const rawId = useId().replace(/[^a-zA-Z0-9_-]/g, "");173 const patternId = `emerald-dust-${rawId}`;174 const starlightPatternId = `emerald-starlight-${rawId}`;175 const filterId = `emerald-refract-${rawId}`;176 const crestGradId = `emerald-crest-${rawId}`;177 const waveMaskId = `emerald-wave-mask-${rawId}`;178
179 const radiusClass = SHAPE_RADIUS[shape];180
181 useEffect(() => {182 const waves = activeWavesRef.current;183 return () => {184 if (physicsRafRef.current !== null) {185 window.cancelAnimationFrame(physicsRafRef.current);186 physicsRafRef.current = null;187 }188 for (const wave of waves) {189 wave.el.remove();190 wave.maskCircle.remove();191 }192 waves.clear();193 };194 }, []);195
196 const stepPhysics = (now: number) => {197 const waves = activeWavesRef.current;198 const opticsEl = opticsLayerRef.current;199 const displaceEl = displaceRef.current;200 const dustRect = waveDustRectRef.current;201
202 let maxCrestGlint = 0;203 let totalDisplacement = 0;204
205 for (const wave of Array.from(waves)) {206 const elapsed = now - wave.startTime;207 const t = elapsed / WAVE_DURATION_MS;208
209 if (t >= 1) {210 wave.el.remove();211 wave.maskCircle.remove();212 waves.delete(wave);213 continue;214 }215
216 const p = easeLiquidWave(t);217 const crestRadius = Math.max(5, wave.maxCrestRadius * p);218 // Crest sits at 82% of container radius so outer specular falloff dissipates organically inside bounds219 const crestPct = 82;220 const boxRadius = crestRadius / (crestPct / 100);221 const boxDiameter = boxRadius * 2;222
223 const normDist = crestRadius / wave.boundRadius;224 const edgeDamp = 1 - smoothstep01((normDist - 0.72) / 0.48) * 0.55;225
226 // Single continuous 3D crest + trough optical wave (soft specular rise & emerald trough, zero wireframe lines)227 const strokePx = 2.4 - 1.6 * clamp01(p * 0.75);228 const halfStrokePct = Math.max(0.28, ((strokePx * 0.55) / boxRadius) * 100);229 const featherPct = Math.max(1.8, ((strokePx * 2.2 + 2.2) / boxRadius) * 100);230 const troughWidthPct = Math.max(5.5, ((9 + strokePx * 4.5) / boxRadius) * 100);231
232 const attack = smoothstep01(t / 0.08);233 const decay = Math.pow(1 - t, 1.15);234 const waveEnergy = attack * decay * edgeDamp;235
236 const troughAlpha = (0.58 * (1 - 0.35 * p)).toFixed(3);237 const mintAlpha = (0.34 * (1 - 0.25 * p)).toFixed(3);238 const crestAlpha = (0.52 * (1 - 0.2 * p)).toFixed(3);239 const outerMintAlpha = (0.22 * (1 - 0.35 * p)).toFixed(3);240
241 const s0 = Math.max(0, crestPct - troughWidthPct - featherPct).toFixed(2);242 const s1 = Math.max(0, crestPct - troughWidthPct * 0.45).toFixed(2);243 const s2 = Math.max(0, crestPct - halfStrokePct - featherPct * 0.45).toFixed(2);244 const s3 = Math.max(0, crestPct - halfStrokePct).toFixed(2);245 const s4 = Math.min(98.5, crestPct + halfStrokePct).toFixed(2);246 const s5 = Math.min(99.2, crestPct + halfStrokePct + featherPct).toFixed(2);247 const s6 = Math.min(100, crestPct + halfStrokePct + featherPct * 2.2).toFixed(2);248
249 wave.el.style.width = `${boxDiameter.toFixed(1)}px`;250 wave.el.style.height = `${boxDiameter.toFixed(1)}px`;251 wave.el.style.opacity = clamp01(waveEnergy * 0.92).toFixed(3);252 wave.el.style.background = `radial-gradient(circle, transparent ${s0}%, rgba(1, 16, 11, ${troughAlpha}) ${s1}%, rgba(110, 231, 183, ${mintAlpha}) ${s2}%, rgba(236, 253, 245, ${crestAlpha}) ${s3}%, rgba(236, 253, 245, ${crestAlpha}) ${s4}%, rgba(110, 231, 183, ${outerMintAlpha}) ${s5}%, transparent ${s6}%)`;253
254 // Synchronize SVG starlight mask circle strictly to the advancing 3D wave crest255 const starMaskR = Math.max(8, crestRadius * 1.18);256 const starOpacity = clamp01(257 Math.sin(Math.min(1, t * 1.05) * Math.PI) * Math.pow(1 - t, 0.55) * 1.45,258 );259 wave.maskCircle.setAttribute("r", starMaskR.toFixed(1));260 wave.maskCircle.setAttribute("fill-opacity", starOpacity.toFixed(3));261
262 maxCrestGlint = Math.max(maxCrestGlint, starOpacity);263 totalDisplacement +=264 Math.sin(Math.min(1, t * 1.05) * Math.PI) * Math.pow(1 - t, 0.95) * 15;265 }266
267 if (waves.size > 0) {268 if (opticsEl && displaceEl) {269 if (!opticsEl.style.filter) {270 opticsEl.style.filter = `url(#${filterId})`;271 }272 displaceEl.setAttribute(273 "scale",274 Math.max(0, Math.min(18, totalDisplacement)).toFixed(2),275 );276 }277 if (dustRect) {278 dustRect.style.opacity = clamp01(maxCrestGlint).toFixed(3);279 }280 physicsRafRef.current = window.requestAnimationFrame(stepPhysics);281 } else {282 physicsRafRef.current = null;283 if (displaceEl) displaceEl.setAttribute("scale", "0");284 if (dustRect) dustRect.style.opacity = "0";285 if (opticsEl) opticsEl.style.filter = "";286 }287 };288
289 const triggerLakeWave = (clientX?: number, clientY?: number) => {290 if (disabled || prefersReducedMotion()) return;291 const host = controlRef.current;292 const layer = rippleLayerRef.current;293 const maskGroup = waveMaskGroupRef.current;294 if (!host || !layer || !maskGroup) return;295
296 const rect = host.getBoundingClientRect();297 const x =298 typeof clientX === "number" ? clientX - rect.left : rect.width / 2;299 const y =300 typeof clientY === "number" ? clientY - rect.top : rect.height / 2;301 const maxCornerDist = Math.hypot(302 Math.max(x, rect.width - x),303 Math.max(y, rect.height - y),304 );305 const maxCrestRadius = Math.max(maxCornerDist * 1.12, 48);306 const boundRadius = Math.max(maxCornerDist, 44);307
308 const el = createRippleNode(x, y);309 layer.appendChild(el);310
311 const maskCircle = document.createElementNS(SVG_NS, "circle");312 maskCircle.setAttribute("cx", `${x}`);313 maskCircle.setAttribute("cy", `${y}`);314 maskCircle.setAttribute("r", "8");315 maskCircle.setAttribute("fill", `url(#${crestGradId})`);316 maskCircle.setAttribute("fill-opacity", "0");317 maskGroup.appendChild(maskCircle);318
319 activeWavesRef.current.add({320 x,321 y,322 maxCrestRadius,323 boundRadius,324 startTime: performance.now(),325 el,326 maskCircle,327 });328
329 if (physicsRafRef.current === null) {330 physicsRafRef.current = window.requestAnimationFrame(stepPhysics);331 }332 };333
334 const handlePointerMove = (e: React.PointerEvent<HTMLElement>) => {335 onPointerMove?.(e);336 if (disabled || prefersReducedMotion()) return;337 const host = controlRef.current;338 if (!host) return;339 const rect = host.getBoundingClientRect();340 host.style.setProperty("--mx", `${Math.round(e.clientX - rect.left)}px`);341 host.style.setProperty("--my", `${Math.round(e.clientY - rect.top)}px`);342 };343
344 const handlePointerDown = (e: React.PointerEvent<HTMLElement>) => {345 onPointerDown?.(e);346 if (disabled) return;347 lastPointerRippleAtRef.current = performance.now();348 triggerLakeWave(e.clientX, e.clientY);349 };350
351 const handleClick = (e: React.MouseEvent<HTMLElement>) => {352 if (353 !disabled &&354 e.detail === 0 &&355 performance.now() - lastPointerRippleAtRef.current > 80356 ) {357 triggerLakeWave();358 }359 onClick?.(e);360 };361
362 const mineralMask =363 "radial-gradient(105px circle at var(--mx, 50%) var(--my, 50%), rgba(0,0,0,1) 0%, rgba(0,0,0,0.45) 45%, transparent 76%)";364
365 const glassLayers = (366 <>367 {/* 1px optical glass bezel catching light on top-left & bottom-right arcs */}368 <span369 aria-hidden="true"370 style={{371 ...RIM_MASK_STYLE,372 background:373 "linear-gradient(135deg, rgba(209,250,229,0.55) 0%, rgba(16,185,129,0.22) 38%, rgba(4,47,34,0.35) 68%, rgba(209,250,229,0.42) 100%)",374 }}375 className={`pointer-events-none absolute inset-0 ${radiusClass}`}376 />377
378 {/* Scoped optical refraction filter & reusable mineral pattern defs */}379 <svg380 aria-hidden="true"381 className="pointer-events-none absolute h-0 w-0 overflow-hidden"382 >383 <defs>384 <pattern385 id={patternId}386 width={PATTERN_WIDTH}387 height={PATTERN_HEIGHT}388 patternUnits="userSpaceOnUse"389 >390 {MINERAL_SPECKS.map((speck, idx) => (391 <circle392 key={idx}393 cx={speck.cx}394 cy={speck.cy}395 r={speck.r}396 fill={speck.cool ? "#ECFEFF" : "#D1FAE5"}397 opacity={speck.opacity}398 />399 ))}400 </pattern>401
402 <pattern403 id={starlightPatternId}404 width={PATTERN_WIDTH}405 height={PATTERN_HEIGHT}406 patternUnits="userSpaceOnUse"407 >408 {MINERAL_SPECKS.map((speck, idx) => (409 <circle410 key={idx}411 cx={speck.cx}412 cy={speck.cy}413 r={Number((speck.r * 1.45).toFixed(2))}414 fill={speck.cool ? "#FFFFFF" : "#D1FAE5"}415 opacity={Number(Math.min(1, speck.opacity + 0.42).toFixed(2))}416 />417 ))}418 </pattern>419
420 <radialGradient id={crestGradId}>421 <stop offset="0%" stopColor="white" stopOpacity="0" />422 <stop offset="48%" stopColor="white" stopOpacity="0" />423 <stop offset="72%" stopColor="white" stopOpacity="1" />424 <stop offset="86%" stopColor="white" stopOpacity="0.82" />425 <stop offset="100%" stopColor="white" stopOpacity="0" />426 </radialGradient>427
428 <mask id={waveMaskId}>429 <rect width="100%" height="100%" fill="black" />430 <g ref={waveMaskGroupRef} />431 </mask>432
433 <filter434 id={filterId}435 x="-12%"436 y="-12%"437 width="124%"438 height="124%"439 colorInterpolationFilters="sRGB"440 >441 <feTurbulence442 type="fractalNoise"443 baseFrequency="0.022 0.048"444 numOctaves="2"445 seed="7"446 result="rippleNoise"447 />448 <feDisplacementMap449 ref={displaceRef}450 in="SourceGraphic"451 in2="rippleNoise"452 scale={0}453 xChannelSelector="R"454 yChannelSelector="G"455 />456 </filter>457 </defs>458 </svg>459
460 {/* Inner clipped glass optics (keeps parent focus outline unclipped) */}461 <span462 aria-hidden="true"463 className={`pointer-events-none absolute inset-0 overflow-hidden ${radiusClass}`}464 >465 {/* Sub-surface refraction group warped smoothly during active click waves */}466 <span467 ref={opticsLayerRef}468 className="pointer-events-none absolute inset-0"469 >470 {/* Ultra-subtle chromatic/prismatic refraction glint along lower-right edge */}471 <span472 style={{473 background:474 "radial-gradient(65px circle at 82% 88%, rgba(52,211,153,0.22), rgba(56,189,248,0.14) 35%, rgba(251,191,36,0.10) 58%, transparent 75%)",475 }}476 className="pointer-events-none absolute inset-0"477 />478
479 {/* Hover sub-surface emerald-cyan scatter */}480 <span481 style={{482 background:483 "radial-gradient(110px circle at var(--mx, 50%) var(--my, 50%), rgba(110,231,183,0.16), transparent 72%)",484 }}485 className="pointer-events-none absolute inset-0 opacity-0 transition-opacity duration-300 ease-out group-hover:opacity-100 motion-reduce:hidden"486 />487
488 {/* Hover-only ultra-fine sub-pixel mineral glints masked inside pointer spotlight */}489 <span490 style={{491 maskImage: mineralMask,492 WebkitMaskImage: mineralMask,493 }}494 className="pointer-events-none absolute inset-0 opacity-0 transition-opacity duration-300 ease-out group-hover:opacity-85 motion-reduce:hidden"495 >496 <svg aria-hidden="true" className="block h-full w-full">497 <rect width="100%" height="100%" fill={`url(#${patternId})`} />498 </svg>499 </span>500
501 {/* Click wave-crest starlight swell: illuminates & refracts mineral starlight along passing 3D wave crest */}502 <svg503 aria-hidden="true"504 className="pointer-events-none absolute inset-0 block h-full w-full mix-blend-screen motion-reduce:hidden"505 >506 <rect507 ref={waveDustRectRef}508 width="100%"509 height="100%"510 fill={`url(#${starlightPatternId})`}511 mask={`url(#${waveMaskId})`}512 style={{ opacity: 0 }}513 />514 </svg>515 </span>516
517 {/* 3D Optical Water Wave Crest & Trough Ripples */}518 <span519 ref={rippleLayerRef}520 className="pointer-events-none absolute inset-0"521 />522 </span>523
524 <span className="relative z-10 inline-flex items-center justify-center gap-2">525 {children}526 </span>527 </>528 );529
530 const mergedClassName =531 `${BASE_SURFACE_CLASSES} ${radiusClass} ${className}`.trim();532
533 if (href) {534 return (535 <Link536 ref={controlRef as React.RefObject<HTMLAnchorElement>}537 href={href}538 target={target}539 rel={rel}540 aria-label={ariaLabel}541 onPointerMove={handlePointerMove}542 onPointerDown={handlePointerDown}543 onClick={handleClick}544 className={mergedClassName}545 >546 {glassLayers}547 </Link>548 );549 }550
551 return (552 <button553 ref={controlRef as React.RefObject<HTMLButtonElement>}554 type={type}555 disabled={disabled}556 aria-label={ariaLabel}557 onPointerMove={handlePointerMove}558 onPointerDown={handlePointerDown}559 onClick={handleClick}560 className={mergedClassName}561 >562 {glassLayers}563 </button>564 );565}Usage Example
import { ArrowRight } from "lucide-react";import { EmeraldLiquidGlassButton } from "@/components/ui/EmeraldLiquidGlassButton";
export default function GlassActions() { return ( <div className="flex flex-wrap items-center gap-4"> <EmeraldLiquidGlassButton href="/components" shape="pill" className="min-h-11 px-6 text-sm"> <span>Explore Components</span> <ArrowRight className="h-4 w-4 shrink-0" strokeWidth={1.75} aria-hidden="true" /> </EmeraldLiquidGlassButton>
<EmeraldLiquidGlassButton shape="machined" className="min-h-11 px-6 text-sm"> <span>Unlock Studio</span> </EmeraldLiquidGlassButton> </div> );}3. Props Reference
| Prop | Type | Default | Description |
|---|---|---|---|
| shape | "pill" | "machined" | "pill" | Switches between an optical Liquid Glass capsule (rounded-full) and a machined rectangle (rounded-xl). |
| href | string | undefined | Optional destination route. Renders as Next.js Link when provided, or native button otherwise. |
| children | React.ReactNode | required | Button label and optional inline icon. |
| onClick | React.MouseEventHandler<HTMLElement> | undefined | Optional click handler invoked alongside lake-water ripple feedback. |
| type | "button" | "submit" | "reset" | "button" | Native button type when href is omitted. |
| disabled | boolean | false | Disables interaction, pointer tracking, and ripple effects. |
| className | string | "" | Optional Tailwind sizing or spacing classes. |