@@ -10,6 +10,8 @@ import Data.Maybe (Maybe(..), fromMaybe)
10
10
import React.Basic (Component , JSX , Self , StateUpdate (..), capture , createComponent , make )
11
11
import React.Basic.DOM as H
12
12
import React.Basic.DOM.Events (preventDefault , targetValue )
13
+ import Simple.JSON (class WriteForeign , writeImpl )
14
+ import Simple.JSON as SimpleJSON
13
15
14
16
type Props =
15
17
{ }
@@ -25,10 +27,19 @@ type Form =
25
27
type OptionLabel = String
26
28
type OptionValue = String
27
29
data Option = Option OptionLabel OptionValue
30
+
31
+ instance writeForeignOption :: WriteForeign Option where
32
+ writeImpl (Option label value) = do
33
+ writeImpl { label, value }
34
+
28
35
type Label = String
29
36
type Name = String
30
37
data Select = Select Name Label (Array Option )
31
38
39
+ instance writeForeignSelect :: WriteForeign Select where
40
+ writeImpl (Select name label options) = do
41
+ writeImpl { name, label, options }
42
+
32
43
type State =
33
44
{ built :: Maybe (Array Select )
34
45
, form :: Form
@@ -53,6 +64,10 @@ app = make component { initialState, render, update } {}
53
64
buildFromForm :: Form -> Array Select
54
65
buildFromForm { selects } = selects
55
66
67
+ jsonTextFromSelects :: Array Select -> String
68
+ jsonTextFromSelects selects =
69
+ SimpleJSON .writeJSON selects
70
+
56
71
initialForm :: Form
57
72
initialForm =
58
73
{ label: " "
@@ -190,6 +205,13 @@ render self@{ state: { built, form } } =
190
205
)
191
206
)
192
207
]
208
+ , H .div_
209
+ [ H .span_
210
+ [ H .text " selects (json)"
211
+ ]
212
+ , H .textarea
213
+ { readOnly: true , value: jsonTextFromSelects form.selects }
214
+ ]
193
215
]
194
216
, H .div_
195
217
[ H .button
0 commit comments