Components / Interface
Achievement Tracker
A counter that opens a list of hidden achievements with hints, a progress bar and a reward slot. Comes with a localStorage hook.
Installation
npx shadcn@latest add https://jiaweing.com/r/achievement-tracker.jsonWith the @jiaweing namespace set up, use @jiaweing/achievement-tracker in place of the URL.
Usage
tsx
import {
AchievementTracker,
useAchievements,
} from "@/components/achievement-tracker";tsx
const { found, unlock } = useAchievements("my-site-eggs");
<AchievementTracker
achievements={[
{ id: "konami", name: "Old school", hint: "Up, up, down, down..." },
{ id: "night", name: "Night owl", hint: "Visit after midnight" },
]}
found={found}
note="Find them all for a surprise."
/>Props
AchievementTracker
| Prop | Type | Default | Description |
|---|---|---|---|
| achievements | Achievement[] | - | { id, name, hint, description?, group? }. Rows with a group sit under one heading. |
| found | string[] | - | Ids found so far. |
| title | string | "Achievements" | Heading in the panel. |
| note | ReactNode | - | Under the progress bar until all are found. |
| reward | ReactNode | - | Replaces the note once all are found. |
| icon | ReactNode | - | Trigger icon. A trophy replaces it at the end. |
| lockedLabel | string | "Hidden" | Name shown on locked rows. |
| align | "start" | "center" | "end" | "end" | Panel alignment to the trigger. |
useAchievements(storageKey)
| Prop | Type | Default | Description |
|---|---|---|---|
| found | string[] | - | Ids in localStorage, kept in step across tabs. |
| unlock(id) | (id: string) => boolean | - | Marks one found. True the first time only. |
| reset() | () => void | - | Clears them all. |
MIT licensed. Copy it, change it, ship it.