UNPKG

element-plus

Version:

A Component Library for Vue 3

48 lines (45 loc) 1.7 kB
import { computed, unref } from 'vue'; import { useGlobalConfig } from '../use-global-config/index.mjs'; const defaultNamespace = "el"; const statePrefix = "is-"; const _bem = (namespace, block, blockSuffix, element, modifier) => { let cls = `${namespace}-${block}`; if (blockSuffix) { cls += `-${blockSuffix}`; } if (element) { cls += `__${element}`; } if (modifier) { cls += `--${modifier}`; } return cls; }; const useNamespace = (block) => { const globalConfig = useGlobalConfig("namespace"); const namespace = computed(() => globalConfig.value || defaultNamespace); const b = (blockSuffix = "") => _bem(unref(namespace), block, blockSuffix, "", ""); const e = (element) => element ? _bem(unref(namespace), block, "", element, "") : ""; const m = (modifier) => modifier ? _bem(unref(namespace), block, "", "", modifier) : ""; const be = (blockSuffix, element) => blockSuffix && element ? _bem(unref(namespace), block, blockSuffix, element, "") : ""; const em = (element, modifier) => element && modifier ? _bem(unref(namespace), block, "", element, modifier) : ""; const bm = (blockSuffix, modifier) => blockSuffix && modifier ? _bem(unref(namespace), block, blockSuffix, "", modifier) : ""; const bem = (blockSuffix, element, modifier) => blockSuffix && element && modifier ? _bem(unref(namespace), block, blockSuffix, element, modifier) : ""; const is = (name, ...args) => { const state = args.length >= 1 ? args[0] : true; return name && state ? `${statePrefix}${name}` : ""; }; return { namespace, b, e, m, be, em, bm, bem, is }; }; export { useNamespace }; //# sourceMappingURL=index.mjs.map