@@ -10,7 +10,75 @@
10{-# LANGUAGE RecursiveDo #-}
10{-# LANGUAGE RecursiveDo #-}
11{-# LANGUAGE ScopedTypeVariables #-}
11{-# LANGUAGE ScopedTypeVariables #-}
12{-# LANGUAGE TypeFamilies #-}
12{-# LANGUAGE TypeFamilies #-}
13−module Reflex.Dom.Widget.Basic where
13+module Reflex.Dom.Widget.Basic
14+ ( partitionMapBySetLT
19+ -- * Displaying Values
27+ -- * Working with Maps
31+ , mapPartitionEithers
34+ -- * Widgets on Collections
37+ , listWithKeyShallowDiff
39+ , selectViewListWithKey
40+ , selectViewListWithKey_
42+ -- * Creating DOM Elements
49+ -- ** With Element Results
56+ , dynamicAttributesToModifyAttributes
62+ -- * Specific DOM Elements
76+ -- * Tables and Lists
15import Reflex.Class as Reflex
83import Reflex.Class as Reflex
16import Reflex.Dom.Builder.Class
84import Reflex.Dom.Builder.Class
@@ -215,43 +283,65 @@ selectViewListWithKey_ :: forall t m k v a. (DomBuilder t m, Ord k, PostBuild t
215 -> m (Event t k) -- ^ Event that fires when any child's return Event fires. Contains key of an arbitrary firing widget.
283 -> m (Event t k) -- ^ Event that fires when any child's return Event fires. Contains key of an arbitrary firing widget.
216selectViewListWithKey_ selection vals mkChild = fmap fst <$> selectViewListWithKey selection vals mkChild
284selectViewListWithKey_ selection vals mkChild = fmap fst <$> selectViewListWithKey selection vals mkChild
286+-- | Create a DOM element
287+-- > el "div" (text "Hello World")
288+-- <div>Hello World</div>
218{-# INLINABLE el #-}
289{-# INLINABLE el #-}
219el :: forall t m a. DomBuilder t m => Text -> m a -> m a
290el :: forall t m a. DomBuilder t m => Text -> m a -> m a
220el elementTag child = snd <$> el' elementTag child
291el elementTag child = snd <$> el' elementTag child
293+-- | Create a DOM element with attributes
294+-- > elAttr "a" ("href" =: "http://google.com") (text "Google!")
295+-- <a href="http://google.com">Google!</a>
222{-# INLINABLE elAttr #-}
296{-# INLINABLE elAttr #-}
223elAttr :: forall t m a. DomBuilder t m => Text -> Map Text Text -> m a -> m a
297elAttr :: forall t m a. DomBuilder t m => Text -> Map Text Text -> m a -> m a
224elAttr elementTag attrs child = snd <$> elAttr' elementTag attrs child
298elAttr elementTag attrs child = snd <$> elAttr' elementTag attrs child
300+-- | Create a DOM element with classes
301+-- > elClass "div" "row" (return ())
302+-- <div class="row"></div>
226{-# INLINABLE elClass #-}
303{-# INLINABLE elClass #-}
227elClass :: forall t m a. DomBuilder t m => Text -> Text -> m a -> m a
304elClass :: forall t m a. DomBuilder t m => Text -> Text -> m a -> m a
228elClass elementTag c child = snd <$> elClass' elementTag c child
305elClass elementTag c child = snd <$> elClass' elementTag c child
307+-- | Create a DOM element with Dynamic Attributes
308+-- > elClass "div" (constDyn ("class" =: "row")) (return ())
309+-- <div class="row"></div>
230{-# INLINABLE elDynAttr #-}
310{-# INLINABLE elDynAttr #-}
231elDynAttr :: forall t m a. (DomBuilder t m, PostBuild t m) => Text -> Dynamic t (Map Text Text) -> m a -> m a
311elDynAttr :: forall t m a. (DomBuilder t m, PostBuild t m) => Text -> Dynamic t (Map Text Text) -> m a -> m a
232elDynAttr elementTag attrs child = snd <$> elDynAttr' elementTag attrs child
312elDynAttr elementTag attrs child = snd <$> elDynAttr' elementTag attrs child
314+-- | Create a DOM element with a Dynamic Class
315+-- > elDynClass "div" (constDyn "row") (return ())
316+-- <div class="row"></div>
234{-# INLINABLE elDynClass #-}
317{-# INLINABLE elDynClass #-}
235elDynClass :: forall t m a. (DomBuilder t m, PostBuild t m) => Text -> Dynamic t Text -> m a -> m a
318elDynClass :: forall t m a. (DomBuilder t m, PostBuild t m) => Text -> Dynamic t Text -> m a -> m a
236elDynClass elementTag c child = snd <$> elDynClass' elementTag c child
319elDynClass elementTag c child = snd <$> elDynClass' elementTag c child
321+-- | Create a DOM element and return the element
322+-- > do (e, _) <- el' "div" (text "Click")
323+-- > return $ domEvent Click e
238{-# INLINABLE el' #-}
324{-# INLINABLE el' #-}
239el' :: forall t m a. DomBuilder t m => Text -> m a -> m (Element EventResult (DomBuilderSpace m) t, a)
325el' :: forall t m a. DomBuilder t m => Text -> m a -> m (Element EventResult (DomBuilderSpace m) t, a)
240el' elementTag = element elementTag def
326el' elementTag = element elementTag def
328+-- | Create a DOM element with attributes and return the element
242{-# INLINABLE elAttr' #-}
329{-# INLINABLE elAttr' #-}
243elAttr' :: forall t m a. DomBuilder t m => Text -> Map Text Text -> m a -> m (Element EventResult (DomBuilderSpace m) t, a)
330elAttr' :: forall t m a. DomBuilder t m => Text -> Map Text Text -> m a -> m (Element EventResult (DomBuilderSpace m) t, a)
244elAttr' elementTag attrs = element elementTag $ def
331elAttr' elementTag attrs = element elementTag $ def
245 & initialAttributes .~ Map.mapKeys (AttributeName Nothing) attrs
332 & initialAttributes .~ Map.mapKeys (AttributeName Nothing) attrs
334+-- | Create a DOM element with a class and return the element
247{-# INLINABLE elClass' #-}
335{-# INLINABLE elClass' #-}
248elClass' :: forall t m a. DomBuilder t m => Text -> Text -> m a -> m (Element EventResult (DomBuilderSpace m) t, a)
336elClass' :: forall t m a. DomBuilder t m => Text -> Text -> m a -> m (Element EventResult (DomBuilderSpace m) t, a)
249elClass' elementTag c = elAttr' elementTag ("class" =: c)
337elClass' elementTag c = elAttr' elementTag ("class" =: c)
339+-- | Create a DOM element with Dynamic Attributes and return the element
251{-# INLINABLE elDynAttr' #-}
340{-# INLINABLE elDynAttr' #-}
252elDynAttr' :: forall t m a. (DomBuilder t m, PostBuild t m) => Text -> Dynamic t (Map Text Text) -> m a -> m (Element EventResult (DomBuilderSpace m) t, a)
341elDynAttr' :: forall t m a. (DomBuilder t m, PostBuild t m) => Text -> Dynamic t (Map Text Text) -> m a -> m (Element EventResult (DomBuilderSpace m) t, a)
253elDynAttr' = elDynAttrNS' Nothing
342elDynAttr' = elDynAttrNS' Nothing
344+-- | Create a DOM element with a Dynamic class and return the element
255{-# INLINABLE elDynClass' #-}
345{-# INLINABLE elDynClass' #-}
256elDynClass' :: forall t m a. (DomBuilder t m, PostBuild t m) => Text -> Dynamic t Text -> m a -> m (Element EventResult (DomBuilderSpace m) t, a)
346elDynClass' :: forall t m a. (DomBuilder t m, PostBuild t m) => Text -> Dynamic t Text -> m a -> m (Element EventResult (DomBuilderSpace m) t, a)
257elDynClass' elementTag c = elDynAttr' elementTag (fmap ("class" =:) c)
347elDynClass' elementTag c = elDynAttr' elementTag (fmap ("class" =:) c)
@@ -324,6 +414,17 @@ linkClass s c = do
324link :: DomBuilder t m => Text -> m (Link t)
414link :: DomBuilder t m => Text -> m (Link t)
325link s = linkClass s ""
415link s = linkClass s ""
417+divClass :: forall t m a. DomBuilder t m => Text -> m a -> m a
418+divClass = elClass "div"
420+dtdd :: forall t m a. DomBuilder t m => Text -> m a -> m a
425+blank :: forall m. Monad m => m ()
327newtype Workflow t m a = Workflow { unWorkflow :: m (a, Event t (Workflow t m a)) }
428newtype Workflow t m a = Workflow { unWorkflow :: m (a, Event t (Workflow t m a)) }
329workflow :: forall t m a. (DomBuilder t m, MonadFix m, MonadHold t m) => Workflow t m a -> m (Dynamic t a)
430workflow :: forall t m a. (DomBuilder t m, MonadFix m, MonadHold t m) => Workflow t m a -> m (Dynamic t a)
@@ -340,17 +441,6 @@ workflowView w0 = do
340mapWorkflow :: (DomBuilder t m) => (a -> b) -> Workflow t m a -> Workflow t m b
441mapWorkflow :: (DomBuilder t m) => (a -> b) -> Workflow t m a -> Workflow t m b
341mapWorkflow f (Workflow x) = Workflow (fmap (f *** fmap (mapWorkflow f)) x)
442mapWorkflow f (Workflow x) = Workflow (fmap (f *** fmap (mapWorkflow f)) x)
343−divClass :: forall t m a. DomBuilder t m => Text -> m a -> m a
344−divClass = elClass "div"
346−dtdd :: forall t m a. DomBuilder t m => Text -> m a -> m a
351−blank :: forall m. Monad m => m ()
354-- | A widget to display a table with static columns and dynamic rows.
444-- | A widget to display a table with static columns and dynamic rows.
355tableDynAttr :: forall t m r k v. (Ord k, DomBuilder t m, MonadHold t m, PostBuild t m, MonadFix m)
445tableDynAttr :: forall t m r k v. (Ord k, DomBuilder t m, MonadHold t m, PostBuild t m, MonadFix m)
356 => Text -- ^ Class applied to <table> element
446 => Text -- ^ Class applied to <table> element