@morehook/component
Version:
关于 vue 的小型业务组件库
47 lines (42 loc) • 1.11 kB
JavaScript
const truthProp = {
type: Boolean,
default: true
};
const makeStringProp = (defaultVal) => ({
type: String,
default: defaultVal
});
function genBem(name, mods) {
if (!mods)
return "";
if (typeof mods === "string")
return ` ${name}--${mods}`;
if (Array.isArray(mods))
return mods.reduce((ret, item) => ret + genBem(name, item), "");
return Object.keys(mods).reduce((ret, key) => ret + (mods[key] ? genBem(name, key) : ""), "");
}
function createBEM(name) {
return (el, mods) => {
if (el && typeof el !== "string") {
mods = el;
el = "";
}
el = el ? `${name}__${el}` : name;
return `${el}${genBem(el, mods)}`;
};
}
function createNamespace(name) {
const prefixedName = `fastuse-${name}`;
return [prefixedName, createBEM(prefixedName)];
}
function withInstall(options) {
options.install = (app) => {
const { name } = options;
if (name) {
app.component(name, options);
}
};
return options;
}
const extend = Object.assign;
export { createNamespace as c, extend as e, makeStringProp as m, truthProp as t, withInstall as w };