@@ -10,11 +10,9 @@
10{-# LANGUAGE ScopedTypeVariables #-}
10{-# LANGUAGE ScopedTypeVariables #-}
11{-# LANGUAGE TypeFamilies #-}
11{-# LANGUAGE TypeFamilies #-}
12module Reflex.Dom.Widget.Basic
12module Reflex.Dom.Widget.Basic
13− ( partitionMapBySetLT
13+ (
16 -- * Displaying Values
14 -- * Displaying Values
@@ -57,6 +55,8 @@ module Reflex.Dom.Widget.Basic
57 , module Data.Map.Misc
55 , module Data.Map.Misc
58 , module Reflex.Collection
56 , module Reflex.Collection
59 , module Reflex.Workflow
57 , module Reflex.Workflow
58+ , partitionMapBySetLT
62import Reflex.Class
62import Reflex.Class
@@ -131,7 +131,7 @@ button t = do
131--TODO: Should this be renamed to 'widgetView' for consistency with 'widgetHold'?
131--TODO: Should this be renamed to 'widgetView' for consistency with 'widgetHold'?
132-- | Given a Dynamic of widget-creating actions, create a widget that is recreated whenever the Dynamic updates.
132-- | Given a Dynamic of widget-creating actions, create a widget that is recreated whenever the Dynamic updates.
133-- The returned Event of widget results occurs when the Dynamic does.
133-- The returned Event of widget results occurs when the Dynamic does.
134−-- Note: Often, the type 'a' is an Event, in which case the return value is an Event-of-Events that would typically be flattened (via 'switchPromptly').
134+-- Note: Often, the type @a@ is an 'Event', in which case the return value is an Event-of-Events that would typically be flattened (via 'switchHold').
135dyn :: (DomBuilder t m, PostBuild t m) => Dynamic t (m a) -> m (Event t a)
135dyn :: (DomBuilder t m, PostBuild t m) => Dynamic t (m a) -> m (Event t a)
136dyn = networkView
136dyn = networkView
@@ -141,7 +141,7 @@ dyn_ = void . dyn
142-- | Given an initial widget and an Event of widget-creating actions, create a widget that is recreated whenever the Event fires.
142-- | Given an initial widget and an Event of widget-creating actions, create a widget that is recreated whenever the Event fires.
143-- The returned Dynamic of widget results occurs when the Event does.
143-- The returned Dynamic of widget results occurs when the Event does.
144−-- Note: Often, the type 'a' is an Event, in which case the return value is a Dynamic-of-Events that would typically be flattened.
144+-- Note: Often, the type 'a' is an Event, in which case the return value is a Dynamic-of-Events that would typically be flattened (via 'switchDyn').
145widgetHold :: (DomBuilder t m, MonadHold t m) => m a -> Event t (m a) -> m (Dynamic t a)
145widgetHold :: (DomBuilder t m, MonadHold t m) => m a -> Event t (m a) -> m (Dynamic t a)
146widgetHold = networkHold
146widgetHold = networkHold
@@ -150,43 +150,51 @@ widgetHold_ :: (DomBuilder t m, MonadHold t m) => m a -> Event t (m a) -> m ()
150widgetHold_ z = void . widgetHold z
150widgetHold_ z = void . widgetHold z
152-- | Create a DOM element
152-- | Create a DOM element
153−-- > el "div" (text "Hello World")
154+-- >>> el "div" (text "Hello World")
154-- <div>Hello World</div>
155-- <div>Hello World</div>
155{-# INLINABLE el #-}
156{-# INLINABLE el #-}
156el :: forall t m a. DomBuilder t m => Text -> m a -> m a
157el :: forall t m a. DomBuilder t m => Text -> m a -> m a
157el elementTag child = snd <$> el' elementTag child
158el elementTag child = snd <$> el' elementTag child
159-- | Create a DOM element with attributes
160-- | Create a DOM element with attributes
160−-- > elAttr "a" ("href" =: "http://google.com") (text "Google!")
162+-- >>> elAttr "a" ("href" =: "https://reflex-frp.org") (text "Reflex-FRP!")
161−-- <a href="http://google.com">Google!</a>
163+-- <a href="https://reflex-frp.org">Reflex-FRP!</a>
162{-# INLINABLE elAttr #-}
164{-# INLINABLE elAttr #-}
163elAttr :: forall t m a. DomBuilder t m => Text -> Map Text Text -> m a -> m a
165elAttr :: forall t m a. DomBuilder t m => Text -> Map Text Text -> m a -> m a
164elAttr elementTag attrs child = snd <$> elAttr' elementTag attrs child
166elAttr elementTag attrs child = snd <$> elAttr' elementTag attrs child
166-- | Create a DOM element with classes
168-- | Create a DOM element with classes
167−-- > elClass "div" "row" (return ())
170+-- >>> elClass "div" "row" (return ())
168-- <div class="row"></div>
171-- <div class="row"></div>
169{-# INLINABLE elClass #-}
172{-# INLINABLE elClass #-}
170elClass :: forall t m a. DomBuilder t m => Text -> Text -> m a -> m a
173elClass :: forall t m a. DomBuilder t m => Text -> Text -> m a -> m a
171elClass elementTag c child = snd <$> elClass' elementTag c child
174elClass elementTag c child = snd <$> elClass' elementTag c child
173-- | Create a DOM element with Dynamic Attributes
176-- | Create a DOM element with Dynamic Attributes
174−-- > elClass "div" (constDyn ("class" =: "row")) (return ())
178+-- >>> elClass "div" (constDyn ("class" =: "row")) (return ())
175-- <div class="row"></div>
179-- <div class="row"></div>
176{-# INLINABLE elDynAttr #-}
180{-# INLINABLE elDynAttr #-}
177elDynAttr :: forall t m a. (DomBuilder t m, PostBuild t m) => Text -> Dynamic t (Map Text Text) -> m a -> m a
181elDynAttr :: forall t m a. (DomBuilder t m, PostBuild t m) => Text -> Dynamic t (Map Text Text) -> m a -> m a
178elDynAttr elementTag attrs child = snd <$> elDynAttr' elementTag attrs child
182elDynAttr elementTag attrs child = snd <$> elDynAttr' elementTag attrs child
180-- | Create a DOM element with a Dynamic Class
184-- | Create a DOM element with a Dynamic Class
181−-- > elDynClass "div" (constDyn "row") (return ())
186+-- >>> elDynClass "div" (constDyn "row") (return ())
182-- <div class="row"></div>
187-- <div class="row"></div>
183{-# INLINABLE elDynClass #-}
188{-# INLINABLE elDynClass #-}
184elDynClass :: forall t m a. (DomBuilder t m, PostBuild t m) => Text -> Dynamic t Text -> m a -> m a
189elDynClass :: forall t m a. (DomBuilder t m, PostBuild t m) => Text -> Dynamic t Text -> m a -> m a
185elDynClass elementTag c child = snd <$> elDynClass' elementTag c child
190elDynClass elementTag c child = snd <$> elDynClass' elementTag c child
187-- | Create a DOM element and return the element
192-- | Create a DOM element and return the element
188−-- > do (e, _) <- el' "div" (text "Click")
195+-- do (e, _) <- el' "div" (text "Click")
189−-- > return $ domEvent Click e
196+-- return $ domEvent Click e
190{-# INLINABLE el' #-}
198{-# INLINABLE el' #-}
191el' :: forall t m a. DomBuilder t m => Text -> m a -> m (Element EventResult (DomBuilderSpace m) t, a)
199el' :: forall t m a. DomBuilder t m => Text -> m a -> m (Element EventResult (DomBuilderSpace m) t, a)
192el' elementTag = element elementTag def
200el' elementTag = element elementTag def
@@ -272,6 +280,8 @@ newtype Link t
272 = Link { _link_clicked :: Event t ()
280 = Link { _link_clicked :: Event t ()
283+-- | >>> linkClass "Click here" "link-class"
284+-- > <a class="link-class">Click here</a>
275linkClass :: DomBuilder t m => Text -> Text -> m (Link t)
285linkClass :: DomBuilder t m => Text -> Text -> m (Link t)
276linkClass s c = do
286linkClass s c = do
277 (l,_) <- elAttr' "a" ("class" =: c) $ text s
287 (l,_) <- elAttr' "a" ("class" =: c) $ text s