UIPin
ComponentsIconsIllustrationsMotionTemplatesApps
Boards
UIPin

Free, open-source UI components, icons, illustrations, motion, templates and apps, in one search. Every item links to its source and licence.

UIPin is free. If it saved you time, you can keep it running:

Buy me a coffee
ComponentsIconsIllustrationsMotionTemplatesAppsLibrariesCompareNew this weekMCP for agentsBoardsPrivacy

Components, icons and artwork belong to their authors and are shown under their open-source licences.

8bitcn/8-bit Enemy Health Display

Feedback & loaders
Compiling

Theme it

Every preview, live

Brand colour

Corner radius

Font

Recolours shadcn’s tokens, Tailwind’s accent colours and colours set in the code. Red, amber and green classes stay, since they usually mean error, warning or success.

8-bit Enemy Health Display

A retro-styled enemy health display component with health bar, name, and level

npx shadcn@latest add https://www.8bitcn.com/r/enemy-health-display.json
Open in v0 Docs Repo
Library
8bitcn
License
MIT
Stack
React · Tailwind CSS
Size
261 lines

Code

components/ui/8bit/enemy-health-display.tsx

import { type VariantProps, cva } from "class-variance-authority";

import { cn } from "@/lib/utils";

import HealthBar from "@/components/ui/8bit/health-bar";

import "@/components/ui/8bit/styles/retro.css";

export const enemyHealthDisplayVariants = cva("", {
  variants: {
    variant: {
      default: "",
      retro: "retro",
    },
    size: {
      sm: "text-xs",
      md: "text-sm",
      lg: "text-base",
    },
    textColor: {
      red: "text-red-500",
      orange: "text-orange-500",
      yellow: "text-yellow-500",
      green: "text-green-500",
      blue: "text-blue-500",
      purple: "text-purple-500",
    },
  },
  defaultVariants: {
    variant: "retro",
    size: "md",
    textColor: "red",
  },
});

export interface EnemyHealthDisplayProps
  extends React.ComponentProps<"div">,
    VariantProps<typeof enemyHealthDisplayVariants> {
  enemyName: string;
  level?: number;
  currentHealth: number;
  maxHealth: number;
  showLevel?: boolean;
  showHealthText?: boolean;
  healthBarVariant?: "retro" | "default";
  healthBarColor?: string;
  enemyNameColor?: string;
}

export default function EnemyHealthDisplay({
  className,
  variant,
  size,
  textColor,
  enemyName,
  level,
  currentHealth,
  maxHealth,
  showLevel = true,
  showHealthText = true,
  healthBarVariant = "retro",
  healthBarColor = "bg-red-500",
  enemyNameColor = "text-foreground",
  ...props
}: EnemyHealthDisplayProps) {
  const healthPercentage = Math.max(
    0,
    Math.min(100, (currentHealth / maxHealth) * 100)
  );
  const healthText = `${currentHealth}/${maxHealth}`;

  return (
    <div
      className={cn(
        "relative w-full space-y-2",
        enemyHealthDisplayVariants({ variant, size, textColor }),
        className
      )}
      {...props}
    >
      {/* Enemy Name and Level */}
      <div className="flex items-center justify-between">
        <div className="flex items-center gap-2">
          <span className={cn("font-bold", enemyNameColor)}>{enemyName}</span>
          {showLevel && level && (
            <span className="text-muted-foreground">Lv.{level}</span>
          )}
        </div>
        {showHealthText && (
          <span className="text-muted-foreground text-[9px]">{healthText}</span>
        )}
      </div>

      {/* Health Bar Container */}
      <div className="relative">
        <HealthBar
          value={healthPercentage}
          variant={healthBarVariant}
          className="w-full"
          props={{ progressBg: healthBarColor }}
        />

        {/* Health percentage overlay for retro variant */}
        {healthBarVariant === "retro" && (
          <div className="absolute inset-0 flex items-center justify-center">
            <span className="text-xs font-bold text-white drop-shadow-lg bg-black/50 px-1">
              {Math.round(healthPercentage)}%
            </span>
          </div>
        )}
      </div>
    </div>
  );
}

More like this

8-bit Health Bar

8bitcn·Feedback & loaders

8-bit Mana Bar

8bitcn·Feedback & loaders

8-bit Progress

8bitcn·Feedback & loaders

8-bit Slider

8bitcn·Inputs & forms

8-bit Textarea

8bitcn·Text effects

8-bit XP Bar

8bitcn·Feedback & loaders

Progress

shadcn/ui·Feedback & loaders

Slider

shadcn/ui·Inputs & forms

Input Otp

shadcn/ui·Inputs & forms

Card Nav

React Bits·NavigationMIT+

Carousel

HextaUI·Media & 3D

Grid Pattern

Magic UI·Backgrounds

Drape Background

Kokonut UI·Backgrounds

Carousel

shadcn/ui·Media & 3D

Skeleton

shadcn/ui·Feedback & loaders