Skip to content

Commit

Permalink
Flatten classes
Browse files Browse the repository at this point in the history
  • Loading branch information
dsrees committed Oct 24, 2023
1 parent ddb8157 commit 06a1aed
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/phx_component_helpers/css.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ defmodule PhxComponentHelpers.CSS do

is_list(default_classes) ->
default_classes
|> List.flatten()
|> Enum.filter(&is_binary/1)
|> Enum.join(" ")

Expand Down
5 changes: 3 additions & 2 deletions test/phx_component_helpers_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -382,13 +382,14 @@ defmodule PhxComponentHelpersTest do
"bg-blue-500 mt-8",
assigns[:active] == true && "text-green-500",
nil,
["flex"],
if(assigns[:circle] == true, do: "rounded-full", else: "rounded-md")
])

assert new_assigns ==
assigns
|> Map.put(:class, "bg-blue-500 text-green-500 rounded-md mt-2")
|> Map.put(:heex_class, class: "bg-blue-500 text-green-500 rounded-md mt-2")
|> Map.put(:class, "bg-blue-500 text-green-500 flex rounded-md mt-2")
|> Map.put(:heex_class, class: "bg-blue-500 text-green-500 flex rounded-md mt-2")
end

test "does not extend with error_class when a form field is not faulty" do
Expand Down

0 comments on commit 06a1aed

Please sign in to comment.