shadimage
8bitcn UI
blockcharacter-sheetsource: ok · hit

8-bit Character Sheet

A comprehensive RPG character stats page with attributes, equipment, and customizable sections.

npx shadcn add "https://www.8bitcn.com/r/character-sheet.json"
free

Where it goes

stats

Interaction

animated-counter

Tags auto-generated by rules on 9/24/2026 — empty means no evidence, not lack of support.

Dependencies

Bundle weight · light

Registry dependencies

avatarbadgecardprogressseparator

Files9 · source cached 10/8/2026, 3:38:30 PM

components/ui/8bit/blocks/character-sheet.tsx
import type * as React from "react";

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

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 { Separator } from "@/components/ui/8bit/separator";
import "@/components/ui/8bit/styles/retro.css";

export interface PrimaryAttribute {
  name: string;
  shortName: string;
  value: number;
  max?: number;
  color?: string;
}

export interface SecondaryStat {
  name: string;
  value: number;
  max?: number;
  isPercentage?: boolean;
  icon?: React.ReactNode;
  color?: string;
}

export interface EquipmentItem {
  slot: string;
  name: string;
  rarity?: "common" | "uncommon" | "rare" | "epic" | "legendary";
  icon?: React.ReactNode;
}

export interface CustomSection {
  title: string;
  content: React.ReactNode;
}

export const characterSheetVariants = cva("", {
  variants: {
    font: {
      normal: "",
      retro: "retro",
    },
  },
  defaultVariants: {
    font: "retro",
  },
});

export interface CharacterSheetProps
  extends React.HTMLAttributes<HTMLDivElement>,
    VariantProps<typeof characterSheetVariants> {
  characterName: string;
  characterClass?: string;
  characterTitle?: string;
  characterLevel?: number;
  avatarSrc?: string;
  avatarFallback?: string;

  primaryAttributes?: PrimaryAttribute[];

  secondaryStats?: SecondaryStat[];

  health?: { current: number; max: number };
  mana?: { current: number; max: number };
  experience?: { current: number; max: number };

  equipment?: EquipmentItem[];

  customSections?: CustomSection[];

  showAvatar?: boolean;
  showLevel?: boolean;
  showHealth?: boolean;
  showMana?: boolean;
  showExperience?: boolean;
  showAttributes?: boolean;
  showSecondaryStats?: boolean;
  showEquipment?: boolean;
}

const defaultPrimaryAttributes: PrimaryAttribute[] = [
  { name: "Strength", shortName: "STR", value: 10 },
  { name: "Dexterity", shortName: "DEX", value: 10 },
  { name: "Intelligence", shortName: "INT", value: 10 },
  { name: "Vitality", shortName: "VIT", value: 10 },
  { name: "Wisdom", shortName: "WIS", value: 10 },
  { name: "Charisma", shortName: "CHA", value: 10 },
];

export function CharacterSheet({
  className,
  font,
  characterName,
  characterClass,
  characterTitle,
  characterLevel = 1,
  avatarSrc,
  avatarFallback,
  primaryAttributes,
  secondaryStats,
  health,
  mana,
  experience,
  equipment,
  customSections,
  showAvatar = true,
  showLevel = true,
  showHealth = true,
  showMana = true,
  showExperience = true,
  showAttributes = true,
  showSecondaryStats = true,
  showEquipment = true,
  ...props
}: CharacterSheetProps) {
  const attributes = primaryAttributes || defaultPrimaryAttributes;

  const healthPercentage = health
    ? Math.round((health.current / health.max) * 100)
    : 0;

  const manaPercentage = mana
    ? Math.round((mana.current / mana.max) * 100)
    : 0;

  const experiencePercentage = experience
    ? Math.round((experience.current / experience.max) * 100)
    : 0;

  return (
    <Card
      className={cn(
        "w-full",
        font !== "normal" && "retro",
        className
      )}
      {...props}
    >
      {/* Character Header */}
      <CardHeader className="pb-4">
        <div className="flex sm:flex-row flex-col items-start gap-4">
          {showAvatar && (
            <Avatar className="size-20" variant="pixel" font="retro">
              <AvatarImage src={avatarSrc} alt={characterName} />
              <AvatarFallback className="text-xl">
                {avatarFallback || characterName.charAt(0).toUpperCase()}
              </AvatarFallback>
            </Avatar>
          )}

          <div className="flex-1 min-w-0 space-y-2">
            <div className="flex flex-wrap flex-col gap-1 sm:flex-row sm:items-center sm:justify-between">
              <h2 className="text-xl font-bold truncate">{characterName}</h2>
              {showLevel && (
                <Badge className="text-xs w-fit">LV. {characterLevel}</Badge>
              )}
            </div>

            {(characterClass || characterTitle) && (
              <div className="flex flex-wrap gap-2 text-sm text-muted-foreground">
                {characterClass && <span>{characterClass}</span>}
                {characterTitle && (
                  <span className="text-amber-800 dark:text-amber-300">
                    {characterTitle}
                  </span>
                )}
              </div>
            )}
          </div>
        </div>
      </CardHeader>

      <CardContent className="space-y-6">
        {/* Health/Mana/XP Bars */}
        {(showHealth || showMana || showExperience) && (
          <div className="space-y-3">
            {showHealth && health && (
              <div className="space-y-1">
                <div className="flex sm:flex-row flex-col justify-between items-center">
                  <span className="font-medium text-red-700 text-sm dark:text-red-300">
                    Health
                  </span>
                  <span className="text-xs text-muted-foreground retro">
                    {health.current}/{health.max}
                  </span>
                </div>
                <HealthBar
                  value={healthPercentage}
                  variant="retro"
                  className="h-3"
                />
              </div>
            )}

            {showMana && mana && (
              <div className="space-y-1">
                <div className="flex sm:flex-row flex-col justify-between items-center">
                  <span className="font-medium text-blue-700 text-sm dark:text-blue-300">
                    Mana
                  </span>
                  <span className="text-xs text-muted-foreground retro">
                    {mana.current}/{mana.max}
                  </span>
                </div>
                <ManaBar
                  value={manaPercentage}
                  variant="retro"
                  className="h-3"
                />
              </div>
            )}

            {showExperience && experience && (
              <div className="space-y-1">
                <div className="flex sm:flex-row flex-col justify-between items-center">
                  <span className="font-medium text-sm text-yellow-800 dark:text-yellow-300">
                    Experience
                  </span>
                  <span className="text-xs text-muted-foreground retro">
                    {experience.current}/{experience.max} XP
                  </span>
                </div>
                <Progress
                  value={experiencePercentage}
                  variant="retro"
                  progressBg="bg-yellow-500"
                  className="h-3"
                />
              </div>
            )}
          </div>
        )}

        {/* Primary Attributes */}
        {showAttributes && attributes.length > 0 && (
          <>
            <Separator />
            <div className="space-y-3">
              <h3 className="text-sm font-bold uppercase tracking-wide">
                Attributes
              </h3>
              <div className="grid grid-cols-2 sm:grid-cols-3 gap-3">
                {attributes.map((attr) => (
                  <div
                    key={attr.shortName}
                    className="flex items-center justify-between p-2 bg-muted/30 border-2"
                  >
                    <span className="text-xs font-bold">
                      {attr.shortName}
                    </span>
                    <span className="text-xs font-bold">{attr.value}</span>
                  </div>
                ))}
              </div>
            </div>
          </>
        )}

        {/* Secondary Stats */}
        {showSecondaryStats && secondaryStats && secondaryStats.length > 0 && (
          <>
            <Separator />
            <div className="space-y-3">
              <h3 className="text-sm font-bold uppercase tracking-wide">
                Stats
              </h3>
              <div className="grid sm:grid-cols-2 gap-2">
                {secondaryStats.map((stat) => (
                  <div
                    key={stat.name}
                    className="flex items-center justify-between py-1.5 px-2"
                  >
                    <span className="text-xs text-muted-foreground flex items-center gap-1">
                      {stat.icon}
                      {stat.name}
                    </span>
                    <span
                      className={cn(
                        "text-sm font-bold",
                        stat.color || "text-foreground"
                      )}
                    >
                      {stat.value}
                      {stat.isPercentage && "%"}
                      {stat.max && !stat.isPercentage && `/${stat.max}`}
                    </span>
                  </div>
                ))}
              </div>
            </div>
          </>
        )}

        {/* Equipment */}
        {showEquipment && equipment && equipment.length > 0 && (
          <>
            <Separator />
            <div className="space-y-3">
              <h3 className="text-sm font-bold uppercase tracking-wide">
                Equipment
              </h3>
              <div className="space-y-2">
                {equipment.map((item) => (
                  <div
                    key={item.slot}
                    className="flex sm:flex-row flex-col items-center justify-between py-2 px-3 bg-muted/30 border-2"
                  >
                    <span className="text-xs text-muted-foreground uppercase">
                      {item.slot}
                    </span>
                    <span className="text-sm font-medium flex items-center gap-1">
                      {item.icon}
                      {item.name}
                    </span>
                  </div>
                ))}
              </div>
            </div>
          </>
        )}

        {/* Custom Sections */}
        {customSections &&
          customSections.map((section, index) => (
            <div key={index}>
              <Separator />
              <div className="space-y-3 pt-4">
                <h3 className="text-sm font-bold uppercase tracking-wide">
                  {section.title}
                </h3>
                {section.content}
              </div>
            </div>
          ))}
      </CardContent>
    </Card>
  );
}


export function CharacterSheetStatRow({
  label,
  value,
  icon,
  color,
  className,
}: {
  label: string;
  value: string | number;
  icon?: React.ReactNode;
  color?: string;
  className?: string;
}) {
  return (
    <div
      className={cn(
        "flex items-center justify-between py-1.5 px-2",
        className
      )}
    >
      <span className="text-xs text-muted-foreground flex items-center gap-1">
        {icon}
        {label}
      </span>
      <span className={cn("text-sm font-bold", color || "text-foreground")}>
        {value}
      </span>
    </div>
  );
}

export function CharacterSheetAttributeBox({
  shortName,
  value,
  color,
  className,
}: {
  shortName: string;
  value: number;
  color?: string;
  className?: string;
}) {
  return (
    <div
      className={cn(
        "flex items-center justify-between p-2 bg-muted/30 border-2",
        className
      )}
    >
      <span
        className={cn("text-xs font-bold", color || "text-foreground")}
      >
        {shortName}
      </span>
      <span className="text-sm font-bold">{value}</span>
    </div>
  );
}

export default CharacterSheet;
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/separator.tsx
"use client";

import type * as React from "react";

import * as SeparatorPrimitive from "@radix-ui/react-separator";

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

function Separator({
  className,
  orientation = "horizontal",
  decorative = true,
  ...props
}: React.ComponentProps<typeof SeparatorPrimitive.Root>) {
  return (
    <SeparatorPrimitive.Root
      data-slot="separator-root"
      decorative={decorative}
      orientation={orientation}
      className={cn(
        "data-[orientation=horizontal]:bg-[length:16px_8px] data-[orientation=horizontal]:bg-[linear-gradient(90deg,var(--foreground)_75%,transparent_75%)] dark:data-[orientation=horizontal]:bg-[linear-gradient(90deg,var(--ring)_75%,transparent_75%)] shrink-0 data-[orientation=horizontal]:h-0.5 data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-0.5 data-[orientation=vertical]:bg-[length:2px_16px] data-[orientation=vertical]:bg-[linear-gradient(0deg,var(--foreground)_75%,transparent_75%)] dark:data-[orientation=vertical]:bg-[linear-gradient(0deg,var(--ring)_75%,transparent_75%)]",
        className
      )}
      {...props}
    />
  );
}

export { Separator };
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;
}

More from 8bitcn UI

Browse all components in this library →