From 75817ed3fe7f809102355a481c8e29aec619b074 Mon Sep 17 00:00:00 2001 From: Z8MB1E Date: Tue, 13 Oct 2026 15:52:57 -0400 Subject: [PATCH] feat(contributions): fade the XP hint out and polish the amount --- src/app/(frontend)/styles.css | 86 +++++++++++-------- .../frontend/contributions/XpHint.tsx | 42 +++++++-- .../frontend/journals/JournalFormDialog.tsx | 8 +- 3 files changed, 90 insertions(+), 46 deletions(-) diff --git a/src/app/(frontend)/styles.css b/src/app/(frontend)/styles.css index a5233313..20602293 100644 --- a/src/app/(frontend)/styles.css +++ b/src/app/(frontend)/styles.css @@ -313,10 +313,10 @@ } /* "This will earn XP" hint: the sparkles pop in, the copy wipes in from the - left half a beat later, and a gold glint sweeps from the sparkles across the - text. The motion is skipped when the user asks for reduced motion; the hint - itself still shows, just without animating. Reused wherever a surface grants - contribution XP (see components/frontend/contributions/XpHint.tsx). */ + left, then a gold shimmer sweeps across the copy itself (clipped to the + glyphs). The motion is skipped when the user asks for reduced motion; the + hint itself still shows, just without animating. Reused wherever a surface + grants contribution XP (see components/frontend/contributions/XpHint.tsx). */ @keyframes xp-hint-icon-in { 0% { opacity: 0; @@ -346,20 +346,12 @@ } } -@keyframes xp-hint-glint { - 0% { - opacity: 0; - transform: translateX(-100%); +@keyframes xp-hint-shimmer { + from { + background-position: 100% center; } - 15% { - opacity: 1; - } - 85% { - opacity: 1; - } - 100% { - opacity: 0; - transform: translateX(100%); + to { + background-position: 0% center; } } @@ -368,33 +360,55 @@ } .xp-hint-text { - animation: xp-hint-text-in 0.45s ease-out 0.5s both; + background-image: linear-gradient( + 100deg, + #fbbf24 0%, + #fbbf24 42%, + #fff7d6 50%, + #fbbf24 58%, + #fbbf24 100% + ); + background-size: 250% 100%; + -webkit-background-clip: text; + background-clip: text; + color: transparent; + animation: + xp-hint-text-in 0.45s ease-out 0.5s both, + xp-hint-shimmer 2s ease-in-out 1s both; } -.xp-hint-glint { - position: absolute; - inset: 0; - z-index: 10; - pointer-events: none; - background: linear-gradient( - 90deg, - transparent 40%, - rgb(253 224 71 / 0.95) 50%, - transparent 60% - ); - animation: xp-hint-glint 1s ease-in-out 0.3s both; +/* The XP amount sits a touch brighter than the copy and carries a soft glow. */ +.xp-hint-amount { + color: #fde68a; + text-shadow: + 0 0 12px rgb(251 191 36 / 0.8), + 0 0 24px rgb(251 191 36 / 0.4); +} + +/* Added when the hint stops applying; it fades up and away before unmounting. */ +.xp-hint-leaving { + transition: + opacity 0.25s ease-in, + transform 0.25s ease-in; + opacity: 0; + transform: translateY(-0.25rem); } @media (prefers-reduced-motion: reduce) { - .xp-hint-icon, - .xp-hint-text { + .xp-hint-icon { animation: none; - opacity: 1; - clip-path: none; } - .xp-hint-glint { - display: none; + .xp-hint-text { + animation: none; + background-image: none; + -webkit-background-clip: border-box; + background-clip: border-box; + color: inherit; + } + + .xp-hint-leaving { + transition: none; } } diff --git a/src/components/frontend/contributions/XpHint.tsx b/src/components/frontend/contributions/XpHint.tsx index 4d9a4e88..d28d83cb 100644 --- a/src/components/frontend/contributions/XpHint.tsx +++ b/src/components/frontend/contributions/XpHint.tsx @@ -1,10 +1,13 @@ "use client"; +import * as React from "react"; import { SparklesIcon } from "lucide-react"; import { cn } from "@/lib/utils"; interface XpHintProps { + /** Whether the hint applies; turning it off fades it out and away. */ + visible: boolean; /** XP the action will grant. */ points: number; /** Optional trailing context, e.g. "from this journal entry". */ @@ -12,24 +15,49 @@ interface XpHintProps { className?: string; } +/** Fade-out duration before the hint unmounts (kept in step with the CSS). */ +const EXIT_MS = 250; + /** * Small gold "you'll earn N XP" hint. The sparkles pop in, the copy wipes in - * from the left half a beat later, and a gold glint sweeps across. Callers - * render it once their content qualifies; the animation is skipped under - * `prefers-reduced-motion` (the hint still shows). + * from the left, then a gold shimmer sweeps across the copy itself (clipped to + * the glyphs). When `visible` turns false the hint fades out before it + * unmounts. The animation is skipped under `prefers-reduced-motion`. */ -export function XpHint({ points, context, className }: XpHintProps) { +export function XpHint({ visible, points, context, className }: XpHintProps) { + const [mounted, setMounted] = React.useState(visible); + const [leaving, setLeaving] = React.useState(false); + + React.useEffect(() => { + if (visible) { + setMounted(true); + setLeaving(false); + return; + } + if (!mounted) return; + setLeaving(true); + const timer = window.setTimeout(() => { + setMounted(false); + setLeaving(false); + }, EXIT_MS); + return () => window.clearTimeout(timer); + }, [visible, mounted]); + + if (!mounted) return null; + return (

- - {`Nice - you'll earn ${points} XP${context ? ` ${context}` : ""}!`} + {`Nice - you'll earn `} + {`${points} XP`} + {context ? ` ${context}!` : "!"}

); diff --git a/src/components/frontend/journals/JournalFormDialog.tsx b/src/components/frontend/journals/JournalFormDialog.tsx index ce35a6f5..b88ff8ab 100644 --- a/src/components/frontend/journals/JournalFormDialog.tsx +++ b/src/components/frontend/journals/JournalFormDialog.tsx @@ -251,9 +251,11 @@ export function JournalFormDialog({ onChange={setBody} placeholder="Write your entry here..." /> - {bodyLength >= JOURNAL_XP_MIN_CHARS && ( - - )} + = JOURNAL_XP_MIN_CHARS} + points={JOURNAL_XP_POINTS} + context="from this journal entry" + />