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,34 @@
namespace Htmx.ApiDemo.Templates.Components;
/// <summary>
/// shadcn-style Toast notification. Typically created dynamically via window.showToast(),
/// but can also be server-rendered and injected via htmx.
/// </summary>
public sealed class Toast : ToastBase
{
private static readonly Dictionary<string, string> VariantClasses = new()
{
["default"] = "",
["destructive"] = "border-destructive text-destructive",
};
private readonly byte[] _titleData;
private readonly byte[] _descriptionData;
private readonly byte[] _extraClassesData;
public Toast(
string title,
string description = "",
string variant = "default")
{
_titleData = $"""<div class="text-sm font-semibold">{title}</div>""".ToUtf8Bytes();
_descriptionData = string.IsNullOrEmpty(description)
? []
: $"""<div class="text-sm opacity-90">{description}</div>""".ToUtf8Bytes();
_extraClassesData = VariantClasses.GetValueOrDefault(variant, "").ToUtf8Bytes();
}
protected override void RenderTitle(HtmxRenderContext ctx) => ctx.Writer.WriteUtf8(_titleData);
protected override void RenderDescription(HtmxRenderContext ctx) => ctx.Writer.WriteUtf8(_descriptionData);
protected override void RenderExtraClasses(HtmxRenderContext ctx)=> ctx.Writer.WriteUtf8(_extraClassesData);
}