Skip to content

Commit c53e1ba

Browse files
committed
miso-capa wip
1 parent 7447f95 commit c53e1ba

File tree

6 files changed

+45
-52
lines changed

6 files changed

+45
-52
lines changed

ghcjs/miso-capa/miso-capa.cabal

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ library
104104
Functora.Miso.Capa.Dialog
105105
Functora.Miso.Capa.Field
106106
Functora.Miso.Capa.FieldPairs
107-
Functora.Miso.Capa.Frame
107+
Functora.Miso.Capa.Flex
108108
Functora.Miso.Capa.Grid
109109
Functora.Miso.Capa.Header
110110
Functora.Miso.Capa.Money
@@ -138,7 +138,7 @@ test-suite miso-capa-test
138138
Functora.Miso.Capa.Dialog
139139
Functora.Miso.Capa.Field
140140
Functora.Miso.Capa.FieldPairs
141-
Functora.Miso.Capa.Frame
141+
Functora.Miso.Capa.Flex
142142
Functora.Miso.Capa.Grid
143143
Functora.Miso.Capa.Header
144144
Functora.Miso.Capa.Money
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module Functora.Miso.Capa.Flex
2+
( flex,
3+
)
4+
where
5+
6+
import Functora.Miso.Prelude
7+
8+
flex :: [Attribute action] -> [View action] -> View action
9+
flex attrs =
10+
div_ $ style_ [("display", "flex")] : attrs

ghcjs/miso-capa/src/Functora/Miso/Capa/Frame.hs

Lines changed: 0 additions & 35 deletions
This file was deleted.

ghcjs/miso-capa/src/Functora/Miso/Capa/Switch.hs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@ module Functora.Miso.Capa.Switch
55
)
66
where
77

8-
import qualified Functora.Miso.Capa.Frame as Frame
8+
import qualified Functora.Miso.Capa.Flex as Flex
99
import Functora.Miso.Prelude
10-
import qualified Material.Icon as Icon
11-
import qualified Material.Switch as Switch
10+
import Functora.Miso.Types
1211
import Miso hiding (at, view)
1312

1413
data Args model action = Args
1514
{ argsModel :: model,
1615
argsOptic :: ATraversal' model Bool,
17-
argsAction :: JSM (model -> model) -> action
16+
argsAction :: Updater model -> action
1817
}
1918
deriving stock (Generic)
2019

@@ -39,18 +38,28 @@ switch ::
3938
Opts model action ->
4039
View action
4140
switch Args {argsModel = st, argsOptic = optic, argsAction = action} opts =
42-
Frame.frame
41+
Flex.flex mempty
4342
$ maybeToList
44-
( fmap (Icon.icon mempty)
43+
( fmap (\icon -> i_ [class_ icon] mempty)
4544
$ optsIcon opts
4645
)
4746
<> [ Miso.rawHtml "&nbsp;",
4847
Miso.text $ opts ^. #optsPlaceholder,
4948
Miso.rawHtml "&nbsp;&nbsp;",
50-
Switch.switch
51-
$ Switch.config
52-
& Switch.setChecked
53-
( fromMaybe False $ st ^? cloneTraversal optic
54-
)
55-
& Switch.setOnChange (action $ pure (& cloneTraversal optic %~ not))
49+
input_
50+
[ type_ "checkbox",
51+
disabled_
52+
$ opts
53+
^. #optsDisabled,
54+
checked_
55+
. fromMaybe False
56+
$ st
57+
^? cloneTraversal optic,
58+
onChange
59+
. const
60+
. action
61+
. PureUpdater
62+
$ cloneTraversal optic
63+
%~ not
64+
]
5665
]
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
module Functora.Miso.Css (fullWidth) where
1+
module Functora.Miso.Css
2+
( fullWidth,
3+
)
4+
where
25

36
import Functora.Miso.Prelude
47

58
fullWidth :: Attribute action
6-
fullWidth =
7-
style_ [("width", "100%")]
9+
fullWidth = style_ [("width", "100%")]

ghcjs/miso-capa/src/Functora/Miso/Types.hs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ module Functora.Miso.Types
4848
StaticOrDynamic (..),
4949
LeadingOrTrailing (..),
5050
OpenedOrClosed (..),
51+
Updater (..),
5152
)
5253
where
5354

@@ -525,3 +526,9 @@ data OpenedOrClosed
525526
| Closed
526527
deriving stock (Eq, Ord, Show, Enum, Bounded, Data, Generic)
527528
deriving (Binary) via GenericType OpenedOrClosed
529+
530+
data Updater model
531+
= PureUpdater (model -> model)
532+
| ImpureUpdater (model -> JSM model)
533+
| PureAndImpureUpdater (model -> model) (model -> JSM model)
534+
deriving stock (Generic)

0 commit comments

Comments
 (0)