Ir al contenido
Evaluar mi proyecto
Componentes · BotonesDisponible

Botón liquid glass

Vidrio líquido al estilo de iOS 26: refracta lo que hay detrás, brilla donde pasa el puntero y se estira al presionar.

Material
Fondo

Prueba el material con el puntero, al pulsar y con el teclado.

Código completo

Es exactamente el archivo que se descarga. Cópialo a tu proyecto y úsalo.

boton-liquid-glass.tsx278 líneas
Descargar
"use client";

import { createElement, useCallback, useEffect, useId, useState, useSyncExternalStore, type CSSProperties, type PointerEvent, type ReactNode } from "react";

/** Botón liquid glass: cristal con grosor que refracta lo que hay detrás en el borde (mapa de desplazamiento SVG en Chromium), con borde óptico, reflejos que siguen al puntero y compresión elástica al presionar. Variantes regular y clear; esquemas dark y light. React + TypeScript, sin dependencias. */
export type BotonLiquidGlassProps = {
  children?: ReactNode;
  type?: "button" | "submit";
  disabled?: boolean;
  onClick?: () => void;
  /** Regular suaviza el fondo; clear deja pasar casi todo. */
  variant?: "regular" | "clear";
  /** Dark para fondos oscuros o con color; light para fondos claros. */
  scheme?: "dark" | "light";
  className?: string;
  style?: CSSProperties;
};

const CSS = `
.gcliq-root { box-sizing: border-box; display: inline-block; max-width: 100%; font: 500 16px/1.2 -apple-system, "SF Pro Display", ui-sans-serif, system-ui, sans-serif; }
.gcliq-root *, .gcliq-root *::before, .gcliq-root *::after { box-sizing: border-box; }
.gcliq-root button { font: inherit; -webkit-tap-highlight-color: transparent; }
.gcliq-root :focus-visible { outline: 2px solid rgba(255, 255, 255, .95); outline-offset: 4px; }
@property --gcliq-a { syntax: "<angle>"; inherits: true; initial-value: 135deg; }
@property --gcliq-p { syntax: "<angle>"; inherits: true; initial-value: 0deg; }
@property --gcliq-sx { syntax: "<percentage>"; inherits: true; initial-value: 24%; }
@property --gcliq-sy { syntax: "<percentage>"; inherits: true; initial-value: 8%; }
@property --gcliq-hi { syntax: "<number>"; inherits: true; initial-value: .78; }
@property --gcliq-tc { syntax: "<color>"; inherits: true; initial-value: transparent; }
@property --gcliq-te { syntax: "<color>"; inherits: true; initial-value: transparent; }
.gcliq-g, .gcliq-gf {
  --gcliq-a: 135deg; --gcliq-p: 0deg; --gcliq-sx: 24%; --gcliq-sy: 8%;
  --gcliq-bl: var(--gcliq-blur, 2.6px); --gcliq-tc: rgba(255,255,255,.025); --gcliq-te: rgba(255,255,255,.12);
  --gcliq-sh: rgba(12,16,24,.16); --gcliq-hi: .78; --gcliq-ink: 12,16,24; --gcliq-ins: 3px;
  --gcliq-contact: .14; --gcliq-ambient: .2;
  position: relative; isolation: isolate; border: 0; color: var(--gcliq-fg, #fff);
  background: radial-gradient(115% 120% at 50% 40%, var(--gcliq-tc) 42%, var(--gcliq-te) 100%), linear-gradient(var(--gcliq-sh),var(--gcliq-sh));
  -webkit-backdrop-filter: blur(var(--gcliq-bl)) saturate(1.08) brightness(1.02);
  backdrop-filter: blur(var(--gcliq-bl)) saturate(1.08) brightness(1.02);
  box-shadow: inset .5px 1px 1px rgba(255,255,255,.42), inset -.5px -1px 1.5px rgba(255,255,255,.16), inset 2px 3px 7px -5px rgba(255,255,255,.45), inset -2px -4px 8px -5px rgba(var(--gcliq-ink),.26), 0 1px 2px rgba(var(--gcliq-ink),var(--gcliq-contact)), 0 12px 28px -10px rgba(var(--gcliq-ink),var(--gcliq-ambient));
  transition: --gcliq-a 280ms cubic-bezier(.16,1,.3,1), --gcliq-p 320ms cubic-bezier(.22,1.08,.36,1), --gcliq-sx 240ms cubic-bezier(.16,1,.3,1), --gcliq-sy 240ms cubic-bezier(.16,1,.3,1), --gcliq-hi 180ms ease-out, --gcliq-tc 180ms ease-out, --gcliq-te 180ms ease-out, box-shadow 240ms ease-out, transform 360ms cubic-bezier(.22,1.08,.36,1);
}
.gcliq-g[data-v="clear"], .gcliq-gf[data-v="clear"] { --gcliq-bl: var(--gcliq-clear-blur,.45px); --gcliq-tc: rgba(255,255,255,.008); --gcliq-te: rgba(255,255,255,.065); --gcliq-sh: rgba(12,16,24,.07); }
.gcliq-root[data-s="light"] :is(.gcliq-g,.gcliq-gf), .gcliq-g[data-s="light"], .gcliq-gf[data-s="light"] { --gcliq-tc: rgba(255,255,255,.06); --gcliq-te: rgba(255,255,255,.18); --gcliq-sh: rgba(255,255,255,.025); --gcliq-ink: 24,30,38; --gcliq-fg: #17202b; --gcliq-contact: .09; --gcliq-ambient: .13; }
.gcliq-root[data-s="light"] :is(.gcliq-g,.gcliq-gf)[data-v="clear"], .gcliq-g[data-s="light"][data-v="clear"], .gcliq-gf[data-s="light"][data-v="clear"] { --gcliq-tc: rgba(255,255,255,.015); --gcliq-te: rgba(255,255,255,.085); }
/* Nested controls share their parent's optical plane; never blur glass twice. */
.gcliq-gf { -webkit-backdrop-filter: none; backdrop-filter: none; --gcliq-tc: rgba(255,255,255,.04); --gcliq-te: rgba(255,255,255,.12); --gcliq-sh: transparent; }
.gcliq-g[data-r="1"] { backdrop-filter: blur(var(--gcliq-bl)) var(--gcliq-f) saturate(1.08) brightness(1.02); }
.gcliq-g[data-t="solid"], .gcliq-gf[data-t="solid"] { --gcliq-tc: rgba(255,255,255,.19); --gcliq-te: rgba(255,255,255,.32); --gcliq-sh: rgba(12,16,24,.2); font-weight: 650; }
.gcliq-g[data-t="solid"][data-s="light"], .gcliq-gf[data-t="solid"][data-s="light"] { --gcliq-sh: rgba(255,255,255,.08); }
.gcliq-g::before, .gcliq-gf::before { content: ""; position: absolute; inset: 0; z-index: 3; padding: .8px; border-radius: inherit; pointer-events: none; opacity: var(--gcliq-hi);
  background: conic-gradient(from calc(var(--gcliq-a) + var(--gcliq-p)), rgba(255,255,255,.04), rgba(255,255,255,.06) 12%, rgba(255,255,255,.88) 21%, rgba(255,255,255,.16) 28%, rgba(255,255,255,.025) 42%, rgba(255,255,255,.04) 60%, rgba(255,255,255,.62) 72%, rgba(255,255,255,.13) 79%, rgba(255,255,255,.04));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); mask-composite: exclude;
}
.gcliq-g::after, .gcliq-gf::after { content: ""; position: absolute; inset: var(--gcliq-ins); z-index: -1; border-radius: max(0px,calc(var(--gcliq-r,24px) - var(--gcliq-ins))); pointer-events: none; opacity: .55; transition: opacity 180ms ease-out;
  background: radial-gradient(38% 24% at var(--gcliq-sx) var(--gcliq-sy), rgba(255,255,255,.22), transparent 75%), radial-gradient(30% 18% at 84% 98%, rgba(255,255,255,.085), transparent 75%);
  box-shadow: inset .5px 1px 1px rgba(255,255,255,.15), inset -.5px -1px 2px rgba(var(--gcliq-ink),.12);
}
.gcliq-root[data-s="light"] :is(.gcliq-g,.gcliq-gf)::before, .gcliq-g[data-s="light"]::before, .gcliq-gf[data-s="light"]::before { background: conic-gradient(from calc(var(--gcliq-a) + var(--gcliq-p)), rgba(var(--gcliq-ink),.08), rgba(255,255,255,.3) 12%, #fff 21%, rgba(255,255,255,.25) 28%, rgba(var(--gcliq-ink),.13) 45%, rgba(var(--gcliq-ink),.03) 60%, rgba(255,255,255,.95) 72%, rgba(255,255,255,.3) 79%, rgba(var(--gcliq-ink),.08)); }
.gcliq-g[data-e="2"] { --gcliq-contact: .17; --gcliq-ambient: .25; box-shadow: inset .5px 1px 1px rgba(255,255,255,.5), inset -.5px -1px 2px rgba(255,255,255,.2), inset 2px 3px 8px -5px rgba(255,255,255,.45), inset -2px -5px 10px -6px rgba(var(--gcliq-ink),.24), 0 2px 4px rgba(var(--gcliq-ink),var(--gcliq-contact)), 0 24px 52px -18px rgba(var(--gcliq-ink),var(--gcliq-ambient)); }
.gcliq-g[data-i], .gcliq-gf[data-i] { cursor: pointer; touch-action: manipulation; }
.gcliq-g:focus-visible, .gcliq-gf:focus-visible { outline: 2px solid var(--gcliq-fg,#fff); outline-offset: 4px; }
@media (hover: hover) and (pointer: fine) {
  .gcliq-g[data-i]:hover:not(:disabled), .gcliq-gf[data-i]:hover:not(:disabled) { --gcliq-hi: .98; }
  .gcliq-g[data-i]:hover:not(:disabled)::after, .gcliq-gf[data-i]:hover:not(:disabled)::after { opacity: .85; }
  .gcliq-g[data-t="solid"][data-i]:hover:not(:disabled), .gcliq-gf[data-t="solid"][data-i]:hover:not(:disabled) { --gcliq-tc: rgba(255,255,255,.25); }
}
.gcliq-g[data-i]:active:not(:disabled), .gcliq-gf[data-i]:active:not(:disabled) { --gcliq-p: 14deg; --gcliq-hi: 1; transform: scale(.985,.97); transition-duration: 80ms; }
.gcliq-g[data-i]:active:not(:disabled)::after, .gcliq-gf[data-i]:active:not(:disabled)::after { opacity: .95; }
.gcliq-g:disabled, .gcliq-gf:disabled { cursor: not-allowed; }
.gcliq-svg { position: absolute; width: 0; height: 0; overflow: hidden; pointer-events: none; }
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .gcliq-g { background: rgba(30,36,46,.9); }
  .gcliq-root[data-s="light"] .gcliq-g, .gcliq-g[data-s="light"] { background: rgba(245,247,250,.94); }
}
@media (prefers-reduced-transparency: reduce) { .gcliq-g, .gcliq-gf { background: #26303d; color: #fff; -webkit-backdrop-filter: none; backdrop-filter: none; } .gcliq-root[data-s="light"] :is(.gcliq-g,.gcliq-gf), .gcliq-g[data-s="light"], .gcliq-gf[data-s="light"] { background: #f2f5f8; color: #17202b; } }
@media (prefers-reduced-motion: reduce) {
  .gcliq-root *, .gcliq-root *::before, .gcliq-root *::after { animation: none !important; transition-duration: .01ms !important; }
  .gcliq-g[data-i]:active:not(:disabled), .gcliq-gf[data-i]:active:not(:disabled) { transform: none; }
}
@media (forced-colors: active) { .gcliq-g, .gcliq-gf { border: 1px solid CanvasText; background: Canvas; color: CanvasText; -webkit-backdrop-filter: none; backdrop-filter: none; } .gcliq-g::before, .gcliq-g::after, .gcliq-gf::before, .gcliq-gf::after { display: none; } }

.gcliq-btn { display: inline-flex; align-items: center; justify-content: center; gap: 10px; min-height: 54px; padding: 0 30px; border-radius: 999px; text-shadow: 0 1px 2px rgba(10, 10, 50, .3); letter-spacing: -.005em; }
.gcliq-btn[data-s="light"] { text-shadow: none; }
.gcliq-btn:disabled { opacity: .5; cursor: not-allowed; }`;

/* Motor de vidrio líquido: mapa de desplazamiento por borde (refracción) + dispersión leve, calculado a la medida de cada pieza. */
const noop = () => () => {};
const canRefract = () => typeof window !== "undefined" && typeof window.CSS !== "undefined" && window.CSS.supports("backdrop-filter", "url(#a)") && /Chrome\//.test(navigator.userAgent);
const bend = (t: number) => {
  const u = 1 - t;
  const th = Math.atan(Math.pow(Math.max(1 - u * u * u * u, 1e-6), -0.75) * u * u * u * 0.9);
  return Math.sin(th - Math.asin(Math.sin(th) / 1.5));
};
const PEAK = bend(0.02);

/** Mapa R/G de desplazamiento: 0 en el centro, máximo en el borde (perfil de cristal convexo y ley de Snell, n = 1.5). */
const mapCache = new Map<string, string>();
function glassMap(w: number, h: number, r: number, bezel: number): string {
  const key = [w, h, r, bezel].join(":");
  const cached = mapCache.get(key);
  if (cached) return cached;
  const k = Math.min(1, Math.sqrt(90000 / (w * h)));
  const cw = Math.max(2, Math.round(w * k));
  const ch = Math.max(2, Math.round(h * k));
  const canvas = document.createElement("canvas");
  canvas.width = cw;
  canvas.height = ch;
  const ctx = canvas.getContext("2d");
  if (!ctx) return "";
  const img = ctx.createImageData(cw, ch);
  const hx = w / 2;
  const hy = h / 2;
  for (let j = 0; j < ch; j++) {
    for (let i = 0; i < cw; i++) {
      const px = (i + 0.5) * w / cw - hx;
      const py = (j + 0.5) * h / ch - hy;
      const qx = Math.abs(px) - (hx - r);
      const qy = Math.abs(py) - (hy - r);
      let nx = 0;
      let ny = 0;
      let d: number;
      if (qx > 0 && qy > 0) {
        const l = Math.hypot(qx, qy);
        d = r - l;
        nx = qx / l;
        ny = qy / l;
      } else if (qx > qy) {
        d = hx - Math.abs(px);
        nx = 1;
      } else {
        d = hy - Math.abs(py);
        ny = 1;
      }
      const t = d / bezel;
      const m = t >= 1 ? 0 : Math.min(1, bend(Math.max(t, 0.02)) / PEAK);
      const o = (j * cw + i) * 4;
      img.data[o] = 128 - (Math.sign(px) || 1) * nx * m * 127;
      img.data[o + 1] = 128 - (Math.sign(py) || 1) * ny * m * 127;
      img.data[o + 2] = 128;
      img.data[o + 3] = 255;
    }
  }
  ctx.putImageData(img, 0, 0);
  const map = canvas.toDataURL();
  if (mapCache.size >= 24) mapCache.delete(mapCache.keys().next().value!);
  mapCache.set(key, map);
  return map;
}

type SurfaceProps = {
  as?: string;
  /** Radio de las esquinas en px; por defecto el que resuelve el CSS. */
  radius?: number;
  /** Ancho de la franja que refracta, en px. */
  bezel?: number;
  /** Desplazamiento máximo del fondo en el borde, en px. */
  depth?: number;
  variant?: "regular" | "clear";
  /** Solid: mayor contraste para la acción principal, conservando transparencia. */
  tone?: "solid";
  scheme?: "dark" | "light";
  elevated?: boolean;
  flat?: boolean;
  interactive?: boolean;
  elRef?: (node: HTMLElement | null) => void;
  className?: string;
  style?: CSSProperties;
  children?: ReactNode;
  onPointerMove?: (event: PointerEvent<HTMLElement>) => void;
  onPointerLeave?: (event: PointerEvent<HTMLElement>) => void;
  [prop: string]: unknown;
};

/** Superficie de vidrio: refracta el fondo en Chromium (SVG + backdrop-filter) y cae a vidrio con desenfoque en el resto; el borde óptico, el volumen y las sombras no dependen del filtro. */
function Surface({ as = "div", radius, bezel, depth, variant = "regular", tone, scheme = "dark", elevated, flat, interactive, elRef, className = "", style, children, onPointerMove, onPointerLeave, ...rest }: SurfaceProps) {
  const id = `gcliq-f-${useId().replace(/[^a-zA-Z0-9]/g, "")}`;
  const refract = useSyncExternalStore(noop, canRefract, () => false) && !flat;
  const [node, setNode] = useState<HTMLElement | null>(null);
  const [lens, setLens] = useState<{ w: number; h: number; r: number; depth: number; map: string } | null>(null);
  const bind = useCallback(
    (el: HTMLElement | null) => {
      setNode(el);
      elRef?.(el);
    },
    [elRef],
  );

  useEffect(() => {
    if (!node || !refract) return;
    let lw = 0;
    let lh = 0;
    let frame = 0;
    const measure = () => {
      const w = node.offsetWidth;
      const h = node.offsetHeight;
      if (!w || !h || (w === lw && h === lh)) return;
      lw = w;
      lh = h;
      const corner = getComputedStyle(node).borderTopLeftRadius;
      const resolved = corner.endsWith("%") ? parseFloat(corner) / 100 * Math.min(w, h) : parseFloat(corner) || 0;
      const r = Math.min(radius ?? resolved, w / 2, h / 2);
      const bz = Math.max(6, Math.min(bezel ?? Math.min(w, h) * 0.24, Math.min(w, h) / 2, 48));
      const map = glassMap(w, h, r, bz);
      setLens(map ? { w, h, r, depth: (depth ?? Math.round(bz * .85)) * (variant === "clear" ? 1 : .85), map } : null);
    };
    const observer = new ResizeObserver(() => {
      cancelAnimationFrame(frame);
      frame = requestAnimationFrame(measure);
    });
    observer.observe(node);
    return () => { observer.disconnect(); cancelAnimationFrame(frame); };
  }, [node, refract, radius, bezel, depth, variant]);

  const live = refract && lens;
  const move = (event: PointerEvent<HTMLElement>) => {
    if (event.pointerType !== "touch" && !event.currentTarget.matches(":disabled") && !window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
      const box = event.currentTarget.getBoundingClientRect();
      const x = Math.max(0, Math.min(1, (event.clientX - box.left) / box.width));
      const y = Math.max(0, Math.min(1, (event.clientY - box.top) / box.height));
      event.currentTarget.style.setProperty("--gcliq-a", `${135 + (x - 0.5) * 40 - (y - 0.5) * 18}deg`);
      event.currentTarget.style.setProperty("--gcliq-sx", `${18 + x * 64}%`);
      event.currentTarget.style.setProperty("--gcliq-sy", `${3 + y * 12}%`);
    }
    onPointerMove?.(event);
  };
  const leave = (event: PointerEvent<HTMLElement>) => {
    for (const name of ["a", "sx", "sy"]) event.currentTarget.style.removeProperty(`--gcliq-${name}`);
    onPointerLeave?.(event);
  };

  return createElement(
    as,
    {
      ...rest,
      ref: bind,
      className: `gcliq-${flat ? "gf" : "g"} ${className}`,
      "data-v": variant,
      "data-s": scheme,
      "data-t": tone,
      "data-r": live ? "1" : undefined,
      "data-e": elevated ? "2" : undefined,
      "data-i": interactive ? "1" : undefined,
      style: { ...style, "--gcliq-r": live ? `${lens.r}px` : radius !== undefined ? `${radius}px` : undefined, "--gcliq-f": live ? `url(#${id})` : undefined } as CSSProperties,
      onPointerMove: move,
      onPointerLeave: leave,
    },
    live ? (
      <svg className="gcliq-svg" aria-hidden="true" focusable="false">
        <filter id={id} filterUnits="userSpaceOnUse" x={-lens.depth} y={-lens.depth} width={lens.w + lens.depth * 2} height={lens.h + lens.depth * 2} colorInterpolationFilters="sRGB">
          <feImage href={lens.map} x={0} y={0} width={lens.w} height={lens.h} preserveAspectRatio="none" result="m" />
          <feDisplacementMap in="SourceGraphic" in2="m" scale={lens.depth * 1.012} xChannelSelector="R" yChannelSelector="G" result="dr" />
          <feColorMatrix in="dr" type="matrix" values="1 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 0 1" result="cr" />
          <feDisplacementMap in="SourceGraphic" in2="m" scale={lens.depth} xChannelSelector="R" yChannelSelector="G" result="dg" />
          <feColorMatrix in="dg" type="matrix" values="0 0 0 0 0  0 1 0 0 0  0 0 0 0 0  0 0 0 0 1" result="cg" />
          <feDisplacementMap in="SourceGraphic" in2="m" scale={lens.depth * .988} xChannelSelector="R" yChannelSelector="G" result="db" />
          <feColorMatrix in="db" type="matrix" values="0 0 0 0 0  0 0 0 0 0  0 0 1 0 0  0 0 0 0 1" result="cb" />
          <feBlend in="cr" in2="cg" mode="screen" result="rg" />
          <feBlend in="rg" in2="cb" mode="screen" />
        </filter>
      </svg>
    ) : null,
    children,
  );
}

export function BotonLiquidGlass({ children = "Continuar", type = "button", disabled, onClick, variant = "regular", scheme = "dark", className = "", style }: BotonLiquidGlassProps) {
  return (
    <span className={`gcliq-root ${className}`} style={style}>
      <style>{CSS}</style>
      <Surface as="button" className="gcliq-btn" type={type} disabled={disabled} onClick={onClick} variant={variant} scheme={scheme} interactive bezel={20} depth={22}>
        {children}
      </Surface>
    </span>
  );
}

Úsalo en tu proyecto

Instálalo con la CLI de shadcn.

terminal.sh1 líneas
npx shadcn@latest add https://www.gassierconsulting.com/r/boton-liquid-glass

Ejemplo de uso de Botón liquid glass

Después de copiar boton-liquid-glass.tsx a tu proyecto, impórtalo y colócalo donde lo necesites.

ejemplo.tsx5 líneas
import { BotonLiquidGlass } from "./boton-liquid-glass";

export default function Ejemplo() {
  return <BotonLiquidGlass type="button">Contenido</BotonLiquidGlass>;
}

Propiedades de BotonLiquidGlass

BotonLiquidGlass acepta 8 propiedades: todas son opcionales y tienen un valor por defecto, así que funciona sin configurar nada.

PropiedadTipoDescripción
children?ReactNodeOpcional.
type?"button" | "submit"Opcional.
disabled?booleanOpcional.
onClick?() => voidOpcional.
variant?"regular" | "clear"Regular suaviza el fondo; clear deja pasar casi todo.
scheme?"dark" | "light"Dark para fondos oscuros o con color; light para fondos claros.
className?stringOpcional.
style?CSSPropertiesOpcional.

Variantes disponibles

  • type: button, submit
  • variant: regular, clear
  • scheme: dark, light

Personaliza Botón liquid glass con variables CSS

Define estas variables en el contenedor o en tu hoja de estilos para cambiar los colores sin tocar el componente. Si no las defines, se usa el valor por defecto.

VariableValor por defecto
--gcliq-blur2.6px
--gcliq-fg#fff
--gcliq-clear-blur.45px
--gcliq-r24px

Accesibilidad y rendimiento

El archivo tiene 278 líneas (17 KB) y no necesita @keyframes. Esto es lo que hace Botón liquid glass por quien lo usa:

  • Detecta prefers-reduced-motion y baja o quita el movimiento cuando la persona lo pide.
  • Muestra un anillo de foco visible al navegar con teclado (:focus-visible).
  • Expone su estado a tecnologías de apoyo con atributos aria-*.
  • Reacciona al puntero con eventos pointer (ratón, lápiz y táctil).
  • Anima con requestAnimationFrame, sincronizado con el refresco de pantalla.
  • Usa backdrop-filter para el efecto de vidrio; en navegadores sin soporte el panel se ve sin desenfoque.
  • Lee preferencias del navegador con useSyncExternalStore, sin parpadeos en la hidratación.
  • Usa @property de CSS para animar valores que normalmente no se interpolan.
  • Es un componente de cliente de Next.js: incluye la directiva "use client".
Licencia
MIT
Dependencias
React >=18
Compatibilidad
React 18 y 19 · Next.js (componente de cliente)