Skip to content
This repository was archived by the owner on Sep 6, 2018. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions src/Table.elm
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ you have. Stories make it possible to design better!
type alias Customizations data msg =
{ tableAttrs : List (Attribute msg)
, caption : Maybe (HtmlDetails msg)
, colgroup : Maybe (HtmlDetails msg)
, thead : List (String, Status, Attribute msg) -> HtmlDetails msg
, tfoot : Maybe (HtmlDetails msg)
, tbodyAttrs : List (Attribute msg)
Expand All @@ -205,6 +206,7 @@ defaultCustomizations : Customizations data msg
defaultCustomizations =
{ tableAttrs = []
, caption = Nothing
, colgroup = Nothing
, thead = simpleThead
, tfoot = Nothing
, tbodyAttrs = []
Expand Down Expand Up @@ -421,6 +423,22 @@ view (Config { toId, toMsg, columns, customizations }) state data =
sortedData =
sort state columns data

caption =
case customizations.caption of
Nothing ->
identity

Just { attributes, children } ->
(::) <| Html.caption attributes children
Copy link
Copy Markdown

@ChristophP ChristophP May 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this could be simplified with Maybe.withDefault. Like

caption = Maybe.map (\{ attributes, children } -> (::) <| Html.caption attributes children) customizations.caption |> Maybe.withDefault identity

Not sure if its actually simpler but it would allow for more reuse if you broke some stuff up into smaller functions.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's harder to read your way. What I have takes more lines, but is easier to follow.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, true. Might have been a microoptmization suggestion by me anyway :-).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has Evan ever replied to your PR?


colgroup =
case customizations.colgroup of
Nothing ->
identity

Just { attributes, children } ->
(::) <| Html.colgroup attributes children

theadDetails =
customizations.thead (List.map (toHeaderInfo state toMsg) columns)

Expand All @@ -439,13 +457,8 @@ view (Config { toId, toMsg, columns, customizations }) state data =
Just { attributes, children } ->
Html.tfoot attributes children :: tbody :: []
in
Html.table customizations.tableAttrs <|
case customizations.caption of
Nothing ->
thead :: withFoot

Just { attributes, children } ->
Html.caption attributes children :: thead :: withFoot
Html.table customizations.tableAttrs
(caption <| colgroup <| thead :: withFoot)


toHeaderInfo : State -> (State -> msg) -> ColumnData data msg -> ( String, Status, Attribute msg )
Expand Down