Skip to content

Commit c01f0a8

Browse files
committed
icons wip
1 parent 1731545 commit c01f0a8

File tree

4 files changed

+112
-42
lines changed

4 files changed

+112
-42
lines changed

ghcjs/delivery-calculator/src/App/Types.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,8 @@ pushActionQueue st =
321321
. atomically
322322
. writeTChan (st ^. #modelProducerQueue)
323323

324-
icon :: Icon.Fa -> View action
325-
icon = Icon.icon
324+
icon :: Icon.Icon -> View action
325+
icon = Icon.icon @Icon.Fa
326326

327327
vsn :: Unicode
328328
vsn =

ghcjs/delivery-calculator/src/App/Widgets/Menu.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ menu st =
4545
pure id
4646
)
4747
]
48-
[ icon Icon.menu
48+
[ icon Icon.IconMenu
4949
],
5050
li_
5151
[ role_ "button",
@@ -74,7 +74,7 @@ menu st =
7474
pure id
7575
)
7676
]
77-
[ icon Icon.fav
77+
[ icon Icon.IconFav
7878
],
7979
li_
8080
[ role_ "button",
@@ -86,7 +86,7 @@ menu st =
8686
Jsm.printCurrentPage "delivery-calculator"
8787
pure id
8888
]
89-
[ icon Icon.print
89+
[ icon Icon.IconPrint
9090
],
9191
li_
9292
[ role_ "button",
@@ -101,7 +101,7 @@ menu st =
101101
Xlsx.newXlsx
102102
pure id
103103
]
104-
[ icon Icon.download
104+
[ icon Icon.IconDownload
105105
],
106106
li_
107107
[ role_ "button",
@@ -113,7 +113,7 @@ menu st =
113113
. either impureThrow URI.renderStr
114114
$ stUri st
115115
]
116-
[ icon Icon.share
116+
[ icon Icon.IconShare
117117
]
118118
]
119119
]

ghcjs/miso-functora/src/Functora/Miso/Widgets/Dialog.hs

Lines changed: 77 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ where
1010

1111
import Functora.Miso.Prelude
1212
import Functora.Miso.Types
13+
import qualified Functora.Miso.Widgets.Icon as Icon
1314
import qualified Language.Javascript.JSaddle as JS
1415

1516
data Args model action = Args
@@ -20,22 +21,34 @@ data Args model action = Args
2021
}
2122
deriving stock (Generic)
2223

23-
data Opts model = Opts
24+
data Opts model action = Opts
2425
{ optsTitle :: Maybe Unicode,
25-
optsExtraOnOpen :: model -> model,
26-
optsExtraOnClose :: model -> model
26+
optsHeaderLeft :: [View action] -> [View action],
27+
optsHeaderRight :: [View action] -> [View action],
28+
optsFooterLeft :: [View action] -> [View action],
29+
optsFooterRight :: [View action] -> [View action],
30+
optsExtraOnClose :: model -> model,
31+
optsIcon :: Icon.Icon -> View action
2732
}
2833
deriving stock (Generic)
2934

30-
defOpts :: Opts model
35+
defOpts :: Opts model action
3136
defOpts =
3237
Opts
3338
{ optsTitle = Nothing,
34-
optsExtraOnOpen = id,
35-
optsExtraOnClose = id
39+
optsHeaderLeft = id,
40+
optsHeaderRight = id,
41+
optsFooterLeft = id,
42+
optsFooterRight = id,
43+
optsExtraOnClose = id,
44+
optsIcon = Icon.icon @Icon.Fa
3645
}
3746

38-
dialog :: forall model action. Opts model -> Args model action -> [View action]
47+
dialog ::
48+
forall model action.
49+
Opts model action ->
50+
Args model action ->
51+
[View action]
3952
dialog opts args =
4053
singleton
4154
. nodeHtml
@@ -49,22 +62,65 @@ dialog opts args =
4962
/= Just Opened
5063
then mempty
5164
else
52-
maybeToList
53-
( fmap
54-
( \x -> header_ mempty [h2_ mempty [text x]]
55-
)
56-
$ optsTitle opts
57-
)
65+
newFlex
66+
header_
67+
id
68+
(optsHeaderLeft opts defHeaderLeft)
69+
(optsHeaderRight opts defHeaderRight)
5870
<> argsContent args
59-
<> [ footer_
60-
mempty
61-
[ button_
62-
[onClick $ closeDialogAction opts args]
63-
[text "Back"]
64-
]
65-
]
71+
<> newFlex
72+
footer_
73+
id
74+
(optsFooterLeft opts defFooterRight)
75+
(optsFooterRight opts mempty)
76+
where
77+
defHeaderLeft =
78+
maybeToList
79+
. fmap (h2_ [style_ [("margin", "0")]] . singleton . text)
80+
$ optsTitle opts
81+
defHeaderRight =
82+
[ button_
83+
[onClick $ closeDialogAction opts args]
84+
[optsIcon opts Icon.IconClose]
85+
]
86+
defFooterRight =
87+
[ button_
88+
[onClick $ closeDialogAction opts args]
89+
[text "Back"]
90+
]
91+
92+
newFlex ::
93+
([Attribute action] -> [View action] -> View action) ->
94+
([Attribute action] -> [Attribute action]) ->
95+
[View action] ->
96+
[View action] ->
97+
[View action]
98+
newFlex newTag newAttr lhs rhs =
99+
if null lhs && null rhs
100+
then mempty
101+
else
102+
singleton
103+
. newTag
104+
( newAttr
105+
[ style_
106+
[ ("display", "flex"),
107+
("flex-wrap", "wrap"),
108+
("flex-direction", "row"),
109+
("justify-content", "space-between")
110+
]
111+
]
112+
)
113+
$ lhs
114+
<> [ span_
115+
[ style_
116+
[ ("flex-grow", "1")
117+
]
118+
]
119+
mempty
120+
]
121+
<> rhs
66122

67-
closeDialogAction :: Opts model -> Args model action -> action
123+
closeDialogAction :: Opts model action -> Args model action -> action
68124
closeDialogAction opts args =
69125
argsAction args
70126
$ PureAndImpureUpdate

ghcjs/miso-functora/src/Functora/Miso/Widgets/Icon.hs

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,51 @@
11
module Functora.Miso.Widgets.Icon
22
( Icon (..),
3+
IsIcon (..),
34
Fa,
45
)
56
where
67

78
import Functora.Miso.Prelude
89
import Text.Casing (kebab)
910

10-
class Icon a where
11-
icon :: a -> View action
12-
menu :: a
13-
fav :: a
14-
print :: a
15-
download :: a
16-
share :: a
11+
data Icon
12+
= IconMenu
13+
| IconFav
14+
| IconPrint
15+
| IconDownload
16+
| IconShare
17+
| IconClose
18+
deriving stock (Eq, Ord, Show, Read, Data, Generic, Enum, Bounded)
19+
20+
class (From Icon a) => IsIcon a where
21+
icon :: Icon -> View action
1722

1823
data Fa
1924
= FaBars
2025
| FaHeart
2126
| FaPrint
2227
| FaDownload
2328
| FaShareNodes
29+
| FaXmark
2430
deriving stock (Eq, Ord, Show, Read, Data, Generic, Enum, Bounded)
2531

26-
instance Icon Fa where
32+
instance From Icon Fa where
33+
from = \case
34+
IconMenu -> FaBars
35+
IconFav -> FaHeart
36+
IconPrint -> FaPrint
37+
IconDownload -> FaDownload
38+
IconShare -> FaShareNodes
39+
IconClose -> FaXmark
40+
41+
instance IsIcon Fa where
2742
icon x =
2843
i_
2944
[ class_ "fa-solid",
30-
class_ . from @String @Unicode . kebab $ inspect @String x
45+
class_
46+
. from @String @Unicode
47+
. kebab
48+
. inspect @String
49+
$ from @Icon @Fa x
3150
]
3251
mempty
33-
menu = FaBars
34-
fav = FaHeart
35-
print = FaPrint
36-
download = FaDownload
37-
share = FaShareNodes

0 commit comments

Comments
 (0)