@@ -22,55 +22,37 @@ from tailwind_merge import TailwindMerge
22
22
# Initialize
23
23
twm = TailwindMerge()
24
24
25
- # --- Basic Merging ---
26
- # Conflicting classes for the same property (width, text color) are resolved, keeping the last one.
27
25
result = twm.merge(
28
26
" p-4 w-6 text-blue-500" , # Initial classes
29
27
" w-8 text-red-500" # Overrides for width and text color
30
28
)
31
- print (result)
32
- # Output: "p-4 text-red-500 w-8" (Order might vary slightly based on processing, but content is correct)
33
-
34
- # --- Handling Specific Sides/Axes ---
35
- # Padding/Margin sides don't conflict with each other, but conflict with axis/all setters.
36
- result = twm.merge(" pl-4 pr-6" ) # Left and Right padding coexist
37
- print (result)
38
- # Output: "pl-4 pr-6"
39
-
40
- # --- Modifier Handling ---
41
- # Modifiers (hover:, focus:, md:, etc.) are handled correctly.
42
- # Conflicts are resolved independently for base classes and each modifier combination.
43
- result = twm.merge(" p-2 hover:p-4" , " p-3" ) # Base padding is overridden
44
- print (result)
45
- # Output: "hover:p-4 p-3"
46
-
47
- result = twm.merge(" hover:p-2 hover:p-4" , " focus:p-1" ) # Hover conflict resolved, focus added
48
- print (result)
49
- # Output: "hover:p-4 focus:p-1"
50
-
51
- # --- Arbitrary Value Support ---
52
- # Classes with arbitrary values are correctly grouped and merged.
29
+ # "p-4 text-red-500 w-8"
30
+
31
+ result = twm.merge(" pl-4" , " pr-6 pl-2" )
32
+ # "pl-2 pr-6"
33
+
34
+ result = twm.merge(" p-2 hover:p-4" , " p-3" )
35
+ # "hover:p-4 p-3"
36
+
37
+ result = twm.merge(" hover:p-2" , " focus:p-1 hover:p-4" )
38
+ # "hover:p-4 focus:p-1"
39
+
53
40
result = twm.merge(" p-1" , " p-[2px]" )
54
- print (result)
55
- # Output: "p-[2px]"
41
+ # "p-[2px]"
56
42
57
- # --- Combining Multiple Strings ---
58
- # Pass multiple strings as arguments
59
43
result = twm.merge(
60
44
" flex items-center justify-center" , # Base layout
61
45
" justify-between" , # Override justify
62
46
" text-red-500" , # Add text color
63
47
" hover:text-blue-500 text-lg" # Add hover color and text size
64
48
)
65
- print (result)
66
- # Output: "flex items-center justify-between text-red-500 hover:text-blue-500 text-lg"
67
-
68
-
69
- # --- Extensibility ---
70
- # Add your own custom class groups if needed
71
- # twm.add_rule('custom-icon-size', ['icon-sm', 'icon-md', 'icon-lg'])
72
- # result = twm.merge("icon-sm icon-lg")
73
- # print(result) # Output: "icon-lg"
49
+ # "flex items-center justify-between text-red-500 hover:text-blue-500 text-lg"
50
+ ```
51
+ ### Custom Rules
52
+ ``` python
53
+ twm.add_rule(' custom-icon-size' , [' icon-sm' , ' icon-md' , ' icon-lg' ])
54
+ twm.merge(" icon-sm icon-lg" )
55
+ # "icon-lg"
74
56
```
75
57
76
58
## Features
0 commit comments