feat(contributions): add a reusable XP hint with a glint animation
This commit is contained in:
parent
076de5d60c
commit
f481efb108
3 changed files with 94 additions and 21 deletions
|
|
@ -312,21 +312,27 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Journal "this will earn XP" hint: the sparkles pop in, then the copy wipes in
|
/* "This will earn XP" hint: the sparkles pop in, the copy wipes in from the
|
||||||
from the left half a beat later. The motion is skipped when the user asks for
|
left half a beat later, and a gold glint sweeps from the sparkles across the
|
||||||
reduced motion; the hint itself still shows, just without animating. */
|
text. The motion is skipped when the user asks for reduced motion; the hint
|
||||||
@keyframes journal-xp-icon-in {
|
itself still shows, just without animating. Reused wherever a surface grants
|
||||||
from {
|
contribution XP (see components/frontend/contributions/XpHint.tsx). */
|
||||||
|
@keyframes xp-hint-icon-in {
|
||||||
|
0% {
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
transform: scale(0.7);
|
transform: scale(0.4);
|
||||||
}
|
}
|
||||||
to {
|
60% {
|
||||||
|
opacity: 1;
|
||||||
|
transform: scale(1.15);
|
||||||
|
}
|
||||||
|
100% {
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
transform: scale(1);
|
transform: scale(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes journal-xp-text-in {
|
@keyframes xp-hint-text-in {
|
||||||
from {
|
from {
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
clip-path: inset(0 100% 0 0);
|
clip-path: inset(0 100% 0 0);
|
||||||
|
|
@ -340,21 +346,56 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.journal-xp-hint-icon {
|
@keyframes xp-hint-glint {
|
||||||
animation: journal-xp-icon-in 0.35s ease-out both;
|
0% {
|
||||||
|
opacity: 0;
|
||||||
|
transform: translateX(-100%);
|
||||||
|
}
|
||||||
|
15% {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
85% {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
opacity: 0;
|
||||||
|
transform: translateX(100%);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.journal-xp-hint-text {
|
.xp-hint-icon {
|
||||||
animation: journal-xp-text-in 0.45s ease-out 0.5s both;
|
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) {
|
@media (prefers-reduced-motion: reduce) {
|
||||||
.journal-xp-hint-icon,
|
.xp-hint-icon,
|
||||||
.journal-xp-hint-text {
|
.xp-hint-text {
|
||||||
animation: none;
|
animation: none;
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
clip-path: none;
|
clip-path: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.xp-hint-glint {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.locker-search-highlight {
|
.locker-search-highlight {
|
||||||
|
|
|
||||||
36
src/components/frontend/contributions/XpHint.tsx
Normal file
36
src/components/frontend/contributions/XpHint.tsx
Normal 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>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { Loader2Icon, SparklesIcon } from "lucide-react";
|
import { Loader2Icon } from "lucide-react";
|
||||||
|
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import {
|
import {
|
||||||
|
|
@ -28,6 +28,7 @@ import {
|
||||||
type LexicalJson,
|
type LexicalJson,
|
||||||
} from "@/components/frontend/intelligence/LexicalRichTextEditor";
|
} from "@/components/frontend/intelligence/LexicalRichTextEditor";
|
||||||
import { createJournal, updateJournal } from "@/app/(frontend)/journals/actions";
|
import { createJournal, updateJournal } from "@/app/(frontend)/journals/actions";
|
||||||
|
import { XpHint } from "@/components/frontend/contributions/XpHint";
|
||||||
import { journalBodyLength } from "@/lib/journals/excerpt";
|
import { journalBodyLength } from "@/lib/journals/excerpt";
|
||||||
import { JOURNAL_XP_MIN_CHARS, JOURNAL_XP_POINTS } from "@/lib/journals/xp";
|
import { JOURNAL_XP_MIN_CHARS, JOURNAL_XP_POINTS } from "@/lib/journals/xp";
|
||||||
|
|
||||||
|
|
@ -251,12 +252,7 @@ export function JournalFormDialog({
|
||||||
placeholder="Write your entry here..."
|
placeholder="Write your entry here..."
|
||||||
/>
|
/>
|
||||||
{bodyLength >= JOURNAL_XP_MIN_CHARS && (
|
{bodyLength >= JOURNAL_XP_MIN_CHARS && (
|
||||||
<p className="flex items-center gap-1.5 text-xs text-amber-400">
|
<XpHint points={JOURNAL_XP_POINTS} context="from this journal entry" />
|
||||||
<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>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue