Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/sxzz/element-plus-solidjs. element-plus-solidjs.vercel.app
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091const statePrefix = 'is-'
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 createNamespace = (namespace: string, block: string) => { const b = (blockSuffix = '') => _bem(namespace, block, blockSuffix, '', '') const e = (element?: string) => element ? _bem(namespace, block, '', element, '') : '' const m = (modifier?: string) => modifier ? _bem(namespace, block, '', '', modifier) : '' const be = (blockSuffix?: string, element?: string) => blockSuffix && element ? _bem(namespace, block, blockSuffix, element, '') : '' const em = (element?: string, modifier?: string) => element && modifier ? _bem(namespace, block, '', element, modifier) : '' const bm = (blockSuffix?: string, modifier?: string) => blockSuffix && modifier ? _bem(namespace, block, blockSuffix, '', modifier) : '' const bem = (blockSuffix?: string, element?: string, modifier?: string) => blockSuffix && element && modifier ? _bem(namespace, block, blockSuffix, element, modifier) : '' const is: { (name: string, state: boolean | undefined): string (name: string): string } = (name: string, ...args: [boolean | undefined] | []) => { const state = args.length > 0 ? args[0]! : true return name && state ? `${statePrefix}${name}` : '' }
// for css var // --el-xxx: value; const cssVar = (object: Record<string, string>) => { const styles: Record<string, string> = {} for (const key of Object.keys(object)) { styles[`--${namespace}-${key}`] = object[key] } return styles } // with block const cssVarBlock = (object: Record<string, string>) => { const styles: Record<string, string> = {} for (const key of Object.keys(object)) { styles[`--${namespace}-${block}-${key}`] = object[key] } return styles }
const cssVarName = (name: string) => `--${namespace}-${name}` const cssVarBlockName = (name: string) => `--${namespace}-${block}-${name}`
return { namespace, b, e, m, be, em, bm, bem, is, // css cssVar, cssVarName, cssVarBlock, cssVarBlockName, }}
export type UseNamespaceReturn = ReturnType<typeof createNamespace>