10
10
11
11
import Functora.Miso.Prelude
12
12
import Functora.Miso.Types
13
+ import qualified Functora.Miso.Widgets.Icon as Icon
13
14
import qualified Language.Javascript.JSaddle as JS
14
15
15
16
data Args model action = Args
@@ -20,22 +21,34 @@ data Args model action = Args
20
21
}
21
22
deriving stock (Generic )
22
23
23
- data Opts model = Opts
24
+ data Opts model action = Opts
24
25
{ 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
27
32
}
28
33
deriving stock (Generic )
29
34
30
- defOpts :: Opts model
35
+ defOpts :: Opts model action
31
36
defOpts =
32
37
Opts
33
38
{ 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
36
45
}
37
46
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 ]
39
52
dialog opts args =
40
53
singleton
41
54
. nodeHtml
@@ -49,22 +62,65 @@ dialog opts args =
49
62
/= Just Opened
50
63
then mempty
51
64
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)
58
70
<> 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
66
122
67
- closeDialogAction :: Opts model -> Args model action -> action
123
+ closeDialogAction :: Opts model action -> Args model action -> action
68
124
closeDialogAction opts args =
69
125
argsAction args
70
126
$ PureAndImpureUpdate
0 commit comments