namespace Htmx.ApiDemo.Templates.Components; /// /// shadcn-style Alert component. /// Variant: default | destructive /// public sealed class Alert : AlertBase { private static readonly Dictionary 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 = $"""
{title}
""".ToUtf8Bytes(); _descriptionData = string.IsNullOrEmpty(description) ? [] : $"""
{description}
""".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); }