Last active
July 22, 2017 18:22
-
-
Save mmaz/5fc96b5554e0d8666ac7 to your computer and use it in GitHub Desktop.
add Google's Material Design Lite to Reflex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import GHCJS.DOM.Types (Element, unElement) | |
import GHCJS.DOM.Element (toElement) | |
import GHCJS.Prim (JSRef) | |
-- http://www.getmdl.io/started/index.html#dynamic | |
#ifdef __GHCJS__ | |
foreign import javascript unsafe "componentHandler.upgradeElement($1);" | |
materialInitJS :: JSRef Element -> IO () | |
#else | |
materialInitJS = error "y u no javascript?" | |
#endif | |
rippleButton :: MonadWidget t m => ... | |
rippleButton = do | |
... | |
(myReflexEl, _) <- el' "button" $ text "Ripples!!!" | |
let jsel = unElement $ toElement $ _el_element myReflexEl | |
pb <- getPostBuild | |
performEvent_ $ (liftIO $ materialInitJS jsel) <$ pb | |
... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<script language="javascript" src="rts.js"></script> | |
<script language="javascript" src="lib.js"></script> | |
<script language="javascript" src="out.js"></script> | |
<link rel="stylesheet" href="https://storage.googleapis.com/code.getmdl.io/1.0.4/material.indigo-pink.min.css"> | |
<script src="https://storage.googleapis.com/code.getmdl.io/1.0.4/material.min.js"></script> | |
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons"> | |
</head> | |
<body> | |
</body> | |
<script language="javascript" src="runmain.js" defer></script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The types have changed a little since this was originally posted. Here's the code I wrote for MDL text inputs:
FWIW, MDL's sample code also calls
componentHandler.upgradeElement()
before adding the element to the page, so that's probably not a problem. It does probably need to be called after the attributes are set (e.g.class="mdl-textfield"
), though, which I think happens in post-build?