Created more components
This commit is contained in:
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user