@@ -17,7 +17,7 @@ import Data.String as String
17
17
import Data.String.NonEmpty (NonEmptyString , appendString , length , toString )
18
18
import Data.Symbol (SProxy (..))
19
19
import Effect (Effect )
20
- import Effect.Aff (Aff , Milliseconds (..), delay , error , throwError )
20
+ import Effect.Aff (Milliseconds (..), delay , error , throwError )
21
21
import Effect.Class (liftEffect )
22
22
import Effect.Random (randomRange )
23
23
import Lumi.Components.Button as Button
@@ -85,9 +85,8 @@ docs = unit # make component { initialState, render }
85
85
SetUser update ->
86
86
let
87
87
formProps =
88
- { loadColor: loadColor self.state.simulatePauses
89
- , loadColors: loadColors self.state.simulatePauses
90
- , readonly: self.state.readonly
88
+ { readonly: self.state.readonly
89
+ , simulatePauses: self.state.simulatePauses
91
90
}
92
91
in
93
92
self.setState \s -> s
@@ -166,11 +165,10 @@ docs = unit # make component { initialState, render }
166
165
[ userComponent
167
166
{ value: user
168
167
, onChange: send self <<< SetUser
169
- , loadColor: loadColor simulatePauses
170
- , loadColors: loadColors simulatePauses
171
168
, inlineTable
172
169
, forceTopLabels: forceTopLabels && not inlineTable
173
170
, readonly
171
+ , simulatePauses
174
172
}
175
173
, row
176
174
{ style: css { justifyContent: " flex-end" }
@@ -204,30 +202,6 @@ docs = unit # make component { initialState, render }
204
202
}
205
203
]
206
204
207
- loadColor simulatePauses c = do
208
- when simulatePauses do
209
- delay (Milliseconds 500.0 )
210
- case String .toLower c of
211
- " red" -> pure { label: " Red" , value: " red" }
212
- " green" -> pure { label: " Green" , value: " green" }
213
- " blue" -> pure { label: " Blue" , value: " blue" }
214
- " brown" -> pure { label: " Brown" , value: " brown" }
215
- " black" -> pure { label: " Black" , value: " black" }
216
- " white" -> pure { label: " White" , value: " white" }
217
- _ -> throwError (error " No color" )
218
-
219
- loadColors simulatePauses search = do
220
- when simulatePauses do
221
- delay (Milliseconds 1000.0 )
222
- pure
223
- [ { label: " Red" , value: " red" }
224
- , { label: " Green" , value: " green" }
225
- , { label: " Blue" , value: " blue" }
226
- , { label: " Brown" , value: " brown" }
227
- , { label: " Black" , value: " black" }
228
- , { label: " White" , value: " white" }
229
- ]
230
-
231
205
data Country
232
206
= BR
233
207
| US
@@ -297,21 +271,19 @@ type ValidatedPet =
297
271
userComponent
298
272
:: { value :: User
299
273
, onChange :: (User -> User ) -> Effect Unit
300
- , loadColor :: String -> Aff { label :: String , value :: String }
301
- , loadColors :: String -> Aff (Array { label :: String , value :: String } )
302
274
, inlineTable :: Boolean
303
275
, forceTopLabels :: Boolean
304
276
, readonly :: Boolean
277
+ , simulatePauses :: Boolean
305
278
}
306
279
-> JSX
307
280
userComponent = F .build userForm
308
281
309
282
userForm
310
283
:: forall props
311
284
. FormBuilder
312
- { loadColor :: String -> Aff { label :: String , value :: String }
313
- , loadColors :: String -> Aff (Array { label :: String , value :: String } )
314
- , readonly :: Boolean
285
+ { readonly :: Boolean
286
+ , simulatePauses :: Boolean
315
287
| props
316
288
}
317
289
User
@@ -448,14 +420,15 @@ userForm = ado
448
420
}
449
421
color <-
450
422
FT .column_ " Color"
451
- $ F .focus (prop (SProxy :: SProxy " color" ))
452
- $ F .asyncSelectByKey
453
- (SProxy :: SProxy " loadColor" )
454
- (SProxy :: SProxy " loadColors" )
455
- identity
456
- identity
457
- identity
458
- (R .text <<< _.label)
423
+ $ F .withProps \props ->
424
+ F .focus (prop (SProxy :: SProxy " color" ))
425
+ $ F .asyncSelectByKey
426
+ (loadColor props.simulatePauses)
427
+ (loadColors props.simulatePauses)
428
+ identity
429
+ identity
430
+ identity
431
+ (R .text <<< _.label)
459
432
in
460
433
{ name
461
434
, animal
@@ -507,6 +480,26 @@ userForm = ado
507
480
interval <- liftEffect $ randomRange 100.0 700.0
508
481
delay $ Milliseconds interval
509
482
483
+ loadColor simulatePauses c = do
484
+ when simulatePauses do
485
+ randomPause
486
+ case String .toLower c of
487
+ " red" -> pure { label: " Red" , value: " red" }
488
+ " green" -> pure { label: " Green" , value: " green" }
489
+ " blue" -> pure { label: " Blue" , value: " blue" }
490
+ _ -> throwError (error " No color" )
491
+
492
+ loadColors simulatePauses search = do
493
+ when simulatePauses do
494
+ randomPause
495
+ randomPause
496
+ pure
497
+ [ { label: " Red" , value: " red" }
498
+ , { label: " Green" , value: " green" }
499
+ , { label: " Blue" , value: " blue" }
500
+ ]
501
+
502
+
510
503
type Address =
511
504
{ name :: Validated String
512
505
, street :: Validated String
0 commit comments