Created
June 14, 2022 02:07
-
-
Save aboqasem/ac42b5a2f00c514e97959bca96a865f0 to your computer and use it in GitHub Desktop.
Simple styling utilites
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
/** | |
* Join string class names and ignore falsy values. | |
* | |
* ### Example | |
* | |
* ```tsx | |
* <div className={`class1 class2 class3 ${condition ? 'class4' : ''} ${data ? 'class5' : ''}`} /> | |
* // becomes | |
* <div | |
* className={classNames( | |
* 'class1 class2 class3', | |
* condition && 'class4', | |
* data && 'class5', | |
* )} | |
* /> | |
* ``` | |
* | |
* @param classes List of string class names to join. | |
* @returns Joined list of strings. | |
*/ | |
export function classNames(...classes: (string | false | null | undefined | 0)[]) { | |
return classes.filter(Boolean).join(' '); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment