8bitcn UI
blockplayer-profile-cardsource: ok · refreshed
8-bit Player Profile Card
A comprehensive player profile card component with stats, health/mana bars, and custom stats support.
npx shadcn add "https://www.8bitcn.com/r/player-profile-card.json"free
Where it goes
statsprofile
Interaction
animated-counter
Tags auto-generated by rules on 9/24/2026 — empty means no evidence, not lack of support.
Dependencies
Bundle weight · lightRegistry dependencies
avatarbadgecardprogress
Files8 · source cached 10/8/2026, 2:51:38 AM
components/ui/8bit/blocks/player-profile-card.tsx
import React from "react";
import { cn } from "@/lib/utils";
import {
Avatar,
AvatarFallback,
AvatarImage,
} from "@/components/ui/8bit/avatar";
import { Badge } from "@/components/ui/8bit/badge";
import { Card, CardContent, CardHeader } from "@/components/ui/8bit/card";
import HealthBar from "@/components/ui/8bit/health-bar";
import ManaBar from "@/components/ui/8bit/mana-bar";
import { Progress } from "@/components/ui/8bit/progress";
import "@/components/ui/8bit/styles/retro.css";
export interface PlayerStats {
health?: {
current: number;
max: number;
};
mana?: {
current: number;
max: number;
};
experience?: {
current: number;
max: number;
};
level?: number;
[key: string]: unknown; // Allow custom stats
}
export interface PlayerProfileCardProps {
className?: string;
playerName: string;
avatarSrc?: string;
avatarFallback?: string;
level?: number;
stats?: PlayerStats;
playerClass?: string;
showLevel?: boolean;
showHealth?: boolean;
showMana?: boolean;
showExperience?: boolean;
customStats?: Array<{
label: string;
value: number;
max?: number;
color?: string;
variant?: "retro" | "default";
}>;
}
export default function PlayerProfileCard({
className,
playerName,
avatarSrc,
avatarFallback,
level = 1,
stats,
playerClass,
showLevel = true,
showHealth = true,
showMana = true,
showExperience = true,
customStats = [],
...props
}: PlayerProfileCardProps) {
const healthPercentage = stats?.health
? Math.round((stats.health.current / stats.health.max) * 100)
: 0;
const manaPercentage = stats?.mana
? Math.round((stats.mana.current / stats.mana.max) * 100)
: 0;
const experiencePercentage = stats?.experience
? Math.round((stats.experience.current / stats.experience.max) * 100)
: 0;
return (
<Card className={cn("w-full max-w-md", className)} {...props}>
<CardHeader className="pb-4">
<div className="flex items-center gap-4">
<Avatar className="size-16" variant="pixel" font="retro">
<AvatarImage src={avatarSrc} alt={playerName} />
<AvatarFallback className="text-lg">
{avatarFallback || playerName.charAt(0).toUpperCase()}
</AvatarFallback>
</Avatar>
<div className="flex-1 min-w-0">
<div className="space-y-2">
<div className="flex flex-col gap-1 md:flex-row md:items-center md:gap-2 justify-between">
<h3 className="font-bold truncate">{playerName}</h3>
{showLevel && (
<span>
<Badge className="text-[9px]">Lv.{level}</Badge>
</span>
)}
</div>
<div className="flex flex-wrap gap-1">
{playerClass && (
<span className="text-xs text-muted-foreground">
{playerClass}
</span>
)}
</div>
</div>
</div>
</div>
</CardHeader>
<CardContent className="space-y-4">
{/* Health Bar */}
{showHealth && stats?.health && (
<div className="space-y-1">
<div className="flex justify-between items-center">
<span className="text-sm font-medium">Health</span>
<span className="text-[9px] sm:text-xs text-muted-foreground retro">
{stats.health.current}/{stats.health.max}
</span>
</div>
<HealthBar
value={healthPercentage}
variant="retro"
className="h-3"
/>
</div>
)}
{/* Mana Bar */}
{showMana && stats?.mana && (
<div className="space-y-1">
<div className="flex justify-between items-center">
<span className="text-sm font-medium">Mana</span>
<span className="text-[9px] sm:text-xs text-muted-foreground retro">
{stats.mana.current}/{stats.mana.max}
</span>
</div>
<ManaBar value={manaPercentage} variant="retro" className="h-3" />
</div>
)}
{/* Experience Bar */}
{showExperience && stats?.experience && (
<div className="space-y-1">
<div className="flex justify-between items-center">
<span className="text-sm font-medium">Experience</span>
<span className="text-[9px] sm:text-xs text-muted-foreground retro">
{stats.experience.current}/{stats.experience.max} XP
</span>
</div>
<Progress
value={experiencePercentage}
variant="retro"
progressBg="bg-yellow-500"
className="h-3"
/>
</div>
)}
{/* Custom Stats */}
{customStats.length > 0 && (
<div className="space-y-2">
{customStats.map((stat, index) => {
const percentage = stat.max
? Math.round((stat.value / stat.max) * 100)
: 0;
return (
<div key={index} className="space-y-1">
<div className="flex justify-between items-center">
<span className="text-sm font-medium">{stat.label}</span>
<span className="text-[9px] sm:text-xs text-muted-foreground retro">
{stat.value}
{stat.max ? `/${stat.max}` : ""}
</span>
</div>
<Progress
value={percentage}
variant={stat.variant || "retro"}
progressBg={stat.color || "bg-primary"}
className="h-3"
/>
</div>
);
})}
</div>
)}
</CardContent>
</Card>
);
}
components/ui/8bit/card.tsx
import { type VariantProps, cva } from "class-variance-authority";
import { cn } from "@/lib/utils";
import {
Card as ShadcnCard,
CardAction as ShadcnCardAction,
CardContent as ShadcnCardContent,
CardDescription as ShadcnCardDescription,
CardFooter as ShadcnCardFooter,
CardHeader as ShadcnCardHeader,
CardTitle as ShadcnCardTitle,
} from "@/components/ui/card";
import "@/components/ui/8bit/styles/retro.css";
export const cardVariants = cva("", {
variants: {
font: {
normal: "",
retro: "retro",
},
},
defaultVariants: {
font: "retro",
},
});
export interface BitCardProps
extends React.ComponentProps<"div">,
VariantProps<typeof cardVariants> {
asChild?: boolean;
}
function Card({ className, font, ...props }: BitCardProps) {
return (
<div
className={cn(
"relative bg-card text-card-foreground border-y-6 border-foreground dark:border-ring p-0!",
className
)}
>
<ShadcnCard
{...props}
className={cn(
"rounded-none border-0 w-full! h-full flex flex-col bg-card text-card-foreground shadow-none",
font !== "normal" && "retro",
className
)}
/>
<div
className={cn("absolute inset-0 border-x-6 -mx-1.5 border-inherit pointer-events-none")}
aria-hidden="true"
/>
</div>
);
}
function CardHeader({ ...props }: BitCardProps) {
const { className, font } = props;
return (
<ShadcnCardHeader
className={cn(font !== "normal" && "retro", className)}
{...props}
/>
);
}
function CardTitle({ ...props }: BitCardProps) {
const { className, font } = props;
return (
<ShadcnCardTitle
className={cn(font !== "normal" && "retro", className)}
{...props}
/>
);
}
function CardDescription({ ...props }: BitCardProps) {
const { className, font } = props;
return (
<ShadcnCardDescription
className={cn(font !== "normal" && "retro", className)}
{...props}
/>
);
}
function CardAction({ ...props }: BitCardProps) {
const { className, font } = props;
return (
<ShadcnCardAction
className={cn(font !== "normal" && "retro", className)}
{...props}
/>
);
}
function CardContent({ ...props }: BitCardProps) {
const { className, font } = props;
return (
<ShadcnCardContent
className={cn("flex-1", font !== "normal" && "retro", className)}
{...props}
/>
);
}
function CardFooter({ ...props }: BitCardProps) {
const { className, font } = props;
return (
<ShadcnCardFooter
data-slot="card-footer"
className={cn(font !== "normal" && "retro", className)}
{...props}
/>
);
}
export {
Card,
CardHeader,
CardFooter,
CardTitle,
CardAction,
CardDescription,
CardContent,
};
components/ui/8bit/avatar.tsx
import type React from "react";
import { forwardRef } from "react";
import * as AvatarPrimitive from "@radix-ui/react-avatar";
import { cva } from "class-variance-authority";
import { cn } from "@/lib/utils";
import "@/components/ui/8bit/styles/retro.css";
export const avatarVariants = cva("", {
variants: {
font: {
normal: "",
retro: "retro",
},
variant: {
default: "",
retro: "",
pixel: "",
},
},
defaultVariants: {
font: "retro",
variant: "pixel",
},
});
const Avatar = forwardRef<
React.ComponentRef<typeof AvatarPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Root> & {
font?: "normal" | "retro";
variant?: "default" | "retro" | "pixel";
}
>(({ className = "", font, variant = "pixel", ...props }, ref) => {
const isPixel = variant === "pixel";
return (
<div className={cn("relative size-max", className)}>
{/* Pixel frame (only show if pixel variant) */}
{isPixel && (
<div
className="absolute inset-0 w-full h-full pointer-events-none"
style={{ zIndex: 10 }}
>
{/* Top section - Row 1 */}
<div className="absolute top-0 left-[23%] right-[23%] h-[7%] bg-foreground dark:bg-ring"></div>
{/* Top section - Row 2 */}
<div className="absolute top-[6.25%] left-[17%] right-[17%] h-[7%] bg-foreground dark:bg-ring"></div>
{/* Top section - Row 3 */}
<div className="absolute top-[12.5%] left-[11%] h-[7%] bg-foreground dark:bg-ring w-[20%]"></div>
<div className="absolute top-[12.5%] right-[11%] h-[7%] bg-foreground dark:bg-ring w-[20%]"></div>
{/* Top section - Row 4 */}
<div className="absolute top-[18.75%] left-[5%] w-[20%] h-[7%] bg-foreground dark:bg-ring"></div>
<div className="absolute top-[18.75%] right-[5%] w-[20%] h-[7%] bg-foreground dark:bg-ring"></div>
{/* Top section - Row 5 */}
<div className="absolute top-[25%] left-0 w-[20%] h-[7%] bg-foreground dark:bg-ring"></div>
<div className="absolute top-[25%] right-0 w-[20%] h-[7%] bg-foreground dark:bg-ring"></div>
{/* Top section - Rows 6-7 */}
<div className="absolute top-[31.25%] left-0 w-[13.5%] h-[13%] bg-foreground dark:bg-ring"></div>
<div className="absolute top-[31.25%] right-0 w-[13.5%] h-[13%] bg-foreground dark:bg-ring"></div>
{/* Top section - Rows 8-10 */}
<div className="absolute top-[43.75%] left-0 w-[13.5%] h-[7%] bg-foreground dark:bg-ring"></div>
<div className="absolute top-[43.75%] right-0 w-[13.5%] h-[7%] bg-foreground dark:bg-ring"></div>
{/* Bottom section - Rows 8-10 (mirror) */}
<div className="absolute top-[50%] left-0 w-[13.5%] h-[7%] bg-foreground dark:bg-ring"></div>
<div className="absolute top-[50%] right-0 w-[13.5%] h-[7%] bg-foreground dark:bg-ring"></div>
{/* Bottom section - Rows 6-7 (mirror) */}
<div className="absolute top-[56.25%] left-0 w-[13.5%] h-[13%] bg-foreground dark:bg-ring"></div>
<div className="absolute top-[56.25%] right-0 w-[13.5%] h-[13%] bg-foreground dark:bg-ring"></div>
{/* Bottom section - Row 5 (mirror) */}
<div className="absolute top-[68.75%] left-0 w-[20%] h-[7%] bg-foreground dark:bg-ring"></div>
<div className="absolute top-[68.75%] right-0 w-[20%] h-[7%] bg-foreground dark:bg-ring"></div>
{/* Bottom section - Row 4 (mirror) */}
<div className="absolute top-[75%] left-[5%] w-[20%] h-[7%] bg-foreground dark:bg-ring"></div>
<div className="absolute top-[75%] right-[5%] w-[20%] h-[7%] bg-foreground dark:bg-ring"></div>
{/* Bottom section - Row 3 (mirror) */}
<div className="absolute top-[81.25%] left-[11%] h-[7%] bg-foreground dark:bg-ring w-[20%]"></div>
<div className="absolute top-[81.25%] right-[11%] h-[7%] bg-foreground dark:bg-ring w-[20%]"></div>
{/* Bottom section - Row 2 (mirror) */}
<div className="absolute top-[87.5%] left-[17%] right-[17%] h-[7%] bg-foreground dark:bg-ring"></div>
{/* Bottom section - Row 1 (mirror) */}
<div className="absolute bottom-0 left-[23%] right-[23%] h-[7%] bg-foreground dark:bg-ring"></div>
</div>
)}
<AvatarPrimitive.Root
ref={ref}
data-slot="avatar"
className={cn(
"relative flex size-10 shrink-0 overflow-hidden text-xs",
!isPixel && "rounded-none",
isPixel && "rounded-full",
font !== "normal" && "retro",
variant === "retro" && "image-rendering-pixelated",
className
)}
{...props}
/>
{/* Original border styling (only show if not pixel variant) */}
{!isPixel && (
<>
<div className="absolute top-0 left-0 w-full h-1.5 bg-foreground dark:bg-ring pointer-events-none" />
<div className="absolute bottom-0 w-full h-1.5 bg-foreground dark:bg-ring pointer-events-none" />
<div className="absolute top-1.5 -left-1.5 w-1.5 h-1/2 bg-foreground dark:bg-ring pointer-events-none" />
<div className="absolute bottom-1.5 -left-1.5 w-1.5 h-1/2 bg-foreground dark:bg-ring pointer-events-none" />
<div className="absolute top-1.5 -right-1.5 w-1.5 h-1/2 bg-foreground dark:bg-ring pointer-events-none" />
<div className="absolute bottom-1.5 -right-1.5 w-1.5 h-1/2 bg-foreground dark:bg-ring pointer-events-none" />
</>
)}
</div>
);
});
Avatar.displayName = AvatarPrimitive.Root.displayName;
interface BitAvatarImageProps
extends React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Image> {
font?: "normal" | "retro";
variant?: "default" | "retro" | "pixel";
}
const AvatarImage = forwardRef<
React.ComponentRef<typeof AvatarPrimitive.Image>,
BitAvatarImageProps
>(({ className, font, ...props }, ref) => {
return (
<AvatarPrimitive.Image
ref={ref}
data-slot="avatar-image"
className={cn(
"aspect-square h-full w-full",
font === "retro" && "retro",
className
)}
{...props}
/>
);
});
AvatarImage.displayName = AvatarPrimitive.Image.displayName;
const AvatarFallback = forwardRef<
React.ComponentRef<typeof AvatarPrimitive.Fallback>,
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Fallback>
>(({ className, ...props }, ref) => (
<AvatarPrimitive.Fallback
ref={ref}
data-slot="avatar-fallback"
className={cn(
"flex h-full w-full items-center justify-center rounded-full bg-muted text-foreground",
className
)}
{...props}
/>
));
AvatarFallback.displayName = AvatarPrimitive.Fallback.displayName;
export { Avatar, AvatarImage, AvatarFallback };
components/ui/8bit/badge.tsx
import { type VariantProps, cva } from "class-variance-authority";
import { cn } from "@/lib/utils";
import { Badge as ShadcnBadge } from "@/components/ui/badge";
export const badgeVariants = cva("", {
variants: {
font: {
normal: "",
retro: "retro",
},
variant: {
default: "border-primary bg-primary",
destructive: "border-destructive bg-destructive",
outline: "border-background bg-background",
secondary: "border-secondary bg-secondary",
},
},
defaultVariants: {
variant: "default",
},
});
export interface BitButtonProps
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
VariantProps<typeof badgeVariants> {
asChild?: boolean;
}
function Badge({
children,
className = "",
font,
variant,
...props
}: BitButtonProps) {
const color = badgeVariants({ variant, font });
const classes = className.split(" ");
// visual classes for badge and sidebars
const visualClasses = classes.filter(
(c) =>
c.startsWith("bg-") ||
c.startsWith("border-") ||
c.startsWith("text-") ||
c.startsWith("rounded-")
);
// Container should accept all non-visual utility classes (e.g., size, spacing, layout)
const containerClasses = classes.filter(
(c) =>
!(
c.startsWith("bg-") ||
c.startsWith("border-") ||
c.startsWith("text-") ||
c.startsWith("rounded-")
)
);
return (
<div className={cn("relative inline-flex items-stretch", containerClasses)}>
<ShadcnBadge
{...props}
className={cn(
"h-full",
"rounded-none",
"w-full",
font !== "normal" && "retro",
visualClasses
)}
variant={variant}
>
{children}
</ShadcnBadge>
{/* Left pixel bar */}
<div
className={cn(
"-left-1.5 absolute inset-y-[4px] w-1.5",
color,
visualClasses
)}
/>
{/* Right pixel bar */}
<div
className={cn(
"-right-1.5 absolute inset-y-[4px] w-1.5",
color,
visualClasses
)}
/>
</div>
);
}
export { Badge };
components/ui/8bit/health-bar.tsx
import { type BitProgressProps, Progress } from "@/components/ui/8bit/progress";
interface ManaBarProps extends React.ComponentProps<"div"> {
className?: string;
props?: BitProgressProps;
variant?: "retro" | "default";
value?: number;
}
export default function HealthBar({
className,
variant,
value,
...props
}: ManaBarProps) {
return (
<Progress
{...props}
value={value}
variant={variant}
className={className}
progressBg="bg-red-500"
/>
);
}
components/ui/8bit/mana-bar.tsx
import { type BitProgressProps, Progress } from "@/components/ui/8bit/progress";
interface ManaBarProps extends React.ComponentProps<"div"> {
className?: string;
props?: BitProgressProps;
variant?: "retro" | "default";
value?: number;
}
export default function ManaBar({
className,
variant,
value,
...props
}: ManaBarProps) {
return (
<Progress
{...props}
value={value}
variant={variant}
className={className}
progressBg="bg-blue-500"
/>
);
}
components/ui/8bit/progress.tsx
import * as ProgressPrimitive from "@radix-ui/react-progress";
import { type VariantProps, cva } from "class-variance-authority";
import { cn } from "@/lib/utils";
import "@/components/ui/8bit/styles/retro.css";
export const progressVariants = cva("", {
variants: {
variant: {
default: "",
retro: "retro",
},
font: {
normal: "",
retro: "retro",
},
},
defaultVariants: {
font: "retro",
},
});
export interface BitProgressProps
extends React.ComponentProps<typeof ProgressPrimitive.Root>,
VariantProps<typeof progressVariants> {
className?: string;
font?: VariantProps<typeof progressVariants>["font"];
progressBg?: string;
}
function Progress({
className,
font,
variant,
value,
progressBg,
...props
}: BitProgressProps) {
// Extract height from className if present
const heightMatch = className?.match(/h-(\d+|\[.*?\])/);
const heightClass = heightMatch ? heightMatch[0] : "h-2";
return (
<div className={cn("relative w-full", className)}>
<ProgressPrimitive.Root
data-slot="progress"
className={cn(
"bg-primary/20 relative w-full overflow-hidden",
heightClass,
font !== "normal" && "retro"
)}
value={value}
{...props}
>
<ProgressPrimitive.Indicator
data-slot="progress-indicator"
className={cn(
"h-full transition-all",
variant === "retro" ? "flex w-full" : "w-full flex-1",
variant !== "retro" && (progressBg || "bg-primary")
)}
style={
variant === "retro"
? undefined
: { transform: `translateX(-${100 - (value || 0)}%)` }
}
>
{variant === "retro" && (
<div className="flex w-full">
{Array.from({ length: 20 }).map((_, i) => {
const filledSquares = Math.round(((value || 0) / 100) * 20);
return (
<div
key={i}
className={cn(
"flex-1 h-full mx-[1px]",
i < filledSquares
? progressBg || "bg-primary"
: "bg-transparent"
)}
/>
);
})}
</div>
)}
</ProgressPrimitive.Indicator>
</ProgressPrimitive.Root>
<div
className="absolute inset-0 border-y-4 -my-1 border-foreground dark:border-ring pointer-events-none"
aria-hidden="true"
/>
<div
className="absolute inset-0 border-x-4 -mx-1 border-foreground dark:border-ring pointer-events-none"
aria-hidden="true"
/>
</div>
);
}
export { Progress };
components/ui/8bit/styles/retro.css
@import url("https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap");
.retro {
font-family:
"Press Start 2P",
system-ui,
-apple-system,
sans-serif;
line-height: 1.5;
letter-spacing: 0.5px;
}
.pixelated {
image-rendering: pixelated;
image-rendering: crisp-edges;
}