Skip to content

Commit bed9e39

Browse files
Fix columns of editable table forms overflowing (#95)
1 parent 68a27ea commit bed9e39

File tree

2 files changed

+42
-26
lines changed

2 files changed

+42
-26
lines changed

src/Lumi/Components/Form/Table.purs

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,21 @@ column label orientation (FormBuilder f) =
203203
(f props row).validate
204204
}
205205
where
206+
innerColumn_ children =
207+
Column.column
208+
{ style: R.css { maxWidth: "100%" }
209+
, children
210+
}
211+
212+
innerRow_ children =
213+
Row.row
214+
{ style: R.css { maxWidth: "100%" }
215+
, children
216+
}
217+
206218
horizontalRenderer :: Boolean -> Forest -> JSX
207219
horizontalRenderer readonly forest =
208-
Row.row_
220+
innerRow_
209221
[ intercalate (hspace S12) (map (toColumn readonly) forest)
210222
]
211223

@@ -214,20 +226,16 @@ column label orientation (FormBuilder f) =
214226
case _ of
215227
Child { key, child } ->
216228
maybe identity keyed key $ child
217-
Wrapper { key, children } ->
218-
R.div
219-
{ key: fromMaybe "" key
220-
, style: R.css { flex: "1" }
221-
, children:
222-
[ Row.row_
223-
[ intercalate (hspace S12) (map (toColumn readonly) children)
224-
]
229+
Wrapper { key, wrap, children } ->
230+
maybe identity keyed key $ wrap
231+
[ innerRow_
232+
[ intercalate (hspace S12) (map (toColumn readonly) children)
225233
]
226-
}
234+
]
227235
Node { key, validationError, children } ->
228236
maybe identity keyed key $
229-
Column.column_
230-
[ Row.row_
237+
innerColumn_
238+
[ innerRow_
231239
[ intercalate (hspace S12) (map (toColumn readonly) children)
232240
]
233241
, guard (not readonly) $
@@ -236,7 +244,7 @@ column label orientation (FormBuilder f) =
236244

237245
verticalRenderer :: Boolean -> Forest -> JSX
238246
verticalRenderer readonly forest =
239-
Column.column_
247+
innerColumn_
240248
[ intercalate (vspace S8) (map (toRow readonly) forest)
241249
]
242250

@@ -245,19 +253,15 @@ column label orientation (FormBuilder f) =
245253
case _ of
246254
Child { key, child } ->
247255
maybe identity keyed key $ child
248-
Wrapper { key, children } ->
249-
R.div
250-
{ key: fromMaybe "" key
251-
, style: R.css { flex: "1" }
252-
, children:
253-
[ Column.column_
254-
[ intercalate (vspace S8) (map (toColumn readonly) children)
255-
]
256+
Wrapper { key, wrap, children } ->
257+
maybe identity keyed key $ wrap
258+
[ innerColumn_
259+
[ intercalate (vspace S8) (map (toColumn readonly) children)
256260
]
257-
}
261+
]
258262
Node { key, validationError, children } ->
259263
maybe identity keyed key $
260-
Column.column_
264+
innerColumn_
261265
[ intercalate (vspace S8) (map (toColumn readonly) children)
262266
, guard (not readonly) $
263267
foldMap errLine validationError

src/Lumi/Components/Form/Validation.purs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import Data.String.NonEmpty (fromString) as NES
3737
import Data.String.Pattern (Pattern(..))
3838
import Data.Traversable (traverse)
3939
import Heterogeneous.Mapping (class MapRecordWithIndex, class Mapping, ConstMapping, hmap, mapping)
40-
import Lumi.Components.Column (column_)
40+
import Lumi.Components.Column (column)
4141
import Lumi.Components.Form.Internal (Forest, FormBuilder, FormBuilder'(..), Tree(..))
4242
import Lumi.Components.LabeledField (ValidationMessage(..))
4343
import Lumi.Components.Text (subtext, text)
@@ -215,14 +215,20 @@ validated
215215
validated runValidator editor = FormBuilder \props@{ readonly } v ->
216216
let value = fromValidated v
217217

218+
innerColumn_ children =
219+
column
220+
{ style: R.css { maxWidth: "100%", maxHeight: "100%" }
221+
, children
222+
}
223+
218224
{ edit, validate } = un FormBuilder editor props value
219225

220226
modify :: Maybe String -> Forest -> Forest
221227
modify message forest =
222228
case Array.unsnoc forest of
223229
Nothing -> [Child { key: Nothing, child: errLine }]
224230
Just { init, last: Child c } ->
225-
Array.snoc init (Child c { child = column_ [c.child, errLine] })
231+
Array.snoc init (Child c { child = innerColumn_ [c.child, errLine] })
226232
Just { init, last: Wrapper c } ->
227233
Array.snoc init (Wrapper c { children = modify message c.children })
228234
Just { init, last: Node n } ->
@@ -276,12 +282,18 @@ warn
276282
warn warningValidator editor = FormBuilder \props@{ readonly } v ->
277283
let { edit, validate } = un FormBuilder editor props (fromValidated v)
278284

285+
innerColumn_ children =
286+
column
287+
{ style: R.css { maxWidth: "100%", maxHeight: "100%" }
288+
, children
289+
}
290+
279291
modify :: Forest -> Forest
280292
modify forest =
281293
case Array.unsnoc forest of
282294
Nothing -> [Child { key: Nothing, child: errLine }]
283295
Just { init, last: Child c } ->
284-
Array.snoc init (Child c { child = column_ [c.child, errLine] })
296+
Array.snoc init (Child c { child = innerColumn_ [c.child, errLine] })
285297
Just { init, last: Wrapper c } ->
286298
Array.snoc init (Wrapper c { children = modify c.children })
287299
Just { init, last: Node n } ->

0 commit comments

Comments
 (0)