Skip to content

Commit

Permalink
fix: properly merge directional classes with dashes before the direct…
Browse files Browse the repository at this point in the history
…ions

closes: #16
  • Loading branch information
zachdaniel committed Dec 18, 2023
1 parent ba7a7cb commit ae98381
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
17 changes: 12 additions & 5 deletions lib/custom.ex
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,7 @@ defmodule Tails.Custom do
end
end

for {class, %{prefix: string_class}} <- @directional do
for {class, %{prefix: string_class} = config} <- @directional do
@dirs %{
x: [:r, :l],
y: [:t, :b],
Expand All @@ -977,25 +977,32 @@ defmodule Tails.Custom do
}

for {dir, clears} <- @dirs do
string_dir =
if config[:dash_suffix?] do
"-" <> to_string(dir)
else
to_string(dir)
end

@clears Enum.map(clears, &{&1, nil})

def merge_class(
%{unquote(class) => nil} = tailwind,
unquote(string_class) <> unquote(to_string(dir)) <> "-" <> value
unquote(string_class) <> unquote(string_dir) <> "-" <> value
) do
Map.put(tailwind, unquote(class), struct(Directions, %{unquote(dir) => value}))
end

def merge_class(
%{unquote(class) => nil} = tailwind,
"-" <> unquote(string_class) <> unquote(to_string(dir)) <> "-" <> value
"-" <> unquote(string_class) <> unquote(string_dir) <> "-" <> value
) do
Map.put(tailwind, unquote(class), struct(Directions, %{unquote(dir) => "-" <> value}))
end

def merge_class(
%{unquote(class) => directions} = tailwind,
unquote(string_class) <> unquote(to_string(dir)) <> "-" <> value
unquote(string_class) <> unquote(string_dir) <> "-" <> value
) do
Map.put(
tailwind,
Expand All @@ -1006,7 +1013,7 @@ defmodule Tails.Custom do

def merge_class(
%{unquote(class) => directions} = tailwind,
"-" <> unquote(string_class) <> unquote(to_string(dir)) <> "-" <> value
"-" <> unquote(string_class) <> unquote(string_dir) <> "-" <> value
) do
Map.put(
tailwind,
Expand Down
22 changes: 20 additions & 2 deletions test/tails_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,26 @@ defmodule TailsTest do

describe "Tails.classes" do
test "border-b-* and border-opacity-* do not override one another" do
refute Tails.classes(["border-b-4 border-opacity-20"]) == "border-opacity-20"
refute Tails.classes(["border-opacity-20 border-b-4"]) == "border-b-4"
refute Tails.classes("border-b-4 border-opacity-20") == "border-opacity-20"
refute Tails.classes("border-opacity-20 border-b-4") == "border-b-4"
end

test "border-b-*, border-t-*, border-l-*, and border-r-* do not override one another" do
num_of_consolidated_classes =
Tails.classes("border-b-4 border-t-4 border-r-4 border-l-4")
|> String.split(" ")
|> Enum.count()

assert num_of_consolidated_classes == 4
end

test "border-x-* and border-y-* do not override one another" do
num_of_consolidated_classes =
Tails.classes("border-x-4 border-y-4")
|> String.split(" ")
|> Enum.count()

assert num_of_consolidated_classes == 2
end
end
end

0 comments on commit ae98381

Please sign in to comment.