blob: bfb5e0216e22f6c48804970479395ee5a8481311 (
plain)
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
|
{-# LANGUAGE ScopedTypeVariables #-}
module Component.Modal
( ModalIn(..)
, ModalOut(..)
, modal
) where
import qualified Data.Map as M
import Reflex.Dom (Event, MonadWidget)
import qualified Reflex.Dom as R
data ModalIn t m = ModalIn
{ _modalIn_show :: Event t ()
, _modalIn_content :: m ()
}
data ModalOut = ModalOut {}
modal :: forall t m. MonadWidget t m => ModalIn t m -> m ModalOut
modal modalIn = do
rec
showModal <- R.holdDyn False $ R.leftmost
[ True <$ _modalIn_show modalIn
, False <$ curtainClick
]
let attr = flip fmap showModal (\s -> M.fromList $
[ ("style", if s then "display:block" else "display:none")
, ("class", "modal")
])
curtainClick <- R.elDynAttr "div" attr $ do
(curtain, _) <- R.elAttr' "div" (M.singleton "class" "curtain") $ R.blank
R.divClass "content" $ _modalIn_content modalIn
return $ R.domEvent R.Click curtain
return $ ModalOut {}
|