Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

3.3 KB
Raw Blame
// SPDX-License-Identifier: AGPL-3.0-only
// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0

import { cn } from "@/lib/utils";
import type { ReactNode } from "react";

export function StatsCard({
  title,
  description,
  action,
  children,
  className,
}: {
  title?: string;
  description?: string;
  action?: ReactNode;
  children: ReactNode;
  className?: string;
}) {
  return (
    <section
      {...(title ? { "data-settings-label": title } : {})}
      className={cn(
        "flex w-full flex-col gap-4 rounded-2xl border border-border bg-background dark:border-transparent dark:bg-[rgb(255_255_255_/_calc(0.06*var(--contrast-wash-gain,1)))] px-5 py-5",
        className,
      )}
    >
      {title ? (
        <header className="flex flex-wrap items-start justify-between gap-3">
          <div className="flex min-w-0 flex-col gap-0.5">
            <h3 className="text-sm font-semibold font-heading text-foreground">
              {title}
            </h3>
            {description ? (
              <p className="text-xs text-muted-foreground">{description}</p>
            ) : null}
          </div>
          {action ? (
            <div
              className={cn(
                "max-w-full shrink-0",
                // Top edge on the h3's cap top (text-sm at its default leading; Hellix: 0.336em).
                description && "mt-[calc(var(--text-sm)*0.336)]",
              )}
            >
              {action}
            </div>
          ) : null}
        </header>
      ) : null}
      {children}
    </section>
  );
}

export function StatTile({
  value,
  label,
  hint,
  className,
}: {
  value: string;
  label: string;
  hint?: string;
  className?: string;
}) {
  return (
    <div
      data-settings-label={label}
      className={cn(
        "flex min-w-0 flex-col items-center gap-0.5 px-2 py-1 text-center",
        className,
      )}
      {...(hint ? { title: hint } : {})}
    >
      <span className="text-xl font-semibold font-heading tabular-nums text-foreground">
        {value}
      </span>
      <span className="text-xs text-muted-foreground">{label}</span>
    </div>
  );
}

export function StatRow({
  label,
  value,
  emphasis,
}: {
  label: string;
  value: string;
  emphasis?: boolean;
}) {
  return (
    <div
      data-settings-label={label}
      className="flex items-center justify-between gap-4 py-1.5"
    >
      <span className="min-w-0 truncate text-sm text-muted-foreground">
        {label}
      </span>
      <span
        className={cn(
          "shrink-0 text-sm tabular-nums",
          emphasis ? "font-semibold text-foreground" : "text-foreground",
        )}
      >
        {value}
      </span>
    </div>
  );
}

export function StatMeter({
  progress,
  className,
  tone = "primary",
}: {
  progress: number;
  className?: string;
  tone?: "primary" | "muted";
}) {
  const clamped = Math.min(
    1,
    Math.max(0, Number.isFinite(progress) ? progress : 0),
  );
  return (
    <div
      className={cn(
        "h-1.5 w-full overflow-hidden rounded-full bg-muted-foreground/15",
        className,
      )}
    >
      <div
        className={cn(
          "h-full rounded-full transition-[width] duration-500",
          tone === "primary" ? "bg-primary" : "bg-muted-foreground/50",
        )}
        style={{ width: `${clamped * 100}%` }}
      />
    </div>
  );
}