labs

surface studies

2026-11-08
3.0 px
60 %

light, edge and depth

inspired by the buttons on vibrant.design, which have just enough depth to feel pressable: a lit upper rim, a darker lower edge and a small shadow underneath, and by the keycap submit button on designeer.xyz. the surface lives on a pseudo-element, so a press can squash or sink the material while the label keeps its size.

four surfaces

these four studies start there and pull in different directions: soft strips the rim back, bevel keeps the layered edge, push gives the cap a base to travel into, and key sets a lit keycap inside a recessed body that sinks in two stages when you press it. each is shown in a neutral and an accent colour so the lighting has to work on both.

one set of controls

the controls change the same css variables in all four, and the stage follows the site’s theme. no image assets or animation library, just gradients, shadows and interruptible transitions.

take it with you

three steps, and the stage above runs in your own project.

  1. install

    nothing to add. it runs on react alone, 18 or newer.

  2. copy

    2 files, kept together in one folder, surface-studies/. the styles travel with them.

    "use client";
    
    import type { ButtonHTMLAttributes, CSSProperties } from "react";
    import "./surface-buttons.css";
    
    // Inspired by vibrant.design and designeer.xyz.
    export type Surface = "soft" | "bevel" | "push" | "key";
    export interface SurfaceSettings {
      hue?: number;
      radius?: number;
      height?: number;
      depth?: number;
      light?: number;
      icons?: boolean;
      disabled?: boolean;
    }
    
    export default function SurfaceButton({
      surface = "bevel", tone = "primary", hue = 222, radius = 14,
      height = 48, depth = 3, light = 60, style, children, className = "", ...props
    }: ButtonHTMLAttributes<HTMLButtonElement> & Omit<SurfaceSettings, "icons"> & {
      surface?: Surface;
      tone?: "primary" | "neutral";
    }) {
      return (
        <button {...props} type={props.type ?? "button"}
          className={`sb-button ${className}`} data-surface={surface} data-tone={tone}
          style={{ "--sb-hue": hue, "--sb-radius": `${radius}px`, "--sb-height": `${height}px`,
            "--sb-depth": `${depth}px`, "--sb-light": light / 100, ...style } as CSSProperties}>
          <span className="sb-content">{children}</span>
        </button>
      );
    }
    
  3. use

    the stage above, exactly as it runs here. the comments mark what to change.

    example.tsx
    "use client";
    
    import { useState } from "react";
    import SurfaceButton, { type Surface, type SurfaceSettings } from "./surface-studies/SurfaceButton";
    
    const SURFACES: Surface[] = ["soft", "bevel", "push", "key"];
    
    function Icon({ kind }: { kind: "plus" | "dice" }) {
      return <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
        {kind === "plus" ? <path d="M12 5v14M5 12h14" /> : <><rect x="3" y="3" width="18" height="18" rx="5" /><path d="M8 8h.01M16 8h.01M12 12h.01M8 16h.01M16 16h.01" /></>}
      </svg>;
    }
    
    export default function SurfaceButtonsExample({ icons = true, disabled = false, onPress, onStyleChange, ...settings }: SurfaceSettings & { onPress?: () => void; onStyleChange?: () => void }) {
      const [surface, setSurface] = useState<Surface>("bevel");
      return (
        <div className="sb-lab">
          <div className="sb-specimen">
            <div className="sb-pair">
              <SurfaceButton {...settings} surface={surface} tone="neutral" disabled={disabled} onClick={onPress}>
                {icons && <Icon kind="dice" />}surprise me
              </SurfaceButton>
              <SurfaceButton {...settings} surface={surface} disabled={disabled} onClick={onPress}>
                {icons && <Icon kind="plus" />}new board
              </SurfaceButton>
            </div>
          </div>
          <footer className="sb-footer">
            <div className="sb-picker" role="group" aria-label="Button surface">
              {SURFACES.map((s) => <button key={s} type="button" aria-pressed={surface === s} onClick={() => { if (s !== surface) { setSurface(s); onStyleChange?.(); } }}>{s}</button>)}
            </div>
          </footer>
        </div>
      );
    }