mithril-mdl
v1.1.0
Published
Material Design Lite components via mithril.js
Downloads
1
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:
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
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--fab
tomdl-button--mini-fab
color
: Setsmdl-button--colored
accent
: Setsmdl-button--accent
raised
: Setsmdl-shadow--4dp
primary
: Setsmdl-button--primary
Button
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
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__indeterminate
buffer
: 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
: 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)
Grid
Tag: div
Class: mdl-grid
Cell
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
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--scroll
waterfall
: Setsmdl-layout__header--waterfall
transparent
: Setsmdl-layout__header--transparent
Title
Tag: span
Class: mdl-layout-title
Header
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
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)