-
Notifications
You must be signed in to change notification settings - Fork 0
/
blocks.go
138 lines (122 loc) · 3.88 KB
/
blocks.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// Copyright 2018 Martin Bertschler.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package blocks
import (
"fmt"
"github.com/mbertschler/blocks/html"
"github.com/mbertschler/bunny/pkg/data"
)
func menuBlock() html.Block {
return html.Div(html.Class("ui two item menu"),
// html.A(append(html.Class("item"),
// html.AttrPair{Key: "onclick", Value: "listView()"}),
// html.I(html.Class("comments purple icon")),
// html.Text("Updates")),
html.A(append(html.Class("item"),
html.AttrPair{Key: "onclick", Value: "focusView()"}),
html.I(html.Class(focusNowIcon+" icon")),
html.Text("Focus")),
html.A(append(html.Class("item"),
html.AttrPair{Key: "onclick", Value: "listView()"}),
html.I(html.Class("clone violet icon")),
html.Text("Workspace")),
)
}
func listItemBlock(item data.Thing) html.Block {
switch it := item.(type) {
case data.Item:
return itemBlock(it)
case data.List:
return listBlock(it)
}
return nil
}
func itemBlock(item data.Item) html.Block {
var iconClass string
switch item.State {
case data.ItemOpen:
iconClass = "radio grey"
default:
iconClass = "checkmark green"
}
var focusIcon html.Block
switch item.Focus {
case data.FocusLater:
focusIcon = html.I(html.Class("large middle aligned icon " + focusLaterIcon).Styles("padding-left:10px"))
case data.FocusNow:
focusIcon = html.I(html.Class("large middle aligned icon " + focusNowIcon).Styles("padding-left:10px"))
case data.FocusWatch:
focusIcon = html.I(html.Class("large middle aligned icon " + focusWatchIcon).Styles("padding-left:10px"))
}
return html.Div(append(html.Class("item").Data("item-id", item.ID),
html.AttrPair{Key: "onclick", Value: fmt.Sprintf("itemView(%d)", item.ID)}),
html.I(html.Class("large middle aligned icon "+iconClass)),
focusIcon,
html.Div(html.Class("middle aligned content").Styles("color:rgba(0,0,0,0.87)"),
html.Text(item.Title),
),
)
}
func listBlock(list data.List) html.Block {
var iconClass string
switch list.State {
case data.ItemOpen:
iconClass = "violet square"
default:
iconClass = "purple square check"
}
return html.Div(append(html.Class("item").Data("list-id", list.ID),
html.AttrPair{Key: "onclick", Value: fmt.Sprintf("listView(%d)", list.ID)}),
html.I(html.Class("large middle aligned icon "+iconClass)),
html.Div(html.Class("middle aligned content").Styles("color:rgba(0,0,0,0.87)"),
html.Text(list.Title),
),
)
}
func gridColumnBlock(children ...html.Block) html.Block {
return html.Div(html.Class("ui grid"),
html.Div(html.Class("column").Styles("text-align:center"),
children...,
),
)
}
func buttonGroupBlock(buttons ...html.Block) html.Block {
return gridColumnBlock(
html.Div(html.Class("ui buttons"),
buttons...,
),
)
}
func floatedButton(class, action, text string) html.Block {
return floatedIconButton(class, action, "", text)
}
func floatedIconButton(class, action, icon, text string) html.Block {
var iconBlock html.Block
if icon != "" {
iconBlock = html.I(html.Class("icon " + icon))
}
return html.Button(append(
html.Class("ui "+class+" floated button"),
html.AttrPair{Key: "onclick", Value: action}),
iconBlock,
html.Text(text),
)
}
func compactIconButton(class, action, icon, text string) html.Block {
return html.Button(append(
html.Class("ui "+class+" compact button "),
html.AttrPair{Key: "onclick", Value: action}),
html.I(html.Class("icon "+icon)),
html.Text(text),
)
}