Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/tailwind_merge/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -769,8 +769,8 @@ module Config
{
"font" => [
THEME_FONT_WEIGHT,
IS_ARBITRARY_VARIABLE,
IS_ARBITRARY_NUMBER,
IS_ARBITRARY_VARIABLE_WEIGHT,
IS_ARBITRARY_WEIGHT,
],
},
],
Expand Down Expand Up @@ -799,7 +799,7 @@ module Config
# Font Family
# @see https://tailwindcss.com/docs/font-family
##
"font-family" => [{ "font" => [IS_ARBITRARY_VARIABLE_FAMILY_NAME, IS_ARBITRARY_VALUE, THEME_FONT] }],
"font-family" => [{ "font" => [IS_ARBITRARY_VARIABLE_FAMILY_NAME, IS_ARBITRARY_FAMILY_NAME, THEME_FONT] }],
##
# Font Variant Numeric
# @see https://tailwindcss.com/docs/font-variant-numeric
Expand Down
16 changes: 16 additions & 0 deletions lib/tailwind_merge/validators.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ def integer?(x)
arbitrary_value?(value, IS_LABEL_NUMBER, IS_NUMBER)
}

IS_ARBITRARY_WEIGHT = ->(value) {
arbitrary_value?(value, IS_LABEL_WEIGHT, IS_ANY)
}

IS_ARBITRARY_FAMILY_NAME = ->(value) {
arbitrary_value?(value, IS_LABEL_FAMILY_NAME, IS_NEVER)
}

IS_ARBITRARY_POSITION = ->(value) {
arbitrary_value?(value, IS_LABEL_POSITION, IS_NEVER)
}
Expand Down Expand Up @@ -142,6 +150,10 @@ def integer?(x)
arbitrary_variable?(value, IS_LABEL_SHADOW, should_match_no_label: true)
}

IS_ARBITRARY_VARIABLE_WEIGHT = ->(value) {
arbitrary_variable?(value, IS_LABEL_WEIGHT, should_match_no_label: true)
}

############
# Labels
############
Expand Down Expand Up @@ -170,6 +182,10 @@ def integer?(x)
label == "family-name"
}

IS_LABEL_WEIGHT = ->(label) {
label == "number" || label == "weight"
}

IS_LABEL_SHADOW = ->(label) {
label == "shadow"
}
Expand Down
2 changes: 1 addition & 1 deletion lib/tailwind_merge/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module TailwindMerge
VERSION = "1.3.2"
VERSION = "1.3.3"
end
11 changes: 11 additions & 0 deletions test/test_arbitrary_values.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,21 @@ def test_handles_ambiguous_arbitrary_values_correctly
assert_equal("bg-[percentage:30%] bg-[length:200px_100px]", @merger.merge("bg-cover bg-[percentage:30%] bg-[size:200px_100px] bg-[length:200px_100px]"))
assert_equal("bg-linear-to-r", @merger.merge("bg-none bg-[url(.)] bg-[image:.] bg-[url:.] bg-[linear-gradient(.)] bg-linear-to-r"))
assert_equal("border-[color-mix(in_oklab,var(--background),var(--calendar-color)_30%)] border", @merger.merge("border-[color-mix(in_oklab,var(--background),var(--calendar-color)_30%)] border"))

assert_equal("font-[600]", @merger.merge("font-[400] font-[600]"))
assert_equal("font-[var(--b)]", @merger.merge("font-[var(--a)] font-[var(--b)]"))
assert_equal("font-[var(--b)]", @merger.merge("font-[weight:var(--a)] font-[var(--b)]"))
assert_equal("font-[weight:var(--b)]", @merger.merge("font-[400] font-[weight:var(--b)]"))
assert_equal("font-[weight:var(--b)]", @merger.merge("font-[weight:var(--a)] font-[weight:var(--b)]"))
assert_equal("font-[family-name:var(--a)] font-[var(--b)]", @merger.merge("font-[family-name:var(--a)] font-[var(--b)]"))
end

def test_handles_arbitrary_custom_properties_correctly
assert_equal("bg-(--other-red) bg-(position:-my-pos)", @merger.merge("bg-red bg-(--other-red) bg-bottom bg-(position:-my-pos)"))
assert_equal("shadow-(--some-other-shadow) shadow-(color:--some-color)", @merger.merge("shadow-xs shadow-(shadow:--something) shadow-red shadow-(--some-other-shadow) shadow-(color:--some-color)"))

assert_equal("font-(--b)", @merger.merge("font-(--a) font-(--b)"))
assert_equal("font-(--b)", @merger.merge("font-(weight:--a) font-(--b)"))
assert_equal("font-(family-name:--a) font-(--b)", @merger.merge("font-(family-name:--a) font-(--b)"))
end
end
34 changes: 34 additions & 0 deletions test/test_validators.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ def test_is_any_non_arbitrary
refute(IS_ANY_NON_ARBITRARY.call("(label:test)"))
end

def test_is_arbitrary_family_name
assert(IS_ARBITRARY_FAMILY_NAME.call("[family-name:Open_Sans]"))
assert(IS_ARBITRARY_FAMILY_NAME.call("[family-name:var(--my-font)]"))

refute(IS_ARBITRARY_FAMILY_NAME.call("[Open_Sans]"))
refute(IS_ARBITRARY_FAMILY_NAME.call("[number:400]"))
refute(IS_ARBITRARY_FAMILY_NAME.call("[weight:400]"))
refute(IS_ARBITRARY_FAMILY_NAME.call("family-name:test"))
refute(IS_ARBITRARY_FAMILY_NAME.call("(family-name:test)"))
end

def test_is_arbitrary_image
assert(IS_ARBITRARY_IMAGE.call("[url:var(--my-url)]"))
assert(IS_ARBITRARY_IMAGE.call("[url(something)]"))
Expand Down Expand Up @@ -94,6 +105,19 @@ def test_is_arbitrary_shadow
refute(IS_ARBITRARY_SHADOW.call("[something-else]"))
end

def test_is_arbitrary_weight
assert(IS_ARBITRARY_WEIGHT.call("[weight:400]"))
assert(IS_ARBITRARY_WEIGHT.call("[weight:bold]"))
assert(IS_ARBITRARY_WEIGHT.call("[number:400]"))
assert(IS_ARBITRARY_WEIGHT.call("[number:var(--my-weight)]"))
assert(IS_ARBITRARY_WEIGHT.call("[400]"))
assert(IS_ARBITRARY_WEIGHT.call("[bold]"))

refute(IS_ARBITRARY_WEIGHT.call("[family-name:test]"))
refute(IS_ARBITRARY_WEIGHT.call("weight:400"))
refute(IS_ARBITRARY_WEIGHT.call("(weight:400)"))
end

def test_is_arbitrary_size
assert(IS_ARBITRARY_SIZE.call("[size:2px]"))
assert(IS_ARBITRARY_SIZE.call("[size:bla]"))
Expand Down Expand Up @@ -186,6 +210,16 @@ def test_is_arbitrary_variable_size
refute(IS_ARBITRARY_VARIABLE_SIZE.call("percentage:test"))
end

def test_is_arbitrary_variable_weight
assert(IS_ARBITRARY_VARIABLE_WEIGHT.call("(weight:test)"))
assert(IS_ARBITRARY_VARIABLE_WEIGHT.call("(number:test)"))
assert(IS_ARBITRARY_VARIABLE_WEIGHT.call("(--my-weight)"))

refute(IS_ARBITRARY_VARIABLE_WEIGHT.call("(other:test)"))
refute(IS_ARBITRARY_VARIABLE_WEIGHT.call("weight:test"))
refute(IS_ARBITRARY_VARIABLE_WEIGHT.call("[weight:test]"))
end

def test_is_fraction
assert(IS_FRACTION.call("1/2"))
assert(IS_FRACTION.call("123/209"))
Expand Down