forked from purescript-react/purescript-react-basic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathToggleButton.purs
42 lines (34 loc) · 903 Bytes
/
ToggleButton.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
module ToggleButton where
import Prelude
import Effect.Console (log)
import React.Basic (Component, JSX, StateUpdate(..), capture_, createComponent, make)
import React.Basic.DOM as R
component :: Component Props
component = createComponent "ToggleButton"
type Props =
{ label :: String
}
data Action
= Toggle
toggleButton :: Props -> JSX
toggleButton = make component
{ initialState:
{ on: false
}
, update: \self -> case _ of
Toggle ->
UpdateAndSideEffects
self.state { on = not self.state.on }
\nextSelf -> do
log $ "next state: " <> show nextSelf.state
, render: \self ->
R.button
{ onClick: capture_ self Toggle
, children:
[ R.text self.props.label
, R.text if self.state.on
then " On"
else " Off"
]
}
}