Last active
August 29, 2015 14:13
-
-
Save azproduction/d7f730a27b0fc26079a3 to your computer and use it in GitHub Desktop.
BEM class name generator curring – b_.with
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
var B = require('b_'); | |
var Array_of = function (any) { | |
return Array.prototype.slice.call(any); | |
}; | |
B.with = function () { | |
var b = this, | |
curriedArgs = Array_of(arguments); | |
return function () { | |
return b.apply(null, curriedArgs.concat(Array_of(arguments))); | |
}; | |
}; | |
var b = B.with('b-button'); | |
var e = B.with('b-button', 'elem'); | |
// After | |
function render() { | |
return ( | |
<div className={b()}> | |
<span className={b('icon', {type: 'add'})}></span> | |
<span className={b('text')}></span> | |
</div> | |
<div className={b({size: 'small'})}> | |
<span className={b('icon', {type: 'add'})}></span> | |
<span className={b('text')}></span> | |
</div> | |
); | |
} | |
// Before | |
function render() { | |
return ( | |
<div className={b('b-button')}> | |
<span className={b('b-button', 'icon', {type: 'add'})}></span> | |
<span className={b('b-button', 'text')}></span> | |
</div> | |
<div className={b('b-button', {size: 'small'})}> | |
<span className={b('b-button', 'icon', {type: 'add'})}></span> | |
<span className={b('b-button', 'text')}></span> | |
</div> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment