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 all 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,147 @@ | ||
defmodule Harmonium.Table do | ||
@moduledoc """ | ||
Adds component to render pagination with correct harmonium classes. | ||
""" | ||
|
||
import Phoenix.HTML.Tag | ||
|
||
@doc """ | ||
Constructs a callout class. | ||
|
||
iex> table_class() | ||
"rev-Table" | ||
|
||
iex> table_class(color: "blue") | ||
"rev-Table rev-Table--colorblue" | ||
|
||
iex> table_class(bold: true) | ||
"rev-Table rev-Table--bold" | ||
""" | ||
def table_class(modifiers \\ []), do: Harmonium.rev_class("rev-Table", modifiers) | ||
|
||
@doc """ | ||
Renders a table element (<table>). | ||
|
||
iex> safe_to_string(table(do: [])) | ||
~S(<table class="rev-Table"></table>) | ||
""" | ||
def table(opts \\ []), do: table_element(:table, :table_class, opts) | ||
|
||
@doc """ | ||
Constructs a table head class. | ||
|
||
iex> table_head_class() | ||
"rev-Table-head" | ||
|
||
iex> table_head_class(stacked: true) | ||
"rev-Table-head rev-Table-head--stacked" | ||
""" | ||
def table_head_class(modifiers \\ []), do: Harmonium.rev_class("rev-Table-head", modifiers) | ||
|
||
@doc """ | ||
Renders a table head element (<thead>). | ||
|
||
iex> safe_to_string(table_head(do: [])) | ||
~S(<thead class="rev-Table-head"></thead>) | ||
""" | ||
def table_head(opts \\ []), do: table_element(:thead, :table_head_class, opts) | ||
|
||
@doc """ | ||
Constructs a table body class. | ||
|
||
iex> table_body_class() | ||
"rev-Table-body" | ||
|
||
iex> table_body_class(stacked: true) | ||
"rev-Table-body rev-Table-body--stacked" | ||
""" | ||
def table_body_class(modifiers \\ []), do: Harmonium.rev_class("rev-Table-body", modifiers) | ||
|
||
@doc """ | ||
Renders a table body element (<tbody>). | ||
|
||
iex> safe_to_string(table_body(do: [])) | ||
~S(<tbody class="rev-Table-body"></tbody>) | ||
""" | ||
def table_body(opts \\ []), do: table_element(:tbody, :table_body_class, opts) | ||
|
||
@doc """ | ||
Constructs a table row class. | ||
|
||
iex> table_row_class() | ||
"rev-Table-row" | ||
|
||
iex> table_row_class(stacked: true) | ||
"rev-Table-row rev-Table-row--stacked" | ||
""" | ||
def table_row_class(modifiers \\ []), do: Harmonium.rev_class("rev-Table-row", modifiers) | ||
|
||
@doc """ | ||
Renders a table row element (<tr>). | ||
|
||
iex> safe_to_string(table_row(do: [])) | ||
~S(<tr class="rev-Table-row"></tr>) | ||
""" | ||
def table_row(opts \\ []), do: table_element(:tr, :table_row_class, opts) | ||
|
||
@doc """ | ||
Constructs a table header class. | ||
|
||
iex> table_header_class() | ||
"rev-Table-header" | ||
|
||
iex> table_header_class(stacked: true) | ||
"rev-Table-header rev-Table-header--stacked" | ||
""" | ||
def table_header_class(modifiers \\ []), do: Harmonium.rev_class("rev-Table-header", modifiers) | ||
|
||
@doc """ | ||
Renders a table header element (<th>). | ||
|
||
iex> safe_to_string(table_header(do: [])) | ||
~S(<th class="rev-Table-header"></th>) | ||
""" | ||
def table_header(opts \\ []), do: table_element(:th, :table_header_class, opts) | ||
|
||
@doc """ | ||
Constructs a table data class. | ||
|
||
iex> table_data_class() | ||
"rev-Table-data" | ||
|
||
iex> table_data_class(stacked: true) | ||
"rev-Table-data rev-Table-data--stacked" | ||
""" | ||
def table_data_class(modifiers \\ []), do: Harmonium.rev_class("rev-Table-data", modifiers) | ||
|
||
@doc """ | ||
Renders a table data element (<td>). | ||
|
||
iex> safe_to_string(table_data) | ||
~S(<td class="rev-Table-data"></td>) | ||
|
||
iex> safe_to_string(table_data(attrs: [colspan: 2])) | ||
~S(<td class="rev-Table-data" colspan="2"></td>) | ||
|
||
iex> safe_to_string(table_data(do: [])) | ||
~S(<td class="rev-Table-data"></td>) | ||
|
||
iex> safe_to_string(table_data(bold: true, attrs: [colspan: 2], do: [])) | ||
~S(<td class="rev-Table-data rev-Table-data--bold" colspan="2"></td>) | ||
|
||
iex> safe_to_string(table_data(bold: true, italic: true, attrs: [colspan: 2], do: [])) | ||
~S(<td class="rev-Table-data rev-Table-data--bold rev-Table-data--italic" colspan="2"></td>) | ||
""" | ||
def table_data(opts \\ []), do: table_element(:td, :table_data_class, opts) | ||
|
||
defp table_element(tag, class_function, opts) do | ||
{block, opts} = Keyword.pop(opts, :do, []) | ||
{attrs, modifiers} = Keyword.pop(opts, :attrs, []) | ||
modifier_classes = apply(__MODULE__, class_function, [modifiers]) | ||
opts = Keyword.merge(attrs, [class: modifier_classes]) | ||
|
||
content_tag tag, opts do | ||
block | ||
end | ||
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
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,7 @@ | ||
defmodule Harmonium.TableTest do | ||
use ExUnit.Case | ||
import Phoenix.HTML, only: [safe_to_string: 1] | ||
import Harmonium.Table | ||
|
||
doctest Harmonium.Table | ||
end |
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.
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:
Our Harmonium SCSS Table does include some very useful SUIT modifiers: https://github.com/revelrylabs/harmonium/blob/master/scss/components/_Table.scss