first
This commit is contained in:
44
node_modules/vant/lib/utils/create/bem.js
generated
vendored
Normal file
44
node_modules/vant/lib/utils/create/bem.js
generated
vendored
Normal file
@ -0,0 +1,44 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.createBEM = createBEM;
|
||||
|
||||
/**
|
||||
* bem helper
|
||||
* b() // 'button'
|
||||
* b('text') // 'button__text'
|
||||
* b({ disabled }) // 'button button--disabled'
|
||||
* b('text', { disabled }) // 'button__text button__text--disabled'
|
||||
* b(['disabled', 'primary']) // 'button button--disabled button--primary'
|
||||
*/
|
||||
function gen(name, mods) {
|
||||
if (!mods) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (typeof mods === 'string') {
|
||||
return " " + name + "--" + mods;
|
||||
}
|
||||
|
||||
if (Array.isArray(mods)) {
|
||||
return mods.reduce(function (ret, item) {
|
||||
return ret + gen(name, item);
|
||||
}, '');
|
||||
}
|
||||
|
||||
return Object.keys(mods).reduce(function (ret, key) {
|
||||
return ret + (mods[key] ? gen(name, key) : '');
|
||||
}, '');
|
||||
}
|
||||
|
||||
function createBEM(name) {
|
||||
return function (el, mods) {
|
||||
if (el && typeof el !== 'string') {
|
||||
mods = el;
|
||||
el = '';
|
||||
}
|
||||
|
||||
el = el ? name + "__" + el : name;
|
||||
return "" + el + gen(el, mods);
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user