mirror of
https://github.com/formbricks/formbricks.git
synced 2026-05-21 11:49:32 -05:00
refactor: allow arrays and falsy values in cn util
This commit is contained in:
@@ -552,4 +552,12 @@ describe("cn", () => {
|
||||
test("handles all undefined", () => {
|
||||
expect(cn(undefined, undefined)).toBe("");
|
||||
});
|
||||
|
||||
test("handles nested arrays of classes", () => {
|
||||
expect(cn(["foo", ["foo", ["foo", "bar"]]])).toBe("foo foo foo bar");
|
||||
});
|
||||
|
||||
test("handles nulls, booleans and undefined values", () => {
|
||||
expect(cn(null, true, false, undefined, [null, true, false, undefined])).toBe("");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -12,8 +12,14 @@ import { type TSurveyElement, type TSurveyElementChoice } from "@formbricks/type
|
||||
import { type TShuffleOption } from "@formbricks/types/surveys/types";
|
||||
import { ApiResponse, ApiSuccessResponse } from "@/types/api";
|
||||
|
||||
export const cn = (...classes: (string | undefined)[]) => {
|
||||
return twMerge(classes.filter(Boolean).join(" "));
|
||||
type ClassValue = string | boolean | null | undefined | ClassValue[];
|
||||
export const cn = (...classes: ClassValue[]): string => {
|
||||
return twMerge(
|
||||
classes
|
||||
.map((c) => (Array.isArray(c) ? cn(...c) : c))
|
||||
.filter((c): c is string => typeof c === "string" && c.length > 0)
|
||||
.join(" ")
|
||||
);
|
||||
};
|
||||
|
||||
export const getSecureRandom = (): number => {
|
||||
|
||||
Reference in New Issue
Block a user