elm-ssr 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,344 @@
1
+ module ElmSsr.Html.Attributes exposing
2
+ ( attr
3
+ , class, classList, id, title, style
4
+ , href, target, rel
5
+ , src, height, width, alt
6
+ , type_, value, defaultValue, placeholder, selected, checked, autofocus, disabled, name, readonly, required, multiple
7
+ , method, action, enctype, novalidate, target_
8
+ , for, form
9
+ , max, min, step, cols, rows, wrap
10
+ , spellcheck, download, hreflang, media, ping, shape, coords, usemap, ismap, hreflang_, type__
11
+ , alt_, src_, srcset, usemap_, longdesc
12
+ )
13
+
14
+ {-| Plain HTML attributes. Mirrors `elm/html`'s `Html.Attributes`.
15
+
16
+ @docs attr
17
+ @docs class, classList, id, title, style
18
+ @docs href, target, rel
19
+ @docs src, height, width, alt
20
+ @docs type_, value, defaultValue, placeholder, selected, checked, autofocus, disabled, name, readonly, required, multiple
21
+ @docs method, action, enctype, novalidate, target_
22
+ @docs for, form
23
+ @docs max, min, step, cols, rows, wrap
24
+ @docs spellcheck, download, hreflang, media, ping, shape, coords, usemap, ismap, hreflang_, type__
25
+ @docs alt_, src_, srcset, usemap_, longdesc
26
+
27
+ -}
28
+
29
+ import ElmSsr.Html exposing (Attribute(..))
30
+
31
+
32
+ {-| Set an arbitrary attribute. -}
33
+ attr : String -> String -> Attribute msg
34
+ attr attributeName attributeValue =
35
+ Property attributeName attributeValue
36
+
37
+
38
+ class : String -> Attribute msg
39
+ class =
40
+ attr "class"
41
+
42
+
43
+ classList : List ( String, Bool ) -> Attribute msg
44
+ classList list =
45
+ list
46
+ |> List.filter Tuple.second
47
+ |> List.map Tuple.first
48
+ |> String.join " "
49
+ |> class
50
+
51
+
52
+ id : String -> Attribute msg
53
+ id =
54
+ attr "id"
55
+
56
+
57
+ title : String -> Attribute msg
58
+ title =
59
+ attr "title"
60
+
61
+
62
+ style : String -> String -> Attribute msg
63
+ style key val =
64
+ attr "style" (key ++ ":" ++ val)
65
+
66
+
67
+ href : String -> Attribute msg
68
+ href =
69
+ attr "href"
70
+
71
+
72
+ target : String -> Attribute msg
73
+ target =
74
+ attr "target"
75
+
76
+
77
+ rel : String -> Attribute msg
78
+ rel =
79
+ attr "rel"
80
+
81
+
82
+ src : String -> Attribute msg
83
+ src =
84
+ attr "src"
85
+
86
+
87
+ height : Int -> Attribute msg
88
+ height amount =
89
+ attr "height" (String.fromInt amount)
90
+
91
+
92
+ width : Int -> Attribute msg
93
+ width amount =
94
+ attr "width" (String.fromInt amount)
95
+
96
+
97
+ alt : String -> Attribute msg
98
+ alt =
99
+ attr "alt"
100
+
101
+
102
+ type_ : String -> Attribute msg
103
+ type_ =
104
+ attr "type"
105
+
106
+
107
+ value : String -> Attribute msg
108
+ value =
109
+ attr "value"
110
+
111
+
112
+ defaultValue : String -> Attribute msg
113
+ defaultValue =
114
+ attr "defaultValue"
115
+
116
+
117
+ placeholder : String -> Attribute msg
118
+ placeholder =
119
+ attr "placeholder"
120
+
121
+
122
+ selected : Bool -> Attribute msg
123
+ selected isSelected =
124
+ if isSelected then
125
+ attr "selected" "selected"
126
+
127
+ else
128
+ attr "selected" ""
129
+
130
+
131
+ checked : Bool -> Attribute msg
132
+ checked isChecked =
133
+ if isChecked then
134
+ attr "checked" "checked"
135
+
136
+ else
137
+ attr "checked" ""
138
+
139
+
140
+ autofocus : Bool -> Attribute msg
141
+ autofocus isAutofocus =
142
+ if isAutofocus then
143
+ attr "autofocus" "autofocus"
144
+
145
+ else
146
+ attr "autofocus" ""
147
+
148
+
149
+ disabled : Bool -> Attribute msg
150
+ disabled isDisabled =
151
+ if isDisabled then
152
+ attr "disabled" "disabled"
153
+
154
+ else
155
+ attr "disabled" ""
156
+
157
+
158
+ name : String -> Attribute msg
159
+ name =
160
+ attr "name"
161
+
162
+
163
+ readonly : Bool -> Attribute msg
164
+ readonly isReadonly =
165
+ if isReadonly then
166
+ attr "readonly" "readonly"
167
+
168
+ else
169
+ attr "readonly" ""
170
+
171
+
172
+ required : Bool -> Attribute msg
173
+ required isRequired =
174
+ if isRequired then
175
+ attr "required" "required"
176
+
177
+ else
178
+ attr "required" ""
179
+
180
+
181
+ multiple : Bool -> Attribute msg
182
+ multiple isMultiple =
183
+ if isMultiple then
184
+ attr "multiple" "multiple"
185
+
186
+ else
187
+ attr "multiple" ""
188
+
189
+
190
+ method : String -> Attribute msg
191
+ method =
192
+ attr "method"
193
+
194
+
195
+ action : String -> Attribute msg
196
+ action =
197
+ attr "action"
198
+
199
+
200
+ enctype : String -> Attribute msg
201
+ enctype =
202
+ attr "enctype"
203
+
204
+
205
+ novalidate : Bool -> Attribute msg
206
+ novalidate isNovalidate =
207
+ if isNovalidate then
208
+ attr "novalidate" "novalidate"
209
+
210
+ else
211
+ attr "novalidate" ""
212
+
213
+
214
+ target_ : String -> Attribute msg
215
+ target_ =
216
+ attr "target"
217
+
218
+
219
+ for : String -> Attribute msg
220
+ for =
221
+ attr "for"
222
+
223
+
224
+ form : String -> Attribute msg
225
+ form =
226
+ attr "form"
227
+
228
+
229
+ max : String -> Attribute msg
230
+ max =
231
+ attr "max"
232
+
233
+
234
+ min : String -> Attribute msg
235
+ min =
236
+ attr "min"
237
+
238
+
239
+ step : String -> Attribute msg
240
+ step =
241
+ attr "step"
242
+
243
+
244
+ cols : Int -> Attribute msg
245
+ cols amount =
246
+ attr "cols" (String.fromInt amount)
247
+
248
+
249
+ rows : Int -> Attribute msg
250
+ rows amount =
251
+ attr "rows" (String.fromInt amount)
252
+
253
+
254
+ wrap : String -> Attribute msg
255
+ wrap =
256
+ attr "wrap"
257
+
258
+
259
+ spellcheck : Bool -> Attribute msg
260
+ spellcheck isSpellcheck =
261
+ if isSpellcheck then
262
+ attr "spellcheck" "true"
263
+
264
+ else
265
+ attr "spellcheck" "false"
266
+
267
+
268
+ download : String -> Attribute msg
269
+ download =
270
+ attr "download"
271
+
272
+
273
+ hreflang : String -> Attribute msg
274
+ hreflang =
275
+ attr "hreflang"
276
+
277
+
278
+ media : String -> Attribute msg
279
+ media =
280
+ attr "media"
281
+
282
+
283
+ ping : String -> Attribute msg
284
+ ping =
285
+ attr "ping"
286
+
287
+
288
+ shape : String -> Attribute msg
289
+ shape =
290
+ attr "shape"
291
+
292
+
293
+ coords : String -> Attribute msg
294
+ coords =
295
+ attr "coords"
296
+
297
+
298
+ usemap : String -> Attribute msg
299
+ usemap =
300
+ attr "usemap"
301
+
302
+
303
+ ismap : Bool -> Attribute msg
304
+ ismap isIsmap =
305
+ if isIsmap then
306
+ attr "ismap" "ismap"
307
+
308
+ else
309
+ attr "ismap" ""
310
+
311
+
312
+ hreflang_ : String -> Attribute msg
313
+ hreflang_ =
314
+ attr "hreflang"
315
+
316
+
317
+ type__ : String -> Attribute msg
318
+ type__ =
319
+ attr "type"
320
+
321
+
322
+ alt_ : String -> Attribute msg
323
+ alt_ =
324
+ attr "alt"
325
+
326
+
327
+ src_ : String -> Attribute msg
328
+ src_ =
329
+ attr "src"
330
+
331
+
332
+ srcset : String -> Attribute msg
333
+ srcset =
334
+ attr "srcset"
335
+
336
+
337
+ usemap_ : String -> Attribute msg
338
+ usemap_ =
339
+ attr "usemap"
340
+
341
+
342
+ longdesc : String -> Attribute msg
343
+ longdesc =
344
+ attr "longdesc"
@@ -0,0 +1,95 @@
1
+ module ElmSsr.Html.Events exposing
2
+ ( onClick, onDoubleClick
3
+ , onMouseDown, onMouseUp, onMouseEnter, onMouseLeave, onMouseOver, onMouseOut
4
+ , onInput, onChange, onSubmit
5
+ , onBlur, onFocus
6
+ )
7
+
8
+ {-| Event handlers. Mirrors `elm/html`'s `Html.Events`.
9
+
10
+ Handlers are bridged by DOM path and event name, not by serializing `Msg`, so
11
+ author code stays plain Elm.
12
+
13
+ @docs onClick, onDoubleClick
14
+ @docs onMouseDown, onMouseUp, onMouseEnter, onMouseLeave, onMouseOver, onMouseOut
15
+ @docs onInput, onChange, onSubmit
16
+ @docs onBlur, onFocus
17
+
18
+ -}
19
+
20
+ import ElmSsr.Html exposing (Attribute(..), EventCapture(..), EventValue(..))
21
+
22
+
23
+ onClick : msg -> Attribute msg
24
+ onClick message =
25
+ EventHandler "click" NoEventData (\_ -> message)
26
+
27
+
28
+ onDoubleClick : msg -> Attribute msg
29
+ onDoubleClick message =
30
+ EventHandler "dblclick" NoEventData (\_ -> message)
31
+
32
+
33
+ onMouseDown : msg -> Attribute msg
34
+ onMouseDown message =
35
+ EventHandler "mousedown" NoEventData (\_ -> message)
36
+
37
+
38
+ onMouseUp : msg -> Attribute msg
39
+ onMouseUp message =
40
+ EventHandler "mouseup" NoEventData (\_ -> message)
41
+
42
+
43
+ onMouseEnter : msg -> Attribute msg
44
+ onMouseEnter message =
45
+ EventHandler "mouseenter" NoEventData (\_ -> message)
46
+
47
+
48
+ onMouseLeave : msg -> Attribute msg
49
+ onMouseLeave message =
50
+ EventHandler "mouseleave" NoEventData (\_ -> message)
51
+
52
+
53
+ onMouseOver : msg -> Attribute msg
54
+ onMouseOver message =
55
+ EventHandler "mouseover" NoEventData (\_ -> message)
56
+
57
+
58
+ onMouseOut : msg -> Attribute msg
59
+ onMouseOut message =
60
+ EventHandler "mouseout" NoEventData (\_ -> message)
61
+
62
+
63
+ onInput : (String -> msg) -> Attribute msg
64
+ onInput toMessage =
65
+ EventHandler "input" TargetValue (fromTargetValue toMessage)
66
+
67
+
68
+ onChange : (String -> msg) -> Attribute msg
69
+ onChange toMessage =
70
+ EventHandler "change" TargetValue (fromTargetValue toMessage)
71
+
72
+
73
+ onSubmit : msg -> Attribute msg
74
+ onSubmit message =
75
+ EventHandler "submit" NoEventData (\_ -> message)
76
+
77
+
78
+ onBlur : msg -> Attribute msg
79
+ onBlur message =
80
+ EventHandler "blur" NoEventData (\_ -> message)
81
+
82
+
83
+ onFocus : msg -> Attribute msg
84
+ onFocus message =
85
+ EventHandler "focus" NoEventData (\_ -> message)
86
+
87
+
88
+ fromTargetValue : (String -> msg) -> EventValue -> msg
89
+ fromTargetValue toMessage eventValue =
90
+ case eventValue of
91
+ StringValue currentValue ->
92
+ toMessage currentValue
93
+
94
+ NoValue ->
95
+ toMessage ""