Skip to content

Instantly share code, notes, and snippets.

@DefectingCat
Created April 16, 2024 01:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DefectingCat/5fd43c63de236bb5d194c3ae957b04b7 to your computer and use it in GitHub Desktop.
Save DefectingCat/5fd43c63de236bb5d194c3ae957b04b7 to your computer and use it in GitHub Desktop.
Build css module className
/**
* 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