Created more components

This commit is contained in:
2026-05-04 18:58:48 +05:00
parent fb1cb8e834
commit 40a7d9018c
52 changed files with 2526 additions and 11 deletions
@@ -0,0 +1,46 @@
namespace Htmx.ApiDemo.Templates.Components;
/// <summary>
/// shadcn-style RadioGroup.
/// Direction: flex-col | flex-row
/// </summary>
public sealed class RadioGroup : RadioGroupBase
{
private readonly byte[] _groupLabelData;
private readonly byte[] _directionData;
private readonly byte[] _itemsData;
public RadioGroup(
string name,
IEnumerable<(string Value, string Label, bool Selected)> options,
string label = "",
string direction = "flex-col")
{
_groupLabelData = string.IsNullOrEmpty(label)
? []
: $"""<span class="text-sm font-medium leading-none">{label}</span>""".ToUtf8Bytes();
_directionData = direction.ToUtf8Bytes();
var sb = new System.Text.StringBuilder();
foreach (var (value, optLabel, selected) in options)
{
var optId = $"{name}-{value}";
var sel = selected ? " checked" : "";
sb.Append($"""
<label class="flex items-center gap-2 cursor-pointer text-sm">
<input type="radio" id="{optId}" name="{name}" value="{value}"{sel}
class="h-4 w-4 border border-input accent-primary
focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring
disabled:cursor-not-allowed disabled:opacity-50" />
{optLabel}
</label>
""");
}
_itemsData = sb.ToString().ToUtf8Bytes();
}
protected override void RenderGroupLabel(HtmxRenderContext ctx) => ctx.Writer.WriteUtf8(_groupLabelData);
protected override void RenderDirection(HtmxRenderContext ctx) => ctx.Writer.WriteUtf8(_directionData);
protected override void RenderItems(HtmxRenderContext ctx) => ctx.Writer.WriteUtf8(_itemsData);
}