Documentation
¶
Overview ¶
Package modal provides modal dialog components with Alpine.js state management.
Modal is the foundation for overlay components including Dialog, AlertDialog, Drawer, and Sheet. It provides:
- Backdrop with fade transition
- Content with scale-in transition
- Configurable sizes (sm, md, lg, xl, full)
- Close on escape (configurable)
- Close on outside click (configurable)
- Optional close button
- Focus trap using Alpine Focus plugin
Basic usage:
modal.Modal(
modal.ModalProps{
Size: forgeui.SizeMD,
CloseOnEscape: true,
CloseOnOutsideClick: true,
},
button.Button(g.Text("Open Modal")),
html.Div(
modal.ModalHeader("Confirm Action", "Are you sure?"),
html.P(g.Text("This action cannot be undone.")),
modal.ModalFooter(
button.Button(g.Text("Cancel")),
button.Button(g.Text("Confirm")),
),
),
)
Index ¶
- func AlertDialog(children ...g.Node) g.Node
- func AlertDialogAction(child g.Node) g.Node
- func AlertDialogCancel(child g.Node) g.Node
- func AlertDialogContent(children ...g.Node) g.Node
- func AlertDialogContentWithSize(size forgeui.Size, children ...g.Node) g.Node
- func AlertDialogDescription(text string) g.Node
- func AlertDialogFooter(children ...g.Node) g.Node
- func AlertDialogHeader(children ...g.Node) g.Node
- func AlertDialogTitle(text string) g.Node
- func AlertDialogTrigger(child g.Node) g.Node
- func Dialog(children ...g.Node) g.Node
- func DialogBody(children ...g.Node) g.Node
- func DialogClose(child g.Node) g.Node
- func DialogContent(children ...g.Node) g.Node
- func DialogContentWithOptions(props DialogContentProps, children ...g.Node) g.Node
- func DialogDescription(text string) g.Node
- func DialogFooter(children ...g.Node) g.Node
- func DialogFull(children ...g.Node) g.Node
- func DialogHeader(children ...g.Node) g.Node
- func DialogLG(children ...g.Node) g.Node
- func DialogSM(children ...g.Node) g.Node
- func DialogTitle(text string) g.Node
- func DialogTrigger(child g.Node) g.Node
- func DialogXL(children ...g.Node) g.Node
- func Drawer(props DrawerProps, trigger g.Node, content ...g.Node) g.Node
- func DrawerBody(children ...g.Node) g.Node
- func DrawerClose(child g.Node) g.Node
- func DrawerFooter(children ...g.Node) g.Node
- func DrawerHeader(title, description string) g.Node
- func Modal(props ModalProps, trigger g.Node, content ...g.Node) g.Node
- func ModalClose(child g.Node) g.Node
- func ModalFooter(children ...g.Node) g.Node
- func ModalHeader(title, description string) g.Node
- func Sheet(children ...g.Node) g.Node
- func SheetBody(children ...g.Node) g.Node
- func SheetBottom(children ...g.Node) g.Node
- func SheetClose(child g.Node) g.Node
- func SheetContent(side forgeui.Side, children ...g.Node) g.Node
- func SheetContentWithOptions(props SheetContentProps, children ...g.Node) g.Node
- func SheetDescription(text string) g.Node
- func SheetFooter(children ...g.Node) g.Node
- func SheetHeader(children ...g.Node) g.Node
- func SheetLeft(children ...g.Node) g.Node
- func SheetRight(children ...g.Node) g.Node
- func SheetTitle(text string) g.Node
- func SheetTop(children ...g.Node) g.Node
- func SheetTrigger(child g.Node) g.Node
- type DialogContentProps
- type DrawerProps
- type ModalProps
- type SheetContentProps
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AlertDialog ¶
AlertDialog creates an alert dialog for critical confirmations.
Unlike regular dialogs, alert dialogs:
- Cannot be closed by clicking outside (by design)
- Require explicit user action
- Are typically used for destructive actions
- Auto-focus on the primary action button
Example:
alertDialog.AlertDialog(
alertDialog.AlertDialogTrigger(
button.Button(g.Text("Delete Account"), button.WithVariant("destructive")),
),
alertDialog.AlertDialogContent(
alertDialog.AlertDialogHeader(
alertDialog.AlertDialogTitle("Are you absolutely sure?"),
alertDialog.AlertDialogDescription("This action cannot be undone."),
),
alertDialog.AlertDialogFooter(
alertDialog.AlertDialogCancel(button.Button(g.Text("Cancel"))),
alertDialog.AlertDialogAction(button.Button(g.Text("Delete"), button.WithVariant("destructive"))),
),
),
)
func AlertDialogAction ¶
AlertDialogAction wraps a confirm/action button.
This should be the primary action button, often with a destructive variant. The button itself handles the actual action; this wrapper only provides the proper HTML structure.
func AlertDialogCancel ¶
AlertDialogCancel wraps a cancel button to close the alert dialog.
This is the safe action - typically an outline or ghost button.
func AlertDialogContent ¶
AlertDialogContent creates the alert dialog content panel.
By design, alert dialogs: - Cannot close on outside click - Always show close button - Use medium size by default
func AlertDialogContentWithSize ¶
AlertDialogContentWithSize creates alert dialog content with custom size
func AlertDialogDescription ¶
AlertDialogDescription creates the alert dialog description element.
func AlertDialogFooter ¶
AlertDialogFooter creates a footer section for action buttons.
Typically contains Cancel and Action buttons.
func AlertDialogHeader ¶
AlertDialogHeader creates a header section for the alert dialog.
func AlertDialogTitle ¶
AlertDialogTitle creates the alert dialog title element.
func AlertDialogTrigger ¶
AlertDialogTrigger wraps an element to trigger opening the alert dialog.
func Dialog ¶
Dialog creates a dialog container with compound component API.
Dialog provides a more semantic API than the base Modal component, with separate components for trigger, content, header, footer, etc.
Example:
dialog.Dialog(
dialog.DialogTrigger(button.Button(g.Text("Edit Profile"))),
dialog.DialogContent(
dialog.DialogHeader(
dialog.DialogTitle("Edit Profile"),
dialog.DialogDescription("Make changes here."),
),
html.Div(/* form fields */),
dialog.DialogFooter(
dialog.DialogClose(button.Button(g.Text("Cancel"))),
button.Button(g.Text("Save")),
),
),
)
func DialogBody ¶
DialogBody creates the main content area of the dialog.
func DialogClose ¶
DialogClose wraps an element to close the dialog when clicked.
func DialogContent ¶
DialogContent creates the dialog content panel with backdrop.
Options can be passed to customize size and behavior:
DialogContent(opts ...DialogOption)
func DialogContentWithOptions ¶
func DialogContentWithOptions(props DialogContentProps, children ...g.Node) g.Node
DialogContentWithOptions creates dialog content with custom props
func DialogDescription ¶
DialogDescription creates the dialog description element.
func DialogFooter ¶
DialogFooter creates a footer section for action buttons.
func DialogHeader ¶
DialogHeader creates a header section for the dialog.
func DialogTitle ¶
DialogTitle creates the dialog title element.
func DialogTrigger ¶
DialogTrigger wraps an element to trigger opening the dialog when clicked.
func Drawer ¶
Drawer creates a drawer that slides in from a screen edge.
Drawers are panels that slide in from the edge of the screen, commonly used for navigation menus, filters, or forms.
Example:
drawer.Drawer(
drawer.DrawerProps{
Side: forgeui.SideRight,
Size: forgeui.SizeMD,
},
button.Button(g.Text("Open Drawer")),
html.Div(
drawer.DrawerHeader("Settings", "Configure your preferences"),
html.Div(g.Text("Drawer content")),
),
)
func DrawerBody ¶
DrawerBody creates the main content area of the drawer.
func DrawerClose ¶
DrawerClose wraps an element to close the drawer when clicked.
func DrawerFooter ¶
DrawerFooter creates a footer section for action buttons.
func DrawerHeader ¶
DrawerHeader creates a header section for the drawer.
func Modal ¶
Modal creates a modal dialog with Alpine.js state management.
The modal consists of three main parts:
- Trigger element - clicks to open the modal
- Backdrop - semi-transparent overlay
- Content - the actual modal panel
Example:
modal.Modal(
modal.ModalProps{Size: forgeui.SizeLG},
button.Button(g.Text("Open")),
html.Div(g.Text("Modal content")),
)
func ModalClose ¶
ModalClose wraps a child element to close the modal when clicked.
Example:
modal.ModalClose(button.Button(g.Text("Close")))
func ModalFooter ¶
ModalFooter creates a footer section for action buttons.
Example:
modal.ModalFooter(
button.Button(g.Text("Cancel")),
button.Button(g.Text("Confirm")),
)
func ModalHeader ¶
ModalHeader creates a header section for the modal with title and optional description.
Example:
modal.ModalHeader("Delete Account", "This action cannot be undone.")
func Sheet ¶
Sheet creates a sheet container with compound component API.
Sheet provides a more semantic API than the base Drawer component, similar to how Dialog wraps Modal.
Example:
sheet.Sheet(
sheet.SheetTrigger(button.Button(g.Text("Open Settings"))),
sheet.SheetContent(
forgeui.SideRight,
sheet.SheetHeader(
sheet.SheetTitle("Settings"),
sheet.SheetDescription("Configure your preferences"),
),
html.Div(/* settings content */),
sheet.SheetFooter(
sheet.SheetClose(button.Button(g.Text("Close"))),
),
),
)
func SheetClose ¶
SheetClose wraps an element to close the sheet when clicked.
func SheetContent ¶
SheetContent creates the sheet content panel with specified side.
func SheetContentWithOptions ¶
func SheetContentWithOptions(props SheetContentProps, children ...g.Node) g.Node
SheetContentWithOptions creates sheet content with custom props
func SheetDescription ¶
SheetDescription creates the sheet description element.
func SheetFooter ¶
SheetFooter creates a footer section for action buttons.
func SheetHeader ¶
SheetHeader creates a header section for the sheet.
Types ¶
type DialogContentProps ¶
type DialogContentProps struct {
Size forgeui.Size
CloseOnOutsideClick bool
ShowClose bool
Class string
}
DialogContentProps defines configuration for dialog content
type DrawerProps ¶
type DrawerProps struct {
// Side specifies which edge the drawer slides in from
Side forgeui.Side
// Size controls the width (for left/right) or height (for top/bottom)
Size forgeui.Size
// CloseOnEscape enables closing when Escape key is pressed
CloseOnEscape bool
// CloseOnOutsideClick enables closing when clicking the backdrop
CloseOnOutsideClick bool
// ShowClose displays a close button
ShowClose bool
// Class adds additional CSS classes
Class string
}
DrawerProps defines configuration for a drawer component
type ModalProps ¶
type ModalProps struct {
// Size controls the maximum width of the modal
Size forgeui.Size
// CloseOnEscape enables closing the modal when Escape key is pressed
CloseOnEscape bool
// CloseOnOutsideClick enables closing when clicking the backdrop
CloseOnOutsideClick bool
// ShowClose displays a close button in the top-right corner
ShowClose bool
// Class adds additional CSS classes to the modal content
Class string
}
ModalProps defines configuration for a modal dialog