-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExamples.purs
64 lines (46 loc) · 1.82 KB
/
Examples.purs
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
module AUI.Examples where
import Prelude
import AUI.AUI as A
import AUI.FreeApAUI as FA
import Control.Apply (lift2)
import Data.List (List(Nil), (:))
import Data.Traversable (traverse, sum)
import Math (pow)
-- Example 1
ui1 :: FA.FAUI Number
ui1 = pow <$> FA.numberField "Base" (state 2.0) <*> FA.numberField "Exponent" (state 10.0) where
state v = A.NumberFieldState { value : v, constraints : A.WithNumberConstraints { min : -100.0, max : 100.0, step : 0.5 }}
-- Example 2
ui2 :: FA.FAUI String
ui2 = FA.stringField "" "Hello" <> pure " " <> FA.stringField "" "World"
-- Example 3
ui3 :: FA.FAUI Int
ui3 = sum <$> traverse (\i -> FA.intField (label i) (state i)) [2, 13, 27, 42] where
min i = (-1) * i
max i = i * i
label i = "[" <> show (min i) <> ".." <> show (max i) <> "]"
state i = A.IntFieldState { value : i, constraints : A.WithIntConstraints { min : min i, max : max i }}
-- Example 4
ui4 :: FA.FAUI Number
ui4 = lift2 (/) (FA.numberField "" (state 5.0)) (FA.numberField "" (state 2.0)) where
state v = A.NumberFieldState { value : v, constraints : A.NoNumberConstraints }
-- Example 6
data Language = English | French | German
toString :: Language -> String
toString English = "english"
toString French = "french"
toString German = "german"
greet :: Language -> String
greet English = "Hello"
greet French = "Salut"
greet German = "Hallo"
ui6 :: FA.FAUI String
ui6 = (greet <$> (FA.selectbox "Language" (A.Select English (French : German : Nil) toString)))
<> pure " " <> FA.stringField "Name" "Pierre" <> pure "!"
-- Example 9
ui9 :: FA.FAUI Boolean
ui9 = lift2 (&&) (check A.Unchecked) (check A.Checked) where
check c = FA.checkbox "" (A.CheckboxState { status : c, checked : true, unchecked : false })
-- Example 11
ui11 :: FA.FAUI Int
ui11 = FA.button "Increment" (A.ButtonState { up : 0, down : 1 })