This repository has been archived by the owner on Jul 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
confirmation_modal.go
72 lines (65 loc) · 1.93 KB
/
confirmation_modal.go
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
60
61
62
63
64
65
66
67
68
69
70
71
72
package components
import (
"github.com/maxence-charriere/go-app/v9/pkg/app"
)
// ConfirmationModal is a modal with callbacks intended to enable confirm destructive operations such as deleting something
type ConfirmationModal struct {
app.Compo
ID string // HTML ID of the modal; must be unique across the page
Icon string // Class of the icon to use to the left of the title; may be empty
Title string // Title of the modal
Class string // Class to be applied to the modal's outmost component
Body string // Body text of the modal
ActionClass string // Class to be applied to the modal's primary action
ActionLabel string // Text to display on the modal's primary action
CancelLabel string // Text to display on the modal's cancel action
CancelLink string // Link to display as the cancel action; if empty, `OnClose` is being called
OnClose func() // Handler to call when closing/cancelling the modal
OnAction func() // Handler to call when triggering the modal's primary action
}
func (c *ConfirmationModal) Render() app.UI {
actionClass := "pf-c-button"
if c.ActionClass == "" {
actionClass += " " + "pf-m-primary"
} else {
actionClass += " " + c.ActionClass
}
return &Modal{
ID: c.ID,
Icon: c.Icon,
Title: c.Title,
Class: c.Class,
Body: []app.UI{
app.Text(c.Body),
},
Footer: []app.UI{
app.Button().
Aria("disabled", "false").
Class(actionClass).
Type("button").
Text(c.ActionLabel).
OnClick(func(ctx app.Context, e app.Event) {
c.OnAction()
}),
app.If(
c.CancelLink == "",
app.Button().
Class("pf-c-button pf-m-link").
Type("button").
Text(c.CancelLabel).
OnClick(func(ctx app.Context, e app.Event) {
c.OnClose()
}),
).Else(
app.A().
Class("pf-c-button pf-m-link").
Target("_blank").
Href(c.CancelLink).
Text(c.CancelLabel),
),
},
OnClose: func() {
c.OnClose()
},
}
}