Documentation
¶
Overview ¶
Package modal provides modal/dialog components.
Available variants:
- New() creates a modal dialog (template: "lvt:modal:default:v1")
- NewConfirm() creates a confirmation dialog (template: "lvt:modal:confirm:v1")
- NewSheet() creates a slide-in sheet (template: "lvt:modal:sheet:v1")
Open/close is handled client-side via onclick handlers and CSS classes.
Example usage:
// In your controller/state
DeleteConfirm: modal.NewConfirm("delete",
modal.WithTitle("Delete Item"),
modal.WithMessage("Are you sure?"),
)
// In your template
{{template "lvt:modal:confirm:v1" .DeleteConfirm}}
Index ¶
- func Templates() *base.TemplateSet
- type ConfirmModal
- func (c *ConfirmModal) ConfirmButtonClass() string
- func (c *ConfirmModal) HasIcon() bool
- func (c *ConfirmModal) HasMessage() bool
- func (c *ConfirmModal) HasTitle() bool
- func (c *ConfirmModal) Hide()
- func (c *ConfirmModal) IconClass() string
- func (c *ConfirmModal) IsDestructive() bool
- func (c *ConfirmModal) Show()
- func (c *ConfirmModal) Styles() styles.ConfirmModalStyles
- type ConfirmOption
- func WithCancelText(text string) ConfirmOption
- func WithConfirmDestructive(destructive bool) ConfirmOption
- func WithConfirmIcon(icon string) ConfirmOption
- func WithConfirmMessage(message string) ConfirmOption
- func WithConfirmOpen(open bool) ConfirmOption
- func WithConfirmStyled(styled bool) ConfirmOption
- func WithConfirmText(text string) ConfirmOption
- func WithConfirmTitle(title string) ConfirmOption
- type Modal
- type Option
- func WithCentered(centered bool) Option
- func WithCloseOnEscape(close bool) Option
- func WithCloseOnOverlay(close bool) Option
- func WithOpen(open bool) Option
- func WithScrollable(scrollable bool) Option
- func WithShowClose(show bool) Option
- func WithSize(size Size) Option
- func WithStyled(styled bool) Option
- func WithTitle(title string) Option
- type SheetModal
- func (s *SheetModal) HasTitle() bool
- func (s *SheetModal) Hide()
- func (s *SheetModal) IsBottom() bool
- func (s *SheetModal) IsHorizontal() bool
- func (s *SheetModal) IsLeft() bool
- func (s *SheetModal) IsRight() bool
- func (s *SheetModal) IsTop() bool
- func (s *SheetModal) IsVertical() bool
- func (s *SheetModal) PositionClass() string
- func (s *SheetModal) Show()
- func (s *SheetModal) SizeClass() string
- func (s *SheetModal) Styles() styles.SheetStyles
- func (s *SheetModal) Toggle()
- func (s *SheetModal) TransformClass() string
- type SheetOption
- func WithSheetCloseOnOverlay(close bool) SheetOption
- func WithSheetOpen(open bool) SheetOption
- func WithSheetPosition(position string) SheetOption
- func WithSheetShowClose(show bool) SheetOption
- func WithSheetSize(size Size) SheetOption
- func WithSheetStyled(styled bool) SheetOption
- func WithSheetTitle(title string) SheetOption
- type Size
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Templates ¶
func Templates() *base.TemplateSet
Templates returns the modal component's template set for registration with the LiveTemplate framework.
Example usage in main.go:
import "github.com/livetemplate/lvt/components/modal"
tmpl, err := livetemplate.New("app",
livetemplate.WithComponentTemplates(modal.Templates()),
)
Available templates:
- "lvt:modal:default:v1" - Standard modal dialog
- "lvt:modal:confirm:v1" - Confirmation dialog
- "lvt:modal:sheet:v1" - Slide-in sheet panel
Types ¶
type ConfirmModal ¶
type ConfirmModal struct {
base.Base
// Open indicates whether the modal is visible
Open bool
// Title is the dialog header
Title string
// Message is the confirmation message
Message string
// ConfirmText is the confirm button text
ConfirmText string
// CancelText is the cancel button text
CancelText string
// Destructive styles the confirm button as destructive
Destructive bool
// Icon shows an icon in the dialog
Icon string
}
ConfirmModal is a confirmation dialog.
func NewConfirm ¶
func NewConfirm(id string, opts ...ConfirmOption) *ConfirmModal
NewConfirm creates a confirmation dialog.
Example:
c := modal.NewConfirm("delete",
modal.WithConfirmTitle("Delete Item"),
modal.WithConfirmMessage("Are you sure you want to delete this item?"),
modal.WithConfirmDestructive(true),
)
func (*ConfirmModal) ConfirmButtonClass ¶
func (c *ConfirmModal) ConfirmButtonClass() string
ConfirmButtonClass returns CSS class for confirm button.
func (*ConfirmModal) HasIcon ¶
func (c *ConfirmModal) HasIcon() bool
HasIcon returns true if dialog has an icon.
func (*ConfirmModal) HasMessage ¶
func (c *ConfirmModal) HasMessage() bool
HasMessage returns true if dialog has a message.
func (*ConfirmModal) HasTitle ¶
func (c *ConfirmModal) HasTitle() bool
HasTitle returns true if dialog has a title.
func (*ConfirmModal) IconClass ¶
func (c *ConfirmModal) IconClass() string
IconClass returns CSS class for the icon.
func (*ConfirmModal) IsDestructive ¶
func (c *ConfirmModal) IsDestructive() bool
IsDestructive returns true if action is destructive.
func (*ConfirmModal) Styles ¶
func (c *ConfirmModal) Styles() styles.ConfirmModalStyles
Styles returns the resolved ConfirmModalStyles for this component.
type ConfirmOption ¶
type ConfirmOption func(*ConfirmModal)
ConfirmOption is a functional option for confirm dialogs.
func WithCancelText ¶
func WithCancelText(text string) ConfirmOption
WithCancelText sets the cancel button text.
func WithConfirmDestructive ¶
func WithConfirmDestructive(destructive bool) ConfirmOption
WithConfirmDestructive marks the action as destructive.
func WithConfirmIcon ¶
func WithConfirmIcon(icon string) ConfirmOption
WithConfirmIcon sets the dialog icon.
func WithConfirmMessage ¶
func WithConfirmMessage(message string) ConfirmOption
WithConfirmMessage sets the confirmation message.
func WithConfirmOpen ¶
func WithConfirmOpen(open bool) ConfirmOption
WithConfirmOpen sets the initial open state.
func WithConfirmStyled ¶
func WithConfirmStyled(styled bool) ConfirmOption
WithConfirmStyled enables Tailwind CSS styling.
func WithConfirmText ¶
func WithConfirmText(text string) ConfirmOption
WithConfirmText sets the confirm button text.
func WithConfirmTitle ¶
func WithConfirmTitle(title string) ConfirmOption
WithConfirmTitle sets the dialog title.
type Modal ¶
type Modal struct {
base.Base
// Open indicates whether the modal is visible
Open bool
// Title is the modal header
Title string
// Size of the modal
Size Size
// ShowClose shows the close button
ShowClose bool
// CloseOnOverlay closes modal when clicking overlay
CloseOnOverlay bool
// CloseOnEscape closes modal on Escape key
CloseOnEscape bool
// Centered vertically centers the modal
Centered bool
// Scrollable makes the modal body scrollable
Scrollable bool
}
Modal is a dialog component. Use template "lvt:modal:default:v1" to render.
func New ¶
New creates a modal dialog.
Example:
m := modal.New("settings",
modal.WithTitle("Settings"),
modal.WithSize(modal.SizeLg),
)
func (*Modal) Styles ¶
func (m *Modal) Styles() styles.ModalStyles
Styles returns the resolved ModalStyles for this component.
type Option ¶
type Option func(*Modal)
Option is a functional option for configuring modals.
func WithCentered ¶
WithCentered enables vertical centering.
func WithCloseOnEscape ¶
WithCloseOnEscape enables closing on Escape key.
func WithCloseOnOverlay ¶
WithCloseOnOverlay enables closing on overlay click.
func WithScrollable ¶
WithScrollable enables scrollable modal body.
func WithShowClose ¶
WithShowClose shows or hides the close button.
type SheetModal ¶
type SheetModal struct {
base.Base
// Open indicates whether the sheet is visible
Open bool
// Title is the sheet header
Title string
// Position is where the sheet slides from (left, right, top, bottom)
Position string
// Size controls the sheet width/height
Size Size
// ShowClose shows the close button
ShowClose bool
// CloseOnOverlay closes sheet when clicking overlay
CloseOnOverlay bool
}
SheetModal is a slide-in panel/sheet.
func NewSheet ¶
func NewSheet(id string, opts ...SheetOption) *SheetModal
NewSheet creates a slide-in sheet.
Example:
s := modal.NewSheet("filters",
modal.WithSheetTitle("Filters"),
modal.WithSheetPosition("right"),
)
func (*SheetModal) HasTitle ¶
func (s *SheetModal) HasTitle() bool
HasTitle returns true if sheet has a title.
func (*SheetModal) IsBottom ¶
func (s *SheetModal) IsBottom() bool
IsBottom returns true if position is bottom.
func (*SheetModal) IsHorizontal ¶
func (s *SheetModal) IsHorizontal() bool
IsHorizontal returns true if position is left or right.
func (*SheetModal) IsLeft ¶
func (s *SheetModal) IsLeft() bool
IsLeft returns true if position is left.
func (*SheetModal) IsRight ¶
func (s *SheetModal) IsRight() bool
IsRight returns true if position is right.
func (*SheetModal) IsVertical ¶
func (s *SheetModal) IsVertical() bool
IsVertical returns true if position is top or bottom.
func (*SheetModal) PositionClass ¶
func (s *SheetModal) PositionClass() string
PositionClass returns CSS classes for position.
func (*SheetModal) SizeClass ¶
func (s *SheetModal) SizeClass() string
SizeClass returns CSS class for sheet size.
func (*SheetModal) Styles ¶
func (s *SheetModal) Styles() styles.SheetStyles
Styles returns the resolved SheetStyles for this component.
func (*SheetModal) TransformClass ¶
func (s *SheetModal) TransformClass() string
TransformClass returns CSS transform for animation.
type SheetOption ¶
type SheetOption func(*SheetModal)
SheetOption is a functional option for sheet modals.
func WithSheetCloseOnOverlay ¶
func WithSheetCloseOnOverlay(close bool) SheetOption
WithSheetCloseOnOverlay enables closing on overlay click.
func WithSheetOpen ¶
func WithSheetOpen(open bool) SheetOption
WithSheetOpen sets the initial open state.
func WithSheetPosition ¶
func WithSheetPosition(position string) SheetOption
WithSheetPosition sets the sheet position.
func WithSheetShowClose ¶
func WithSheetShowClose(show bool) SheetOption
WithSheetShowClose shows or hides the close button.
func WithSheetStyled ¶
func WithSheetStyled(styled bool) SheetOption
WithSheetStyled enables Tailwind CSS styling.
func WithSheetTitle ¶
func WithSheetTitle(title string) SheetOption
WithSheetTitle sets the sheet title.