A class group is an array of Tailwind classes that modify the same CSS property. When multiple classes from the same group are passed to merge, only the last one is kept.
Defining Class Groups
Class groups can be defined in two ways:
- Simple Array: A flat list of class names.
Example:
["static", "fixed", "absolute", "relative", "sticky"] - Recursive Object: An object where keys are joined with elements in the array using a dash (
-). This is useful for classes like overflow-auto.
Example: { overflow: ["auto", "hidden", "visible", "scroll"] }
Using Validators for Arbitrary Values
If you cannot enumerate every class (e.g., classes with arbitrary values like fill-[color]), you can use a validator function. The function receives the class part (the string after the prefix) and must return a boolean.
To indicate a class that represents the DEFAULT state in Tailwind (where the preceding part is the end of the name), use an empty string "" as a class part.
Example: [{ filter: ["", "none"] }] resolves to filter and filter-none.
# Simple array group
position_class_group = ["static", "fixed", "absolute", "relative", "sticky"]
@merger.merge("static sticky relative") # → "relative"
# Recursive object group
overflow_class_group = [{ overflow: ["auto", "hidden", "visible", "scroll"] }]
# Group with a validator for arbitrary values
is_arbitrary_value = (class_part: string) => /^\[.+\]$/.test(class_part)
fill_class_group = [{ fill: ["current", IS_ARBITRARY_VALUE] }]