This repository has been archived by the owner on May 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Table #47
Merged
Merged
Table #47
Changes from 5 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
bb36881
Add table component
bryanjos a602771
Pagination component
bryanjos 33519b4
Refactor table functions into Table module and then delegate functions
bryanjos 9856fbb
Refactor table module
bryanjos 8e3ef15
Refactor table module
bryanjos 8a23392
Remove pagination
bryanjos 9742d27
Made table element more in line with other top level elements
bryanjos 8aca288
Merge branch 'master' of https://github.com/revelrylabs/phoenix_harmo…
brianberlin 07b2426
adds tests
brianberlin 60daebf
fix test
brianberlin f16585a
Refactor table module
brianberlin 00d9ebf
Delegate class functions
brianberlin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
defmodule Harmonium.Pagination do | ||
@moduledoc false | ||
@page_links_to_show 2 | ||
import Phoenix.HTML | ||
|
||
def pagination(_conn, _url, _page_number, 1) do | ||
nil | ||
end | ||
|
||
def pagination(conn, url, page_number, total_pages) do | ||
~E""" | ||
<div class="rev-PaginationWrapper text-center"> | ||
<ul class="rev-Pagination" role="navigation" aria-label="Pagination"> | ||
<%= unless first_page?(page_number) do %> | ||
<li class="rev-Pagination-arrow"> | ||
<a href="<%= make_page_link(conn, 1, url) %>"> | ||
<span><i class="icon-angle-double-left"></i>First<span class="ShowForSR"> page</span></span> | ||
</a> | ||
</li> | ||
<li class="rev-Pagination-arrow"> | ||
<a href="<%= make_previous_page_link(conn, page_number, url) %>"> | ||
<span><i class="icon-angle-left"></i>Previous<span class="ShowForSR"> page</span></span> | ||
</a> | ||
</li> | ||
<% end %> | ||
|
||
<%= for page <- 1..total_pages do %> | ||
<%= if show_previous_ellipsis?(page, page_number) do %> | ||
<li class="rev-Pagination-dots"> | ||
... | ||
</li> | ||
<% end %> | ||
<%= if show_page_link?(page, page_number) do %> | ||
<li class="rev-Pagination-number <%= selected_page_class(page, page_number)%>"> | ||
<%= if page == page_number do %> | ||
<span class="ShowForSR">You're on page </span><a><%= page_number %></a> | ||
<% else %> | ||
<a href="<%= make_page_link(conn, page, url) %>" aria-label="Page <%= page %>"><%= page %></a> | ||
<% end %> | ||
</li> | ||
<% end %> | ||
<%= if show_next_ellipsis?(page, page_number, total_pages) do %> | ||
<li class="rev-Pagination-dots"> | ||
... | ||
</li> | ||
<% end %> | ||
<% end %> | ||
<%= unless last_page?(page_number, total_pages) do %> | ||
<li class="rev-Pagination-arrow"> | ||
<a href="<%= make_next_page_link(conn, page_number, url) %>"> | ||
<span>Next<span class="ShowForSR"> page</span><i class="icon-angle-right"></i></span> | ||
</a> | ||
</li> | ||
<li class="rev-Pagination-arrow"> | ||
<a href="<%= make_page_link(conn, total_pages, url) %>"> | ||
<span>Last<span class="ShowForSR"> page</span><i class="icon-angle-double-right"></i></span> | ||
</a> | ||
</li> | ||
<% end %> | ||
</ul> | ||
<div class="rev-PaginationWrapper-pageList"> | ||
<span class="Small">( Page <%= page_number %> of <%= total_pages %> )</span> | ||
</div> | ||
</div> | ||
""" | ||
end | ||
|
||
defp make_next_page_link(conn, current_page, url) do | ||
make_page_link(conn, current_page + 1, url) | ||
end | ||
|
||
defp make_previous_page_link(conn, current_page, url) do | ||
make_page_link(conn, current_page - 1, url) | ||
end | ||
|
||
defp make_page_link(conn, page, url) do | ||
query_params = conn.query_params | ||
|
||
query_params = Map.put(query_params, "page", page) | ||
|
||
uri = URI.parse(url) | ||
|
||
query_params = | ||
if is_nil(uri.query) do | ||
query_params | ||
else | ||
URI.decode_query(uri.query, query_params) | ||
end | ||
|
||
uri = %{uri | query: Plug.Conn.Query.encode(query_params)} | ||
|
||
URI.to_string(uri) | ||
end | ||
|
||
defp first_page?(1), do: true | ||
defp first_page?(_), do: false | ||
|
||
defp last_page?(page_number, total_pages) when page_number == total_pages, do: true | ||
defp last_page?(_, _), do: false | ||
|
||
defp selected_page_class(page_number, current_page) when page_number == current_page do | ||
"rev-Pagination-number--selected" | ||
end | ||
|
||
defp selected_page_class(_, _) do | ||
"" | ||
end | ||
|
||
defp show_previous_ellipsis?(1, _) do | ||
false | ||
end | ||
|
||
defp show_previous_ellipsis?(page, page_number) do | ||
page == page_number - @page_links_to_show | ||
end | ||
|
||
defp show_next_ellipsis?(page, page_number, total_pages) do | ||
page == page_number + @page_links_to_show and page != total_pages | ||
end | ||
|
||
defp show_page_link?(page, page_number) do | ||
page >= page_number - @page_links_to_show and page <= page_number + @page_links_to_show | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
defmodule Harmonium.Table do | ||
@moduledoc false | ||
|
||
import Phoenix.HTML.Tag | ||
|
||
def table(opts \\ [], do: block) do | ||
table_element(:table, [class: "rev-Table"], opts, do: block) | ||
end | ||
|
||
def table_head(opts \\ [], do: block) do | ||
table_element(:thead, [class: "rev-Table-head"], opts, do: block) | ||
end | ||
|
||
def table_body(opts \\ [], do: block) do | ||
table_element(:tbody, [class: "rev-Table-body"], opts, do: block) | ||
end | ||
|
||
def table_row(opts \\ [], do: block) do | ||
table_element(:tr, [class: "rev-Table-row"], opts, do: block) | ||
end | ||
|
||
def table_header(opts \\ [], do: block) do | ||
table_element(:th, [class: "rev-Table-header"], opts, do: block) | ||
end | ||
|
||
def table_data(opts \\ [], do: block) do | ||
table_element(:td, [class: "rev-Table-Data"], opts, do: block) | ||
end | ||
|
||
defp table_element(tag, default_opts, opts, do: block) do | ||
opts = Keyword.merge(default_opts, opts) | ||
|
||
content_tag tag, opts do | ||
block | ||
end | ||
end | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I should have said this before, but I think all these helper functions should follow the current standard Harmonium pattern where you can optionally pass CSS class modifiers as the 2nd arg: @doc """
Constructs a callout class.
"""
def callout_class(modifiers \\ []), do: rev_class(@callout_class, modifiers)
@doc """
Renders a callout.
"""
def callout(do: block), do: callout([], do: block)
def callout(modifiers, do: block), do: callout(:div, modifiers, do: block)
def callout(tag, modifiers, do: block) do
content_tag tag, class: callout_class(modifiers) do
block
end
end Our Harmonium SCSS Table does include some very useful SUIT modifiers: https://github.com/revelrylabs/harmonium/blob/master/scss/components/_Table.scss |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we change all of these to...
Then we can do something like...
otherwise you have to do
or you can also do this i guess but be nice to the other way i think