Specification
- Catalogue
- No. 102 of 110
- Section
- Cards and accordions
- Interaction
- Press, Feedback, Layout Animation
- Element
- Card
- Preview
- Live component
- Imports
- react 19.3.1
- Added
Notes
A small call card: two people in the room and a Join button. Join and you arrive as a third face with a short spring, the person speaking gets four bars over their face, and the one button turns into a row: mute, more, and a red Leave.
The button row is the point. The single wide action splits into three without the card changing size, so the hand does not have to look for anything; Leave keeps the wide button's place and weight. The speaking bars beat a few times and stop, so nothing on the page moves for ever. Muting puts a small badge on your own face as well as changing the button, so the state reads from the room and from the control.
The faces are coloured initials, not photographs.
Code
React and plain CSS"use client";
import { useEffect, useState, type CSSProperties } from "react";
import type { LivePreviewProps } from "@/components/live/types";
import styles from "./huddle.module.css";
type Person = { id: string; name: string; initials: string; hue: number };
const ROOM: Person[] = [
{ id: "mara", name: "Mara", initials: "MO", hue: 6 },
{ id: "theo", name: "Theo", initials: "TB", hue: 3 },
];
const YOU: Person = { id: "you", name: "You", initials: "", hue: 7 };
/** The card demo: join, mute, unmute, leave, in a loop while the card is hovered. */
const DEMO: Array<{ joined: boolean; muted: boolean; wait: number }> = [
{ joined: false, muted: false, wait: 900 },
{ joined: true, muted: false, wait: 1700 },
{ joined: true, muted: true, wait: 1100 },
{ joined: true, muted: false, wait: 1300 },
];
function Orb({ person, speaking, muted, entering }: { person: Person; speaking: boolean; muted?: boolean; entering?: boolean }) {
const style = { "--hue": `var(--cat-${person.hue}, var(--accent, currentColor))` } as CSSProperties;
return (
<div className={styles.person} data-entering={entering || undefined}>
<span className={styles.orb} style={style} data-you={person.id === "you" || undefined}>
{person.initials && <span className={styles.initials}>{person.initials}</span>}
<span className={styles.wave} data-on={speaking || undefined} aria-hidden="true">
<i />
<i />
<i />
<i />
</span>
{muted && (
<span className={styles.mutedBadge} aria-hidden="true">
<MicIcon off size={10} />
</span>
)}
</span>
<span className={styles.name} data-speaking={speaking || undefined}>
{person.name}
</span>
</div>
);
}
function MicIcon({ off, size = 16 }: { off?: boolean; size?: number }) {
return (
<svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" aria-hidden="true">
<rect x="9" y="3" width="6" height="11" rx="3" />
<path d="M5 11a7 7 0 0 0 14 0M12 18v3" />
{off && <path d="M4 4l16 16" />}
</svg>
);
}
export default function Huddle({ active, context }: LivePreviewProps) {
const card = context === "card";
const [joined, setJoined] = useState(false);
const [muted, setMuted] = useState(false);
const [step, setStep] = useState(0);
const demo = card && active;
// Each time the demo starts, it starts from the room as it is before anyone joins.
const [running, setRunning] = useState(demo);
if (running !== demo) {
setRunning(demo);
setStep(0);
}
useEffect(() => {
if (!demo) return;
const id = window.setTimeout(() => setStep((s) => s + 1), DEMO[step % DEMO.length]?.wait ?? 1000);
return () => window.clearTimeout(id);
}, [demo, step]);
const frame = DEMO[step % DEMO.length];
const isJoined = card ? Boolean(demo && frame?.joined) : joined;
const isMuted = card ? Boolean(demo && frame?.muted) : muted;
// Mara speaks while you are in the room; the wave stops after a few beats (huddle.module.css).
const speaker = isJoined ? "mara" : null;
const tab = card ? -1 : 0;
return (
<div className={styles.area}>
<div className={styles.panel} data-joined={isJoined || undefined}>
<div className={styles.head}>
<span className={styles.title}>Huddle</span>
{isJoined && <span className={styles.live}>Live</span>}
</div>
<div className={styles.room} aria-label={isJoined ? "In the huddle: Mara, Theo and you" : "In the huddle: Mara and Theo"}>
{ROOM.map((p) => (
<Orb key={p.id} person={p} speaking={speaker === p.id} />
))}
{isJoined && <Orb person={YOU} speaking={false} muted={isMuted} entering />}
</div>
<div className={styles.keys}>
{isJoined ? (
<>
<button
type="button"
className={styles.round}
aria-pressed={isMuted}
aria-label={isMuted ? "Unmute microphone" : "Mute microphone"}
tabIndex={tab}
onClick={() => setMuted((m) => !m)}
>
<MicIcon off={isMuted} />
</button>
<button type="button" className={styles.round} aria-label="More options" tabIndex={tab}>
<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
<circle cx="5" cy="12" r="1.8" />
<circle cx="12" cy="12" r="1.8" />
<circle cx="19" cy="12" r="1.8" />
</svg>
</button>
<button
type="button"
className={styles.leave}
tabIndex={tab}
onClick={() => {
setJoined(false);
setMuted(false);
}}
>
Leave
</button>
</>
) : (
<button type="button" className={styles.join} tabIndex={tab} data-pressed={demo && step % DEMO.length === 0 ? "" : undefined} onClick={() => setJoined(true)}>
Join huddle
</button>
)}
</div>
</div>
<p className="visually-hidden" role="status">
{isJoined ? (isMuted ? "You joined the huddle, microphone muted." : "You joined the huddle.") : ""}
</p>
</div>
);
}