namespace Htmx.ApiDemo.Templates.Components; /// /// shadcn-style RadioGroup. /// Direction: flex-col | flex-row /// 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) ? [] : $"""{label}""".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($""" """); } _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); }