Game UI

Special

Gaming UI components including health bars, inventory, achievements, and damage numbers.

Import

import { 
  PixelHealthBar, 
  PixelManaBar, 
  PixelXPBar,
  PixelInventory,
  PixelInventorySlot,
  PixelAchievement,
  PixelDamageNumber
} from "@/components/ui/pixel/pixel-game-ui"

Usage

🧙

Wizard

Level 12

HP
85/100
MP
60/100
XP
350/500

Inventory

⚔️
🛡️
💊5
🔮
👑
🏆

First Victory

+50

Complete your first quest

50
25
100!

Component Source

Copy and paste the following code into your project at /src/components/ui/pixel/pixel-game-ui.tsx

"use client";

import { cva, type VariantProps } from "class-variance-authority";
import * as React from "react";
import { cn } from "@/lib/utils";

// ========================================
// HEALTH BAR COMPONENT
// ========================================

const pixelHealthBarVariants = cva(
  "relative border-4 border-black shadow-[4px_4px_0px_0px_rgba(0,0,0,1)]",
  {
    variants: {
      variant: {
        default: "bg-white dark:bg-[#2a2a2a]",
        outlined: "bg-transparent",
      },
      size: {
        sm: "h-6",
        md: "h-8",
        lg: "h-12",
      },
    },
    defaultVariants: {
      variant: "default",
      size: "md",
    },
  },
);

export interface PixelHealthBarProps
  extends React.HTMLAttributes<HTMLDivElement>,
    VariantProps<typeof pixelHealthBarVariants> {
  current: number;
  max: number;
  showLabel?: boolean;
  label?: string;
  color?: string;
}

const PixelHealthBar = React.forwardRef<HTMLDivElement, PixelHealthBarProps>(
  (
    {
      className,
      variant,
      size,
      current,
      max,
      showLabel = true,

// ... (more code below)

Props

PropTypeDefaultDescription
currentnumber-Current health/mana value
maxnumber-Maximum health/mana value
currentXPnumber-Current experience points
requiredXPnumber-XP required for next level
levelnumber-Character level
columns3 | 4 | 5 | 65Inventory grid columns
rarity"common" | "rare" | "epic" | "legendary"-Item rarity
variant"bronze" | "silver" | "gold" | "platinum"-Achievement tier

Examples

Health Bar

HP bar with auto-coloring

🧙

Wizard

Level 12

HP
85/100
MP
60/100
XP
350/500

Inventory

⚔️
🛡️
💊5
🔮
👑
🏆

First Victory

+50

Complete your first quest

50
25
100!

XP Bar

Experience bar with level

🧙

Wizard

Level 12

HP
85/100
MP
60/100
XP
350/500

Inventory

⚔️
🛡️
💊5
🔮
👑
🏆

First Victory

+50

Complete your first quest

50
25
100!

Inventory

Grid-based inventory system

🧙

Wizard

Level 12

HP
85/100
MP
60/100
XP
350/500

Inventory

⚔️
🛡️
💊5
🔮
👑
🏆

First Victory

+50

Complete your first quest

50
25
100!

Achievement

Trophy notification

🧙

Wizard

Level 12

HP
85/100
MP
60/100
XP
350/500

Inventory

⚔️
🛡️
💊5
🔮
👑
🏆

First Victory

+50

Complete your first quest

50
25
100!

Accessibility

This component is built with accessibility in mind, including proper ARIA attributes, keyboard navigation, and focus management.