Skip to content

Commit 746df99

Browse files
committed
image field options
1 parent a436fb8 commit 746df99

File tree

7 files changed

+62
-48
lines changed

7 files changed

+62
-48
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,16 +165,16 @@ newAsset :: (MonadIO m) => m (Asset Unique)
165165
newAsset = do
166166
link <-
167167
newFieldPair "Link"
168-
$ DynamicFieldText "https://bitcoin.org/en/"
168+
$ DynamicFieldText mempty
169169
photo <-
170170
fmap
171171
( (#fieldPairValue . #fieldOpts . #fieldOptsTruncateLimit .~ Nothing)
172172
. (#fieldPairValue . #fieldType .~ FieldTypeImage)
173173
)
174174
. newFieldPair "Photo"
175-
$ DynamicFieldText "https://bitcoin.org/img/home/bitcoin-img.svg?1725887272"
175+
$ DynamicFieldText mempty
176176
price <-
177-
newFieldPair "Price" $ DynamicFieldNumber 10
177+
newFieldPair "Price" $ DynamicFieldNumber 0
178178
qty <-
179179
newFieldPair "Quantity" $ DynamicFieldNumber 1
180180
comment <-

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

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import App.Types
77
import qualified Functora.Miso.Jsm as Jsm
88
import Functora.Miso.Prelude
99
import qualified Functora.Miso.Widgets.Dialog as Dialog
10+
import qualified Functora.Miso.Widgets.Field as Field
1011
import qualified Functora.Miso.Widgets.FieldPairs as FieldPairs
1112
import qualified Functora.Miso.Widgets.Icon as Icon
1213

@@ -35,42 +36,28 @@ assetViewer st idx =
3536
]
3637
]
3738
)
38-
: FieldPairs.fieldPairsViewer FieldPairs.defOpts args
39+
: FieldPairs.fieldPairsViewer fieldPairsOpts args
3940
]
4041
<> ( Dialog.dialog
4142
( Dialog.defOpts
4243
{ Dialog.optsTitle = Just title,
4344
Dialog.optsHeaderRight =
4445
const
4546
[ button_
46-
[ type_ "reset",
47-
onClick removeAction
48-
]
49-
[ icon Icon.IconDelete
50-
],
47+
[type_ "reset", onClick removeAction]
48+
[icon Icon.IconDelete],
5149
button_
52-
[ type_ "submit",
53-
onClick saveAction
54-
]
55-
[ icon Icon.IconSave
56-
]
50+
[type_ "submit", onClick saveAction]
51+
[icon Icon.IconSave]
5752
],
5853
Dialog.optsFooterRight =
5954
const
6055
[ button_
61-
[ type_ "reset",
62-
onClick removeAction
63-
]
64-
[ icon Icon.IconDelete,
65-
text " Remove"
66-
],
56+
[type_ "reset", onClick removeAction]
57+
[icon Icon.IconDelete, text " Remove"],
6758
button_
68-
[ type_ "submit",
69-
onClick saveAction
70-
]
71-
[ icon Icon.IconSave,
72-
text " Save"
73-
]
59+
[type_ "submit", onClick saveAction]
60+
[icon Icon.IconSave, text " Save"]
7461
]
7562
}
7663
)
@@ -81,9 +68,9 @@ assetViewer st idx =
8168
Dialog.argsContent =
8269
FieldPairs.fieldPairsEditor
8370
args
84-
$ FieldPairs.defOpts
85-
& #optsAdvanced
86-
.~ False
71+
fieldPairsOpts
72+
{ FieldPairs.optsAdvanced = False
73+
}
8774
}
8875
)
8976
where
@@ -114,3 +101,14 @@ assetViewer st idx =
114101
. PureUpdate
115102
$ cloneTraversal modalOptic
116103
.~ Closed
104+
105+
fieldPairsOpts :: FieldPairs.Opts model action
106+
fieldPairsOpts =
107+
FieldPairs.defOpts
108+
{ FieldPairs.optsField =
109+
Field.defOpts
110+
{ Field.optsExtraAttributesImage =
111+
[ style_ [("max-height", "10vh")]
112+
]
113+
}
114+
}

ghcjs/miso-functora/dist/miso-functora/post-theme.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ghcjs/miso-functora/lib/miso-functora/post-theme.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ dialog:after {
7979
all: initial;
8080
}
8181

82+
dialog > * {
83+
max-height: initial !important;
84+
overflow: initial !important;
85+
}
86+
8287
@media print {
8388
body {
8489
color-adjust: exact !important;

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ data Opts model action = Opts
5454
optsTrailingWidget :: Maybe (OptsWidgetPair model action),
5555
optsOnKeyDownAction :: Uid -> KeyCode -> Update model,
5656
optsExtraAttributes :: [Attribute action],
57-
optsLeftRightViewer :: [View action] -> [View action] -> [View action]
57+
optsLeftRightViewer :: [View action] -> [View action] -> [View action],
58+
optsExtraAttributesImage :: [Attribute action]
5859
}
5960
deriving stock (Generic)
6061

@@ -77,7 +78,8 @@ defOpts =
7778
optsTrailingWidget = Just $ OptsWidgetPair ClearWidget ClearWidget,
7879
optsOnKeyDownAction = Jsm.enterOrEscapeBlur,
7980
optsExtraAttributes = mempty,
80-
optsLeftRightViewer = (<>)
81+
optsLeftRightViewer = (<>),
82+
optsExtraAttributesImage = mempty
8183
}
8284

8385
data OptsWidget model action
@@ -221,9 +223,10 @@ field full@Full {fullArgs = args, fullParser = parser, fullViewer = viewer} opts
221223
[ img_
222224
( loading_ "lazy"
223225
: src_ src
224-
: optsExtraAttributes opts
226+
: optsExtraAttributesImage opts
225227
),
226-
br_ mempty
228+
br_
229+
mempty
227230
]
228231
)
229232
)
@@ -712,7 +715,11 @@ genericFieldViewer opts0 args widget =
712715
if null input
713716
then mempty
714717
else
715-
[ img_ [loading_ "lazy", src_ input]
718+
[ img_
719+
( loading_ "lazy"
720+
: src_ input
721+
: optsExtraAttributesImage opts0
722+
)
716723
]
717724
else
718725
[ widget

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

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,25 @@ data Args model action f = Args
2121
}
2222
deriving stock (Generic)
2323

24-
data Opts action = Opts
24+
data Opts model action = Opts
2525
{ optsIcon :: Icon.Icon -> View action,
26+
optsField :: Field.Opts model action,
2627
optsAdvanced :: Bool
2728
}
2829
deriving stock (Generic)
2930

30-
defOpts :: Opts action
31+
defOpts :: Opts model action
3132
defOpts =
3233
Opts
3334
{ optsIcon = Icon.icon @Icon.Fa,
35+
optsField = Field.defOpts,
3436
optsAdvanced = True
3537
}
3638

3739
fieldPairsViewer ::
3840
( Foldable1 f
3941
) =>
40-
Opts action ->
42+
Opts model action ->
4143
Args model action f ->
4244
[View action]
4345
fieldPairsViewer opts args@Args {argsOptic = optic} =
@@ -57,7 +59,7 @@ fieldPairViewer ::
5759
forall model action f.
5860
( Foldable1 f
5961
) =>
60-
Opts action ->
62+
Opts model action ->
6163
Args model action f ->
6264
Int ->
6365
FieldPair DynamicField f ->
@@ -76,7 +78,7 @@ fieldPairViewer opts args@Args {argsOptic = optic} idx pair =
7678
then mempty
7779
else
7880
Field.fieldViewer
79-
( Field.defOpts @model @action
81+
( optsField opts
8082
& #optsIcon
8183
.~ optsIcon opts
8284
& #optsLeftRightViewer
@@ -97,15 +99,18 @@ fieldPairViewer opts args@Args {argsOptic = optic} idx pair =
9799
k = pair ^. #fieldPairKey . #fieldOutput
98100
v = inspectDynamicField $ pair ^. #fieldPairValue . #fieldOutput
99101

100-
fieldPairsEditor :: Args model action Unique -> Opts action -> [View action]
102+
fieldPairsEditor ::
103+
Args model action Unique ->
104+
Opts model action ->
105+
[View action]
101106
fieldPairsEditor args@Args {argsModel = st, argsOptic = optic} opts = do
102107
idx <- fst <$> zip [0 ..] (fromMaybe mempty $ st ^? cloneTraversal optic)
103108
fieldPairEditor args opts idx
104109

105110
fieldPairEditor ::
106111
forall model action.
107112
Args model action Unique ->
108-
Opts action ->
113+
Opts model action ->
109114
Int ->
110115
[View action]
111116
fieldPairEditor
@@ -115,7 +120,7 @@ fieldPairEditor
115120
argsAction = action,
116121
argsEmitter = emitter
117122
}
118-
Opts
123+
opts@Opts
119124
{ optsAdvanced = False
120125
}
121126
idx =
@@ -126,7 +131,7 @@ fieldPairEditor
126131
Field.argsAction = action,
127132
Field.argsEmitter = emitter
128133
}
129-
( Field.defOpts
134+
( optsField opts
130135
& #optsLabel
131136
.~ Just
132137
( fromMaybe ("#" <> inspect (idx + 1))
@@ -144,7 +149,7 @@ fieldPairEditor
144149
argsAction = action,
145150
argsEmitter = emitter
146151
}
147-
Opts
152+
opts@Opts
148153
{ optsAdvanced = True
149154
}
150155
idx =
@@ -155,7 +160,7 @@ fieldPairEditor
155160
Field.argsAction = action,
156161
Field.argsEmitter = emitter
157162
}
158-
( Field.defOpts @model @action
163+
( optsField opts
159164
& #optsPlaceholder
160165
.~ ("Label " <> idxTxt)
161166
& ( #optsLeadingWidget ::
@@ -180,7 +185,7 @@ fieldPairEditor
180185
Field.argsAction = action,
181186
Field.argsEmitter = emitter
182187
}
183-
( Field.defOpts
188+
( optsField opts
184189
& #optsPlaceholder
185190
.~ ( "Value "
186191
<> idxTxt

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ flexCol newTag newAttr =
3434
$ newAttr
3535
[ style_
3636
[ ("display", "flex"),
37-
("flex-wrap", "wrap"),
3837
("flex-direction", "column")
3938
]
4039
]

0 commit comments

Comments
 (0)