1
0
Fork 0

feat(contributions): fade the XP hint out and polish the amount

This commit is contained in:
Jason Fraley 2026-10-13 15:52:57 -04:00
parent e96fdb7f58
commit 75817ed3fe
3 changed files with 90 additions and 46 deletions

View file

@ -313,10 +313,10 @@
} }
/* "This will earn XP" hint: the sparkles pop in, the copy wipes in from the /* "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 left, then a gold shimmer sweeps across the copy itself (clipped to the
text. The motion is skipped when the user asks for reduced motion; the hint glyphs). The motion is skipped when the user asks for reduced motion; the
itself still shows, just without animating. Reused wherever a surface grants hint itself still shows, just without animating. Reused wherever a surface
contribution XP (see components/frontend/contributions/XpHint.tsx). */ grants contribution XP (see components/frontend/contributions/XpHint.tsx). */
@keyframes xp-hint-icon-in { @keyframes xp-hint-icon-in {
0% { 0% {
opacity: 0; opacity: 0;
@ -346,20 +346,12 @@
} }
} }
@keyframes xp-hint-glint { @keyframes xp-hint-shimmer {
0% { from {
opacity: 0; background-position: 100% center;
transform: translateX(-100%);
} }
15% { to {
opacity: 1; background-position: 0% center;
}
85% {
opacity: 1;
}
100% {
opacity: 0;
transform: translateX(100%);
} }
} }
@ -368,33 +360,55 @@
} }
.xp-hint-text { .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 { /* The XP amount sits a touch brighter than the copy and carries a soft glow. */
position: absolute; .xp-hint-amount {
inset: 0; color: #fde68a;
z-index: 10; text-shadow:
pointer-events: none; 0 0 12px rgb(251 191 36 / 0.8),
background: linear-gradient( 0 0 24px rgb(251 191 36 / 0.4);
90deg, }
transparent 40%,
rgb(253 224 71 / 0.95) 50%, /* Added when the hint stops applying; it fades up and away before unmounting. */
transparent 60% .xp-hint-leaving {
); transition:
animation: xp-hint-glint 1s ease-in-out 0.3s both; opacity 0.25s ease-in,
transform 0.25s ease-in;
opacity: 0;
transform: translateY(-0.25rem);
} }
@media (prefers-reduced-motion: reduce) { @media (prefers-reduced-motion: reduce) {
.xp-hint-icon, .xp-hint-icon {
.xp-hint-text {
animation: none; animation: none;
opacity: 1;
clip-path: none;
} }
.xp-hint-glint { .xp-hint-text {
display: none; animation: none;
background-image: none;
-webkit-background-clip: border-box;
background-clip: border-box;
color: inherit;
}
.xp-hint-leaving {
transition: none;
} }
} }

View file

@ -1,10 +1,13 @@
"use client"; "use client";
import * as React from "react";
import { SparklesIcon } from "lucide-react"; import { SparklesIcon } from "lucide-react";
import { cn } from "@/lib/utils"; import { cn } from "@/lib/utils";
interface XpHintProps { interface XpHintProps {
/** Whether the hint applies; turning it off fades it out and away. */
visible: boolean;
/** XP the action will grant. */ /** XP the action will grant. */
points: number; points: number;
/** Optional trailing context, e.g. "from this journal entry". */ /** Optional trailing context, e.g. "from this journal entry". */
@ -12,24 +15,49 @@ interface XpHintProps {
className?: string; 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 * 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 * from the left, then a gold shimmer sweeps across the copy itself (clipped to
* render it once their content qualifies; the animation is skipped under * the glyphs). When `visible` turns false the hint fades out before it
* `prefers-reduced-motion` (the hint still shows). * 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 ( return (
<p <p
className={cn( className={cn(
"relative flex items-center gap-1.5 overflow-hidden py-1 text-xs text-amber-400", "flex items-center gap-1.5 text-xs text-amber-400",
leaving && "xp-hint-leaving",
className, className,
)} )}
> >
<span aria-hidden className="xp-hint-glint" />
<SparklesIcon className="xp-hint-icon size-3.5 shrink-0" /> <SparklesIcon className="xp-hint-icon size-3.5 shrink-0" />
<span className="xp-hint-text"> <span className="xp-hint-text">
{`Nice - you'll earn ${points} XP${context ? ` ${context}` : ""}!`} {`Nice - you'll earn `}
<strong className="xp-hint-amount font-semibold">{`${points} XP`}</strong>
{context ? ` ${context}!` : "!"}
</span> </span>
</p> </p>
); );

View file

@ -251,9 +251,11 @@ export function JournalFormDialog({
onChange={setBody} onChange={setBody}
placeholder="Write your entry here..." placeholder="Write your entry here..."
/> />
{bodyLength >= JOURNAL_XP_MIN_CHARS && ( <XpHint
<XpHint points={JOURNAL_XP_POINTS} context="from this journal entry" /> visible={bodyLength >= JOURNAL_XP_MIN_CHARS}
)} points={JOURNAL_XP_POINTS}
context="from this journal entry"
/>
</div> </div>
</div> </div>