You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Results get cached by default, so you don't need to worry about wasteful re-renders. The library uses a thread-safe [LRU cache](<https://en.wikipedia.org/wiki/Cache_replacement_policies#Least_recently_used_(LRU)>) which stores up to 500 different results. The cache size can be modified via config options.
57
-
-Expensive computations happen upfront so that `merge` calls without a cache hit stay fast.
58
-
-These computations are called lazily on the first call to `merge` to prevent it from impacting app startup performance if it isn't used initially.
54
+
- Results get cached by default, so you don't need to worry about wasteful re-renders. The library uses a thread-safe [LRU cache](<https://en.wikipedia.org/wiki/Cache_replacement_policies#Least_recently_used_(LRU)>) which stores up to 500 different results. The cache size can be modified via config options.
55
+
-Expensive computations happen upfront so that `merge` calls without a cache hit stay fast.
56
+
-These computations are called lazily on the first call to `merge` to prevent it from impacting app startup performance if it isn't used initially.
59
57
60
58
### Last conflicting class wins
61
59
@@ -150,10 +148,10 @@ If you're using a custom Tailwind config, you may need to configure tailwind-mer
150
148
151
149
The default [`twMerge`](#twmerge) function is configured in a way that you can still use it if all the following points apply to your Tailwind config:
152
150
153
-
-Only using color names which don't clash with other Tailwind class names
154
-
-Only deviating by number values from number-based Tailwind classes
155
-
-Only using font-family classes which don't clash with default font-weight classes
156
-
-Sticking to default Tailwind config for everything else
151
+
- Only using color names which don't clash with other Tailwind class names
152
+
- Only deviating by number values from number-based Tailwind classes
153
+
- Only using font-family classes which don't clash with default font-weight classes
154
+
- Sticking to default Tailwind config for everything else
157
155
158
156
If some of these points don't apply to you, you can test whether the merge still works as intended with your custom classes. Otherwise, you need create your own custom merge function by either extending the default tailwind-merge config or using a completely custom one.
159
157
@@ -165,9 +163,11 @@ The `tailwind_merge` config is an object with several keys:
165
163
166
164
```ruby
167
165
tailwindMergeConfig = {
168
-
# ↓ Set how many values should be stored in cache.
166
+
# ↓ *Optional* Define how many values should be stored in cache.
169
167
cache_size:500,
170
-
# ↓ Optional prefix from Tailwind config
168
+
# ↓ *Optional* modifier separator from Tailwind config
169
+
separator:':',
170
+
# ↓ *Optional* prefix from Tailwind config
171
171
prefix:'tw-',
172
172
theme: {
173
173
# Theme scales are defined here
@@ -283,17 +283,17 @@ If you modified one of these theme scales in your Tailwind config, you can add a
283
283
284
284
Here's a brief summary for each validator:
285
285
286
-
-`IS_LENGTH` checks whether a class part is a number (`3`, `1.5`), a fraction (`3/4`), a arbitrary length (`[3%]`, `[4px]`, `[length:var(--my-var)]`), or one of the strings `px`, `full` or `screen`.
287
-
-`IS_ARBITRARY_LENGTH` checks for arbitrary length values (`[3%]`, `[4px]`, `[length:var(--my-var)]`).
288
-
-`IS_INTEGER` checks for integer values (`3`) and arbitrary integer values (`[3]`).
289
-
-`IS_ARBITRARY_VALUE` checks whether the class part is enclosed in brackets (`[something]`)
290
-
-`IS_TSHIRT_SIZE`checks whether class part is a T-shirt size (`sm`, `xl`), optionally with a preceding number (`2xl`).
291
-
-`IS_ARBITRARY_SIZE` checks whether class part is an arbitrary value which starts with `size:` (`[size:200px_100px]`) which is necessary for background-size classNames.
292
-
-`IS_ARBITRARY_POSITION` checks whether class part is an arbitrary value which starts with `position:` (`[position:200px_100px]`) which is necessary for background-position classNames.
293
-
-`IS_ARBITRARY_URL` checks whether class part is an arbitrary value which starts with `url:` or `url(` (`[url('/path-to-image.png')]`, `url:var(--maybe-a-url-at-runtime)]`) which is necessary for background-image classNames.
294
-
-`IS_ARBITRARY_NUMBER` checks whether class part is an arbitrary value which starts with `number:` or is a number (`[number:var(--value)]`, `[450]`) which is necessary for font-weight classNames.
295
-
-`IS_ARBITRARY_SHADOW` checks whether class part is an arbitrary value which starts with the same pattern as a shadow value (`[0_35px_60px_-15px_rgba(0,0,0,0.3)]`), namely with two lengths separated by a underscore.
296
-
-`IS_ANY` always returns true. Be careful with this validator as it might match unwanted classes. I use it primarily to match colors or when it's certain there are no other class groups in a namespace.
286
+
-`IS_LENGTH` checks whether a class part is a number (`3`, `1.5`), a fraction (`3/4`), a arbitrary length (`[3%]`, `[4px]`, `[length:var(--my-var)]`), or one of the strings `px`, `full` or `screen`.
287
+
-`IS_ARBITRARY_LENGTH` checks for arbitrary length values (`[3%]`, `[4px]`, `[length:var(--my-var)]`).
288
+
-`IS_INTEGER` checks for integer values (`3`) and arbitrary integer values (`[3]`).
289
+
-`IS_ARBITRARY_VALUE` checks whether the class part is enclosed in brackets (`[something]`)
290
+
-`IS_TSHIRT_SIZE`checks whether class part is a T-shirt size (`sm`, `xl`), optionally with a preceding number (`2xl`).
291
+
-`IS_ARBITRARY_SIZE` checks whether class part is an arbitrary value which starts with `size:` (`[size:200px_100px]`) which is necessary for background-size classNames.
292
+
-`IS_ARBITRARY_POSITION` checks whether class part is an arbitrary value which starts with `position:` (`[position:200px_100px]`) which is necessary for background-position classNames.
293
+
-`IS_ARBITRARY_URL` checks whether class part is an arbitrary value which starts with `url:` or `url(` (`[url('/path-to-image.png')]`, `url:var(--maybe-a-url-at-runtime)]`) which is necessary for background-image classNames.
294
+
-`IS_ARBITRARY_NUMBER` checks whether class part is an arbitrary value which starts with `number:` or is a number (`[number:var(--value)]`, `[450]`) which is necessary for font-weight classNames.
295
+
-`IS_ARBITRARY_SHADOW` checks whether class part is an arbitrary value which starts with the same pattern as a shadow value (`[0_35px_60px_-15px_rgba(0,0,0,0.3)]`), namely with two lengths separated by a underscore.
296
+
-`IS_ANY` always returns true. Be careful with this validator as it might match unwanted classes. I use it primarily to match colors or when it's certain there are no other class groups in a namespace.
0 commit comments