feat(contributions): fade the XP hint out and polish the amount
This commit is contained in:
parent
e96fdb7f58
commit
75817ed3fe
3 changed files with 90 additions and 46 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 (
|
||||
<p
|
||||
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,
|
||||
)}
|
||||
>
|
||||
<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}` : ""}!`}
|
||||
{`Nice - you'll earn `}
|
||||
<strong className="xp-hint-amount font-semibold">{`${points} XP`}</strong>
|
||||
{context ? ` ${context}!` : "!"}
|
||||
</span>
|
||||
</p>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -251,9 +251,11 @@ export function JournalFormDialog({
|
|||
onChange={setBody}
|
||||
placeholder="Write your entry here..."
|
||||
/>
|
||||
{bodyLength >= JOURNAL_XP_MIN_CHARS && (
|
||||
<XpHint points={JOURNAL_XP_POINTS} context="from this journal entry" />
|
||||
)}
|
||||
<XpHint
|
||||
visible={bodyLength >= JOURNAL_XP_MIN_CHARS}
|
||||
points={JOURNAL_XP_POINTS}
|
||||
context="from this journal entry"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue