Alert
Status message that displays contextual feedback or notifications.
TailwindCSS
Note
This is a default alert — check it out!
package showcase
import (
"github.com/axzilla/templui/pkg/components"
"github.com/axzilla/templui/pkg/icons"
)
templ AlertDefault() {
<div class="w-full max-w-xl">
@components.Alert(components.AlertProps{Variant: components.AlertVariantDefault}) {
@icons.Rocket(icons.IconProps{Size: "16"})
@components.AlertTitle() {
Note
}
@components.AlertDescription() {
This is a default alert — check it out!
}
}
</div>
}
package components
import "github.com/axzilla/templui/pkg/utils"
type AlertVariant string
const (
AlertVariantDefault AlertVariant = "default"
AlertVariantDestructive AlertVariant = "destructive"
)
type AlertProps struct {
Variant AlertVariant // Visual style variant
Class string // Additional CSS classes
}
// Alert renders a status message component
templ Alert(props AlertProps) {
<div
class={ utils.TwMerge(
// Layout
"relative w-full p-4",
"[&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4",
"[&>svg+div]:translate-y-[-3px] [&:has(svg)]:pl-11",
// Styling
"rounded-lg border",
getAlertVariantClasses(props.Variant),
// Custom
props.Class,
) }
role="alert"
>
{ children... }
</div>
}
// AlertTitle renders the heading section
templ AlertTitle() {
<h5
class={ utils.TwMerge(
// Layout
"mb-1",
// Styling
"font-medium leading-none tracking-tight",
) }
>
{ children... }
</h5>
}
// AlertDescription renders the body content
templ AlertDescription() {
<div
class={ utils.TwMerge(
// Layout
"[&_p]:leading-relaxed",
// Styling
"text-sm",
) }
>
{ children... }
</div>
}
func getAlertVariantClasses(variant AlertVariant) string {
switch variant {
case AlertVariantDestructive:
return "border-destructive text-destructive"
default:
return "border-border text-foreground"
}
}
Usage
@components.Alert(components.AlertProps{...})
Examples
Destructive
Error
Your session has expired. Please log in again.
package showcase
import (
"github.com/axzilla/templui/pkg/components"
"github.com/axzilla/templui/pkg/icons"
)
templ AlertDestructive() {
<div class="w-full max-w-xl">
@components.Alert(components.AlertProps{Variant: components.AlertVariantDestructive}) {
@icons.TriangleAlert(icons.IconProps{Size: "16"})
@components.AlertTitle() {
Error
}
@components.AlertDescription() {
Your session has expired. Please log in again.
}
}
</div>
}
package components
import "github.com/axzilla/templui/pkg/utils"
type AlertVariant string
const (
AlertVariantDefault AlertVariant = "default"
AlertVariantDestructive AlertVariant = "destructive"
)
type AlertProps struct {
Variant AlertVariant // Visual style variant
Class string // Additional CSS classes
}
// Alert renders a status message component
templ Alert(props AlertProps) {
<div
class={ utils.TwMerge(
// Layout
"relative w-full p-4",
"[&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4",
"[&>svg+div]:translate-y-[-3px] [&:has(svg)]:pl-11",
// Styling
"rounded-lg border",
getAlertVariantClasses(props.Variant),
// Custom
props.Class,
) }
role="alert"
>
{ children... }
</div>
}
// AlertTitle renders the heading section
templ AlertTitle() {
<h5
class={ utils.TwMerge(
// Layout
"mb-1",
// Styling
"font-medium leading-none tracking-tight",
) }
>
{ children... }
</h5>
}
// AlertDescription renders the body content
templ AlertDescription() {
<div
class={ utils.TwMerge(
// Layout
"[&_p]:leading-relaxed",
// Styling
"text-sm",
) }
>
{ children... }
</div>
}
func getAlertVariantClasses(variant AlertVariant) string {
switch variant {
case AlertVariantDestructive:
return "border-destructive text-destructive"
default:
return "border-border text-foreground"
}
}