UI/Components/StatBar.razor
@namespace Sandbox.UI
@using System;
@using Sandbox;
@using Sandbox.UI;
@inherits Panel
<root class="stat-bar-container @CssClass">
<style>
.stat-bar-container {
flex-direction: column;
width: 100%;
margin-bottom: 6px;
}
.stat-bar-header {
flex-direction: row;
justify-content: space-between;
align-items: center;
margin-bottom: 3px;
}
.stat-bar-label {
font-size: 11px;
font-weight: 800;
text-transform: uppercase;
letter-spacing: 1px;
color: #cbd5e1;
}
.stat-bar-values {
font-family: monospace;
font-size: 10px;
font-weight: 700;
color: #94a3b8;
}
.stat-bar-track {
width: 100%;
height: 9px;
background-color: rgba(0, 0, 0, 0.75);
border: 1px solid rgba(255, 255, 255, 0.15);
border-radius: 2px;
overflow: hidden;
}
.stat-bar-fill {
height: 100%;
}
.stat-bar-fill.health {
background-color: #ef4444;
box-shadow: 0 0 8px rgba(239, 68, 68, 0.6);
}
.stat-bar-fill.balance {
background-color: #f59e0b;
box-shadow: 0 0 8px rgba(245, 158, 11, 0.6);
}
.stat-bar-fill.adrenaline {
background-color: #38bdf8;
box-shadow: 0 0 8px rgba(56, 189, 248, 0.6);
}
.stat-bar-container.mini {
margin-bottom: 3px;
}
.stat-bar-container.mini .stat-bar-label,
.stat-bar-container.mini .stat-bar-values {
font-size: 8px;
}
.stat-bar-container.mini .stat-bar-track {
height: 5px;
}
</style>
@if ( !string.IsNullOrEmpty( Label ) || ShowValues )
{
<div class="stat-bar-header">
<span class="stat-bar-label">@Label</span>
@if ( ShowValues )
{
<span class="stat-bar-values">@($"{Current:F0}/{Max:F0}")</span>
}
</div>
}
<div class="stat-bar-track">
<div class="stat-bar-fill @BarType" style="width: @(Math.Clamp( Ratio * 100f, 0f, 100f ).ToString( "F1", System.Globalization.CultureInfo.InvariantCulture ))%;"></div>
</div>
</root>
@code {
[Property] public string Label { get; set; } = "";
[Property] public float Current { get; set; } = 100f;
[Property] public float Max { get; set; } = 100f;
[Property] public float Ratio { get; set; } = 1.0f;
[Property] public string BarType { get; set; } = "health";
[Property] public bool ShowValues { get; set; } = true;
[Property] public string CssClass { get; set; } = "";
}