People tiles: square photos, a frame, even heights, palette initials

Captions are a fixed two lines of name and two of title; what
doesn't fit ends in an ellipsis and gives the tile the down arrow,
whose details show it in full.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Zaldimmar 2026-09-30 14:50:59 -05:00
parent 5dbb203519
commit 592e07f614
3 changed files with 103 additions and 26 deletions

View file

@ -2,6 +2,7 @@ import { ArrowRight, CaretDown, X } from "@phosphor-icons/react";
import {
useEffect,
useId,
useLayoutEffect,
useMemo,
useRef,
useState,
@ -15,6 +16,7 @@ import { get } from "../lib/api.ts";
import { isBadId, personHref } from "../lib/hrefs.ts";
import { mediaUrl, initials } from "../lib/media.ts";
import { useSmallImage } from "../lib/useSmallImage.ts";
import { paletteFill } from "../lib/color.ts";
import "./PeopleTiles.css";
/**
@ -47,6 +49,13 @@ import "./PeopleTiles.css";
* public email or a bio. Not bio alone, the details panel is
* worth opening before anyone has written prose.
*
* At every size the photo is square and the caption a fixed two
* lines of name (and two of title), so a row's cards are one
* height. What doesn't fit ends in an ellipsis, and that tile gets
* the chevron too, opening the details with it in full. A person
* with no photo gets their initials on a palette color
* (paletteFill in color.ts).
*
* Field names follow the API (is_owner, location_label), so a row
* from /api/teams/:id/people drops in unchanged.
*
@ -394,6 +403,9 @@ export function PeopleTilesView({
}) {
const baseId = useId().replace(/:/g, "");
const [openKey, setOpenKey] = useState<string | null>(null);
// Tiles whose name or title didn't fit and was cut off: they get
// the down arrow, and the details panel shows it whole.
const [clipped, setClipped] = useState<ReadonlySet<string>>(() => new Set());
const rootRef = useRef<HTMLDivElement>(null);
const resolvedSize: PeopleTilesSize = SIZE_FEATURES[size] ? size : "md";
@ -428,7 +440,17 @@ export function PeopleTilesView({
return emptyMessage ? <p className="pl__empty">{emptyMessage}</p> : null;
}
const open = features.details ? findByKey(resolvedGroups, openKey) : null;
const open = openKey ? findByKey(resolvedGroups, openKey) : null;
function markClipped(key: string, isClipped: boolean) {
setClipped((current) => {
if (current.has(key) === isClipped) return current;
const next = new Set(current);
if (isClipped) next.add(key);
else next.delete(key);
return next;
});
}
function toggle(group: PeopleGroup, person: Person, index: number) {
const key = keyFor(group, person, index);
@ -486,7 +508,7 @@ export function PeopleTilesView({
<ul className="pl__row">
{group.people.map((person, index) => {
const key = keyFor(group, person, index);
const expandable = features.details && hasDetails(person);
const expandable = (features.details && hasDetails(person)) || clipped.has(key);
const isOpen = expandable && openKey === key;
return (
@ -506,6 +528,7 @@ export function PeopleTilesView({
isOpen={isOpen}
panelId={`${baseId}-bio`}
onToggle={() => toggle(group, person, index)}
onClip={(isClipped) => markClipped(key, isClipped)}
/>
</li>
);
@ -537,6 +560,7 @@ function Tile({
isOpen,
panelId,
onToggle,
onClip,
}: {
person: Person;
showTitle: boolean;
@ -544,15 +568,36 @@ function Tile({
isOpen: boolean;
panelId: string;
onToggle: () => void;
onClip: (isClipped: boolean) => void;
}) {
const title = titleOf(person);
const captionRef = useRef<HTMLSpanElement>(null);
// Every caption is the same height (two lines of name, two of
// title), so the row stays even; a name or title that needs more
// is cut with an ellipsis. Checked again whenever the tile resizes,
// which is also when the web font arrives.
useLayoutEffect(() => {
const caption = captionRef.current;
if (!caption) return undefined;
const check = () =>
onClip(
Array.from(caption.children).some((line) => line.scrollHeight > line.clientHeight + 1),
);
check();
const observer = new ResizeObserver(check);
observer.observe(caption);
return () => observer.disconnect();
// onClip is a fresh closure each render; the name and title are
// what can change the answer.
}, [person.name, title, showTitle]);
const content = (
<span className="pl__frame">
<span className="pl__photo">
<Photo src={mediaUrl(person.photo)} name={person.name} />
</span>
<span className="pl__caption">
<span ref={captionRef} className="pl__caption" data-title={showTitle ? "on" : "off"}>
<span className="pl__name">{person.name}</span>
{showTitle && title && <span className="pl__title">{title}</span>}
</span>
@ -592,9 +637,10 @@ function Tile({
function Photo({ src, name }: { src?: string | null; name: string }) {
const img = useSmallImage(src);
// No photo: the initials on a palette color picked by the name.
if (img.failed) {
return (
<span className="pl__initials" aria-hidden="true">
<span className="pl__initials" style={paletteFill(name)} aria-hidden="true">
{initials(name)}
</span>
);