Created
April 16, 2024 01:31
-
-
Save DefectingCat/5fd43c63de236bb5d194c3ae957b04b7 to your computer and use it in GitHub Desktop.
Build css module className
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* clsx | |
*/ | |
export function cn(...rest: string[]) { | |
return rest.join(' '); | |
} | |
/** | |
* 构建 cn 函数 | |
* | |
* Usage: | |
* | |
* ```ts | |
* import styles from 'index.module.less'; | |
* const cn = buildCN(styles); | |
* <div className={cn('left', 'align-center')}> | |
* ``` | |
*/ | |
export function buildCN(module: typeof import('*.less')) { | |
return (...rest: string[]) => { | |
return cn(rest.map<string>((className) => module[className]).join(' ')); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment