Skip to content

Commit 3ee7c73

Browse files
authored
Merge pull request #5 from wrabit/fix_and_features
Fix and features
2 parents c9874c1 + e008ab1 commit 3ee7c73

File tree

1 file changed

+19
-37
lines changed

1 file changed

+19
-37
lines changed

README.md

Lines changed: 19 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -22,55 +22,37 @@ from tailwind_merge import TailwindMerge
2222
# Initialize
2323
twm = TailwindMerge()
2424

25-
# --- Basic Merging ---
26-
# Conflicting classes for the same property (width, text color) are resolved, keeping the last one.
2725
result = twm.merge(
2826
"p-4 w-6 text-blue-500", # Initial classes
2927
"w-8 text-red-500" # Overrides for width and text color
3028
)
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+
5340
result = twm.merge("p-1", "p-[2px]")
54-
print(result)
55-
# Output: "p-[2px]"
41+
# "p-[2px]"
5642

57-
# --- Combining Multiple Strings ---
58-
# Pass multiple strings as arguments
5943
result = twm.merge(
6044
"flex items-center justify-center", # Base layout
6145
"justify-between", # Override justify
6246
"text-red-500", # Add text color
6347
"hover:text-blue-500 text-lg" # Add hover color and text size
6448
)
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"
7456
```
7557

7658
## Features

0 commit comments

Comments
 (0)