@@ -5,8 +5,9 @@ import Concur.React (HTML)
5
5
import Concur.React.DOM as D
6
6
import Concur.React.Props as P
7
7
import Control.Alt ((<|>))
8
- import Control.Applicative (pure , (*>))
9
- import Control.Bind (bind )
8
+ import Control.Applicative (pure )
9
+ import Control.Bind (bind , discard )
10
+ import Data.BooleanAlgebra (not )
10
11
import Data.Eq (class Eq , (==))
11
12
import Data.Function (($))
12
13
import Data.Maybe (Maybe (..))
@@ -29,12 +30,21 @@ import React.SyntheticEvent as R
29
30
-- A never-ending virtual keypad widget.
30
31
-- Allows the user to navigate and select a key. Displays the selected key.
31
32
keypadWidget :: forall a . Widget HTML a
32
- keypadWidget = liftEffect startListening *> go Enter " "
33
+ keypadWidget = go Enter " " <|> toggleEvents
33
34
where
34
35
go focus msg = do
35
36
keyPressed <- virtualKeyInput focus <|> D .div' [D .text msg]
36
37
go keyPressed $ " You clicked: " <> show keyPressed
37
38
39
+ -- On off button for key events
40
+ toggleEvents :: forall a . Widget HTML a
41
+ toggleEvents = go false
42
+ where
43
+ go enabled = do
44
+ _ <- D .button [P .onClick] [D .text $ if enabled then " stop listening" else " start listening" ]
45
+ liftEffect (if enabled then stopListening else startListening)
46
+ go (not enabled)
47
+
38
48
-- Displays a keypad with the supplied initial focus.
39
49
-- Allows the user to navigate and select a key. Returns the selected key.
40
50
virtualKeyInput :: Focus -> Widget HTML Key
0 commit comments