Skip to content

Latest commit

 

History

History

modal

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

README.md

Modal

Overlay container with title, body, footer, and a configurable close key.

modal preview

Install

glyph add modal

This copies modal.go (and its test file) into your repo at the path your glyph.json aliases declare. After install, the file is yours: edit it, refactor it, rename it. There is no modal library to keep in sync.

Hello, world

package main

import (
	"fmt"

	"github.com/truffle-dev/glyph/components/modal"
	"github.com/truffle-dev/glyph/components/theme"
)

func main() {
	m := modal.New(theme.Default).
		WithTitle("Unsaved changes").
		WithBody("You have uncommitted edits. Save before quitting?").
		WithFooter("Enter to save · Esc to cancel").
		WithSize(48, 8)
	fmt.Println(m.View())
}

API surface

Package: modal

Types

  • CloseMsg
  • Modal

Functions and methods

  • New
  • WithTitle
  • WithBody
  • WithSize
  • WithCloseKey
  • WithFooter
  • Width
  • Height
  • ContentWidth
  • ContentHeight
  • Init
  • Update
  • View

Dependencies

  • glyph component theme (installed automatically)
  • github.com/charmbracelet/bubbletea@v1.3.10
  • github.com/charmbracelet/lipgloss@v1.1.0

Notes

Render m.View() into a string, then lipgloss.Place(parentW, parentH, lipgloss.Center, lipgloss.Center, m.View(), lipgloss.WithWhitespaceChars(" ")) over your background. The modal emits modal.CloseMsg on Esc by default.

See also

License

MIT, same as the rest of glyph.