Add definition table

This commit is contained in:
Andrew Martin 2016-11-18 08:58:13 -05:00
parent 8ed64f1d2b
commit 2dea18bf68

View File

@ -3,6 +3,8 @@
module Yesod.Colonnade module Yesod.Colonnade
( table ( table
, tableHeadless
, definitionTable
, listItems , listItems
, Cell(..) , Cell(..)
, cell , cell
@ -54,23 +56,41 @@ anchorCell getRoute getContent a = cell $ do
-- | This determines the attributes that are added -- | This determines the attributes that are added
-- to the individual @li@s by concatenating the header\'s -- to the individual @li@s by concatenating the header\'s
-- attributes with the data\'s attributes. -- attributes with the data\'s attributes.
listItems :: Foldable f listItems ::
=> (WidgetT site IO () -> WidgetT site IO ()) (WidgetT site IO () -> WidgetT site IO ())
-- ^ Wrapper for items, often @ul@ -- ^ Wrapper for items, often @ul@
-> (WidgetT site IO () -> WidgetT site IO () -> WidgetT site IO ()) -> (WidgetT site IO () -> WidgetT site IO () -> WidgetT site IO ())
-- ^ Combines header with data -- ^ Combines header with data
-> Encoding Headed (Cell site) a -> Encoding Headed (Cell site) a
-- ^ How to encode data as a row -- ^ How to encode data as a row
-> f a -> a
-- ^ Rows of data -- ^ The value to display
-> WidgetT site IO () -> WidgetT site IO ()
listItems ulWrap combine enc xs = listItems ulWrap combine enc =
forM_ xs $ ulWrap . Encoding.runBothMonadic_ enc ulWrap . Encoding.runBothMonadic_ enc
(\(Cell ha hc) (Cell ba bc) -> (\(Cell ha hc) (Cell ba bc) ->
li (ha ++ ba) (combine hc bc) li (ha ++ ba) (combine hc bc)
) )
-- | A two-column table with the header content displayed in the
-- first column and the data displayed in the second column. Note
-- that the generated HTML table does not have a @thead@.
definitionTable ::
[(Text,Text)]
-- ^ Attributes of @table@ element.
-> Encoding Headed (Cell site) a
-- ^ How to encode data as a row
-> a
-- ^ The value to display
-> WidgetT site IO ()
definitionTable attrs enc a = tableEl attrs $ tbody [] $
Encoding.runBothMonadic_ enc
(\theKey theValue -> tr [] $ do
widgetFromCell td theKey
widgetFromCell td theValue
) a
-- | If you are using the bootstrap css framework, then you may want -- | If you are using the bootstrap css framework, then you may want
-- to call this with the first argument as: -- to call this with the first argument as:
-- --