Headers & navigation / Tab bars

Soft Segmented Surface Tabs

A gray rounded-xl track holding text tabs; the active tab is a white raised pill with a ring shadow. Used above a large product mockup stage.

Rebuilt from cal.com in the Warm Paper Calendar style.

npx shadcn@latest add https://justyoink.it/r/warm-paper-calendar/blocks/surface-tab-switcher.json

Looks exactly like cal.com: brings its fonts and colours, namespaced so your own theme stays untouched.

Usage

Pass `tabs` (array of {id, label, caption}) to customize; the sliding white pill follows the active tab and the caption and mockup stage re-animate on change. Renders standalone with no props.

components/surface-tab-switcher.tsx
"use client";

import { useEffect, type CSSProperties, type ElementType, type ReactNode, type RefObject } from "react";
import { useState, useRef, useLayoutEffect } from "react";

type Tab = { id: string; label: string; caption: string };

const DEFAULT_TABS: Tab[] = [
  { id: "web", label: "Web app", caption: "Charts from your schedule, shown beside the page you have open." },
  { id: "desktop", label: "Desktop", caption: "A quick-launch panel that floats above every window on your Mac." },
  { id: "chat", label: "Chat", caption: "Ask in any channel and get a short answer with the numbers inline." },
  { id: "sms", label: "Text message", caption: "Send a text and receive a summary back in seconds." },
];

export default function SoftSegmentedSurfaceTabs({ tabs = DEFAULT_TABS }: { tabs?: Tab[] }) {
  const [active, setActive] = useState(tabs[0].id);
  const refs = useRef<Record<string, HTMLButtonElement | null>>({});
  const [pill, setPill] = useState({ left: 0, width: 0 });

  useLayoutEffect(() => {
    const el = refs.current[active];
    if (el) setPill({ left: el.offsetLeft, width: el.offsetWidth });
  }, [active]);

  const current = tabs.find((t) => t.id === active) || tabs[0];
  const bars = [40, 65, 50, 80, 60, 90, 70];

  return (
    <section className="bg-canvas px-5 py-16 font-sans text-ink md:px-16">
      <div className="mx-auto max-w-5xl">
        <div role="tablist" aria-label="Surfaces" className="relative inline-flex max-w-full overflow-x-auto rounded-xl bg-panel p-1">
          <span
            aria-hidden
            className="absolute top-1 bottom-1 rounded-lg bg-canvas shadow-ring-raised transition-all duration-150 ease-out"
            style={{ left: pill.left, width: pill.width }}
          />
          {tabs.map((t) => (
            <button
              key={t.id}
              ref={(el) => { refs.current[t.id] = el; }}
              role="tab"
              aria-selected={active === t.id}
              onClick={() => setActive(t.id)}
              className={"relative z-10 whitespace-nowrap rounded-lg px-4 py-2 text-ui transition-colors duration-150 focus-visible:outline focus-visible:outline-2 focus-visible:outline-ink " + (active === t.id ? "text-ink" : "text-muted hover:text-ink")}
            >
              {t.label}
            </button>
          ))}
        </div>

        <div key={current.id} className="animate-appear-up">
          <p className="mt-6 text-body text-body">{current.caption}</p>
          <Reveal from="up">
            <div className="mt-6 rounded-xl bg-panel p-4 md:p-12">
              <div className="mx-auto overflow-hidden rounded-lg bg-canvas shadow-soft">
                <div className="flex items-center gap-2 border-b border-hairline px-4 py-3">
                  <span className="h-3 w-3 rounded-pill bg-alert" />
                  <span className="h-3 w-3 rounded-pill bg-sand" />
                  <span className="h-3 w-3 rounded-pill bg-success" />
                  <span className="mx-auto rounded-pill bg-panel px-10 py-1 text-caption text-muted">app.example.com/insights</span>
                </div>
                <div className="grid md:grid-cols-[180px_1fr]">
                  <ul className="hidden space-y-1 bg-panel-alt p-3 text-ui text-body md:block">
                    {["Home", "Links", "Bookings", "Availability", "Insights"].map((n) => (
                      <li key={n} className={"rounded-md px-3 py-1.5 " + (n === "Insights" ? "bg-panel text-ink" : "")}>{n}</li>
                    ))}
                  </ul>
                  <div className="p-5">
                    <h3 className="text-h3">Insights</h3>
                    <div className="mt-4 grid grid-cols-2 gap-3 md:grid-cols-4">
                      {[["Rating", "4.4"], ["No-shows", "2"], ["Late", "10"], ["Score", "89.7"]].map(([a, b]) => (
                        <div key={a} className="rounded-lg bg-panel-alt p-3 shadow-hairline-inset">
                          <div className="text-caption text-muted">{a}</div>
                          <div className="text-h3">{b}</div>
                        </div>
                      ))}
                    </div>
                    <div className="mt-4 flex h-32 items-end gap-3 rounded-lg bg-panel-alt p-4">
                      {bars.map((h, i) => (
                        <div key={i} className="flex-1 rounded-sm bg-ink" style={{ height: h + "%" }} />
                      ))}
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </Reveal>
        </div>
      </div>
    </section>
  );
}

// ---- Yoink motion (inlined, no dependencies): Reveal ----

const YK_EASE = "cubic-bezier(0.16, 1, 0.3, 1)";

const useYkLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;

function ykReducedMotion(): boolean {
  return typeof window !== "undefined" && !!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
}

// "idle": untouched (visible) · "hidden": waiting below the fold · "shown": play the entrance.
// Content is only hidden once we know we can show it again (IntersectionObserver exists, motion allowed,
// and there is a box to watch), and a safety net reveals anything on screen that is still hidden.
type YkRevealState = "idle" | "hidden" | "shown";

function useYkReveal(ref: RefObject<Element | null>, once = true): YkRevealState {
  const [state, setState] = useState<YkRevealState>("idle");
  useYkLayoutEffect(() => {
    const el = ref.current;
    if (!el || ykReducedMotion() || typeof IntersectionObserver === "undefined") return;
    // watch the element's own box, or its children when it has none (display: contents)
    const boxes = () => (getComputedStyle(el).display === "contents" ? Array.from(el.children) : [el]);
    const onScreen = (t: Element) => {
      const r = t.getBoundingClientRect();
      return (r.width > 0 || r.height > 0) && r.bottom > 0 && r.right > 0 && r.top < window.innerHeight && r.left < window.innerWidth;
    };
    if (!boxes().some((t) => t.getBoundingClientRect().width > 0 || t.getBoundingClientRect().height > 0)) return; // e.g. hidden at mount: leave it visible
    let shown = false;
    const show = (v: boolean) => {
      if (v !== shown) (shown = v), setState(v ? "shown" : "hidden");
    };
    setState("hidden");
    const inView = new Set<Element>();
    const io = new IntersectionObserver((entries) => {
      for (const e of entries) {
        if (e.isIntersecting) inView.add(e.target);
        else inView.delete(e.target);
      }
      if (inView.size) {
        show(true);
        if (once) io.disconnect();
      } else if (!once) show(false);
    });
    const watched = new Set<Element>();
    const watch = () => boxes().forEach((t) => !watched.has(t) && (watched.add(t), io.observe(t)));
    watch();
    // safety net: styles that land after mount (display: contents) get watched too, and nothing
    // stays hidden for more than a moment while it is actually on screen
    const start = Date.now();
    const net = setInterval(() => {
      if (shown) return once && clearInterval(net);
      watch();
      if (Date.now() - start > 2400 && boxes().some(onScreen)) show(true);
    }, 600);
    return () => {
      io.disconnect();
      clearInterval(net);
    };
  }, [once]);
  return state;
}

type YkRevealFrom = "up" | "down" | "left" | "right" | "scale" | "blur" | "none";

/** Fades content in as it scrolls into view. */
function Reveal({
  children,
  from = "up",
  delay = 0,
  duration = 700,
  distance = 24,
  once = true,
  as = "div",
  className,
  style,
}: {
  children?: ReactNode;
  from?: YkRevealFrom;
  delay?: number;
  duration?: number;
  distance?: number;
  once?: boolean;
  as?: ElementType;
  className?: string;
  style?: CSSProperties;
}) {
  const Tag = as;
  const ref = useRef<HTMLElement>(null);
  const state = useYkReveal(ref, once);
  const hidden = state === "hidden";
  const offset = {
    up: `translate3d(0, ${distance}px, 0)`,
    down: `translate3d(0, ${-distance}px, 0)`,
    left: `translate3d(${-distance}px, 0, 0)`,
    right: `translate3d(${distance}px, 0, 0)`,
    scale: "scale(0.94)",
    blur: `translate3d(0, ${distance / 2}px, 0)`,
    none: "none",
  }[from];
  const t = `${duration}ms ${YK_EASE} ${delay}ms`;
  return (
    <Tag
      ref={ref}
      className={className}
      style={{
        ...style,
        ...(hidden && { opacity: 0, transform: offset, filter: from === "blur" ? "blur(12px)" : undefined }),
        ...(state === "shown" && { transition: `opacity ${t}, transform ${t}, filter ${t}` }),
      }}
    >
      {children}
    </Tag>
  );
}

Quality checks

Automated, in a real browser · 4d ago
—

More from Warm Paper Calendar

The whole style →

Floating Pill Navigation Bar

Headers & nav bars

Hub-and-Spoke Integration Diagram

Animated graphics

Customer Story Accordion

Accordions

Inline-Chip Headline Hero

Heroes

Frosted Desktop Booking Mockup

Media & mockups

Monochrome Logo Grid

Logo clouds