Implement dynamic list

because of how debug.controls renders records, this implementation artificially indents. This should be fixed in order to make the controls actually usable
This commit is contained in:
Tessa Kelly 2022-03-10 17:13:39 -08:00
parent ee0e46f06d
commit 0534c35a17
2 changed files with 28 additions and 3 deletions

View File

@ -1,12 +1,14 @@
module Debug.Control.Extra exposing
( float, int
, list, listItem, optionalListItem, optionalListItemDefaultChecked, optionalBoolListItem
, dynamicList
)
{-|
@docs float, int
@docs list, listItem, optionalListItem, optionalListItemDefaultChecked, optionalBoolListItem
@docs dynamicList
-}
@ -82,3 +84,28 @@ optionalBoolListItem name f accumulator =
(Control.bool False)
)
(Control.map (++) accumulator)
{-| -}
dynamicList : Control a -> Control (List a)
dynamicList value =
list
|> listItem "Entry" value
|> addAnother value
addAnother : Control a -> Control (List a) -> Control (List a)
addAnother value accumulator =
Control.field "Add another?"
(Control.map
(\maybe ->
case maybe of
Just l ->
l
Nothing ->
[]
)
(Control.maybe False (Control.lazy (\() -> dynamicList value)))
)
(Control.map (++) accumulator)

View File

@ -120,9 +120,7 @@ type alias Settings =
{-| -}
init : State
init =
{ settings =
ControlExtra.list
|> ControlExtra.listItem "entry" controlEntry
{ settings = ControlExtra.dynamicList controlEntry
}