blob: 3a5788065d0ac987d6f67a16e2e97f5d9f2a831a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
package tui
import "github.com/charmbracelet/lipgloss/v2"
type ModalType int
const (
ModalTypeSearch ModalType = iota
ModalTypeClient
ModalTypeProject
ModalTypeDeleteConfirmation
ModalTypeEntry
)
type ModalBoxModel struct {
Active bool
Type ModalType
}
func (m ModalBoxModel) RenderCenteredOver(mainContent string, app AppModel) string {
if !m.Active {
return mainContent
}
modalContent := m.Render()
base := lipgloss.NewLayer(mainContent)
overlayWidth := 60
overlayHeight := 5
overlayLeft := (app.width - overlayWidth) / 2
overlayTop := (app.height - overlayHeight) / 2
overlayStyle := lipgloss.NewStyle().Height(overlayHeight).Width(overlayWidth).Border(lipgloss.RoundedBorder()).BorderForeground(lipgloss.Color("238"))
overlay := lipgloss.NewLayer(overlayStyle.Render(modalContent)).Width(overlayWidth).Height(overlayHeight)
canvas := lipgloss.NewCanvas(
base.Z(0),
overlay.X(overlayLeft).Y(overlayTop).Z(1),
)
return canvas.Render()
}
func (m ModalBoxModel) Render() string {
switch m.Type {
case ModalTypeSearch:
return "SEARCH BOX"
default: // REMOVE ME
return "DEFAULT CONTENT"
}
}
func (m *ModalBoxModel) activate(t ModalType) {
m.Active = true
m.Type = t
}
|