Skip to content

Commit

Permalink
Transform sizing classes
Browse files Browse the repository at this point in the history
  • Loading branch information
angelikatyborska committed Apr 16, 2024
1 parent da54bc9 commit f665232
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
19 changes: 14 additions & 5 deletions lib/bitstyles_phoenix/bitstyles.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,23 @@ defmodule BitstylesPhoenix.Bitstyles do
end

def classname(class, version) when version >= "5.0.0" do
# TODO
case class do
_ -> class
end
class
end

def classname(class, version) when version >= "4.2.0" do
classname(class, "5.0.0")
sizes_renaming = %{
"3xs" => "xxxs",
"2xs" => "xxs",
"2xl" => "xxl",
"3xl" => "xxxl"
}

mapping =
Enum.reduce(sizes_renaming, class, fn {new_size, old_size}, acc ->
String.replace(acc, "-#{new_size}", "-#{old_size}")
end)

classname(mapping, "5.0.0")
end

def classname(class, version) when version >= "4.0.0" do
Expand Down
14 changes: 14 additions & 0 deletions test/bitstyles_phoenix/bitstyles_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ defmodule BitstylesPhoenix.BitstylesTest do
assert classname("u-grid-cols-3", "5.0.0") == "u-grid-cols-3"
assert classname("u-col-span-3", "5.0.0") == "u-col-span-3"
assert classname("u-col-start-1", "5.0.0") == "u-col-start-1"
assert classname("u-margin-2xs", "5.0.0") == "u-margin-2xs"
assert classname("u-margin-3xs\@m", "5.0.0") == "u-margin-3xs\@m"
assert classname("u-margin-3xs-bottom", "5.0.0") == "u-margin-3xs-bottom"
assert classname("u-padding-2xl", "5.0.0") == "u-padding-2xl"
assert classname("u-padding-3xl\@l", "5.0.0") == "u-padding-3xl\@l"
assert classname("u-margin-3xl-bottom", "5.0.0") == "u-margin-3xl-bottom"
assert classname("u-margin-neg-3xl-bottom", "5.0.0") == "u-margin-neg-3xl-bottom"
end

test "version 4.3.0" do
Expand All @@ -47,6 +54,13 @@ defmodule BitstylesPhoenix.BitstylesTest do
assert classname("u-grid-cols-3", "4.3.0") == "u-grid-cols-3"
assert classname("u-col-span-3", "4.3.0") == "u-col-span-3"
assert classname("u-col-start-1", "4.3.0") == "u-col-start-1"
assert classname("u-margin-2xs", "4.3.0") == "u-margin-xxs"
assert classname("u-margin-3xs\@m", "4.3.0") == "u-margin-xxxs\@m"
assert classname("u-margin-3xs-bottom", "4.3.0") == "u-margin-xxxs-bottom"
assert classname("u-padding-2xl", "4.3.0") == "u-padding-xxl"
assert classname("u-padding-3xl\@l", "4.3.0") == "u-padding-xxxl\@l"
assert classname("u-margin-3xl-bottom", "4.3.0") == "u-margin-xxxl-bottom"
assert classname("u-margin-neg-3xl-bottom", "4.3.0") == "u-margin-neg-xxxl-bottom"
end

test "version 4.2.0" do
Expand Down

0 comments on commit f665232

Please sign in to comment.