Skip to content

Commit 33309e2

Browse files
committed
feat: add tailwind-merge utility and update SearchBar component for class merging
1 parent e5db14e commit 33309e2

4 files changed

Lines changed: 35 additions & 1 deletion

File tree

package-lock.json

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"react": "^19.1.0",
3434
"react-dom": "^19.1.1",
3535
"superjson": "^2.2.2",
36+
"tailwind-merge": "^3.3.1",
3637
"webextension-polyfill": "^0.12.0",
3738
"zod": "^4.0.17"
3839
},

src/components/layout/SearchBar.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Search } from "lucide-react";
2+
import { cn } from "../../lib/cn";
23

34
interface SearchBarProps {
45
searchTerm: string;
@@ -14,7 +15,7 @@ export function SearchBar({
1415
className = "",
1516
}: SearchBarProps) {
1617
return (
17-
<div className={`flex-1 enter-animation-scale ${className}`}>
18+
<div className={cn("flex-1", "enter-animation-scale", className)}>
1819
<div className="relative">
1920
<Search className="absolute left-3 top-1/2 transform -translate-y-1/2 w-4 h-4 text-gray-400 dark:text-gray-500" />
2021
<input

src/lib/cn.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { clsx, type ClassValue } from "clsx";
2+
import { twMerge } from "tailwind-merge";
3+
4+
/**
5+
* Utility function that combines clsx and tailwind-merge for intelligent class merging.
6+
*
7+
* This function:
8+
* 1. Uses clsx to handle conditional classes and merge class arrays/objects
9+
* 2. Uses tailwind-merge to resolve CSS class conflicts intelligently
10+
*
11+
* @param inputs - Class values that can be strings, objects, arrays, or conditional
12+
* @returns A merged string with conflicting classes resolved
13+
*
14+
* @example
15+
* cn("px-2 py-1", "px-4") // "py-1 px-4" (px-2 is overridden)
16+
* cn("text-red-500", condition && "text-blue-500") // Conditional classes
17+
* cn({ "bg-blue-500": isActive, "bg-gray-500": !isActive }) // Object syntax
18+
*/
19+
export function cn(...inputs: ClassValue[]): string {
20+
return twMerge(clsx(inputs));
21+
}

0 commit comments

Comments
 (0)