Created more components
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
namespace Htmx.ApiDemo.Templates.Components;
|
||||
|
||||
/// <summary>
|
||||
/// shadcn-style Slider (range input) with optional label and description.
|
||||
/// </summary>
|
||||
public sealed class Slider : SliderBase
|
||||
{
|
||||
private readonly byte[] _idData;
|
||||
private readonly byte[] _nameData;
|
||||
private readonly byte[] _minData;
|
||||
private readonly byte[] _maxData;
|
||||
private readonly byte[] _stepData;
|
||||
private readonly byte[] _valueData;
|
||||
private readonly byte[] _labelData;
|
||||
private readonly byte[] _descriptionData;
|
||||
private readonly byte[] _extraClassesData;
|
||||
private readonly byte[] _hxAttrsData;
|
||||
|
||||
public Slider(
|
||||
string id,
|
||||
string name = "",
|
||||
int min = 0,
|
||||
int max = 100,
|
||||
int step = 1,
|
||||
int value = 50,
|
||||
string label = "",
|
||||
string description = "",
|
||||
string extraClasses = "",
|
||||
string hxAttrs = "")
|
||||
{
|
||||
_idData = id.ToUtf8Bytes();
|
||||
_nameData = (string.IsNullOrEmpty(name) ? id : name).ToUtf8Bytes();
|
||||
_minData = min.ToString().ToUtf8Bytes();
|
||||
_maxData = max.ToString().ToUtf8Bytes();
|
||||
_stepData = step.ToString().ToUtf8Bytes();
|
||||
_valueData = value.ToString().ToUtf8Bytes();
|
||||
_extraClassesData = extraClasses.ToUtf8Bytes();
|
||||
_hxAttrsData = hxAttrs.ToUtf8Bytes();
|
||||
|
||||
_labelData = string.IsNullOrEmpty(label)
|
||||
? []
|
||||
: $"""<label for="{id}" class="text-sm font-medium leading-none">{label}</label>""".ToUtf8Bytes();
|
||||
|
||||
_descriptionData = string.IsNullOrEmpty(description)
|
||||
? []
|
||||
: $"""<p class="text-xs text-muted-foreground">{description}</p>""".ToUtf8Bytes();
|
||||
}
|
||||
|
||||
protected override void RenderId(HtmxRenderContext ctx) => ctx.Writer.WriteUtf8(_idData);
|
||||
protected override void RenderName(HtmxRenderContext ctx) => ctx.Writer.WriteUtf8(_nameData);
|
||||
protected override void RenderMin(HtmxRenderContext ctx) => ctx.Writer.WriteUtf8(_minData);
|
||||
protected override void RenderMax(HtmxRenderContext ctx) => ctx.Writer.WriteUtf8(_maxData);
|
||||
protected override void RenderStep(HtmxRenderContext ctx) => ctx.Writer.WriteUtf8(_stepData);
|
||||
protected override void RenderValue(HtmxRenderContext ctx) => ctx.Writer.WriteUtf8(_valueData);
|
||||
protected override void RenderLabel(HtmxRenderContext ctx) => ctx.Writer.WriteUtf8(_labelData);
|
||||
protected override void RenderDescription(HtmxRenderContext ctx) => ctx.Writer.WriteUtf8(_descriptionData);
|
||||
protected override void RenderExtraClasses(HtmxRenderContext ctx) => ctx.Writer.WriteUtf8(_extraClassesData);
|
||||
protected override void RenderHxAttrs(HtmxRenderContext ctx) => ctx.Writer.WriteUtf8(_hxAttrsData);
|
||||
}
|
||||
Reference in New Issue
Block a user