UNPKG

corporate-frontend-mithril

Version:

Corporate frontend MithrilJS modules

78 lines (63 loc) 1.65 kB
const strings = require('../../lib/helpers/strings'); module.exports = function() { let _id = `button-${strings.random()}`; let _style = ''; let _type = ''; let _htmlTag = 'button'; let _href = null; let _text = ''; let _styleSets = { 'primary': '.b-button--primary', 'secondary': '.b-button--secondary', 'tertiary': '.b-button--tertiary', }; let _iconStyleSets = { 'search': '.b-icon.b-icon--search.b-icon--side-right', }; let _nextFn = null; return { get id() { return _id; }, /** * Style: primary, secondary, tertiary */ get style() { return _style ? _styleSets[_style] : _styleSets.primary; }, set text(v) { _text = v; }, //TODO add validation get text() { return _text; }, set style(v) { _style = v; }, set nextFn(v) { _nextFn = v; }, set type(v) { _type = v; }, set htmlTag(v) { _htmlTag = v; }, get htmlTag() { return _htmlTag; }, get attrs() { return Object.assign( {'data-js-el' : _id}, _nextFn && {onclick: _nextFn}, _type == 'submit' && {type: _type}, _htmlTag == 'a' && {href: 'javascript:void(0);'}, _href && {href: _href}, ); }, get iconStyle() { return _iconStyleSets[_type]; }, }; };