aboutsummaryrefslogtreecommitdiff
path: root/client/src/Component
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/Component')
-rw-r--r--client/src/Component/Input.hs57
1 files changed, 42 insertions, 15 deletions
diff --git a/client/src/Component/Input.hs b/client/src/Component/Input.hs
index 1923463..7eec7d0 100644
--- a/client/src/Component/Input.hs
+++ b/client/src/Component/Input.hs
@@ -4,13 +4,19 @@ module Component.Input
, input
) where
-import Data.Text (Text)
-import Reflex.Dom (Dynamic, 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 Component.Button (ButtonIn (..), ButtonOut (..))
+import qualified Component.Button as Button
+import qualified Icon
data InputIn t a b = InputIn
- { _inputIn_reset :: Event t a
- , _inputIn_placeHolder :: Text
+ { _inputIn_reset :: Event t a
+ , _inputIn_label :: Text
}
data InputOut t = InputOut
@@ -19,13 +25,34 @@ data InputOut t = InputOut
}
input :: forall t m a b. MonadWidget t m => InputIn t a b -> m (InputOut t)
-input inputIn = do
- let placeHolder = R.constDyn ("placeHolder" =: _inputIn_placeHolder inputIn)
- let value = fmap (const "") (_inputIn_reset inputIn)
- textInput <- R.textInput $ R.def & R.attributes .~ placeHolder
- & R.setValue .~ value
- let enter = fmap (const ()) $ R.ffilter ((==) 13) . R._textInput_keypress $ textInput
- return $ InputOut
- { _inputOut_value = R._textInput_value textInput
- , _inputOut_enter = enter
- }
+input inputIn =
+ R.divClass "textInput" $ do
+ rec
+ let resetValue = R.leftmost
+ [ fmap (const "") (_inputIn_reset inputIn)
+ , fmap (const "") (_buttonOut_clic reset)
+ ]
+
+ attributes = R.ffor value (\v ->
+ if T.null v then M.empty else M.singleton "class" "filled")
+
+ value = R._textInput_value textInput
+
+ textInput <- R.textInput $ R.def
+ & R.attributes .~ attributes
+ & R.setValue .~ resetValue
+
+ R.el "label" $ R.text (_inputIn_label inputIn)
+
+ reset <- Button.button $ ButtonIn
+ { _buttonIn_class = R.constDyn ""
+ , _buttonIn_content = Icon.cross
+ , _buttonIn_waiting = R.never
+ }
+
+ let enter = fmap (const ()) $ R.ffilter ((==) 13) . R._textInput_keypress $ textInput
+
+ return $ InputOut
+ { _inputOut_value = value
+ , _inputOut_enter = enter
+ }