mirror of
https://github.com/byteverse/colonnade.git
synced 2026-09-09 05:13:50 +02:00
strip trailing spaces. add more features
This commit is contained in:
parent
dc71d30438
commit
189c95f7fe
@ -21,7 +21,9 @@ library
|
||||
, colonnade
|
||||
, contravariant
|
||||
, vector
|
||||
, reflex
|
||||
, reflex-dom
|
||||
, containers
|
||||
default-language: Haskell2010
|
||||
|
||||
source-repository head
|
||||
|
||||
@ -1,15 +1,50 @@
|
||||
module Reflex.Dom.Colonnade where
|
||||
|
||||
import Colonnade.Types
|
||||
import Control.Monad
|
||||
import Reflex (Dynamic)
|
||||
import Reflex.Dynamic (mapDyn)
|
||||
import Reflex.Dom (MonadWidget)
|
||||
import Reflex.Dom.Widget.Basic
|
||||
import Data.Map (Map)
|
||||
import qualified Data.Map as Map
|
||||
|
||||
-- hmm...
|
||||
-- data WithAttrs
|
||||
cell :: m () -> Cell m
|
||||
cell = Cell Map.empty
|
||||
|
||||
basic :: MonadWidget t m
|
||||
=> Encoding Headed (m ()) Int
|
||||
data Cell m = Cell
|
||||
{ cellAttrs :: Map String String
|
||||
, cellContents :: m ()
|
||||
}
|
||||
|
||||
basic :: (MonadWidget t m, Foldable f)
|
||||
=> Map String String -- ^ Table element attributes
|
||||
-> f a -- ^ Values
|
||||
-> Encoding Headed (Cell m) a -- ^ Encoding of a value into cells
|
||||
-> m ()
|
||||
basic (Encoding v) = do
|
||||
el "table" $ do
|
||||
el "thead" $ mapM_ (getHeaded . fst) v
|
||||
basic tableAttrs as (Encoding v) = do
|
||||
elAttr "table" tableAttrs $ do
|
||||
el "thead" $ forM_ v $ \(Headed (Cell attrs contents),_) ->
|
||||
elAttr "th" attrs contents
|
||||
el "tbody" $ forM_ as $ \a -> do
|
||||
el "tr" $ forM_ v $ \(_,encode) -> do
|
||||
let Cell attrs contents = encode a
|
||||
elAttr "td" attrs contents
|
||||
|
||||
dynamic :: (MonadWidget t m, Foldable f)
|
||||
=> Map String String -- ^ Table element attributes
|
||||
-> f (Dynamic t a) -- ^ Dynamic values
|
||||
-> Encoding Headed (Cell m) a -- ^ Encoding of a value into cells
|
||||
-> m ()
|
||||
dynamic tableAttrs as (Encoding v) = do
|
||||
elAttr "table" tableAttrs $ do
|
||||
el "thead" $ forM_ v $ \(Headed (Cell attrs contents),_) ->
|
||||
elAttr "th" attrs contents
|
||||
el "tbody" $ forM_ as $ \a -> do
|
||||
el "tr" $ forM_ v $ \(_,encode) -> do
|
||||
dynPair <- mapDyn encode a
|
||||
dynAttrs <- mapDyn cellAttrs dynPair
|
||||
dynContent <- mapDyn cellContents dynPair
|
||||
_ <- elDynAttr "td" dynAttrs $ dyn dynContent
|
||||
return ()
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user