@@ -10,7 +10,75 @@
1010{-# LANGUAGE RecursiveDo #-}
1111{-# LANGUAGE ScopedTypeVariables #-}
1212{-# LANGUAGE TypeFamilies #-}
13−module Reflex.Dom.Widget.Basic where
13+module Reflex.Dom.Widget.Basic
14+ ( partitionMapBySetLT
15+ , listHoldWithKey
16+ , ChildResult (..)
17+ , listHoldWithKey
18+
19+ -- * Displaying Values
20+ , text
21+ , dynText
22+ , display
23+ , button
24+ , dyn
25+ , widgetHold
26+
27+ -- * Working with Maps
28+ , diffMapNoEq
29+ , diffMap
30+ , applyMap
31+ , mapPartitionEithers
32+ , applyMapKeysSet
33+
34+ -- * Widgets on Collections
35+ , listWithKey
36+ , listWithKey'
37+ , listWithKeyShallowDiff
38+ , listViewWithKey
39+ , selectViewListWithKey
40+ , selectViewListWithKey_
41+
42+ -- * Creating DOM Elements
43+ , el
44+ , elAttr
45+ , elClass
46+ , elDynAttr
47+ , elDynClass
48+
49+ -- ** With Element Results
50+ , el'
51+ , elAttr'
52+ , elClass'
53+ , elDynAttr'
54+ , elDynClass'
55+ , elDynAttrNS'
56+ , dynamicAttributesToModifyAttributes
57+
58+ -- * List Utils
59+ , list
60+ , simpleList
61+
62+ -- * Specific DOM Elements
63+ , Link (..)
64+ , linkClass
65+ , link
66+ , divClass
67+ , dtdd
68+ , blank
69+
70+ -- * Workflows
71+ , Workflow (..)
72+ , workflow
73+ , workflowView
74+ , mapWorkflow
75+
76+ -- * Tables and Lists
77+ , tableDynAttr
78+ , tabDisplay
79+
80+ , HasAttributes (..)
81+ ) where
1482
1583import Reflex.Class as Reflex
1684import Reflex.Dom.Builder.Class
@@ -215,43 +283,65 @@ selectViewListWithKey_ :: forall t m k v a. (DomBuilder t m, Ord k, PostBuild t
215283 -> m (Event t k) -- ^ Event that fires when any child's return Event fires. Contains key of an arbitrary firing widget.
216284selectViewListWithKey_ selection vals mkChild = fmap fst <$> selectViewListWithKey selection vals mkChild
217285
286+-- | Create a DOM element
287+-- > el "div" (text "Hello World")
288+-- <div>Hello World</div>
218289{-# INLINABLE el #-}
219290el :: forall t m a. DomBuilder t m => Text -> m a -> m a
220291el elementTag child = snd <$> el' elementTag child
221292
293+-- | Create a DOM element with attributes
294+-- > elAttr "a" ("href" =: "http://google.com") (text "Google!")
295+-- <a href="http://google.com">Google!</a>
222296{-# INLINABLE elAttr #-}
223297elAttr :: forall t m a. DomBuilder t m => Text -> Map Text Text -> m a -> m a
224298elAttr elementTag attrs child = snd <$> elAttr' elementTag attrs child
225299
300+-- | Create a DOM element with classes
301+-- > elClass "div" "row" (return ())
302+-- <div class="row"></div>
226303{-# INLINABLE elClass #-}
227304elClass :: forall t m a. DomBuilder t m => Text -> Text -> m a -> m a
228305elClass elementTag c child = snd <$> elClass' elementTag c child
229306
307+-- | Create a DOM element with Dynamic Attributes
308+-- > elClass "div" (constDyn ("class" =: "row")) (return ())
309+-- <div class="row"></div>
230310{-# INLINABLE elDynAttr #-}
231311elDynAttr :: forall t m a. (DomBuilder t m, PostBuild t m) => Text -> Dynamic t (Map Text Text) -> m a -> m a
232312elDynAttr elementTag attrs child = snd <$> elDynAttr' elementTag attrs child
233313
314+-- | Create a DOM element with a Dynamic Class
315+-- > elDynClass "div" (constDyn "row") (return ())
316+-- <div class="row"></div>
234317{-# INLINABLE elDynClass #-}
235318elDynClass :: forall t m a. (DomBuilder t m, PostBuild t m) => Text -> Dynamic t Text -> m a -> m a
236319elDynClass elementTag c child = snd <$> elDynClass' elementTag c child
237320
321+-- | Create a DOM element and return the element
322+-- > do (e, _) <- el' "div" (text "Click")
323+-- > return $ domEvent Click e
238324{-# INLINABLE el' #-}
239325el' :: forall t m a. DomBuilder t m => Text -> m a -> m (Element EventResult (DomBuilderSpace m) t, a)
240326el' elementTag = element elementTag def
241327
328+-- | Create a DOM element with attributes and return the element
242329{-# INLINABLE elAttr' #-}
243330elAttr' :: forall t m a. DomBuilder t m => Text -> Map Text Text -> m a -> m (Element EventResult (DomBuilderSpace m) t, a)
244331elAttr' elementTag attrs = element elementTag $ def
245332 & initialAttributes .~ Map.mapKeys (AttributeName Nothing) attrs
246333
334+-- | Create a DOM element with a class and return the element
247335{-# INLINABLE elClass' #-}
248336elClass' :: forall t m a. DomBuilder t m => Text -> Text -> m a -> m (Element EventResult (DomBuilderSpace m) t, a)
249337elClass' elementTag c = elAttr' elementTag ("class" =: c)
250338
339+-- | Create a DOM element with Dynamic Attributes and return the element
251340{-# INLINABLE elDynAttr' #-}
252341elDynAttr' :: 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)
253342elDynAttr' = elDynAttrNS' Nothing
254343
344+-- | Create a DOM element with a Dynamic class and return the element
255345{-# INLINABLE elDynClass' #-}
256346elDynClass' :: forall t m a. (DomBuilder t m, PostBuild t m) => Text -> Dynamic t Text -> m a -> m (Element EventResult (DomBuilderSpace m) t, a)
257347elDynClass' elementTag c = elDynAttr' elementTag (fmap ("class" =:) c)
@@ -324,6 +414,17 @@ linkClass s c = do
324414link :: DomBuilder t m => Text -> m (Link t)
325415link s = linkClass s ""
326416
417+divClass :: forall t m a. DomBuilder t m => Text -> m a -> m a
418+divClass = elClass "div"
419+
420+dtdd :: forall t m a. DomBuilder t m => Text -> m a -> m a
421+dtdd h w = do
422+ el "dt" $ text h
423+ el "dd" w
424+
425+blank :: forall m. Monad m => m ()
426+blank = return ()
427+
327428newtype Workflow t m a = Workflow { unWorkflow :: m (a, Event t (Workflow t m a)) }
328429
329430workflow :: 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
340441mapWorkflow :: (DomBuilder t m) => (a -> b) -> Workflow t m a -> Workflow t m b
341442mapWorkflow f (Workflow x) = Workflow (fmap (f *** fmap (mapWorkflow f)) x)
342443
343−divClass :: forall t m a. DomBuilder t m => Text -> m a -> m a
344−divClass = elClass "div"
345−
346−dtdd :: forall t m a. DomBuilder t m => Text -> m a -> m a
347−dtdd h w = do
348− el "dt" $ text h
349− el "dd" w
350−
351−blank :: forall m. Monad m => m ()
352−blank = return ()
353−
354444-- | A widget to display a table with static columns and dynamic rows.
355445tableDynAttr :: forall t m r k v. (Ord k, DomBuilder t m, MonadHold t m, PostBuild t m, MonadFix m)
356446 => Text -- ^ Class applied to <table> element