diff options
author | Joris | 2018-01-05 14:45:47 +0100 |
---|---|---|
committer | Joris | 2018-01-05 14:45:47 +0100 |
commit | ab17b6339d16970c3845ec4f153bfeed89eae728 (patch) | |
tree | 47c413dc13c2d21af47b965cb7b34e7dcbda805f /client/src/Component/Modal.hs | |
parent | 17d6a05756479388c91bc2e50f721fcea8a82d38 (diff) |
Add modal component
Diffstat (limited to 'client/src/Component/Modal.hs')
-rw-r--r-- | client/src/Component/Modal.hs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/client/src/Component/Modal.hs b/client/src/Component/Modal.hs new file mode 100644 index 0000000..bfb5e02 --- /dev/null +++ b/client/src/Component/Modal.hs @@ -0,0 +1,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 {} |