|
| 1 | +# purescript-materialize |
| 2 | + |
| 3 | +[](https://travis-ci.com/yehzhang/purescript-materialize) |
| 4 | +[](https://github.com/yehzhang/purescript-materialize/releases) |
| 5 | + |
| 6 | +[Materialize](https://materializecss.com/) bindings in PureScript, with a |
| 7 | +builtin [purescript-smolder](https://github.com/bodil/purescript-smolder)-style |
| 8 | +DSL. |
| 9 | + |
| 10 | +## Overview |
| 11 | + |
| 12 | +### Class DSL |
| 13 | + |
| 14 | +Class DSL is a domain-specific language that makes it easy to markup Materialize |
| 15 | +CSS classes. |
| 16 | + |
| 17 | +A statement in Class DSL starts with a subject, followed by required objects |
| 18 | + |
| 19 | +```purescript |
| 20 | +import Materialize.Color (Color, background, teal) |
| 21 | +
|
| 22 | +color :: Color |
| 23 | +color = background teal |
| 24 | +``` |
| 25 | + |
| 26 | +or optional objects. |
| 27 | + |
| 28 | +```purescript |
| 29 | +import Materialize.Buttons (Button, button, floating) |
| 30 | +import Materialize.Markup ((~)) |
| 31 | +import Materialize.Overriden (large) |
| 32 | +
|
| 33 | +plainButton :: Button |
| 34 | +plainButton = button |
| 35 | +
|
| 36 | +largeButton :: Button |
| 37 | +largeButton = button ~ large |
| 38 | +
|
| 39 | +floatingButton :: Button |
| 40 | +floatingButton = button ~ floating |
| 41 | +
|
| 42 | +largeFloatingButton :: Button |
| 43 | +largeFloatingButton = button ~ large ~ floating |
| 44 | +``` |
| 45 | + |
| 46 | +Class DSL is meant to be spoken along with Smolder DSL. Here is an example to |
| 47 | +describe a complex [Button](https://materializecss.com/buttons.html): |
| 48 | + |
| 49 | +```purescript |
| 50 | +import Data.Typelevel.Num (d1) |
| 51 | +import Text.Smolder.Markup (Markup, text, (!)) |
| 52 | +import Text.Smolder.HTML (div) |
| 53 | +import Prelude |
| 54 | +
|
| 55 | +import Materialize.Buttons (button, floating) |
| 56 | +import Materialize.Color (background, teal, lighten) |
| 57 | +import Materialize.Markup (classList, (~)) |
| 58 | +import Materialize.Overriden (large) |
| 59 | +import Materialize.Visibility (hide, on) |
| 60 | +import Materialize.Waves (waves, light) |
| 61 | +
|
| 62 | +
|
| 63 | +viewButton :: forall e. Markup e |
| 64 | +viewButton = |
| 65 | + div ! classList do |
| 66 | + button ~ large ~ floating |
| 67 | + background teal ~ lighten d1 |
| 68 | + waves ~ light |
| 69 | + hide ~ on large |
| 70 | + $ text "Click me" |
| 71 | +``` |
| 72 | + |
| 73 | +which renders to HTML: |
| 74 | + |
| 75 | +```html |
| 76 | +<div class="btn-large btn-floating teal lighten-1 waves-effect waves-light hide-on-large-only"> |
| 77 | + Click me |
| 78 | +</div> |
| 79 | +``` |
| 80 | + |
| 81 | +See [test cases](https://github.com/yehzhang/purescript-materialize/blob/master/test/Main.purs) |
| 82 | +for more examples. |
| 83 | + |
| 84 | +### DOM API |
| 85 | + |
| 86 | +Some material designs cannot be implemented with pure CSS, e.g., |
| 87 | +[Tooltips](https://materializecss.com/tooltips.html). Therefore, it is sometimes |
| 88 | +inevitable to interact with Materialize's API in JavaScript. Hopefully, included |
| 89 | +is a PureScript API that abstracts away the DOM manipulation required by the |
| 90 | +Materialize API. |
| 91 | + |
| 92 | +```purescript |
| 93 | +import Data.Traversable (traverse) |
| 94 | +import Effect (Effect) |
| 95 | +import Prelude |
| 96 | +import Web.DOM.ParentNode (ParentNode) |
| 97 | +
|
| 98 | +import Materialize.DOM (findElements, findInstances, init, open, destroy) |
| 99 | +import Materialize.Tooltips (Tooltip) |
| 100 | +
|
| 101 | +
|
| 102 | +initTooltipsAndOpen :: Effect ParentNode -> Effect Unit |
| 103 | +initTooltipsAndOpen parentNode = do |
| 104 | + _ :: Array Tooltip <- parentNode >>= findElements |
| 105 | + >>= traverse (init { enterDelay: 400.0 |
| 106 | + , outDuration: 40.0 |
| 107 | + }) |
| 108 | + >>= traverse open |
| 109 | + pure unit |
| 110 | +
|
| 111 | +destroyTooltips :: Effect ParentNode -> Effect Unit |
| 112 | +destroyTooltips parentNode = do |
| 113 | + _ :: Array Tooltip <- parentNode >>= findInstances >>= traverse destroy |
| 114 | + pure unit |
| 115 | +``` |
| 116 | + |
| 117 | +## Supported modules |
| 118 | + |
| 119 | +### CSS |
| 120 | + |
| 121 | +- [x] [Color](https://materializecss.com/color.html) |
| 122 | +- [x] [Grid](https://materializecss.com/grid.html) |
| 123 | +- [x] [Helpers](https://materializecss.com/helpers.html) |
| 124 | +- [x] [Media](https://materializecss.com/media-css.html) |
| 125 | +- [x] [Pulse](https://materializecss.com/pulse.html) |
| 126 | +- [x] [Shadow](https://materializecss.com/shadow.html) |
| 127 | +- [x] [Table](https://materializecss.com/table.html) |
| 128 | +- [x] [Transitions](https://materializecss.com/css-transitions.html) |
| 129 | +- [x] [Typography](https://materializecss.com/typography.html) |
| 130 | + |
| 131 | +### Components |
| 132 | + |
| 133 | +- [x] [Badges](https://materializecss.com/badges.html) |
| 134 | +- [x] [Buttons](https://materializecss.com/buttons.html) |
| 135 | +- [x] [Breadcrumbs](https://materializecss.com/breadcrumbs.html) |
| 136 | +- [x] [Cards](https://materializecss.com/cards.html) |
| 137 | +- [x] [Collections](https://materializecss.com/collections.html) |
| 138 | +- [x] [Floating Action Button](https://materializecss.com/floating-action-button.html) (Class only) |
| 139 | +- [x] [Footer](https://materializecss.com/footer.html) |
| 140 | +- [x] [Icons](https://materializecss.com/icons.html) |
| 141 | +- [x] [Navbar](https://materializecss.com/navbar.html) |
| 142 | +- [x] [Pagination](https://materializecss.com/pagination.html) |
| 143 | +- [x] [Preloader](https://materializecss.com/preloader.html) |
| 144 | + |
| 145 | +### JavaScript |
| 146 | + |
| 147 | +- [x] [Auto Init](https://materializecss.com/auto-init.html) |
| 148 | +- [x] [Carousel](https://materializecss.com/carousel.html) (Class only) |
| 149 | +- [ ] Collapsible |
| 150 | +- [ ] Dropdown |
| 151 | +- [ ] FeatureDiscovery |
| 152 | +- [x] [Media](https://materializecss.com/media.html) (Class only) |
| 153 | +- [ ] Modals |
| 154 | +- [ ] Parallax |
| 155 | +- [ ] Pushpin |
| 156 | +- [ ] Scrollspy |
| 157 | +- [ ] Sidenav |
| 158 | +- [ ] Tabs |
| 159 | +- [x] [Toasts](https://materializecss.com/toasts.html) |
| 160 | +- [x] [Tooltips](https://materializecss.com/tooltips.html) |
| 161 | +- [x] [Waves](https://materializecss.com/waves.html) |
| 162 | + |
| 163 | +### Forms |
| 164 | + |
| 165 | +- [ ] Autocomplete |
| 166 | +- [x] [Checkboxes](https://materializecss.com/checkboxes.html) |
| 167 | +- [x] [Chips](https://materializecss.com/chips.html) |
| 168 | +- [ ] Pickers |
| 169 | +- [x] [Radio Buttons](https://materializecss.com/radio-buttons.html) |
| 170 | +- [ ] Range |
| 171 | +- [x] [Select](https://materializecss.com/select.html) |
| 172 | +- [x] [Switches](https://materializecss.com/switches.html) |
| 173 | +- [x] [Text Inputs](https://materializecss.com/text-inputs.html) (Class only) |
| 174 | + |
| 175 | +(Pull requests are welcomed) :) |
| 176 | + |
| 177 | +## Installation |
| 178 | + |
| 179 | +``` |
| 180 | +bower install purescript-materialize |
| 181 | +``` |
| 182 | + |
| 183 | +Additionally, Materialize 1.0.0-rc needs to be installed. An easy way is to add |
| 184 | +the following line into the `<body>` block of `index.html`, before the |
| 185 | +`<script>` tag of PureScript code: |
| 186 | + |
| 187 | +```html |
| 188 | +<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-rc.2/js/materialize.min.js"></script> |
| 189 | +``` |
| 190 | + |
| 191 | +There are other ways to install Materialize, but please make sure that the |
| 192 | +gloabl Materialize object `M` is available. |
| 193 | + |
| 194 | +## Documentation |
| 195 | + |
| 196 | +Module documentation is [published on Pursuit](https://pursuit.purescript.org/packages/purescript-materialize). |
0 commit comments