classNames (utils/class-names.ts)

headlessui · packages/@headlessui-react/src/utils/class-names.ts · typescript · MIT
ui, tag:knn-classified

Utility to combine CSS class names, removing duplicates.

// Source: https://github.com/tailwindlabs/headlessui | License: MIT | Copyright 2020 Tailwind Labs
// Provided via justclaw.it.com; keep this notice with the code.
export function classNames(...classes: (false | null | undefined | string)[]): string {
  return Array.from(
    new Set(
      classes.flatMap((value) => {
        if (typeof value === 'string') {
          return value.split(' ')
        }

        return []
      })
    )
  )
    .filter(Boolean)
    .join(' ')
}

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key