-
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { cx } from '../cx';
|
||||
|
||||
describe('cx', () => {
|
||||
it('joins truthy strings', () => {
|
||||
expect(cx('a', 'b', 'c')).toBe('a b c');
|
||||
});
|
||||
|
||||
it('filters out falsy values', () => {
|
||||
expect(cx('a', false, 'b', null, undefined, 'c')).toBe('a b c');
|
||||
});
|
||||
|
||||
it('returns empty string when all falsy', () => {
|
||||
expect(cx(false, null, undefined)).toBe('');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,6 @@
|
||||
type ClassValue = string | false | null | undefined;
|
||||
|
||||
/** Tiny className joiner. Filters out falsy values. */
|
||||
export function cx(...args: ClassValue[]): string {
|
||||
return args.filter(Boolean).join(' ');
|
||||
}
|
||||
Reference in New Issue
Block a user