diff --git a/styleguide-app/Debug/Control/Extra.elm b/styleguide-app/Debug/Control/Extra.elm index 77b0192c..72c2d142 100644 --- a/styleguide-app/Debug/Control/Extra.elm +++ b/styleguide-app/Debug/Control/Extra.elm @@ -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) diff --git a/styleguide-app/Examples/SideNav.elm b/styleguide-app/Examples/SideNav.elm index 70b7b9ad..dd505d9c 100644 --- a/styleguide-app/Examples/SideNav.elm +++ b/styleguide-app/Examples/SideNav.elm @@ -120,9 +120,7 @@ type alias Settings = {-| -} init : State init = - { settings = - ControlExtra.list - |> ControlExtra.listItem "entry" controlEntry + { settings = ControlExtra.dynamicList controlEntry }