Created
March 10, 2016 14:32
-
-
Save stephen-james/ab984b504f8d10a29b7e to your computer and use it in GitHub Desktop.
Mithril custom elements
This file contains 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
// Primitive example of creating a helper library to describe elements | |
var m = require('mithril'); | |
var materialElements = ['textfield']; | |
var mt = function(selector, options, children) { | |
if (selector === 'textfield') { | |
return m('div.mdl-textfield.mdl-js-textfield.mdl-textfield--floating-label', [ | |
m('input.mdl-textfield__input', { | |
id: options.id, | |
type: 'text', | |
oninput: m.withAttr('value', options.value) | |
}, options.value()), | |
m('label.mdl-textfield__label', { for: options.id}, options.label) | |
]); | |
} | |
if (selector === 'button') { | |
return m('button.mdl-button.mdl-js-button.mdl-button--raised.mdl-button--colored', options, children); | |
} | |
return m('div.material-unknown'); | |
}; | |
module.exports = mt; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment