module Component.Table ( table , TableIn(..) , TableOut(..) ) where import Data.Text (Text) import Reflex.Dom (Dynamic, MonadWidget) import qualified Reflex.Dom as R data TableIn h r t = TableIn { _tableIn_headerLabel :: h -> Text , _tableIn_rows :: Dynamic t [r] , _tableIn_cell :: h -> r -> Text } data TableOut = TableOut {} table :: forall t m h r. (MonadWidget t m, Bounded h, Enum h) => TableIn h r t -> m (TableOut) table tableIn = do R.divClass "table" $ do R.divClass "lines" $ do R.divClass "header" $ do flip mapM_ [minBound..] $ \header -> R.divClass "cell" . R.text $ _tableIn_headerLabel tableIn header R.simpleList (_tableIn_rows tableIn) $ \r -> R.divClass "row" $ flip mapM_ [minBound..] $ \h -> R.divClass "cell name" $ R.dynText $ R.ffor r (_tableIn_cell tableIn h) return $ TableOut {}