1
0
Fork 0

feat(contributions): add a reusable XP hint with a glint animation

This commit is contained in:
Jason Fraley 2026-10-13 15:27:00 -04:00
parent 076de5d60c
commit f481efb108
3 changed files with 94 additions and 21 deletions

View file

@ -312,21 +312,27 @@
}
}
/* Journal "this will earn XP" hint: the sparkles pop in, then the copy wipes in
from the left half a beat later. The motion is skipped when the user asks for
reduced motion; the hint itself still shows, just without animating. */
@keyframes journal-xp-icon-in {
from {
/* "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). */
@keyframes xp-hint-icon-in {
0% {
opacity: 0;
transform: scale(0.7);
transform: scale(0.4);
}
to {
60% {
opacity: 1;
transform: scale(1.15);
}
100% {
opacity: 1;
transform: scale(1);
}
}
@keyframes journal-xp-text-in {
@keyframes xp-hint-text-in {
from {
opacity: 0;
clip-path: inset(0 100% 0 0);
@ -340,21 +346,56 @@
}
}
.journal-xp-hint-icon {
animation: journal-xp-icon-in 0.35s ease-out both;
@keyframes xp-hint-glint {
0% {
opacity: 0;
transform: translateX(-100%);
}
15% {
opacity: 1;
}
85% {
opacity: 1;
}
100% {
opacity: 0;
transform: translateX(100%);
}
}
.journal-xp-hint-text {
animation: journal-xp-text-in 0.45s ease-out 0.5s both;
.xp-hint-icon {
animation: xp-hint-icon-in 0.4s ease-out both;
}
.xp-hint-text {
animation: xp-hint-text-in 0.45s ease-out 0.5s 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;
}
@media (prefers-reduced-motion: reduce) {
.journal-xp-hint-icon,
.journal-xp-hint-text {
.xp-hint-icon,
.xp-hint-text {
animation: none;
opacity: 1;
clip-path: none;
}
.xp-hint-glint {
display: none;
}
}
.locker-search-highlight {

View file

@ -0,0 +1,36 @@
"use client";
import { SparklesIcon } from "lucide-react";
import { cn } from "@/lib/utils";
interface XpHintProps {
/** XP the action will grant. */
points: number;
/** Optional trailing context, e.g. "from this journal entry". */
context?: string;
className?: string;
}
/**
* 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).
*/
export function XpHint({ points, context, className }: XpHintProps) {
return (
<p
className={cn(
"relative flex items-center gap-1.5 overflow-hidden py-1 text-xs text-amber-400",
className,
)}
>
<span aria-hidden className="xp-hint-glint" />
<SparklesIcon className="xp-hint-icon size-3.5 shrink-0" />
<span className="xp-hint-text">
{`Nice - you'll earn ${points} XP${context ? ` ${context}` : ""}!`}
</span>
</p>
);
}

View file

@ -3,7 +3,7 @@
import * as React from "react";
import { useRouter } from "next/navigation";
import { toast } from "sonner";
import { Loader2Icon, SparklesIcon } from "lucide-react";
import { Loader2Icon } from "lucide-react";
import { Button } from "@/components/ui/button";
import {
@ -28,6 +28,7 @@ import {
type LexicalJson,
} from "@/components/frontend/intelligence/LexicalRichTextEditor";
import { createJournal, updateJournal } from "@/app/(frontend)/journals/actions";
import { XpHint } from "@/components/frontend/contributions/XpHint";
import { journalBodyLength } from "@/lib/journals/excerpt";
import { JOURNAL_XP_MIN_CHARS, JOURNAL_XP_POINTS } from "@/lib/journals/xp";
@ -251,12 +252,7 @@ export function JournalFormDialog({
placeholder="Write your entry here..."
/>
{bodyLength >= JOURNAL_XP_MIN_CHARS && (
<p className="flex items-center gap-1.5 text-xs text-amber-400">
<SparklesIcon className="journal-xp-hint-icon size-3.5 shrink-0" />
<span className="journal-xp-hint-text">
{`Nice - you'll earn ${JOURNAL_XP_POINTS} XP from this journal entry!`}
</span>
</p>
<XpHint points={JOURNAL_XP_POINTS} context="from this journal entry" />
)}
</div>
</div>