"use client"; import { motion, useReducedMotion } from "motion/react"; import { TextMorph } from "@/components/motion/text-morph"; import { EASE_IN, EASE_OUT, SPRING_PRESS, SPRING_SWAP } from "@/lib/ease"; import { useMessages } from "@/lib/i18n"; import { cn } from "@/lib/utils"; export const messageStatusMessages = { sending: "Sending", sent: "Sent", delivered: "Delivered", read: "Read", }; export type MessageStatusMessages = typeof messageStatusMessages; export type MessageStatusValue = "sending" | "sent" | "delivered" | "read"; export interface MessageStatusProps { /** Delivery stage. Moving forward animates the badges to the next state. */ status: MessageStatusValue; /** Show the status as a word next to the badges. */ showLabel?: boolean; /** Override any built-in string, e.g. for translation. */ labels?: Partial; /** Classes merged onto the root element. */ className?: string; } const FADE = { duration: 0.16, ease: EASE_OUT } as const; const QUICK_OUT = { duration: 0.12, ease: EASE_IN } as const; // While it sends the ring creeps toward full and never quite gets there. const PROGRESS = { duration: 2.4, ease: EASE_OUT } as const; // On send the ring closes, then the badge fills and the check draws. const CLOSE = { duration: 0.18, ease: EASE_OUT } as const; const FILL = { ...SPRING_PRESS, delay: 0.14 } as const; const DRAW = { duration: 0.24, ease: EASE_OUT, delay: 0.24 } as const; const POP = { duration: 0.34, ease: EASE_OUT } as const; // For Read the colour lands on the back badge first, then the front. const READ_STAGGER = 0.1; // Badge geometry, in px: two 20px badges overlap by half when delivered. const BADGE = 20; const WIDTH = 30; const CENTER = (WIDTH - BADGE) / 2; const FRONT = WIDTH - BADGE; const CHECK = "M6.4 10.3l2.4 2.4 4.8-5"; /** One round badge: an optional progress ring, then a filled disc with a check. */ function Badge({ filled, ring, progress, read, delay, reduce, }: { filled: boolean; ring: boolean; progress: number; read: boolean; delay: number; reduce: boolean; }) { const instant = { duration: 0 }; return ( ); } /** * The delivery state of a sent message, as round badges. A progress ring * fills while it sends, then closes into a filled badge with a check for * Sent; a second badge slides out from behind it for Delivered; and both * fill with the accent colour, one after the other, when it is read. */ export function MessageStatus({ status, showLabel = false, labels, className }: MessageStatusProps) { const t = useMessages("MessageStatus", messageStatusMessages, labels); const reduce = Boolean(useReducedMotion()); const sending = status === "sending"; const read = status === "read"; const double = status === "delivered" || read; const icon = ( ); const box = cn( "inline-flex items-center gap-1.5 text-sm transition-colors duration-300", read ? "text-primary" : "text-muted-foreground", className, ); // With a label the words name it; icon only, it is an image named for its status. return showLabel ? ( {icon} {t(status)} ) : ( {icon} ); }