Skip to content

Commit

Permalink
Merge pull request #308 from woylie/remove-phoenix-html-tag-references
Browse files Browse the repository at this point in the history
replace Phoenix.HTML.Tag
  • Loading branch information
woylie committed Jan 3, 2024
2 parents ce208ad + 4ce5263 commit 54c5aa0
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 16 deletions.
27 changes: 21 additions & 6 deletions lib/flop_phoenix.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ defmodule Flop.Phoenix do
are deep-merged into the default options.
defmodule MyAppWeb.CoreComponents do
import Phoenix.HTML.Tag
use Phoenix.Component
def pagination_opts do
[
Expand All @@ -34,21 +34,37 @@ defmodule Flop.Phoenix do
end
defp next_icon do
tag :i, class: "fas fa-chevron-right"
assigns = %{}
~H\"""
<i class="fas fa-chevron-right"/>
\"""
end
defp previous_icon do
tag :i, class: "fas fa-chevron-left"
assigns = %{}
~H\"""
<i class="fas fa-chevron-left"/>
\"""
end
def table_opts do
[
container: true,
container_attrs: [class: "table-container"],
no_results_content: content_tag(:p, do: "Nothing found."),
no_results_content: no_results_content(),
table_attrs: [class: "table"]
]
end
defp no_results_content do
assigns = %{}
~H\"""
<p>Nothing found.</p>
\"""
end
end
Refer to `t:pagination_option/0` and `t:table_option/0` for a list of
Expand Down Expand Up @@ -1317,8 +1333,7 @@ defmodule Flop.Phoenix do
The options passed to the inner block are:
- `field` - A `Phoenix.HTML.FormField` struct.
- `type` - The input type as a string. This is _not_ the value returned
by `Phoenix.HTML.Form.input_type/2`.
- `type` - The input type as a string.
- `label` - The label text as a string.
- `rest` - Any additional options passed in the field options.
"""
Expand Down
3 changes: 1 addition & 2 deletions lib/flop_phoenix/table.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ defmodule Flop.Phoenix.Table do
[
container: false,
container_attrs: [class: "table-container"],
no_results_content:
PhoenixHTMLHelpers.Tag.content_tag(:p, do: "No results."),
no_results_content: Phoenix.HTML.raw("<p>No results.</p>"),
symbol_asc: "▴",
symbol_attrs: [class: "order-direction"],
symbol_desc: "▾",
Expand Down
26 changes: 18 additions & 8 deletions test/flop_phoenix_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ defmodule Flop.PhoenixTest do
import Phoenix.HTML
import Phoenix.LiveViewTest
import PhoenixHTMLHelpers.Form
import PhoenixHTMLHelpers.Tag

alias Flop.Filter
alias MyApp.Pet
Expand Down Expand Up @@ -319,7 +318,8 @@ defmodule Flop.PhoenixTest do
path="/pets"
opts={[
previous_link_attrs: [class: "prev", title: "p-p-previous"],
previous_link_content: tag(:i, class: "fas fa-chevron-left")
previous_link_content:
Phoenix.HTML.raw(~s(<i class="fas fa-chevron-left" />))
]}
/>
""")
Expand Down Expand Up @@ -441,7 +441,7 @@ defmodule Flop.PhoenixTest do
path="/pets"
opts={[
next_link_attrs: [class: "next", title: "n-n-next"],
next_link_content: tag(:i, class: "fas fa-chevron-right")
next_link_content: Phoenix.HTML.raw(~s("<i class="fas fa-chevron-right" />))
]}
/>
""")
Expand All @@ -453,8 +453,7 @@ defmodule Flop.PhoenixTest do
assert [href] = Floki.attribute(link, "href")
assert_urls_match(href, "/pets?page=3&page_size=10")

assert link |> Floki.children() |> Floki.raw_html() ==
"<i class=\"fas fa-chevron-right\"></i>"
assert Floki.attribute(link, "i", "class") == ["fas fa-chevron-right"]
end

test "disables next link if on last page" do
Expand Down Expand Up @@ -1344,7 +1343,8 @@ defmodule Flop.PhoenixTest do
meta: build(:meta_with_cursors),
opts: [
previous_link_attrs: [class: "prev", title: "p-p-previous"],
previous_link_content: tag(:i, class: "fas fa-chevron-left")
previous_link_content:
Phoenix.HTML.raw(~s(<i class="fas fa-chevron-left" />))
]
}

Expand Down Expand Up @@ -1468,7 +1468,7 @@ defmodule Flop.PhoenixTest do
path="/pets"
opts={[
next_link_attrs: [class: "next", title: "n-n-next"],
next_link_content: tag(:i, class: "fas fa-chevron-right")
next_link_content: Phoenix.HTML.raw(~s(<i class="fas fa-chevron-right" />))
]}
/>
""")
Expand Down Expand Up @@ -2547,7 +2547,9 @@ defmodule Flop.PhoenixTest do
test "allows to set no_results_content" do
assert render_table(%{
items: [],
opts: [no_results_content: content_tag(:div, do: "Nothing!")]
opts: [
no_results_content: custom_no_results_content()
]
}) == [{"div", [], ["Nothing!"]}]
end

Expand Down Expand Up @@ -3344,4 +3346,12 @@ defmodule Flop.PhoenixTest do
field(:email, :string)
end
end

defp custom_no_results_content do
assigns = %{}

~H"""
<div>Nothing!</div>
"""
end
end

0 comments on commit 54c5aa0

Please sign in to comment.