-
Notifications
You must be signed in to change notification settings - Fork 9
/
expandable_section.go
61 lines (53 loc) · 1.16 KB
/
expandable_section.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
package components
import "github.com/maxence-charriere/go-app/v9/pkg/app"
type ExpandableSection struct {
app.Compo
Open bool
OnToggle func()
Title string
ClosedTitle string
OpenTitle string
Body []app.UI
}
func (c *ExpandableSection) Render() app.UI {
return app.Div().
Class(func() string {
classes := "pf-c-expandable-section"
if c.Open {
classes += " pf-m-expanded"
}
return classes
}()).
Body(
app.Button().
Type("button").
Class("pf-c-expandable-section__toggle").
Aria("label", func() string {
message := c.ClosedTitle
if c.Open {
message = c.OpenTitle
}
return message
}()).
Aria("expanded", c.Open).
OnClick(func(ctx app.Context, e app.Event) {
c.OnToggle()
}).
Body(
app.Span().
Class("pf-c-expandable-section__toggle-icon").
Body(
app.I().
Class("fas fa-angle-right").
Aria("hidden", true),
),
app.Span().
Class("pf-c-expandable-section__toggle-text").
Text(c.Title),
),
app.Div().
Class("pf-c-expandable-section__content").
Hidden(!c.Open).
Body(c.Body...),
)
}