Skip to content

Instantly share code, notes, and snippets.

@stephen-james
Created March 10, 2016 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephen-james/ab984b504f8d10a29b7e to your computer and use it in GitHub Desktop.
Save stephen-james/ab984b504f8d10a29b7e to your computer and use it in GitHub Desktop.
Mithril custom elements
// 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