-
Notifications
You must be signed in to change notification settings - Fork 11
/
if.go
112 lines (91 loc) · 2.46 KB
/
if.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package set
import "qlova.org/seed"
type data struct {
queries map[string]string
}
//Condition backs the If variable and can apply conditional styles.
type Condition struct {
query, portrait, landscape string
styles []Style
}
func (con Condition) AddTo(c seed.Seed) {
var data data
c.Load(&data)
if data.queries == nil {
data.queries = make(map[string]string)
}
var rules string
for _, style := range con.styles {
for _, rule := range style.Rules() {
rules += string(rule)
}
}
var q = `@media`
if con.portrait != "" {
q += ` screen and ` + con.portrait + ` and (orientation:portrait)`
if con.landscape != "" {
q += ","
}
}
if con.landscape != "" {
q += ` screen and ` + con.landscape + ` and (orientation:landscape)`
}
if con.portrait == "" && con.landscape == "" {
q += ` screen and ` + con.query
}
data.queries[q] = rules
c.Save(data)
}
func (con Condition) And(options ...seed.Option) seed.Option {
return seed.And(con, options...)
}
//Tiny applies the styles on tiny screens. ie. SmartWatches.
func (con Condition) Tiny(styles ...Style) Condition {
return Condition{
portrait: `(max-width: 9.9999rem)`,
landscape: `(max-height: 9.9999rem)`,
styles: styles,
}
}
func (con Condition) Small(styles ...Style) Condition {
return Condition{
portrait: `(min-width: 10rem) and (max-width: 29.999rem)`,
landscape: `(min-height: 10rem) and (max-height: 29.999rem)`,
styles: styles,
}
}
func (con Condition) Medium(styles ...Style) Condition {
return Condition{
portrait: `(min-width: 30rem) and (max-width: 49.999rem)`,
landscape: `(min-height: 30rem) and (max-height: 49.999rem)`,
styles: styles,
}
}
func (con Condition) Large(styles ...Style) Condition {
return Condition{
portrait: `(min-width: 50rem) and (max-width: 64.999rem)`,
landscape: `(min-height: 50rem) and (max-height: 64.999rem)`,
styles: styles,
}
}
func (con Condition) Huge(styles ...Style) Condition {
return Condition{
portrait: `(min-width: 65rem)`,
landscape: `(min-height: 65rem)`,
styles: styles,
}
}
func (con Condition) Portrait(styles ...Style) Condition {
con.query = `(orientation: portrait)`
con.landscape = ""
con.styles = append(con.styles, styles...)
return con
}
func (con Condition) Landscape(styles ...Style) Condition {
con.query = `(orientation: landscape)`
con.portrait = ""
con.styles = append(con.styles, styles...)
return con
}
//If allows conditional styles.
var If Condition