Created
April 15, 2024 23:52
-
-
Save mflorida/58c5169f964ee150193aeb1e3e145d08 to your computer and use it in GitHub Desktop.
Don't use clsx. Resolve className for component from a series of arguments as strings or arrays of strings.
This file contains hidden or 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
function resolveClassName(className: string | string[], ...more: (string | string[])[]): string { | |
return Array.from( | |
new Set( | |
[''].concat(className, more.flat()).filter(Boolean).join(' ').split(/\s+/) | |
) | |
).reduce((classes, cur) => { | |
if ((cur = cur.trim())) { | |
classes.push(cur); | |
} | |
return classes; | |
}, [] as string[]).join(' '); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment