Points Badge
trophy/points-badgeFreeComponent
Compact React points badge for totals and currency-style scores in gamification UIs. Fits XP-style displays alongside charts and lists. Built on shadcn/ui + Tailwind. Open source.
Live preview
live · rendered by the registry
Rendered by trophy on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://ui.trophy.so/r/points-badge.jsonSource
1"use client"23import * as React from "react"4import { cva, type VariantProps } from "class-variance-authority"5import { Sparkle } from "lucide-react"67import { cn } from "@/lib/utils"89const pointsBadgeVariants = cva(10 "flex items-center gap-3 rounded-lg transition-colors",11 {12 variants: {13 size: {14 sm: "text-sm gap-2",15 default: "",16 lg: "text-lg gap-4",17 },18 },19 defaultVariants: {20 size: "default",21 },22 }23)2425interface PointsBadgeProps26 extends27 React.HTMLAttributes<HTMLDivElement>,28 VariantProps<typeof pointsBadgeVariants> {29 name: string30 total: number31 /** When omitted or `null`, the default icon is shown instead of an image. */32 badgeUrl?: string | null33 icon?: React.ComponentType<{ className?: string }>34 formatValue?: (value: number) => string35}3637const PointsBadge = React.forwardRef<HTMLDivElement, PointsBadgeProps>(38 (39 {40 className,41 size,42 name,43 badgeUrl,44 total,45 icon: CustomIcon,46 formatValue,47 ...props48 },49 ref50 ) => {51 const Icon = CustomIcon ?? Sparkle52 const displayValue = formatValue53 ? formatValue(total)54 : total.toLocaleString()5556 const iconSize = {57 sm: "h-4 w-4",58 default: "h-5 w-5",59 lg: "h-6 w-6",60 }[size ?? "default"]6162 const badgeSize = {63 sm: "h-6 w-6",64 default: "h-8 w-8",65 lg: "h-10 w-10",66 }[size ?? "default"]67 const statusLabel = `${displayValue} ${name}`6869 return (70 <div71 ref={ref}72 role="status"73 aria-label={statusLabel}74 className={cn(75 pointsBadgeVariants({ size }),76 "bg-card border p-4",77 className78 )}79 {...props}80 >81 <div className="flex items-center gap-2">82 {badgeUrl ? (83 <div>84 <img85 src={badgeUrl}86 alt=""87 aria-hidden="true"88 className={cn("shrink-0 rounded object-contain", badgeSize)}89 />90 </div>91 ) : (92 <div93 aria-hidden="true"94 className={cn(95 "bg-primary/10 flex shrink-0 items-center justify-center rounded-full",96 badgeSize97 )}98 >99 <Icon className={cn(iconSize, "text-primary")} />100 </div>101 )}102103 <div>104 <span105 className={cn(106 "font-bold tabular-nums",107// … truncated
What it pulls in
npm packages
Files it writes
More from trophy
All 18 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Achievement Badgeachievement-badge | trophy | Components | Free | 1 dep | |
| Achievement Cardachievement-card | trophy | Components | Free | no deps | |
| Achievement Gridachievement-grid | trophy | Components | Free | 2 deps | |
| Achievement Listachievement-list | trophy | Components | Free | 2 deps | |
| Achievement Unlockedachievement-unlocked | trophy | Components | Free | 1 dep | |
| Leaderboard Cardleaderboard-card | trophy | Components | Free | no deps | |
| Leaderboard Podiumleaderboard-podium | trophy | Components | Free | 2 deps | |
| Leaderboard Rankingsleaderboard-rankings | trophy | Components | Free | 2 deps |
