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

View File

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