mirror of
https://github.com/byteverse/colonnade.git
synced 2026-08-25 13:33:52 +02:00
strip trailing spaces. add more features
This commit is contained in:
parent
dc71d30438
commit
189c95f7fe
@ -21,7 +21,9 @@ library
|
|||||||
, colonnade
|
, colonnade
|
||||||
, contravariant
|
, contravariant
|
||||||
, vector
|
, vector
|
||||||
|
, reflex
|
||||||
, reflex-dom
|
, reflex-dom
|
||||||
|
, containers
|
||||||
default-language: Haskell2010
|
default-language: Haskell2010
|
||||||
|
|
||||||
source-repository head
|
source-repository head
|
||||||
|
|||||||
@ -1,15 +1,50 @@
|
|||||||
module Reflex.Dom.Colonnade where
|
module Reflex.Dom.Colonnade where
|
||||||
|
|
||||||
import Colonnade.Types
|
import Colonnade.Types
|
||||||
|
import Control.Monad
|
||||||
|
import Reflex (Dynamic)
|
||||||
|
import Reflex.Dynamic (mapDyn)
|
||||||
|
import Reflex.Dom (MonadWidget)
|
||||||
import Reflex.Dom.Widget.Basic
|
import Reflex.Dom.Widget.Basic
|
||||||
|
import Data.Map (Map)
|
||||||
|
import qualified Data.Map as Map
|
||||||
|
|
||||||
-- hmm...
|
cell :: m () -> Cell m
|
||||||
-- data WithAttrs
|
cell = Cell Map.empty
|
||||||
|
|
||||||
basic :: MonadWidget t m
|
data Cell m = Cell
|
||||||
=> Encoding Headed (m ()) Int
|
{ 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 ()
|
-> m ()
|
||||||
basic (Encoding v) = do
|
basic tableAttrs as (Encoding v) = do
|
||||||
el "table" $ do
|
elAttr "table" tableAttrs $ do
|
||||||
el "thead" $ mapM_ (getHeaded . fst) v
|
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