-
Notifications
You must be signed in to change notification settings - Fork 3
/
Atom.elm
287 lines (235 loc) · 6.8 KB
/
Atom.elm
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
module View.Atom exposing
( a4Page
, attrsEl
, autolink
, bodyText
, bodyTextFont
, horizontalDivider
, id
, letterSpacing
, lineHeight
, monospacedFont
, pageColumn
, paragraph
, section
, tableOfContentsLine
, title1
, title2
, title3
, title4
, title5
, titleFont
, verticalDivider
)
import Element exposing (..)
import Element.Background as Background
import Element.Border as Border
import Element.Font as Font
import Html.Attributes
import Util.List exposing (splitInTwo)
import Util.String exposing (autolink)
import View.Colors as Colors
lineHeight : Int -> Element.Attribute msg
lineHeight lineHeight_ =
htmlAttribute <| Html.Attributes.style "line-height" (String.fromInt lineHeight_ ++ "px")
letterSpacing : Float -> Element.Attribute msg
letterSpacing letterSpacing_ =
htmlAttribute <| Html.Attributes.style "letter-spacing" (String.fromFloat letterSpacing_ ++ "px")
id : String -> Element.Attribute msg
id =
htmlAttribute << Html.Attributes.attribute "id"
title1 : List (Element.Attribute msg) -> String -> Element msg
title1 customAttrs title_ =
attrsEl
[ titleFont
, Font.size 26
, Font.bold
, Font.color Colors.grey
, letterSpacing 1
]
customAttrs
(text <| String.toUpper <| title_)
title2 : List (Element.Attribute msg) -> String -> Element msg
title2 customAttrs title_ =
attrsEl
[ titleFont
, Font.size 24
, Font.bold
, Font.color Colors.grey
, letterSpacing 0.5
]
customAttrs
(text title_)
title3 : List (Element.Attribute msg) -> String -> Element msg
title3 customAttrs title_ =
attrsEl
[ titleFont
, Font.size 16
, Font.color Colors.grey
, Font.semiBold
, letterSpacing -0.2
]
customAttrs
(text title_)
title4 : List (Element.Attribute msg) -> String -> Element msg
title4 customAttrs title_ =
attrsEl
[ titleFont
, Font.size 14
, Font.semiBold
, Font.color Colors.grey
]
customAttrs
(text title_)
title5 : List (Element.Attribute msg) -> String -> Element msg
title5 customAttrs title_ =
attrsEl
[ titleFont
, Font.size 14
, Font.color Colors.grey
]
customAttrs
(text title_)
verticalDivider : Element msg
verticalDivider =
el
[ width (px 5)
, Background.color Colors.lightestGrey
, height fill
]
(text " ")
horizontalDivider : Element msg
horizontalDivider =
el
[ height (px 5)
, Background.color Colors.lightGrey
, width fill
]
(text " ")
attrsEl : List (Element.Attribute msg) -> List (Element.Attribute msg) -> Element msg -> Element msg
attrsEl defaultAttrs customAttrs body =
el
(defaultAttrs ++ customAttrs)
body
pageColumn : List (Element.Attribute msg) -> List (Element msg) -> Element msg
pageColumn attrs body =
let
defaultAttrs =
[ width (fillPortion 1)
, height fill
, padding 20
, spacing 30
, Background.color Colors.white
]
in
column (defaultAttrs ++ attrs) body
section : List (Element.Attribute msg) -> List (Element msg) -> Element msg
section attrs body =
let
defaultAttrs =
[ spacing 15
, width fill
]
in
column (defaultAttrs ++ attrs) body
paragraph : List (Element.Attribute msg) -> List (Element msg) -> Element msg
paragraph customAttrs body =
let
defaultAttrs =
[ Font.alignLeft
, bodyTextFont
, Font.color Colors.grey
, Font.size 13
, Font.light
, lineHeight 18
]
in
Element.paragraph (defaultAttrs ++ customAttrs) body
bodyText : List (Element.Attribute msg) -> String -> Element msg
bodyText customAttrs text_ =
attrsEl
[ bodyTextFont, Font.color Colors.grey, Font.size 12, Font.light ]
customAttrs
(text text_)
tableOfContentsLine : String -> String -> Element msg
tableOfContentsLine leftText rightText =
row [ width fill, Font.family [] ]
[ el
[ Font.color
Colors.grey
, paddingEach { bottom = 0, left = 0, top = 0, right = 5 }
]
(title4 [ Font.family [], Font.size 11 ] leftText)
, el
[ width fill
, Border.dotted
, Border.color Colors.lightGrey
, Border.widthEach { bottom = 1, left = 0, top = 0, right = 0 }
, moveUp 7
, Font.color Colors.lightGrey
]
(text " ")
, el
[ Font.color Colors.grey
, paddingEach { bottom = 0, left = 5, top = 0, right = 0 }
]
(title4 [ Font.letterSpacing 0.1, Font.size 10 ] rightText)
]
autolink : String -> Element msg
autolink text_ =
let
config =
{ mapText = text
, mapLink = \link -> newTabLink [ Font.medium ] { url = link, label = text link }
}
in
case Util.String.autolink config text_ of
Ok paragraphItems ->
paragraph [] paragraphItems
Err _ ->
paragraph [] [ text text_ ]
bullets : List String -> Element msg
bullets items =
column [ spacing 15 ] <|
List.map
(\item ->
row [ spacing 3 ]
[ bodyText [ alignTop ] "•"
, paragraph [ Font.size 11, lineHeight 14 ] [ text item ]
]
)
items
---- FONTS ----
bodyTextFont =
Font.family
[ Font.typeface "Museo Sans"
, Font.typeface "Helvetica Neue"
, Font.typeface "Helvetica"
, Font.typeface "Arial"
, Font.typeface "Sans Serif"
]
titleFont =
Font.family
[ Font.typeface "Proxima Nova"
, Font.typeface "Helvetica Neue"
, Font.typeface "Helvetica"
, Font.typeface "Arial"
, Font.typeface "Sans Serif"
]
monospacedFont =
Font.family
[ Font.typeface "monospace" ]
---- PAGES ----
a4Page : List (Element.Attribute msg) -> (Element msg -> Element msg)
a4Page attrs =
let
pageAttrs =
[ htmlAttribute <| Html.Attributes.style "height" "210mm"
, htmlAttribute <| Html.Attributes.style "width" "297.3mm"
, htmlAttribute <| Html.Attributes.attribute "data-class" "page"
, htmlAttribute <| Html.Attributes.style "page-break-after" "always"
, htmlAttribute <| Html.Attributes.style "page-break-before" "always"
, htmlAttribute <| Html.Attributes.style "overflow" "hidden"
]
in
el (pageAttrs ++ attrs)