@@ -7,7 +7,6 @@ module Functora.Miso.Widgets.Field
7
7
OptsWidgetPair (.. ),
8
8
ModalWidget' (.. ),
9
9
truncateUnicode ,
10
- truncateDynamicField ,
11
10
expandDynamicField ,
12
11
field ,
13
12
ratioField ,
@@ -152,33 +151,64 @@ field full@Full {fullArgs = args, fullParser = parser, fullViewer = viewer} opts
152
151
. (br_ mempty : )
153
152
)
154
153
(optsLabel opts)
155
- ( [ input_
156
- $ ( catMaybes
157
- [ fmap
158
- (type_ . htmlFieldType)
159
- (st ^? cloneTraversal optic . # fieldType),
160
- fmap
161
- (textProp " defaultValue" )
162
- (st ^? cloneTraversal optic . # fieldInput . # uniqueValue),
163
- Just $ onInput onInputAction,
164
- Just . disabled_ $ opts ^. # optsDisabled,
165
- fmap placeholder_
166
- $ if null placeholder
167
- then optsLabel opts
168
- else Just placeholder,
169
- Just
170
- . id_
171
- . either impureThrow id
172
- . decodeUtf8Strict
173
- . unTagged
174
- $ htmlUid uid,
175
- Just . onKeyDown $ action . optsOnKeyDownAction opts uid,
176
- Just $ onBlur onBlurAction
177
- ]
178
- )
179
- <> ( opts ^. # optsExtraAttributes
180
- )
181
- ]
154
+ ( ( if typ == FieldTypeImage
155
+ then
156
+ join
157
+ . maybeToList
158
+ $ fmap
159
+ ( \ src ->
160
+ if null src
161
+ then mempty
162
+ else
163
+ [ img_ (src_ src : optsExtraAttributes opts),
164
+ br_ mempty
165
+ ]
166
+ )
167
+ $ st
168
+ ^? cloneTraversal
169
+ optic
170
+ . # fieldInput
171
+ . # uniqueValue
172
+ else
173
+ singleton
174
+ . input_
175
+ $ ( catMaybes
176
+ [ Just . type_ $ htmlFieldType typ,
177
+ fmap
178
+ (textProp " defaultValue" )
179
+ ( st
180
+ ^? cloneTraversal
181
+ optic
182
+ . # fieldInput
183
+ . # uniqueValue
184
+ ),
185
+ Just
186
+ $ onInput onInputAction,
187
+ Just
188
+ . disabled_
189
+ $ opts
190
+ ^. # optsDisabled,
191
+ fmap placeholder_
192
+ $ if null placeholder
193
+ then optsLabel opts
194
+ else Just placeholder,
195
+ Just
196
+ . id_
197
+ . either impureThrow id
198
+ . decodeUtf8Strict
199
+ . unTagged
200
+ $ htmlUid uid,
201
+ Just
202
+ . onKeyDown
203
+ $ action
204
+ . optsOnKeyDownAction opts uid,
205
+ Just
206
+ $ onBlur onBlurAction
207
+ ]
208
+ )
209
+ <> ( opts ^. # optsExtraAttributes
210
+ )
211
+ )
182
212
--
183
213
-- TODO : with new semantic layout separate leading/trailing
184
214
-- widgets do not make a lot of sense, should be a single option
@@ -187,26 +217,21 @@ field full@Full {fullArgs = args, fullParser = parser, fullViewer = viewer} opts
187
217
<> catMaybes
188
218
[ fmap
189
219
(fieldIcon full opts)
190
- (opts ^? # optsLeadingWidget . _Just . cloneTraversal widgetOptic),
220
+ ( opts
221
+ ^? # optsLeadingWidget
222
+ . _Just
223
+ . cloneTraversal widgetOptic
224
+ ),
191
225
fmap
192
226
(fieldIcon full opts)
193
- (opts ^? # optsTrailingWidget . _Just . cloneTraversal widgetOptic)
227
+ ( opts
228
+ ^? # optsTrailingWidget
229
+ . _Just
230
+ . cloneTraversal widgetOptic
231
+ )
194
232
]
195
233
)
196
234
where
197
- --
198
- -- TODO : implement
199
- --
200
- -- & TextField.setLeadingIcon
201
- -- ( fmap
202
- -- (fieldIcon Leading full opts)
203
- -- (opts ^? #optsLeadingWidget . _Just . cloneTraversal widgetOptic)
204
- -- )
205
- -- & TextField.setTrailingIcon
206
- -- ( fmap
207
- -- (fieldIcon Trailing full opts)
208
- -- (opts ^? #optsTrailingWidget . _Just . cloneTraversal widgetOptic)
209
- -- )
210
235
st = argsModel args
211
236
optic = argsOptic args
212
237
action = argsAction args
@@ -215,6 +240,11 @@ field full@Full {fullArgs = args, fullParser = parser, fullViewer = viewer} opts
215
240
if null . fromMaybe mempty $ getInput st
216
241
then # optsWidgetPairEmpty
217
242
else # optsWidgetPairNonEmpty
243
+ typ =
244
+ fromMaybe FieldTypeText
245
+ $ st
246
+ ^? cloneTraversal optic
247
+ . # fieldType
218
248
uid =
219
249
fromMaybe nilUid
220
250
$ st
@@ -567,6 +597,7 @@ fieldViewer opts args =
567
597
FieldTypePercent -> genericFieldViewer opts args $ text . (<> " %" )
568
598
FieldTypeText -> genericFieldViewer opts args text
569
599
FieldTypeTitle -> header val
600
+ FieldTypeImage -> genericFieldViewer opts args text
570
601
FieldTypeHtml ->
571
602
genericFieldViewer
572
603
opts
@@ -627,13 +658,19 @@ genericFieldViewer opts0 args widget =
627
658
)
628
659
<> ( optsLeftRightViewer
629
660
opts0
630
- [ widget
631
- $ truncateFieldViewer
632
- allowTrunc
633
- stateTrunc
634
- (opts ^. # fieldOptsTruncateLimit)
635
- input
636
- ]
661
+ ( if typ == FieldTypeImage
662
+ then
663
+ [ img_ [src_ input]
664
+ ]
665
+ else
666
+ [ widget
667
+ $ truncateFieldViewer
668
+ allowTrunc
669
+ stateTrunc
670
+ (opts ^. # fieldOptsTruncateLimit)
671
+ input
672
+ ]
673
+ )
637
674
( if null extraWidgets
638
675
then mempty
639
676
else extraWidgets
@@ -643,6 +680,11 @@ genericFieldViewer opts0 args widget =
643
680
st = argsModel args
644
681
optic = argsOptic args
645
682
action = argsAction args
683
+ typ =
684
+ fromMaybe FieldTypeText
685
+ $ st
686
+ ^? cloneTraversal (argsOptic args)
687
+ . # fieldType
646
688
input =
647
689
maybe mempty fold1 $ st ^? cloneTraversal optic . # fieldInput
648
690
opts =
@@ -720,17 +762,6 @@ truncateFieldViewer True Closed limit full =
720
762
truncateFieldViewer _ _ _ full =
721
763
full
722
764
723
- truncateDynamicField ::
724
- Maybe Int ->
725
- Field DynamicField Identity ->
726
- Field DynamicField Identity
727
- truncateDynamicField limit =
728
- (# fieldInput . # runIdentity %~ truncateUnicode limit)
729
- . ( # fieldOutput %~ \ case
730
- DynamicFieldNumber {} -> DynamicFieldNumber 0
731
- DynamicFieldText {} -> DynamicFieldText mempty
732
- )
733
-
734
765
truncateUnicode :: Maybe Int -> Unicode -> Unicode
735
766
truncateUnicode limit input =
736
767
if length input <= full
0 commit comments