Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ComposerStashBadge.tsx

57 lines1.9 KB

1import { BookmarkIcon } from "lucide-react";
2import { memo } from "react";
3​
4import { cn } from "~/lib/utils";
5​
6/**
7 * Bookmark pill perched on the composer's top-right shoulder. Shows the
8 * stash count and doubles as the click target for opening the stash menu.
9 *
10 * On save the badge gives one quiet acknowledgement: it lifts to full
11 * opacity and the count ticks over. `pulseKey` changes per stash, remounting
12 * the count so the transition replays without a continuous animation.
13 */
14export const ComposerStashBadge = memo(function ComposerStashBadge(props: {
15 count: number;
16 pulseKey: number;
17 pulsing: boolean;
18 menuOpen: boolean;
19 onToggleMenu: () => void;
20}) {
21 if (props.count === 0) return null;
22​
23 return (
24 <button
25 type="button"
26 data-prompt-stash-badge="true"
27 aria-label={`Stashed prompts: ${props.count}. Open stash.`}
28 aria-expanded={props.menuOpen}
29 className={cn(
30 "absolute -top-3 right-4 z-10 inline-flex cursor-pointer items-center gap-1.5 rounded-full border bg-popover px-2.5 py-0.5 text-xs shadow-sm",
31 "transition-[color,border-color,opacity] duration-200",
32 props.menuOpen || props.pulsing
33 ? "border-border text-foreground opacity-100"
34 : "border-border/70 text-muted-foreground opacity-70 hover:opacity-100 hover:text-foreground",
35 )}
36 onPointerDown={(event) => {
37 // Keep composer focus so Escape/typing flows stay intact.
38 event.preventDefault();
39 }}
40 onClick={props.onToggleMenu}
41 >
42 <BookmarkIcon className="size-3" aria-hidden="true" />
43 Stash
44 <span
45 key={props.pulseKey}
46 className={cn(
47 "rounded-full px-1.5 text-[10px] font-medium tabular-nums",
48 props.pulsing
49 ? "prompt-stash-count-enter bg-primary text-primary-foreground"
50 : "bg-muted text-muted-foreground",
51 )}
52 >
53 {props.count}
54 </span>
55 </button>
56 );
57});