Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

use purescript-number-input-halogen #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"purescript-validation": "^3.1.0",
"purescript-profunctor": "^3.1.0",
"purescript-numbers": "^5.0.0",
"purescript-these": "^3.0.0"
"purescript-these": "^3.0.0",
"purescript-number-input-halogen": "git://github.com/safareli/purescript-number-input-halogen.git#initial"
Copy link
Contributor Author

@safareli safareli Jul 31, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will update this once I merge the PR

}
}
6 changes: 6 additions & 0 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
width: 500px;
margin: 0px 4px;
}
.Picker-input--length-3 {
width: 3.5em;
}
.Picker-input--length-2 {
width: 2.7em;
}
</style>
</head>
<body>
Expand Down
8 changes: 4 additions & 4 deletions src/Halogen/DatePicker/Component/Date.purs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import Halogen.Datepicker.Format.Date as F
import Halogen.Datepicker.Internal.Choice as Choice
import Halogen.Datepicker.Internal.Enums (MonthShort, Year2, Year4, setYear)
import Halogen.Datepicker.Internal.Elements (textElement, PreChoiceConfig, renderChoice, renderNum)
import Halogen.Datepicker.Internal.Num as Num
import Halogen.Datepicker.Internal.Range (Range, bottomTop)
import NumberInput.Halogen.Component as Num
import NumberInput.Range (Range, bottomTop)
import Halogen.Datepicker.Internal.Utils (mapParentHTMLQuery, foldSteps, componentProps, transitionState', pickerProps, mustBeMounted)
import Halogen.HTML as HH

Expand Down Expand Up @@ -126,7 +126,7 @@ buildDate format = do
mkBuildStep = commandCata
{ text: \cmd → pure $ Just mempty
, enum: \cmd → do
num ← queryNum cmd $ H.request (left <<< GetValue)
num ← queryNum cmd $ H.request Num.GetValue
pure $ num <#> \n → Join $ Star $ \t → F.toSetter cmd n t
, choice: \cmd → do
num ← queryChoice cmd $ H.request (left <<< GetValue)
Expand All @@ -152,7 +152,7 @@ propagateChange format date = for_ (unwrap format) $ commandCata
{ text: \cmd → pure unit
, enum: \cmd → do
let val = value date >>= F.toGetter cmd
queryNum cmd $ H.request $ left <<< SetValue val
queryNum cmd $ H.action $ Num.SetValue val
, choice: \cmd → do
let val = value date >>= F.toGetter cmd
res ← queryChoice cmd $ H.request $ left <<< SetValue val
Expand Down
16 changes: 8 additions & 8 deletions src/Halogen/DatePicker/Component/Duration.purs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Prelude
import Data.Array (fold)
import Data.Bifunctor (lmap)
import Data.Either (Either(..))
import Data.Functor.Coproduct (Coproduct, coproduct, right, left)
import Data.Functor.Coproduct (Coproduct, coproduct, right)
import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Show (genericShow)
import Data.Interval (Duration)
Expand All @@ -18,11 +18,11 @@ import Data.String (take)
import Data.Traversable (for)
import Data.Tuple (Tuple(..))
import Halogen as H
import Halogen.Datepicker.Component.Types (BasePickerQuery(..), PickerMessage(..), PickerQuery(..), PickerValue)
import Halogen.Datepicker.Component.Types (BasePickerQuery(..), PickerMessage, PickerQuery(..), PickerValue)
import Halogen.Datepicker.Config (Config, defaultConfig)
import Halogen.Datepicker.Format.Duration as F
import Halogen.Datepicker.Internal.Num as Num
import Halogen.Datepicker.Internal.Range (minRange)
import NumberInput.Halogen.Component as Num
import NumberInput.Range (minRange)
import Halogen.Datepicker.Internal.Utils (mapParentHTMLQuery, foldSteps, componentProps, transitionState, asRight, mustBeMounted, pickerProps)
import Halogen.Datepicker.Internal.Elements (toNumConf)
import Halogen.HTML as HH
Expand Down Expand Up @@ -68,9 +68,9 @@ renderCommand ∷ ∀ m. Config → F.Command → HTML m
renderCommand config cmd = HH.li (componentProps config)
[ HH.slot
cmd
(Num.picker Num.numberHasNumberInputVal $ toNumConf config { title: show cmd, placeholder: take 1 (show cmd), range: minRange 0.0 })
(Num.input Num.numberHasNumberInputVal $ toNumConf config { title: show cmd, placeholder: take 1 (show cmd), range: minRange 0.0 })
unit
(HE.input $ \(NotifyChange n) → UpdateCommand cmd n)]
(HE.input $ \(Num.NotifyChange n) → UpdateCommand cmd n)]

getComponent ∷ F.Command → IsoDuration → Number
getComponent cmd d = fromMaybe 0.0 $ F.toGetter cmd (unIsoDuration d)
Expand Down Expand Up @@ -101,7 +101,7 @@ buildDuration format = do
where
mkBuildStep ∷ F.Command → DSL m BuildStep
mkBuildStep cmd = do
num ← query cmd $ H.request (left <<< GetValue)
num ← query cmd $ H.request (Num.GetValue)
pure $ num <#> F.toSetter cmd >>> Endo
runStep ∷ BuildStep -> Maybe (Either Errors IsoDuration)
runStep step = step <#> \(Endo f) -> mkIsoDuration $ f mempty
Expand All @@ -121,7 +121,7 @@ propagateChange ∷ ∀ m . F.Format → State → DSL m Unit
propagateChange format duration = do
map fold $ for (unwrap format) \cmd → do
let n = duration >>= asRight >>= unIsoDuration >>> F.toGetter cmd
query cmd $ H.request $ left <<< SetValue n
query cmd $ H.action $ Num.SetValue n

query ∷ ∀ m. Slot → ChildQuery ~> DSL m
query cmd q = H.query cmd q >>= mustBeMounted
8 changes: 4 additions & 4 deletions src/Halogen/DatePicker/Component/Time.purs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import Halogen.Datepicker.Format.Time as F
import Halogen.Datepicker.Internal.Choice as Choice
import Halogen.Datepicker.Internal.Enums (Hour12, Meridiem, Millisecond1, Millisecond2)
import Halogen.Datepicker.Internal.Elements (textElement, PreChoiceConfig, renderChoice, renderNum)
import Halogen.Datepicker.Internal.Num as Num
import Halogen.Datepicker.Internal.Range (Range, bottomTop)
import NumberInput.Halogen.Component as Num
import NumberInput.Range (Range, bottomTop)
import Halogen.Datepicker.Internal.Utils (mapParentHTMLQuery, componentProps, foldSteps, mustBeMounted, pickerProps, transitionState')
import Halogen.HTML as HH

Expand Down Expand Up @@ -132,7 +132,7 @@ buildTime format = do
num ← queryChoice cmd $ H.request (left <<< GetValue)
pure $ num <#> \n → Join $ Star $ \t → F.toSetter cmd n t
_ → do
num ← queryNum cmd $ H.request (left <<< GetValue)
num ← queryNum cmd $ H.request (Num.GetValue)
pure $ num <#> \n → Join $ Star $ \t → F.toSetter cmd n t


Expand All @@ -155,7 +155,7 @@ propagateChange format time = for_ (unwrap format) \cmd → case cmd of
Choice.valueMustBeInValues res
_ → do
let val = value time >>= F.toGetter cmd
queryNum cmd $ H.request $ left <<< SetValue val
queryNum cmd $ H.action $ Num.SetValue val

queryChoice ∷ ∀ m. ChoiceSlot → ChoiceQuery ~> DSL m
queryChoice s q = H.query' cpChoice s q >>= mustBeMounted
Expand Down
8 changes: 4 additions & 4 deletions src/Halogen/DatePicker/Internal/Elements.purs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import Halogen.Component.ChildPath (ChildPath)
import Halogen.Datepicker.Component.Types (PickerMessage(..))
import Halogen.Datepicker.Config (Config(..))
import Halogen.Datepicker.Internal.Choice as Choice
import Halogen.Datepicker.Internal.Num as Num
import Halogen.Datepicker.Internal.Range (Range)
import NumberInput.Halogen.Component as Num
import NumberInput.Range (Range)
import Halogen.HTML as HH
import Halogen.HTML.Events as HE
import Halogen.HTML.Properties as HP
Expand Down Expand Up @@ -46,8 +46,8 @@ renderNum cpNum update toSetter cmd mainConf preConf =
conf = toNumConf mainConf preConf
in
HH.slot' cpNum cmd
(Num.picker Num.intHasNumberInputVal conf) unit
(HE.input $ \(NotifyChange n) → update $ \t → n >>= (_ `toSetter cmd` t))
(Num.input Num.intHasNumberInputVal conf) unit
(HE.input $ \(Num.NotifyChange n) → update $ \t → n >>= (_ `toSetter cmd` t))

toChoiceConf ∷
∀ a. Config
Expand Down
222 changes: 0 additions & 222 deletions src/Halogen/DatePicker/Internal/Num.purs

This file was deleted.

Loading