Skip to content

Commit

Permalink
feat(utils): add cn function for merging class names and its unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Callenowy committed Jan 31, 2024
1 parent 01c6b5f commit e5c5323
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/utils/cn.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { cn } from './cn';

describe('cn', () => {
it('should return a string with merged class names', () => {
const result = cn('class1', 'class2', 'class3');
expect(result).toBe('class1 class2 class3');
});

it('should handle empty inputs', () => {
const result = cn();
expect(result).toBe('');
});

it('should handle falsy inputs', () => {
const result = cn('class1', null, undefined, false, 0);
expect(result).toBe('class1');
});
});
4 changes: 4 additions & 0 deletions src/utils/cn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { clsx, type ClassValue } from 'clsx';
import { twMerge } from 'tailwind-merge';

export const cn = (...inputs: ClassValue[]) => twMerge(clsx(...inputs));

0 comments on commit e5c5323

Please sign in to comment.