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/components"
"github.com/axzilla/templui/icons"
)
templ AlertDefault() {
<div class="w-full max-w-xl">
@components.Alert() {
@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/utils"
type AlertVariant string
const (
AlertVariantDefault AlertVariant = "default"
AlertVariantDestructive AlertVariant = "destructive"
)
type AlertProps struct {
ID string
Class string
Attributes templ.Attributes
Variant AlertVariant
}
type AlertTitleProps struct {
ID string
Class string
Attributes templ.Attributes
}
type AlertDescriptionProps struct {
ID string
Class string
Attributes templ.Attributes
}
templ Alert(props ...AlertProps) {
{{ var p AlertProps }}
if len(props) > 0 {
{{ p = props[0] }}
}
<div
if p.ID != "" {
id={ p.ID }
}
class={
utils.TwMerge(
"relative w-full p-4",
"[&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4",
"[&>svg+div]:translate-y-[-3px] [&:has(svg)]:pl-11",
"rounded-lg border",
getAlertVariantClasses(p.Variant),
p.Class,
),
}
role="alert"
{ p.Attributes... }
>
{ children... }
</div>
}
templ AlertTitle(props ...AlertTitleProps) {
{{ var p AlertTitleProps }}
if len(props) > 0 {
{{ p = props[0] }}
}
<h5
if p.ID != "" {
id={ p.ID }
}
class={
utils.TwMerge(
"mb-1 font-medium leading-none tracking-tight",
p.Class,
),
}
{ p.Attributes... }
>
{ children... }
</h5>
}
templ AlertDescription(props ...AlertDescriptionProps) {
{{ var p AlertDescriptionProps }}
if len(props) > 0 {
{{ p = props[0] }}
}
<div
if p.ID != "" {
id={ p.ID }
}
class={
utils.TwMerge(
"[&_p]:leading-relaxed text-sm",
p.Class,
),
}
{ p.Attributes... }
>
{ 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/components"
"github.com/axzilla/templui/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/utils"
type AlertVariant string
const (
AlertVariantDefault AlertVariant = "default"
AlertVariantDestructive AlertVariant = "destructive"
)
type AlertProps struct {
ID string
Class string
Attributes templ.Attributes
Variant AlertVariant
}
type AlertTitleProps struct {
ID string
Class string
Attributes templ.Attributes
}
type AlertDescriptionProps struct {
ID string
Class string
Attributes templ.Attributes
}
templ Alert(props ...AlertProps) {
{{ var p AlertProps }}
if len(props) > 0 {
{{ p = props[0] }}
}
<div
if p.ID != "" {
id={ p.ID }
}
class={
utils.TwMerge(
"relative w-full p-4",
"[&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4",
"[&>svg+div]:translate-y-[-3px] [&:has(svg)]:pl-11",
"rounded-lg border",
getAlertVariantClasses(p.Variant),
p.Class,
),
}
role="alert"
{ p.Attributes... }
>
{ children... }
</div>
}
templ AlertTitle(props ...AlertTitleProps) {
{{ var p AlertTitleProps }}
if len(props) > 0 {
{{ p = props[0] }}
}
<h5
if p.ID != "" {
id={ p.ID }
}
class={
utils.TwMerge(
"mb-1 font-medium leading-none tracking-tight",
p.Class,
),
}
{ p.Attributes... }
>
{ children... }
</h5>
}
templ AlertDescription(props ...AlertDescriptionProps) {
{{ var p AlertDescriptionProps }}
if len(props) > 0 {
{{ p = props[0] }}
}
<div
if p.ID != "" {
id={ p.ID }
}
class={
utils.TwMerge(
"[&_p]:leading-relaxed text-sm",
p.Class,
),
}
{ p.Attributes... }
>
{ children... }
</div>
}
func getAlertVariantClasses(variant AlertVariant) string {
switch variant {
case AlertVariantDestructive:
return "border-destructive text-destructive"
default:
return "border-border text-foreground"
}
}