mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-12-01 02:37:46 +08:00
feat(hooks): [use-namespace] add bm (#5475)
This commit is contained in:
parent
1a9a609444
commit
df3be7c661
@ -1,53 +1,54 @@
|
||||
import { unref, computed } from 'vue'
|
||||
import curry from 'lodash/curry'
|
||||
import { useGlobalConfig } from '../use-global-config'
|
||||
|
||||
const defaultNamespace = 'el'
|
||||
const statePrefix = 'is-'
|
||||
|
||||
const curryBem = curry(
|
||||
(
|
||||
namespace: string,
|
||||
block: string,
|
||||
blockSuffix: string,
|
||||
element: string,
|
||||
modifier: string
|
||||
) => {
|
||||
let cls = `${namespace}-${block}`
|
||||
if (blockSuffix) {
|
||||
cls += `-${blockSuffix}`
|
||||
}
|
||||
if (element) {
|
||||
cls += `__${element}`
|
||||
}
|
||||
if (modifier) {
|
||||
cls += `--${modifier}`
|
||||
}
|
||||
return cls
|
||||
const _bem = (
|
||||
namespace: string,
|
||||
block: string,
|
||||
blockSuffix: string,
|
||||
element: string,
|
||||
modifier: string
|
||||
) => {
|
||||
let cls = `${namespace}-${block}`
|
||||
if (blockSuffix) {
|
||||
cls += `-${blockSuffix}`
|
||||
}
|
||||
)
|
||||
if (element) {
|
||||
cls += `__${element}`
|
||||
}
|
||||
if (modifier) {
|
||||
cls += `--${modifier}`
|
||||
}
|
||||
return cls
|
||||
}
|
||||
|
||||
export const useNamespace = (block: string) => {
|
||||
const namespace = computed(
|
||||
() => useGlobalConfig('namespace').value || defaultNamespace
|
||||
)
|
||||
const b = (blockSuffix = '') =>
|
||||
curryBem(unref(namespace), block, blockSuffix, '', '')
|
||||
_bem(unref(namespace), block, blockSuffix, '', '')
|
||||
const e = (element?: string) =>
|
||||
element ? curryBem(unref(namespace), block, '', element, '') : ''
|
||||
element ? _bem(unref(namespace), block, '', element, '') : ''
|
||||
const m = (modifier?: string) =>
|
||||
modifier ? curryBem(unref(namespace), block, '', '')(modifier) : ''
|
||||
modifier ? _bem(unref(namespace), block, '', '', modifier) : ''
|
||||
const be = (blockSuffix?: string, element?: string) =>
|
||||
blockSuffix && element
|
||||
? curryBem(unref(namespace), block, blockSuffix, element, '')
|
||||
? _bem(unref(namespace), block, blockSuffix, element, '')
|
||||
: ''
|
||||
const em = (element?: string, modifier?: string) =>
|
||||
element && modifier
|
||||
? curryBem(unref(namespace), block, '')(element, modifier)
|
||||
? _bem(unref(namespace), block, '', element, modifier)
|
||||
: ''
|
||||
const bm = (blockSuffix?: string, modifier?: string) =>
|
||||
blockSuffix && modifier
|
||||
? _bem(unref(namespace), block, blockSuffix, '', modifier)
|
||||
: ''
|
||||
const bem = (blockSuffix?: string, element?: string, modifier?: string) =>
|
||||
blockSuffix && element && modifier
|
||||
? curryBem(unref(namespace), block)(blockSuffix, element, modifier)
|
||||
? _bem(unref(namespace), block, blockSuffix, element, modifier)
|
||||
: ''
|
||||
const is = (name: string, state = true) =>
|
||||
state ? `${statePrefix}${name}` : ''
|
||||
@ -58,6 +59,7 @@ export const useNamespace = (block: string) => {
|
||||
m,
|
||||
be,
|
||||
em,
|
||||
bm,
|
||||
bem,
|
||||
is,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user