diff options
Diffstat (limited to 'client/src/Component')
-rw-r--r-- | client/src/Component/Button.hs | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/client/src/Component/Button.hs b/client/src/Component/Button.hs index 9499045..c31cdc6 100644 --- a/client/src/Component/Button.hs +++ b/client/src/Component/Button.hs @@ -7,24 +7,23 @@ module Component.Button , button ) where -import qualified Data.Map as M -import Data.Monoid ((<>)) -import Data.Text (Text) -import qualified Data.Text as T -import Reflex.Dom (Event, MonadWidget) -import qualified Reflex.Dom as R +import qualified Data.Map as M +import Data.Text (Text) +import qualified Data.Text as T +import Reflex.Dom (Dynamic, Event, MonadWidget) +import qualified Reflex.Dom as R import qualified Icon data ButtonIn t m = ButtonIn - { _buttonIn_class :: Text + { _buttonIn_class :: Dynamic t Text , _buttonIn_content :: m () , _buttonIn_waiting :: Event t Bool } buttonInDefault :: forall t m. MonadWidget t m => ButtonIn t m buttonInDefault = ButtonIn - { _buttonIn_class = "" + { _buttonIn_class = R.constDyn "" , _buttonIn_content = R.blank , _buttonIn_waiting = R.never } @@ -35,18 +34,25 @@ data ButtonOut t = ButtonOut button :: forall t m. MonadWidget t m => ButtonIn t m -> m (ButtonOut t) button buttonIn = do - attr <- R.holdDyn - (M.fromList [("type", "button"), ("class", _buttonIn_class buttonIn)]) - (fmap - (\w -> M.fromList $ - [ ("type", "button") ] - <> if w - then [("class", T.concat [ _buttonIn_class buttonIn, " waiting" ])] - else [("class", _buttonIn_class buttonIn)]) - (_buttonIn_waiting buttonIn)) + dynWaiting <- R.holdDyn False $ _buttonIn_waiting buttonIn + + let attr = do + buttonClass <- _buttonIn_class buttonIn + waiting <- dynWaiting + return $ if waiting + then M.fromList [("type", "button"), ("class", T.intercalate " " [ buttonClass, "waiting" ])] + else M.fromList [("type", "button"), ("class", buttonClass)] + (e, _) <- R.elDynAttr' "button" attr $ do Icon.loading R.divClass "content" $ _buttonIn_content buttonIn + return $ ButtonOut { _buttonOut_clic = R.domEvent R.Click e } + +-- mergeAttr :: Map Text Text -> Map Text Text -> Map Text Text +-- mergeAttr = M.unionWithKey $ \k a b -> +-- if k == "class" +-- then T.intercalate " " [ a, b ] +-- else b |