Skip to content

Instantly share code, notes, and snippets.

@alenaksu
Last active June 23, 2022 13:09
Show Gist options
  • Save alenaksu/e2fd8e1d1be02dc2e21967f8afb0697d to your computer and use it in GitHub Desktop.
Save alenaksu/e2fd8e1d1be02dc2e21967f8afb0697d to your computer and use it in GitHub Desktop.
classNames.ts
export const classNames = (
...classes: Array<string | string[] | Record<string]: boolean }>
): string | undefined => classes
.map(cls => cls?.constructor.name === 'Object' ? Object.keys(cls).filter(key => cls[key]) : cls)
.flat()
.filter(Boolean)
.join(' ') || undefined;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment