forked from nobonobo/bootstrap4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
badge.go
59 lines (54 loc) · 1.58 KB
/
badge.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
package bootstrap4
import (
"github.com/gowasm/vecty"
"github.com/gowasm/vecty/elem"
"github.com/gowasm/vecty/prop"
)
// Badge ...
type Badge struct {
vecty.Core
ID string `vecty:"prop"`
Kind Kind `vecty:"prop"`
Pill bool `vecty:"prop"`
Markup vecty.MarkupList `vecty:"prop"`
Children vecty.MarkupOrChild `vecty:"prop"`
}
// Render ...
func (c *Badge) Render() vecty.ComponentOrHTML {
return elem.Span(
vecty.Markup(
vecty.MarkupIf(len(c.ID) > 0, prop.ID(c.ID)),
vecty.Class("badge"),
vecty.MarkupIf(len(c.Kind) == 0, vecty.Class("badge-"+KindPrimary.String())),
vecty.MarkupIf(len(c.Kind) > 0, vecty.Class("badge-"+c.Kind.String())),
vecty.MarkupIf(c.Pill, vecty.Class("badge-pill")),
),
c.Markup,
c.Children,
)
}
// BadgeLinks ...
type BadgeLinks struct {
vecty.Core
ID string `vecty:"prop"`
Kind Kind `vecty:"prop"`
Href string `vecty:"prop"`
Pill bool `vecty:"prop"`
Markup vecty.MarkupList `vecty:"prop"`
Children vecty.MarkupOrChild `vecty:"prop"`
}
// Render ...
func (c *BadgeLinks) Render() vecty.ComponentOrHTML {
return elem.Anchor(
vecty.Markup(
vecty.MarkupIf(len(c.ID) > 0, prop.ID(c.ID)),
vecty.Class("badge"),
vecty.MarkupIf(len(c.Kind) == 0, vecty.Class("badge-"+KindPrimary.String())),
vecty.MarkupIf(len(c.Kind) > 0, vecty.Class("badge-"+c.Kind.String())),
vecty.MarkupIf(c.Pill, vecty.Class("badge-pill")),
vecty.MarkupIf(len(c.Href) > 0, prop.Href(c.Href)),
),
c.Markup,
c.Children,
)
}