modal

package
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 10, 2026 License: MIT Imports: 3 Imported by: 0

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

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) Hide

func (c *ConfirmModal) Hide()

Hide closes the confirmation dialog.

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) Show

func (c *ConfirmModal) Show()

Show opens the confirmation dialog.

func (*ConfirmModal) Styles

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 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

func New(id string, opts ...Option) *Modal

New creates a modal dialog.

Example:

m := modal.New("settings",
    modal.WithTitle("Settings"),
    modal.WithSize(modal.SizeLg),
)

func (*Modal) HasHeader

func (m *Modal) HasHeader() bool

HasHeader returns true if modal should show header.

func (*Modal) HasTitle

func (m *Modal) HasTitle() bool

HasTitle returns true if modal has a title.

func (*Modal) Hide

func (m *Modal) Hide()

Hide closes the modal.

func (*Modal) Show

func (m *Modal) Show()

Show opens the modal.

func (*Modal) SizeClass

func (m *Modal) SizeClass() string

SizeClass returns CSS class for modal size.

func (*Modal) Styles

func (m *Modal) Styles() styles.ModalStyles

Styles returns the resolved ModalStyles for this component.

func (*Modal) Toggle

func (m *Modal) Toggle()

Toggle toggles modal visibility.

type Option

type Option func(*Modal)

Option is a functional option for configuring modals.

func WithCentered

func WithCentered(centered bool) Option

WithCentered enables vertical centering.

func WithCloseOnEscape

func WithCloseOnEscape(close bool) Option

WithCloseOnEscape enables closing on Escape key.

func WithCloseOnOverlay

func WithCloseOnOverlay(close bool) Option

WithCloseOnOverlay enables closing on overlay click.

func WithOpen

func WithOpen(open bool) Option

WithOpen sets the initial open state.

func WithScrollable

func WithScrollable(scrollable bool) Option

WithScrollable enables scrollable modal body.

func WithShowClose

func WithShowClose(show bool) Option

WithShowClose shows or hides the close button.

func WithSize

func WithSize(size Size) Option

WithSize sets the modal size.

func WithStyled

func WithStyled(styled bool) Option

WithStyled enables Tailwind CSS styling.

func WithTitle

func WithTitle(title string) Option

WithTitle sets the modal title.

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) Hide

func (s *SheetModal) Hide()

Hide closes the sheet.

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) IsTop

func (s *SheetModal) IsTop() bool

IsTop returns true if position is top.

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) Show

func (s *SheetModal) Show()

Show opens the sheet.

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) Toggle

func (s *SheetModal) Toggle()

Toggle toggles sheet visibility.

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 WithSheetSize

func WithSheetSize(size Size) SheetOption

WithSheetSize sets the sheet size.

func WithSheetStyled

func WithSheetStyled(styled bool) SheetOption

WithSheetStyled enables Tailwind CSS styling.

func WithSheetTitle

func WithSheetTitle(title string) SheetOption

WithSheetTitle sets the sheet title.

type Size

type Size string

Size defines the modal size.

const (
	SizeSm   Size = "sm"
	SizeMd   Size = "md"
	SizeLg   Size = "lg"
	SizeXl   Size = "xl"
	SizeFull Size = "full"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL