Add ElementColumn

This commit is contained in:
Lukas Turcani 2021-12-18 21:28:40 +01:00
parent 380233423f
commit 94542e85d3
2 changed files with 28 additions and 22 deletions

View File

@ -34,10 +34,11 @@ type alias SortTableStyle msg =
{-| A Sortable list allows you to sort coulmn.
-}
type ColumnType a
type ColumnType a msg
= StringColumn { value : a -> String, toString : String -> String }
| IntColumn { value : a -> Int, toString : Int -> String }
| FloatColumn { value : a -> Float, toString : Float -> String }
| ElementColumn { value : a -> Element msg }
| UnsortableColumn (a -> String)
@ -45,22 +46,22 @@ type ColumnType a
-}
type alias SortTable a msg =
{ content : List a
, columns : List (Column a)
, columns : List (Column a msg)
, sortBy : String
, asc : Bool
, onChange : String -> msg
}
type Column a
type Column a msg
= Column
{ title : String
, content : ColumnType a
, content : ColumnType a msg
, width : Length
}
unsortableColumn : { title : String, toString : a -> String, width : Length } -> Column a
unsortableColumn : { title : String, toString : a -> String, width : Length } -> Column a msg
unsortableColumn { title, toString, width } =
Column
{ title = title
@ -71,7 +72,7 @@ unsortableColumn { title, toString, width } =
{-| A Column containing a Int
-}
intColumn : { title : String, value : a -> Int, toString : Int -> String, width : Length } -> Column a
intColumn : { title : String, value : a -> Int, toString : Int -> String, width : Length } -> Column a msg
intColumn { title, value, toString, width } =
Column
{ title = title
@ -82,7 +83,7 @@ intColumn { title, value, toString, width } =
{-| A Column containing a Float
-}
floatColumn : { title : String, value : a -> Float, toString : Float -> String, width : Length } -> Column a
floatColumn : { title : String, value : a -> Float, toString : Float -> String, width : Length } -> Column a msg
floatColumn { title, value, toString, width } =
Column
{ title = title
@ -93,7 +94,7 @@ floatColumn { title, value, toString, width } =
{-| A Column containing a String
-}
stringColumn : { title : String, value : a -> String, toString : String -> String, width : Length } -> Column a
stringColumn : { title : String, value : a -> String, toString : String -> String, width : Length } -> Column a msg
stringColumn { title, value, toString, width } =
Column
{ title = title
@ -110,7 +111,7 @@ sortTable :
-> Element msg
sortTable style model =
let
findTitle : List (Column a) -> Maybe (ColumnType a)
findTitle : List (Column a msg) -> Maybe (ColumnType a msg)
findTitle list =
case list of
[] ->
@ -140,6 +141,9 @@ sortTable style model =
FloatColumn { value } ->
Just <| List.sortBy value
ElementColumn _ ->
Nothing
UnsortableColumn _ ->
Nothing
)
@ -180,18 +184,20 @@ sortTable style model =
, view =
(case column.content of
IntColumn { value, toString } ->
value >> toString
value >> toString >> Element.text
FloatColumn { value, toString } ->
value >> toString
value >> toString >> Element.text
StringColumn { value, toString } ->
value >> toString
value >> toString >> Element.text
ElementColumn { value } ->
value
UnsortableColumn toString ->
toString
toString >> Element.text
)
>> Element.text
>> List.singleton
>> Element.paragraph []
}

View File

@ -1901,15 +1901,15 @@ type alias SortTableStyle msg =
{-| Column for the Sort Table widget type
-}
type alias Column a =
SortTable.Column a
type alias Column a msg =
SortTable.Column a msg
{-| Sort Table widget type
-}
type alias SortTable a msg =
{ content : List a
, columns : List (Column a)
, columns : List (Column a msg)
, sortBy : String
, asc : Bool
, onChange : String -> msg
@ -1923,7 +1923,7 @@ unsortableColumn :
, toString : a -> String
, width : Length
}
-> Column a
-> Column a msg
unsortableColumn =
SortTable.unsortableColumn
@ -1936,7 +1936,7 @@ intColumn :
, toString : Int -> String
, width : Length
}
-> Column a
-> Column a msg
intColumn =
SortTable.intColumn
@ -1949,7 +1949,7 @@ floatColumn :
, toString : Float -> String
, width : Length
}
-> Column a
-> Column a msg
floatColumn =
SortTable.floatColumn
@ -1969,7 +1969,7 @@ stringColumn :
, toString : String -> String
, width : Length
}
-> Column a
-> Column a msg
stringColumn =
SortTable.stringColumn
@ -2033,7 +2033,7 @@ sortTable :
SortTableStyle msg
->
{ content : List a
, columns : List (Column a)
, columns : List (Column a msg)
, sortBy : String
, asc : Bool
, onChange : String -> msg