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.upgradeElement(element)
on element creation. 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 :)
Some attributes will be used by all components.
The following attributes will be carried over to the topmost resulting element:
id
class
config
disabled
- all attributes beginning with
on
(onclick
,onchange
, etc.)
And these attributes all apply some classes:
large
: appliesmdl-layout--large-screen-only
ripple
: appliesmdl-js-ripple-effect
active
: appliesis-active
primary
: appliesmdl-color--primary
primaryDark
: appliesmdl-color--primary-dark
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>);
Tag: button
Class: mdl-button mdl-js-button mdl-button--fab
Attributes:
mini
: Switchesmdl-button--fab
tomdl-button--mini-fab
color
: Setsmdl-button--colored
accent
: Setsmdl-button--accent
raised
: Setsmdl-shadow--4dp
primary
: Setsmdl-button--primary
Tag: button
Class: mdl-button mdl-js-button
Attributes:
color
: Setsmdl-button--colored
accent
: Setsmdl-button--accent
raised
: Setsmdl-button--raised
primary
: Setsmdl-button--primary
Tag: i
Class: material-icons
Tag: div
Class: mdl-layout__spacer
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__indeterminate
buffer
: A number which will be passed toMaterialProgress.setBuffer()
.
WARNING: The JavaScript portion of this is not tested across redraws and might break.
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
: setsvalue
of theinput
label
: sets text content of thelabel
error
: if this and pattern is set, adds aspan
, with this text set as its text content.pattern
: setspattern
property of theinput
floating
: setsmdl-textfield--floating-label
on thediv
outerClass
: additional classes to apply to thediv
(should be a string)
Tag: div
Class: mdl-grid
Tag: div
Class: mdl-cell
Attributes:
align
: setsmdl-cell--${align}
. Should betop
,stretch
orbottom
width
: setsmdl-cell--${width}-col
. Basically the number of columns for this cellphone
: setsmdl-cell--${phone}-col-phone
tablet
: setsmdl-cell--${tablet}-col-tablet
desktop
: setsmdl-cell--${desktop}-col-desktop
nophone
: setsmdl-cell--hide-phone
notablet
: setsmdl-cell--hide-tablet
nodesktop:
setsmdl-cell--hide-desktop
Tag: div
Class: mdl-layout__tab-bar
Tag: a
Class: mdl-layout__tab
Attributes:
href
: Transferred over
Tag: header
Class: mdl-layout__header
Attributes:
scroll
: Setsmdl-layout__header--scroll
waterfall
: Setsmdl-layout__header--waterfall
transparent
: Setsmdl-layout__header--transparent
Tag: span
Class: mdl-layout-title
Tag: div
Class: mdl-layout mdl-js-layout
Attributes:
drawer
: If this orfixedDrawer
is provided, setsmdl-layout--overlay-drawer-button
fixedDrawer
: Setsmdl-layout--fixed-drawer
fixedHeader
: Setsmdl-layout--fixed-header
fixedTabs
: Setsmdl-layout--fixed-tabs
Tag: div
Class: mdl-layout__header-row
Tag: div
Class: mdl-navigation
Tag: a
Class: mdl-navigation__link
Attributes:
href
: Transferred over
Tag: div
Class: mdl-layout__drawer
Tag: main
Class: mdl-layout__content
Tag: div
Class: mdl-card
Attributes:
shadow
: Setsmdl-shadow--${shadow}db
. Should be 2, 3, 4, 6, 8, or 16
Tag: div
Class: mdl-card--title
Attributes:
expand
: Setsmdl-card--expand
size
: Sets header tag of text. Should be 1 - 6
Tag: div
Class: mdl-card__supporting-text
Attributes:
expand
: Setsmdl-card--expand
border
: Setsmdl-card--border
- 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)