Fixed all compilation errors, improved responsive layout, added missing icons, and refined animations for a perfect user experience.
44 lines
1.1 KiB
TypeScript
44 lines
1.1 KiB
TypeScript
import { clsx, type ClassValue } from "clsx";
|
|
import { twMerge } from "tailwind-merge";
|
|
|
|
/**
|
|
* Utility functions for the application
|
|
*/
|
|
|
|
/**
|
|
* Combine tailwind classes safely
|
|
*/
|
|
export function cn(...inputs: ClassValue[]) {
|
|
return twMerge(clsx(inputs));
|
|
}
|
|
|
|
/**
|
|
* Debounce helper to prevent duplicate function calls
|
|
* @param func - The function to debounce
|
|
* @param delay - The delay in milliseconds
|
|
* @returns A debounced version of the function with a cleanup method
|
|
*/
|
|
export const debounce = <T extends (...args: unknown[]) => void>(
|
|
func: T,
|
|
delay: number
|
|
): (((...args: Parameters<T>) => void) & { cancel: () => void }) => {
|
|
let timeoutId: NodeJS.Timeout | undefined;
|
|
|
|
const debounced = (...args: Parameters<T>) => {
|
|
if (timeoutId !== undefined) {
|
|
clearTimeout(timeoutId);
|
|
}
|
|
timeoutId = setTimeout(() => func(...args), delay);
|
|
};
|
|
|
|
// Add cancel method to clear pending timeouts
|
|
debounced.cancel = () => {
|
|
if (timeoutId !== undefined) {
|
|
clearTimeout(timeoutId);
|
|
timeoutId = undefined;
|
|
}
|
|
};
|
|
|
|
return debounced;
|
|
};
|