Documentation
¶
Overview ¶
Package modal renders a bordered overlay container with an optional inlaid title, framed body, optional footer, and a configurable close key.
The modal owns its own box (title bar, body, footer) and the close-key handler. It does not own its position relative to a parent — that's the parent's job via lipgloss.Place. Keys the modal does not consume are returned untouched so the parent or contained widget can handle them.
Index ¶
- type CloseMsg
- type Modal
- func (m Modal) ContentHeight() int
- func (m Modal) ContentWidth() int
- func (m Modal) Height() int
- func (m Modal) Init() tea.Cmd
- func (m Modal) Update(msg tea.Msg) (Modal, tea.Cmd)
- func (m Modal) View() string
- func (m Modal) Width() int
- func (m Modal) WithBody(s string) Modal
- func (m Modal) WithCloseKey(key string) Modal
- func (m Modal) WithFooter(s string) Modal
- func (m Modal) WithSize(w, h int) Modal
- func (m Modal) WithTitle(s string) Modal
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CloseMsg ¶
type CloseMsg struct{}
CloseMsg is emitted when the user presses the configured close key.
type Modal ¶
type Modal struct {
// contains filtered or unexported fields
}
Modal is a Bubble Tea model for a bordered overlay container.
func New ¶
New constructs a Modal with sensible defaults: 40x10, Esc to close, no title/body/footer.
func (Modal) ContentHeight ¶
ContentHeight returns the inner usable height (outer height minus two border rows, minus one more if a footer is set).
func (Modal) ContentWidth ¶
ContentWidth returns the inner usable width (outer width minus two border columns). Callers can use this to size body content before handing it off via WithBody.
func (Modal) Update ¶
Update handles the close key only. Every other message — including other key events — is returned untouched so the parent or contained widget can route it.
func (Modal) WithBody ¶
WithBody sets the pre-rendered body string the modal frames. Multi-line bodies are split on "\n". Lines wider than the inner content width are truncated by lipgloss.MaxWidth (rune-aware).
func (Modal) WithCloseKey ¶
WithCloseKey sets the key that emits CloseMsg. Default is "esc". Pass an empty string to disable the close-on-key behavior entirely.
func (Modal) WithFooter ¶
WithFooter sets an optional one-line footer rendered just inside the bottom border (e.g. key hints). A non-empty footer subtracts one row from the content area.
