feat: pronoun pill hover details

This commit is contained in:
7w1 committed 2026-05-24 22:29:03 -05:00
1 parent 4c4d146a9f
commit 79cd9bd2bf
2 files changed
+78 -2

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
---
default: patch
---
Adds the ability to hover/tap over `...` to see the rest of someone's pronouns.
+73 -2
View File
@@ -11,10 +11,13 @@ import {
MenuItem,
PopOut,
Text,
Tooltip,
TooltipProvider,
as,
config,
toRem,
} from 'folds';
import type { MouseEventHandler, MouseEvent, ReactNode } from 'react';
import type { KeyboardEventHandler, MouseEventHandler, MouseEvent, ReactNode } from 'react';
import { memo, useCallback, useRef, useState, useEffect, useMemo } from 'react';
import FocusTrap from 'focus-trap-react';
import { useHover, useFocusWithin } from 'react-aria';
@@ -274,6 +277,72 @@ function useMobileDoubleTap(callback: () => void, delay = 300) {
const clamp = (str: string, len: number) => (str.length > len ? `${str.slice(0, len)}...` : str);
type MorePronounsPillProps = {
pronouns: PronounSet[];
tagColor: string;
};
function MorePronounsPill({ pronouns, tagColor }: MorePronounsPillProps) {
const [anchor, setAnchor] = useState<RectCords | undefined>();
const toggleAnchor = (target: HTMLElement) => {
setAnchor((prev) => (prev ? undefined : target.getBoundingClientRect()));
};
const handleClick: MouseEventHandler<HTMLElement> = (e) => {
e.stopPropagation();
toggleAnchor(e.currentTarget);
};
const handleKeyDown: KeyboardEventHandler<HTMLElement> = (e) => {
if (e.key !== 'Enter' && e.key !== ' ') return;
e.preventDefault();
e.stopPropagation();
toggleAnchor(e.currentTarget);
};
// On mobile, tapping the pill pins the tooltip open.
// Tapping anywhere else dismisses it.
useEffect(() => {
if (!anchor) return undefined;
const dismiss = () => setAnchor(undefined);
document.addEventListener('click', dismiss, { once: true });
return () => document.removeEventListener('click', dismiss);
}, [anchor]);
const tooltipText = pronouns.map((p) => clamp(p.summary, 16)).join(', ');
const tooltipContent = (
<Tooltip style={{ maxWidth: toRem(250) }}>
<Text size="T200">{tooltipText}</Text>
</Tooltip>
);
return (
<>
<TooltipProvider position="Top" tooltip={tooltipContent}>
{(triggerRef) => (
<PronounPill
ref={triggerRef as React.Ref<HTMLSpanElement>}
style={{ color: tagColor, cursor: 'help' }}
onClick={handleClick}
onKeyDown={handleKeyDown}
role="button"
tabIndex={0}
>
...
</PronounPill>
)}
</TooltipProvider>
{anchor && (
<PopOut anchor={anchor} position="Top" align="Center" content={tooltipContent}>
{null}
</PopOut>
)}
</>
);
}
/**
* Component to render pronouns in the chat timeline.
* It also filters them.
@@ -320,7 +389,9 @@ const Pronouns = as<
{clamp(p.summary, 16)}
</PronounPill>
))}
{visiblePronouns.length > limit && <PronounPill style={{ color: tagColor }}>...</PronounPill>}
{visiblePronouns.length > limit && (
<MorePronounsPill pronouns={visiblePronouns.slice(limit)} tagColor={tagColor} />
)}
</AsPronouns>
);
});