mithril-mdl
v1.1.0
Published
Material Design Lite components via mithril.js
Maintainers
Readme
Material Design Lite components via mithril.js
This module provides mithril components which construct html to be used with the Material Design Lite framework.
It provides a simple way to apply the needed classes to create MDL components. It spits out normal html elements, and calls componentHandler.upgradeDom() after each render pass. It is designed to work nicely with JSX (via babel or similar).
Not nearly all components are supported right now. I will continue adding them when the need comes up. Your are welcome to submit pull requests :)
Basics
Some attributes will be used by all components.
The following attributes will be carried over to the topmost resulting element:
idclassconfigdisabled- all attributes beginning with
on(onclick,onchange, etc.)
And these attributes all apply some classes:
large: appliesmdl-layout--large-screen-onlyripple: appliesmdl-js-ripple-effectactive: appliesis-activeprimary: appliesmdl-color--primaryprimaryDark: appliesmdl-color--primary-dark
Components
The following components can be imported from the module directly.
ES5
var Button = require('mithril-mdl').Button;ES6
import {Button} from 'mithril-mdl';You may then use them like so:
ES5
m.render(document.body, m(Button, {ripple: true, accent: true, raised: true}, 'I am a button!'));JSX
m.render(document.body, <Button ripple accent raised>I am a button!</Button>);Fab
Tag: button
Class: mdl-button mdl-js-button mdl-button--fab
Attributes:
mini: Switchesmdl-button--fabtomdl-button--mini-fabcolor: Setsmdl-button--coloredaccent: Setsmdl-button--accentraised: Setsmdl-shadow--4dpprimary: Setsmdl-button--primary
Button
Tag: button
Class: mdl-button mdl-js-button
Attributes:
color: Setsmdl-button--coloredaccent: Setsmdl-button--accentraised: Setsmdl-button--raisedprimary: Setsmdl-button--primary
Icon
Tag: i
Class: material-icons
Spacer
Tag: div
Class: mdl-layout__spacer
ProgressBar
Tag: div
Class: mdl-progress mdl-js-progress mdl-progress__indeterminate
Attributes:
progress: A number which will be passed toMaterialProgress.setProgress(). If set also removesmdl-progress__indeterminatebuffer: A number which will be passed toMaterialProgress.setBuffer().
WARNING: The JavaScript portion of this is not tested across redraws and might break.
TextInput
Tag: div wrapping input, label and optionally span
Class: mdl-textfield mdl-js-textfield, mdl-textfield__label and mdl-textfield__error
Attributes:
All default attributes (class, id etc.) are assigned to the input element. id has to be passed to allow for a label.
value: setsvalueof theinputlabel: sets text content of thelabelerror: if this and pattern is set, adds aspan, with this text set as its text content.pattern: setspatternproperty of theinputfloating: setsmdl-textfield--floating-labelon thedivouterClass: additional classes to apply to thediv(should be a string)
Grid
Tag: div
Class: mdl-grid
Cell
Tag: div
Class: mdl-cell
Attributes:
align: setsmdl-cell--${align}. Should betop,stretchorbottomwidth: setsmdl-cell--${width}-col. Basically the number of columns for this cellphone: setsmdl-cell--${phone}-col-phonetablet: setsmdl-cell--${tablet}-col-tabletdesktop: setsmdl-cell--${desktop}-col-desktopnophone: setsmdl-cell--hide-phonenotablet: setsmdl-cell--hide-tabletnodesktop:setsmdl-cell--hide-desktop
Tabs
Tag: div
Class: mdl-layout__tab-bar
Tab
Tag: a
Class: mdl-layout__tab
Attributes:
href: Transferred over
Layout
Tag: header
Class: mdl-layout__header
Attributes:
scroll: Setsmdl-layout__header--scrollwaterfall: Setsmdl-layout__header--waterfalltransparent: Setsmdl-layout__header--transparent
Title
Tag: span
Class: mdl-layout-title
Header
Tag: div
Class: mdl-layout mdl-js-layout
Attributes:
drawer: If this orfixedDraweris provided, setsmdl-layout--overlay-drawer-buttonfixedDrawer: Setsmdl-layout--fixed-drawerfixedHeader: Setsmdl-layout--fixed-headerfixedTabs: Setsmdl-layout--fixed-tabs
HeaderRow
Tag: div
Class: mdl-layout__header-row
Navigation
Tag: div
Class: mdl-navigation
NavLink
Tag: a
Class: mdl-navigation__link
Attributes:
href: Transferred over
Drawer
Tag: div
Class: mdl-layout__drawer
Content
Tag: main
Class: mdl-layout__content
Problems
- Not really reliable for partial redraws (still works, just flickering etc.), due to mdls js adding elements all over the place (or maybe me being an idiot, not sure)
