module Dingo.Widget.Panel ( Panel , mkPanel ) where import Data.Aeson (FromJSON(..), ToJSON(..), Value(..)) import Data.Monoid (mempty) import Data.Typeable (Typeable) import Dingo.Callback import Dingo.Widget import Text.Blaze ((!), toValue) import Text.Julius (julius) import qualified Data.HashMap.Strict as M import qualified Text.Blaze.Html4.Strict as H import qualified Text.Blaze.Html4.Strict.Attributes as A -- Panel type. data Panel = Panel { panelId :: WidgetId } deriving (Show, Typeable) data PanelState = PanelState () deriving (Show, Typeable) instance FromJSON PanelState where parseJSON _ = return $ PanelState () instance ToJSON PanelState where toJSON (PanelState ()) = Object M.empty -- Panel is a widget. instance Widget Panel PanelState where -- Get the widget ID. getWidgetId = panelId -- Render panel to HTML. renderWidget w = H.div ! A.id (toValue $ panelId w) $ do mempty -- Show widget. showWidget w s = show w ++ "->" ++ show s -- Client state handling. encodeClientStateJs _ = [julius| null |] decodeClientStateJs _ = [julius| null |] -- Make a new panel. mkPanel :: Widget w s => w -> CallbackM Panel mkPanel pw = addWidget pw (\i -> return (Panel i, PanelState ()))