Building an interactive org chart in React for a recruiting page

How our recruiting landing page uses an org chart as its hero: open seats that expand into a role's pipeline with shared layout animations, cards dealt to a panel and a hire dropped into a seat.

7 min read

The real component. Click the picture to open it live and try it before you read how it was built.

Hiring software usually sells itself with a kanban board. We wanted the page to start where hiring really starts: an empty seat on your team.

The chart is plain markup

Each department is a branch: a lead card, then a rail down the left with the team and its open seats hanging off it. The lines are borders and one-pixel spans, so the chart reflows on phones into a single column without any drawing code.

src/registry/landing-pages/hirelane/org-chart.tsx

"use client";

import { useState } from "react";
import { AnimatePresence, LayoutGroup, motion } from "motion/react";
import { useEscapeKey } from "@/hooks/use-escape-key";
import { OpenSeat } from "./open-seat";
import { PersonCard, TeamCard } from "./person-card";
import { SeatDetail } from "./seat-detail";
import type { Department, HirelaneContent } from "./types";

type Org = HirelaneContent["org"];

interface BranchProps {
  department: Department;
  org: Org;
  openRole: string | null;
  onOpen: (role: string) => void;
}

// One department as a branch: its lead (when it has a named one), a rail down the left with the team hanging off
// it, and the open seats at the foot of the rail. A seat that is open leaves its space behind so the chart doesn't jump.
function Branch({ department, org, openRole, onOpen }: BranchProps) {
  return (
    <div className="flex flex-col">
      <span aria-hidden className="mx-auto hidden h-6 w-px bg-neutral-300 sm:block" />
      <p className="mb-2 font-rethink text-xs font-medium text-neutral-500">{department.name}</p>
      {department.lead ? <PersonCard person={department.lead} /> : null}
      <ul className="ml-4 flex flex-col gap-2 border-l border-neutral-300 pt-2 pl-4">
        <li className="relative">
          <span aria-hidden className="absolute top-1/2 -left-4 h-px w-4 bg-neutral-300" />
          <TeamCard team={department.team} />
        </li>
        {department.openings.map((opening) => (
          <li key={opening.role} className="relative">
            <span aria-hidden className="absolute top-1/2 -left-4 h-px w-4 bg-rose-400" />
            {openRole === opening.role ? (
              <div aria-hidden className="h-12" />
            ) : (
              <OpenSeat
                opening={opening}
                label={org.seatLabel}
                layoutId={`seat-${opening.role}`}
                onOpen={() => onOpen(opening.role)}
              />
            )}
          </li>
        ))}
      </ul>
    </div>
  );
}

// The hero's product: the company's org chart drawn in code, with every open role as an empty seat. Click a seat and
// it opens in place into that role's pipeline; Escape or the cross puts it back.
export function OrgChart({ org }: { org: Org }) {
  const [openRole, setOpenRole] = useState<string | null>(null);
  useEscapeKey(() => setOpenRole(null), openRole !== null);
  const opening = org.departments.flatMap((department) => department.openings).find((item) => item.role === openRole);
  return (
    <LayoutGroup>
      <div className="relative">
        <div className="flex flex-col items-center">
          <PersonCard person={org.top} className="w-56" />
          <span aria-hidden className="hidden h-6 w-px bg-neutral-300 sm:block" />
        </div>
        <div className="relative grid gap-8 pt-6 sm:grid-cols-3 sm:gap-6 sm:pt-0">
          <span aria-hidden className="absolute inset-x-1/6 top-0 hidden h-px bg-neutral-300 sm:block" />
          {org.departments.map((department) => (
            <Branch key={department.name} department={department} org={org} openRole={openRole} onOpen={setOpenRole} />
          ))}
        </div>
        <AnimatePresence>
          {opening ? (
            <motion.div
              key="backdrop"
              initial={{ opacity: 0 }}
              animate={{ opacity: 1 }}
              exit={{ opacity: 0 }}
              onClick={() => setOpenRole(null)}
              className="absolute inset-0 z-10 flex items-center justify-center rounded-xl bg-neutral-100/70 p-2 backdrop-blur-xs"
            >
              <div onClick={(event) => event.stopPropagation()} className="flex w-full justify-center">
                <SeatDetail
                  opening={opening}
                  layoutId={`seat-${opening.role}`}
                  closeLabel={org.closeLabel}
                  onClose={() => setOpenRole(null)}
                />
              </div>
            </motion.div>
          ) : null}
        </AnimatePresence>
      </div>
    </LayoutGroup>
  );
}
Branches, rails and open seats

A seat that opens in place

The open seat and its detail panel share a layoutId. Click the seat and Motion animates the small dashed card into the big panel, so the role's pipeline grows out of the seat rather than appearing as a modal. Escape or the cross shrinks it back. While open, the seat leaves a spacer so the chart doesn't jump.

src/registry/landing-pages/hirelane/seat-detail.tsx

"use client";

import { motion } from "motion/react";
import { X } from "lucide-react";
import { HireButton } from "./hire-button";
import type { Opening } from "./types";

const PERCENT = 100;

interface SeatDetailProps {
  opening: Opening;
  layoutId: string;
  closeLabel: string;
  onClose: () => void;
}

// The open seat, opened: the role's pipeline as narrowing bars from everyone who applied down to the finalists,
// and what happens next. It grows out of the seat through a shared layout animation and shrinks back into it.
export function SeatDetail({ opening, layoutId, closeLabel, onClose }: SeatDetailProps) {
  const first = opening.stages[0].count;
  return (
    <motion.div
      layoutId={layoutId}
      role="dialog"
      aria-label={opening.role}
      transition={{ type: "spring", stiffness: 300, damping: 30 }}
      className="relative z-10 flex w-full max-w-lg flex-col gap-5 rounded-xl bg-white p-5 shadow-2xl ring-1 shadow-neutral-950/15 ring-neutral-200"
    >
      <div className="flex items-start justify-between gap-4">
        <p className="font-rethink text-lg font-semibold text-neutral-950">{opening.role}</p>
        <button
          type="button"
          onClick={onClose}
          aria-label={closeLabel}
          className="flex size-8 items-center justify-center rounded-md text-neutral-500 outline-none hover:bg-neutral-100 focus-visible:ring-2 focus-visible:ring-rose-500"
        >
          <X aria-hidden className="size-4" />
        </button>
      </div>
      <ol className="flex flex-col gap-2">
        {opening.stages.map((stage, index) => (
          <li key={stage.name} className="grid grid-cols-4 items-center gap-3 font-rethink text-sm">
            <span className="text-neutral-600">{stage.name}</span>
            <span className="col-span-3 flex items-center gap-2">
              <motion.span
                initial={{ scaleX: 0 }}
                animate={{ scaleX: 1 }}
                transition={{
                  delay: 0.15 + index * 0.08,
                  type: "spring",
                  stiffness: 300,
                  damping: 30,
                }}
                style={{
                  width: `${Math.max((stage.count / first) * PERCENT, 2)}%`,
                  originX: 0,
                }}
                className="h-2.5 rounded-xs bg-neutral-950"
              />
              <span className="text-neutral-950 tabular-nums">{stage.count}</span>
            </span>
          </li>
        ))}
      </ol>
      <motion.p
        initial={{ opacity: 0, y: 6 }}
        animate={{ opacity: 1, y: 0 }}
        transition={{ delay: 0.4 }}
        className="rounded-lg bg-rose-50 px-3 py-2.5 font-rethink text-sm text-rose-800"
      >
        {opening.next}
      </motion.p>
      <HireButton href={opening.action.href} label={opening.action.label} className="self-start" />
    </motion.div>
  );
}
The opened seat: a narrowing pipeline and what happens next

Questions dealt like cards

The interview loop is a table seen from above. Each question card animates from the deck to an interviewer's corner, one after another, with useInView starting the deal when the table scrolls into view. The table is drawn at one size and scaled to fit, so the deal lands in the same places on a phone.

src/registry/landing-pages/hirelane/deal-table.tsx

"use client";

import { useEffect, useRef, useState } from "react";
import { useInView } from "motion/react";
import { Shuffle } from "lucide-react";
import { ScaleToFit } from "@/components/ui/scale-to-fit";
import { usePrefersReducedMotion } from "@/hooks/use-prefers-reduced-motion";
import { cn } from "@/lib/utils";
import { PersonCard } from "./person-card";
import { QuestionCard, type CardSpot } from "./question-card";
import type { HirelaneContent } from "./types";

// The table is drawn at one size and scaled to fit, so the deal lands in the same places on a phone.
const STAGE_WIDTH = 560;
// Each seat's direction from the centre, in the order of the panel: top left, top right, and the foot of the table.
const SEATS = [
  [-1, -1],
  [1, -1],
  [0, 1.25],
];
const REACH = 118;
const SEAT_POSITIONS = ["top-0 left-0", "top-0 right-0", "bottom-0 left-1/2 -translate-x-1/2"];
const DEAL_GAP_S = 0.14;
const REDEAL_PAUSE_MS = 650;

// Where the n-th card dealt lands: round the table one seat at a time, the second card at a seat fanned over the
// first.
function spotOf(index: number, seats: number): CardSpot {
  const [dx, dy] = SEATS[index % seats];
  const isSecond = index >= seats;
  return {
    x: dx * REACH + (isSecond ? 14 : -10),
    y: dy * REACH + (isSecond ? 10 : -6),
    rotate: isSecond ? 5 : -7,
  };
}

// Shuffled positions 0..n-1, for dealing the deck again in a new order.
function shuffled(count: number): number[] {
  const order = Array.from({ length: count }, (_, index) => index);
  for (let index = count - 1; index > 0; index -= 1) {
    const swap = Math.floor(Math.random() * (index + 1));
    [order[index], order[swap]] = [order[swap], order[index]];
  }
  return order;
}

// The interview loop as a card table seen from above: the interviewers in their seats and the role's questions
// in a face-down deck in the middle. It deals itself the first time it comes into view, two cards to each person;
// the button gathers the cards and deals them again in a new order.
export function DealTable({ loop }: { loop: HirelaneContent["loop"] }) {
  const ref = useRef<HTMLDivElement>(null);
  const isInView = useInView(ref, { once: true, amount: 0.5 });
  const isReduced = usePrefersReducedMotion();
  // Null until the visitor presses the button; until then the table deals itself once it is on screen.
  const [dealt, setDealt] = useState<boolean | null>(null);
  const isDealt = dealt ?? isInView;
  const [order, setOrder] = useState(() => loop.questions.map((_, index) => index));
  const timer = useRef(0);

  useEffect(() => () => window.clearTimeout(timer.current), []);

  function redeal() {
    setDealt(false);
    timer.current = window.setTimeout(() => {
      setOrder(shuffled(loop.questions.length));
      setDealt(true);
    }, REDEAL_PAUSE_MS);
  }

  return (
    <div ref={ref} className="flex flex-col items-center gap-6">
      <ScaleToFit width={STAGE_WIDTH} className="w-full max-w-140">
        <div className="relative h-140 w-140">
          <div aria-hidden className="absolute inset-16 rounded-full bg-white shadow-inner ring-1 ring-neutral-200" />
          {loop.panel.map((person, index) => (
            <PersonCard key={person.name} person={person} className={cn("absolute w-40", SEAT_POSITIONS[index])} />
          ))}
          {order.map((questionIndex, dealIndex) => (
            <QuestionCard
              key={questionIndex}
              question={loop.questions[questionIndex]}
              spot={spotOf(dealIndex, loop.panel.length)}
              depth={loop.questions.length - dealIndex}
              isDealt={isDealt}
              delay={dealIndex * DEAL_GAP_S}
              isReduced={isReduced}
            />
          ))}
        </div>
      </ScaleToFit>
      <button
        type="button"
        onClick={isDealt ? redeal : () => setDealt(true)}
        className="inline-flex h-9 items-center gap-2 rounded-lg bg-neutral-950 px-4 font-rethink text-sm font-medium text-white transition-colors outline-none hover:bg-rose-600 focus-visible:ring-2 focus-visible:ring-rose-500 focus-visible:ring-offset-2 active:translate-y-px"
      >
        <Shuffle aria-hidden className="size-4" />
        {isDealt ? loop.redealLabel : loop.dealLabel}
      </button>
    </div>
  );
}
The deal: positions, a shuffle and a redeal

Seat the hire

Finally the chosen candidate is dragged onto the empty seat. On release we check whether the pointer is over the seat's box; if it is, the card moves into the seat through another shared layoutId and the team count rolls up by one.

More articles