Created more components
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
namespace Htmx.ApiDemo.Templates.Components;
|
||||
|
||||
/// <summary>
|
||||
/// shadcn-style Alert component.
|
||||
/// Variant: default | destructive
|
||||
/// </summary>
|
||||
public sealed class Alert : AlertBase
|
||||
{
|
||||
private static readonly Dictionary<string, string> VariantClasses = new()
|
||||
{
|
||||
["default"] = "relative w-full rounded-lg border border-border bg-background p-4 " +
|
||||
"[&>svg~*]:pl-7 [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground",
|
||||
["destructive"] = "relative w-full rounded-lg border border-destructive/50 p-4 text-destructive " +
|
||||
"[&>svg~*]:pl-7 [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-destructive",
|
||||
};
|
||||
|
||||
private readonly byte[] _classesData;
|
||||
private readonly byte[] _iconData;
|
||||
private readonly byte[] _titleData;
|
||||
private readonly byte[] _descriptionData;
|
||||
|
||||
public Alert(
|
||||
string title,
|
||||
string description = "",
|
||||
string variant = "default",
|
||||
string icon = "")
|
||||
{
|
||||
_classesData = VariantClasses.GetValueOrDefault(variant, VariantClasses["default"]).ToUtf8Bytes();
|
||||
_iconData = icon.ToUtf8Bytes();
|
||||
_titleData = $"""<h5 class="mb-1 font-medium leading-none tracking-tight">{title}</h5>""".ToUtf8Bytes();
|
||||
_descriptionData = string.IsNullOrEmpty(description)
|
||||
? []
|
||||
: $"""<div class="text-sm [&_p]:leading-relaxed">{description}</div>""".ToUtf8Bytes();
|
||||
}
|
||||
|
||||
protected override void RenderClasses(HtmxRenderContext ctx) => ctx.Writer.WriteUtf8(_classesData);
|
||||
protected override void RenderIcon(HtmxRenderContext ctx) => ctx.Writer.WriteUtf8(_iconData);
|
||||
protected override void RenderTitle(HtmxRenderContext ctx) => ctx.Writer.WriteUtf8(_titleData);
|
||||
protected override void RenderDescription(HtmxRenderContext ctx) => ctx.Writer.WriteUtf8(_descriptionData);
|
||||
}
|
||||
Reference in New Issue
Block a user