-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathToggle.purs
More file actions
39 lines (32 loc) · 853 Bytes
/
Toggle.purs
File metadata and controls
39 lines (32 loc) · 853 Bytes
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
module Components.Toggle where
import Prelude
import Data.Maybe (Maybe(..), fromMaybe)
import React.Basic.Classic (Component, JSX, createComponent, make)
import React.Basic.DOM as R
import React.Basic.DOM.Events (capture_)
type Props =
{ initialValue :: Boolean
}
data Action
= Toggle
component :: Component Props
component = createComponent "App"
toggle :: Props -> JSX
toggle = make component { initialState, render }
where
initialState =
Nothing
render self =
let
on = fromMaybe self.props.initialValue self.state
in
R.button
{ onClick: capture_ do
self.setState (Just <<< not <<< fromMaybe on)
, children:
[ R.text
if on
then "Classic On"
else "Classic Off"
]
}