63 lines
2.1 KiB
Plaintext
63 lines
2.1 KiB
Plaintext
@using System.Globalization
|
|||
|
|
@inherits DComponentBase
|
||
|
|
|
||
|
|
@* daisyUI Radial progress: https://daisyui.com/components/radial-progress/ . Value/Max becomes a 0-100 percentage in
|
||
|
|
the --value style variable and aria-valuenow, and the default text; Diameter and Thickness set --size and
|
||
|
|
--thickness. A consumer's style is appended to those. It is drawn in currentColor, so Color maps to text-*. *@
|
||
|
|
<div @attributes="AdditionalAttributes" class="@CssClass" style="@StyleValue" role="progressbar"
|
||
|
|
aria-valuenow="@PercentText" aria-valuemin="0" aria-valuemax="100">
|
||
|
|
@if (ChildContent is null)
|
||
|
|
{
|
||
|
|
@($"{Math.Round(Percent)}%")
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
@ChildContent
|
||
|
|
}
|
||
|
|
</div>
|
||
|
|
|
||
|
|
@code {
|
||
|
|
[Parameter] public double Value { get; set; }
|
||
|
|
[Parameter] public double Max { get; set; } = 100;
|
||
|
|
[Parameter] public DColor Color { get; set; }
|
||
|
|
/// <summary>A CSS length for --size (daisyUI's default is 5rem).</summary>
|
||
|
|
[Parameter] public string Diameter { get; set; }
|
||
|
|
/// <summary>A CSS length for --thickness (daisyUI's default is a tenth of the size).</summary>
|
||
|
|
[Parameter] public string Thickness { get; set; }
|
||
|
|
/// <summary>Replaces the default "NN%" text.</summary>
|
||
|
|
[Parameter] public RenderFragment ChildContent { get; set; }
|
||
|
|
|
||
|
|
double Percent => Max > 0 ? Math.Clamp(Value / Max * 100, 0, 100) : 0;
|
||
|
|
|
||
|
|
string PercentText => Math.Round(Percent, 2).ToString(CultureInfo.InvariantCulture);
|
||
|
|
|
||
|
|
string StyleValue
|
||
|
|
{
|
||
|
|
get
|
||
|
|
{
|
||
|
|
var style = $"--value:{PercentText};";
|
||
|
|
if (!string.IsNullOrEmpty(Diameter))
|
||
|
|
style += $" --size:{Diameter};";
|
||
|
|
if (!string.IsNullOrEmpty(Thickness))
|
||
|
|
style += $" --thickness:{Thickness};";
|
||
|
|
if (AdditionalAttributes != null && AdditionalAttributes.TryGetValue("style", out var extra) && extra is not null)
|
||
|
|
style += " " + extra;
|
||
|
|
return style;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
string CssClass => Cx("radial-progress", ColorClass, Class);
|
||
|
|
|
||
|
|
string ColorClass => Color switch
|
||
|
|
{
|
||
|
|
DColor.Neutral => "text-neutral",
|
||
|
|
DColor.Primary => "text-primary",
|
||
|
|
DColor.Secondary => "text-secondary",
|
||
|
|
DColor.Accent => "text-accent",
|
||
|
|
DColor.Info => "text-info",
|
||
|
|
DColor.Success => "text-success",
|
||
|
|
DColor.Warning => "text-warning",
|
||
|
|
DColor.Error => "text-error",
|
||
|
|
_ => null
|
||
|
|
};
|
||
|
|
}
|