Glass Panes

Smit-Prajapatiportrait.jpg ↓

Luca Marrella
"use client";

import type { CSSProperties, ReactNode } from "react";

/**
 * Glass Panes: a photo card where frosted panes slide in from the bottom-left
 * corner one after another, biggest first, each carrying a link. Hover fills
 * a pane with ink. The portrait behind the avatar on zosasounds.com, adapted
 * from Smit-Prajapati's "massive-insect-5" card on Uiverse, in greys.
 *
 *   <GlassPanes src="/me.jpg" alt="Me" links={[
 *     { href: "https://instagram.com/you", label: "Instagram", icon: <svg … /> },
 *   ]} />
 *
 * The panes come in on hover, or hold them open with `open`. Up to three
 * links; the fourth, smallest pane is decoration.
 */
export type Pane = { href: string; label: string; icon: ReactNode };

export type GlassPanesProps = {
  src: string;
  alt: string;
  links: Pane[];
  open?: boolean;
  width?: number | string;
  className?: string;
  style?: CSSProperties;
};

const CSS = `
.zs-gp{position:relative;overflow:hidden;border-radius:22px;background:#e8e8ed;
  box-shadow:0 20px 50px rgba(0,0,0,.18);transition:transform 1s cubic-bezier(.65,0,.35,1)}
.zs-gp img{display:block;width:100%;height:auto}
.zs-gp__pane{position:absolute;left:-1px;bottom:-1px;aspect-ratio:1;display:flex;justify-content:flex-end;padding:12px;
  background:rgba(255,255,255,.3);-webkit-backdrop-filter:blur(10px) saturate(120%);backdrop-filter:blur(10px) saturate(120%);
  border-top:2px solid rgba(255,255,255,.9);border-right:1px solid rgba(255,255,255,.9);
  border-radius:10% 13% 42% 0%/10% 12% 75% 0%;box-shadow:-7px 7px 29px rgba(0,0,0,.28);
  transform:translate(-101%,101%);transition:transform 1s cubic-bezier(.65,0,.35,1)}
.zs-gp__pane::before{content:"";position:absolute;inset:0;border-radius:inherit;opacity:0;
  background:radial-gradient(circle at 30% 107%,#6e6e73 0%,#1d1d1f 70%);transition:opacity .5s}
.zs-gp__pane svg{position:relative;width:22px;height:22px;fill:rgba(255,255,255,.85);transition:fill .4s,filter .4s}
.zs-gp__pane:hover::before,.zs-gp__pane:focus-visible::before{opacity:1}
.zs-gp__pane:hover svg,.zs-gp__pane:focus-visible svg{fill:#fff;filter:drop-shadow(0 0 5px rgba(255,255,255,.8))}
.zs-gp__pane:focus-visible{outline:none}
.zs-gp__pane:nth-of-type(1){width:60%}
.zs-gp__pane:nth-of-type(2){width:42%;transition-delay:.2s}
.zs-gp__pane:nth-of-type(3){width:25%;transition-delay:.4s}
.zs-gp__pane:nth-of-type(4){width:9%;padding:0;transition-delay:.6s}
.zs-gp:hover,.zs-gp[data-open]{transform:scale(1.03)}
.zs-gp:hover .zs-gp__pane,.zs-gp[data-open] .zs-gp__pane{transform:none}
@media (prefers-reduced-motion:reduce){.zs-gp,.zs-gp__pane{transition:none}}
`;

export function GlassPanes({ src, alt, links, open, width = 320, className, style }: GlassPanesProps) {
  return (
    <div className={`zs-gp${className ? ` ${className}` : ""}`} data-open={open ? "" : undefined} style={{ width, ...style }}>
      <style>{CSS}</style>
      <img src={src} alt={alt} />
      {links.slice(0, 3).map((l) => (
        <a key={l.href} className="zs-gp__pane" href={l.href} target="_blank" rel="noopener" aria-label={l.label}>
          {l.icon}
        </a>
      ))}
      {Array.from({ length: 4 - Math.min(3, links.length) }, (_, i) => (
        <span key={i} className="zs-gp__pane" aria-hidden="true" />
      ))}
    </div>
  );
}