shadcn-templ 2.0 beta. Switch to templUI v1
1.7k

Alert Dialog

A modal dialog that interrupts the user with important content and expects a response.

package examples import (

Installation

shadcn-templ add alert-dialog

Usage

import "github.com/axadrn/shadcn-templ/v2/components/alertdialog"
@alertdialog.AlertDialog() {	@button.Button(button.Props{Attributes: alertdialog.Trigger(ctx)}) {		Show Dialog	}	@alertdialog.Content() {		@alertdialog.Header() {			@alertdialog.Title() {				Are you absolutely sure?			}			@alertdialog.Description() {				This action cannot be undone. This will permanently delete your account				from our servers.			}		}		@alertdialog.Footer() {			@alertdialog.Cancel() {				Cancel			}			@alertdialog.Action() {				Continue			}		}	}}

Composition

Use the following composition to build an AlertDialog:

alertdialog.AlertDialog├── alertdialog.Trigger└── alertdialog.Content    ├── alertdialog.Header    │   ├── alertdialog.Media    │   ├── alertdialog.Title    │   └── alertdialog.Description    └── alertdialog.Footer        ├── alertdialog.Cancel        └── alertdialog.Action

Basic

A basic alert dialog with a title, description, and cancel and continue buttons.

package examples import (

Small

Use the Size prop to make the alert dialog smaller.

package examples import (

Media

Use the alertdialog.Media component to add a media element such as an icon or image to the alert dialog.

package examples import (

Small with Media

Use the Size prop to make the alert dialog smaller and the alertdialog.Media component to add a media element such as an icon or image to the alert dialog.

package examples import (

Destructive

Use the alertdialog.Action component to add a destructive action button to the alert dialog.

package examples import (

API Reference

AlertDialog

The AlertDialog component is the root that links trigger, content and cancel via context. Unlike the dialog, it never closes on a click outside, only Esc and its buttons close it.

Prop Type Default
Open bool false

Trigger

alertdialog.Trigger(ctx) returns the attributes that turn any element into the trigger, usually spread onto a Button. Use alertdialog.TriggerFor(id) to target an alert dialog outside the current root.

Prop Type Default
ctx context.Context -

Content

The alertdialog.Content component is the alert dialog window.

Prop Type Default
Size "default" | "sm" "default"
Class string -

The alertdialog.Header component holds the media, title and description.

Prop Type Default
Class string -

Media

The alertdialog.Media component holds a media element such as an icon or image.

Prop Type Default
Class string -

Title

The alertdialog.Title component is the accessible alert dialog title.

Prop Type Default
Class string -

Description

The alertdialog.Description component is the accessible alert dialog description.

Prop Type Default
Class string -

The alertdialog.Footer component holds the actions at the bottom of the alert dialog.

Prop Type Default
Class string -

Action

The alertdialog.Action component is the confirm button. Like shadcn’s AlertDialogAction it is a plain button and does not close the alert dialog by itself, spread alertdialog.Close(ctx) into Attributes or submit a form to wire the confirm behavior.

Prop Type Default
Variant button.Variant "default"
Size button.Size "default"
Class string -

Cancel

The alertdialog.Cancel component is the button that closes the alert dialog.

Prop Type Default
Variant button.Variant "outline"
Size button.Size "default"
Class string -

Close

alertdialog.Close(ctx) returns the attributes that make any element close the alert dialog. Use alertdialog.CloseFor(id) to target an alert dialog outside the current root.

Prop Type Default
ctx context.Context -