56 lines
2.6 KiB
C#
56 lines
2.6 KiB
C#
namespace Htmx.ApiDemo.Templates.Components;
|
|
|
|
/// <summary>
|
|
/// shadcn-style Textarea component with optional label and description.
|
|
/// </summary>
|
|
public sealed class Textarea : TextareaBase
|
|
{
|
|
private readonly byte[] _idData;
|
|
private readonly byte[] _nameData;
|
|
private readonly byte[] _rowsData;
|
|
private readonly byte[] _placeholderData;
|
|
private readonly byte[] _labelData;
|
|
private readonly byte[] _descriptionData;
|
|
private readonly byte[] _defaultValueData;
|
|
private readonly byte[] _extraClassesData;
|
|
private readonly byte[] _hxAttrsData;
|
|
|
|
public Textarea(
|
|
string id,
|
|
string name = "",
|
|
string placeholder = "",
|
|
string label = "",
|
|
string description = "",
|
|
string defaultValue = "",
|
|
string extraClasses = "",
|
|
string hxAttrs = "",
|
|
int rows = 4)
|
|
{
|
|
_idData = id.ToUtf8Bytes();
|
|
_nameData = (string.IsNullOrEmpty(name) ? id : name).ToUtf8Bytes();
|
|
_rowsData = rows.ToString().ToUtf8Bytes();
|
|
_placeholderData = placeholder.ToUtf8Bytes();
|
|
_extraClassesData = extraClasses.ToUtf8Bytes();
|
|
_hxAttrsData = hxAttrs.ToUtf8Bytes();
|
|
_defaultValueData = defaultValue.ToUtf8Bytes();
|
|
|
|
_labelData = string.IsNullOrEmpty(label)
|
|
? []
|
|
: $"""<label for="{id}" class="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70">{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 RenderRows(HtmxRenderContext ctx) => ctx.Writer.WriteUtf8(_rowsData);
|
|
protected override void RenderPlaceholder(HtmxRenderContext ctx) => ctx.Writer.WriteUtf8(_placeholderData);
|
|
protected override void RenderLabel(HtmxRenderContext ctx) => ctx.Writer.WriteUtf8(_labelData);
|
|
protected override void RenderDescription(HtmxRenderContext ctx) => ctx.Writer.WriteUtf8(_descriptionData);
|
|
protected override void RenderDefaultValue(HtmxRenderContext ctx) => ctx.Writer.WriteUtf8(_defaultValueData);
|
|
protected override void RenderExtraClasses(HtmxRenderContext ctx) => ctx.Writer.WriteUtf8(_extraClassesData);
|
|
protected override void RenderHxAttrs(HtmxRenderContext ctx) => ctx.Writer.WriteUtf8(_hxAttrsData);
|
|
}
|