fix(hooks): namespace.is default state (#5941)

This commit is contained in:
三咲智子
2022-02-11 09:09:21 +08:00
committed by GitHub
parent eb1adcd491
commit f3e9e53f3d
2 changed files with 11 additions and 2 deletions

View File

@@ -18,11 +18,14 @@ const TestComp = {
ns.be('content', 'active'),
ns.em('content', 'active'),
ns.bem('body', 'content', 'active'),
ns.is('focus'),
ns.e(), // return empty string
ns.m(), // return empty string
ns.be(), // return empty string
ns.em(), // return empty string
ns.bem(), // return empty string
ns.is('hover', undefined), // return empty string
ns.is('clicked', false), // return empty string
],
},
'text'
@@ -67,6 +70,7 @@ describe('use-locale', () => {
'ep-table-content__active', // be('content', 'active')
'ep-table__content--active', // em('content', 'active')
'ep-table-body__content--active', // bem('body', 'content', 'active')
'is-focus', // is('focus')
].join('~')
)
})

View File

@@ -49,8 +49,13 @@ export const useNamespace = (block: string) => {
blockSuffix && element && modifier
? _bem(unref(namespace), block, blockSuffix, element, modifier)
: ''
const is = (name: string, state = true) =>
name && state ? `${statePrefix}${name}` : ''
const is: {
(name: string, state: boolean | undefined): string
(name: string): string
} = (name: string, ...args: [boolean | undefined] | []) => {
const state = args.length >= 1 ? args[0]! : true
return name && state ? `${statePrefix}${name}` : ''
}
return {
namespace,
b,