@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-*. *@
@if (ChildContent is null) { @($"{Math.Round(Percent)}%") } else { @ChildContent }
@code { [Parameter] public double Value { get; set; } [Parameter] public double Max { get; set; } = 100; [Parameter] public DColor Color { get; set; } /// A CSS length for --size (daisyUI's default is 5rem). [Parameter] public string Diameter { get; set; } /// A CSS length for --thickness (daisyUI's default is a tenth of the size). [Parameter] public string Thickness { get; set; } /// Replaces the default "NN%" text. [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 }; }