-
Notifications
You must be signed in to change notification settings - Fork 0
/
class.go
49 lines (40 loc) · 1.05 KB
/
class.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
package gomplements
// Class represents a CSS class, which is applied in the class attribute of a Element.
type Class string
// If allows to add a CSS class to an Element, only if a condition is met.
func (c Class) If(condition bool) Class {
if condition {
return c
}
return ""
}
// Classes contains multiple CSS classes to be applied in the class attribute of an Element.
type Classes []Class
// Classes implements Classeser.
func (c Classes) Classes() []Class {
return c
}
// If allows to add multiple CSS classes to an Element, only if a condition is met.
func (c Classes) If(cond bool) Classes {
if cond {
return c
}
return []Class{}
}
type conditionalClasses struct {
classes Classes
cond bool
}
func (c *conditionalClasses) ModifyParent(p Element) {
if c.cond {
p.With(c.classes)
}
}
// Classer is an interface that allows to add a CSS class to an HTML element.
type Classer interface {
Class() Class
}
// Classeser is an interface that allows to add multiple CSS classes to an HTML element.
type Classeser interface {
Classes() []Class
}