27 lines
911 B
C#
27 lines
911 B
C#
namespace Htmx.ApiDemo.Templates.Components;
|
||
|
||
/// <summary>
|
||
/// shadcn-style Progress bar. Value is clamped to 0–100.
|
||
/// 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);
|
||
}
|