Ir al contenido
Evaluar mi proyecto
Componentes · PreciosDisponible

Precios liquid glass

Planes translúcidos sobre fondo de color y un selector segmentado cuya pastilla de vidrio se desliza entre mensual y anual.

Material
Fondo

Un plan para cada etapa

Esencial

$12 /mes

  • 5 proyectos
  • Panel de actividad
  • Soporte por correo

EquipoPopular

$29 /mes

  • Proyectos ilimitados
  • Automatizaciones
  • Integraciones
  • Soporte prioritario

Empresa

$79 /mes

  • Todo lo de Equipo
  • Roles y auditoría
  • SSO
  • Acuerdo de servicio

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.

precios-vidrio.tsx390 líneas
Descargar
"use client";

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

/** Precios en cristal líquido: planes de vidrio que refractan el fondo y un selector segmentado cuya pastilla de vidrio se desliza entre mensual y anual. Datos de muestra. React + TypeScript, sin dependencias. */
export type PreciosVidrioPlan = { name: string; monthly: number; yearly: number; features: string[]; featured?: boolean };

export type PreciosVidrioProps = {
  title?: string;
  plans?: PreciosVidrioPlan[];
  currency?: string;
  cta?: string;
  onChoose?: (plan: string, billing: "mensual" | "anual") => void;
  variant?: "regular" | "clear";
  scheme?: "dark" | "light";
  className?: string;
  style?: CSSProperties;
};

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

.gcpvi-head { display: grid; justify-items: center; gap: 22px; margin-bottom: 36px; text-align: center; }
.gcpvi-root .gcpvi-title { color: inherit; margin: 0; font: 700 clamp(32px, 5.2cqi, 60px)/1.02 -apple-system, "SF Pro Display", ui-sans-serif, sans-serif; letter-spacing: -.04em; text-wrap: balance; }
.gcpvi-seg { display: inline-grid; grid-template-columns: 1fr 1fr; padding: 5px; border-radius: 999px; }
.gcpvi-seg button { position: relative; z-index: 1; min-width: 116px; min-height: 44px; padding: 0 20px; border: 0; border-radius: 999px; background: none; color: #fff; font-weight: 600; cursor: pointer; text-shadow: 0 1px 2px rgba(10, 10, 60, .28); transition: color .25s; }
.gcpvi-seg button[aria-checked="true"] { color: inherit; }
.gcpvi-root[data-s="light"] .gcpvi-seg button { color: #17202b; text-shadow: none; }
.gcpvi-seg .gcpvi-thumb { position: absolute; z-index: 0; top: 5px; bottom: 5px; left: 5px; width: calc(50% - 5px); border-radius: 999px; --gcpvi-tc: rgba(255,255,255,.12); --gcpvi-te: rgba(255,255,255,.26); transition: --gcpvi-a .7s cubic-bezier(.16, 1, .3, 1), translate 400ms cubic-bezier(1,0,.4,1), box-shadow .3s; }
.gcpvi-seg[data-y="true"] .gcpvi-thumb { translate: 100% 0; }
.gcpvi-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }
.gcpvi-card { display: grid; gap: 14px; align-content: start; padding: 28px 26px; border-radius: 30px; transition: --gcpvi-a .7s cubic-bezier(.16, 1, .3, 1), transform .55s cubic-bezier(.16, 1, .3, 1), box-shadow .35s, background .35s; }
@media (hover: hover) and (pointer: fine) { .gcpvi-card:hover { --gcpvi-hi: .94; --gcpvi-p: 6deg; } }
.gcpvi-card[data-f="true"] { --gcpvi-tc: rgba(255, 255, 255, .1); --gcpvi-te: rgba(255, 255, 255, .27); }
.gcpvi-root .gcpvi-name { color: inherit; margin: 0; font-size: 18px; font-weight: 600; display: flex; justify-content: space-between; align-items: center; }
.gcpvi-pop { padding: 3px 11px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.gcpvi-root .gcpvi-price { color: inherit; margin: 0; font-size: 15px; line-height: 1.5; }
.gcpvi-root .gcpvi-price b { font: 700 clamp(36px,5cqi,52px)/1 -apple-system, "SF Pro Display", ui-sans-serif, sans-serif; letter-spacing: -.035em; font-variant-numeric: tabular-nums; }
.gcpvi-price span { opacity: .9; }
.gcpvi-list { margin: 4px 0; padding: 14px 0 0; list-style: none; display: grid; gap: 10px; border-top: 1px solid rgba(255, 255, 255, .22); box-shadow: inset 0 1px 0 rgba(8, 6, 40, .08); }
.gcpvi-list li { display: flex; gap: 10px; }
.gcpvi-btn { min-height: 50px; border-radius: 999px; font-weight: 600; }
@container (max-width: 860px) { .gcpvi-grid { grid-template-columns: minmax(0, 1fr); } }`;

/** Pulso de forma independiente del viaje: retoma la escala visible si se interrumpe. */
function useGlassStretch(node: HTMLElement | null, position: number, peak = 1.1) {
  const previous = useRef<{ node: HTMLElement; position: number } | null>(null);
  const pulse = useRef<Animation | null>(null);

  useLayoutEffect(() => {
    if (!node) return;
    const preference = window.matchMedia("(prefers-reduced-motion: reduce)");
    const stop = () => { if (preference.matches) pulse.current?.cancel(); };
    preference.addEventListener("change", stop);
    return () => {
      preference.removeEventListener("change", stop);
      pulse.current?.cancel();
      pulse.current = null;
      previous.current = null;
    };
  }, [node]);

  useLayoutEffect(() => {
    if (!node) return;
    const from = previous.current;
    previous.current = { node, position };
    if (!from || from.node !== node || from.position === position) return;
    const visibleScale = getComputedStyle(node).scale;
    pulse.current?.cancel();
    if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) return;
    const origin = position > from.position ? "left center" : "right center";
    pulse.current = node.animate(
      [{ scale: visibleScale === "none" ? "1 1" : visibleScale, transformOrigin: origin }, { scale: `${peak} 1`, transformOrigin: origin, offset: .5 }, { scale: "1 1", transformOrigin: origin }],
      { duration: 440, easing: "ease" },
    );
  }, [node, position, peak]);
}

/* 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 = `gcpvi-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("--gcpvi-a", `${135 + (x - 0.5) * 40 - (y - 0.5) * 18}deg`);
      event.currentTarget.style.setProperty("--gcpvi-sx", `${18 + x * 64}%`);
      event.currentTarget.style.setProperty("--gcpvi-sy", `${3 + y * 12}%`);
    }
    onPointerMove?.(event);
  };
  const leave = (event: PointerEvent<HTMLElement>) => {
    for (const name of ["a", "sx", "sy"]) event.currentTarget.style.removeProperty(`--gcpvi-${name}`);
    onPointerLeave?.(event);
  };

  return createElement(
    as,
    {
      ...rest,
      ref: bind,
      className: `gcpvi-${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, "--gcpvi-r": live ? `${lens.r}px` : radius !== undefined ? `${radius}px` : undefined, "--gcpvi-f": live ? `url(#${id})` : undefined } as CSSProperties,
      onPointerMove: move,
      onPointerLeave: leave,
    },
    live ? (
      <svg className="gcpvi-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,
  );
}

const PLANS: PreciosVidrioPlan[] = [
  { name: "Esencial", monthly: 12, yearly: 9, features: ["5 proyectos", "Panel de actividad", "Soporte por correo"] },
  { name: "Equipo", monthly: 29, yearly: 24, features: ["Proyectos ilimitados", "Automatizaciones", "Integraciones", "Soporte prioritario"], featured: true },
  { name: "Empresa", monthly: 79, yearly: 65, features: ["Todo lo de Equipo", "Roles y auditoría", "SSO", "Acuerdo de servicio"] },
];

export function PreciosVidrio({ title = "Un plan para cada etapa", plans = PLANS, currency = "$", cta = "Empezar", onChoose, variant = "regular", scheme = "dark", className = "", style }: PreciosVidrioProps) {
  const [yearly, setYearly] = useState(false);
  const [indicator, setIndicator] = useState<HTMLElement | null>(null);
  useGlassStretch(indicator, yearly ? 1 : 0);
  return (
    <section className={`gcpvi-root ${className}`} style={style} data-s={scheme}>
      <style>{CSS}</style>
      <div className="gcpvi-head">
        <h2 className="gcpvi-title">{title}</h2>
        <Surface className="gcpvi-seg" role="radiogroup" aria-label="Periodo de facturación" onKeyDown={(event: { key: string; preventDefault: () => void; currentTarget: HTMLElement }) => {
          if (!["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown", "Home", "End"].includes(event.key)) return;
          event.preventDefault();
          const next = event.key === "End" ? true : event.key === "Home" ? false : !yearly;
          setYearly(next);
          (event.currentTarget.querySelectorAll("button")[next ? 1 : 0] as HTMLButtonElement)?.focus();
        }} data-y={yearly} variant="clear" bezel={20} depth={20}>
          <Surface as="span" flat className="gcpvi-thumb" elRef={setIndicator} aria-hidden="true" />
          <button type="button" role="radio" aria-checked={!yearly} tabIndex={yearly ? -1 : 0} onClick={() => setYearly(false)}>
            Mensual
          </button>
          <button type="button" role="radio" aria-checked={yearly} tabIndex={yearly ? 0 : -1} onClick={() => setYearly(true)}>
            Anual −20%
          </button>
        </Surface>
      </div>
      <div className="gcpvi-grid">
        {plans.map((plan) => (
          <Surface as="article" key={plan.name} className="gcpvi-card" data-f={plan.featured ? "true" : undefined} variant={variant} elevated={plan.featured} bezel={28} depth={28}>
            <h3 className="gcpvi-name">
              {plan.name}
              {plan.featured ? (
                <Surface as="span" flat tone="solid" className="gcpvi-pop">
                  Popular
                </Surface>
              ) : null}
            </h3>
            <p className="gcpvi-price" aria-live="polite">
              <b>
                {currency}
                {yearly ? plan.yearly : plan.monthly}
              </b>{" "}
              <span>/mes</span>
            </p>
            <ul className="gcpvi-list">
              {plan.features.map((feature) => (
                <li key={feature}>
                  <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true" style={{ flexShrink: 0, marginTop: 3 }}>
                    <path d="m5 12.5 4.5 4.5L19 7.5" />
                  </svg>
                  {feature}
                </li>
              ))}
            </ul>
            <Surface as="button" flat interactive tone={plan.featured ? "solid" : undefined} className="gcpvi-btn" type="button" onClick={() => onChoose?.(plan.name, yearly ? "anual" : "mensual")}>
              {cta}
            </Surface>
          </Surface>
        ))}
      </div>
    </section>
  );
}

Úsalo en tu proyecto

Instálalo con la CLI de shadcn.

terminal.sh1 líneas
npx shadcn@latest add https://www.gassierconsulting.com/r/precios-vidrio

Ejemplo de uso de Precios liquid glass

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

ejemplo.tsx5 líneas
import { PreciosVidrio } from "./precios-vidrio";

export default function Ejemplo() {
  return <PreciosVidrio variant="regular" title="Ejemplo" />;
}

Propiedades de PreciosVidrio

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

PropiedadTipoDescripción
title?stringOpcional.
plans?PreciosVidrioPlan[]Opcional.
currency?stringOpcional.
cta?stringOpcional.
onChoose?(plan: string, billing: "mensual" | "anual") => voidOpcional.
variant?"regular" | "clear"Opcional.
scheme?"dark" | "light"Opcional.
className?stringOpcional.
style?CSSPropertiesOpcional.

Variantes disponibles

  • variant: regular, clear
  • scheme: dark, light

Personaliza Precios 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
--gcpvi-blur2.6px
--gcpvi-fg#fff
--gcpvi-clear-blur.45px
--gcpvi-r24px

Accesibilidad y rendimiento

El archivo tiene 390 líneas (24 KB) y no necesita @keyframes. Esto es lo que hace Precios 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).
  • Declara roles ARIA para lectores de pantalla: radiogroup, radio.
  • Responde al teclado, no solo al ratón.
  • 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)