Files
Htmx/Htmx.ApiDemo/Templates/Components/Progress.htmx.cs
T
2026-05-04 18:58:48 +05:00

27 lines
911 B
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
namespace Htmx.ApiDemo.Templates.Components;
/// <summary>
/// shadcn-style Progress bar. Value is clamped to 0100.
/// Size: sm (h-2) | default (h-4) | lg (h-6)
/// </summary>
public sealed class Progress : ProgressBase
{
private readonly byte[] _valueNowData;
private readonly byte[] _heightClassData;
public Progress(int value = 0, string size = "default")
{
var clamped = Math.Clamp(value, 0, 100);
_valueNowData = clamped.ToString().ToUtf8Bytes();
_heightClassData = size switch
{
"sm" => "h-2".ToUtf8Bytes(),
"lg" => "h-6".ToUtf8Bytes(),
_ => "h-4".ToUtf8Bytes(),
};
}
protected override void RenderValueNow(HtmxRenderContext ctx) => ctx.Writer.WriteUtf8(_valueNowData);
protected override void RenderHeightClass(HtmxRenderContext ctx) => ctx.Writer.WriteUtf8(_heightClassData);
}