diff --git a/styleguide-app/CommonControls.elm b/styleguide-app/CommonControls.elm index 2510825a..d516d6d7 100644 --- a/styleguide-app/CommonControls.elm +++ b/styleguide-app/CommonControls.elm @@ -1,6 +1,7 @@ -module CommonControls exposing (exampleHtml, httpError, premiumLevel, quickBrownFox, romeoAndJulietQuotation, uiIcon) +module CommonControls exposing (disabledListItem, exampleHtml, httpError, premiumLevel, quickBrownFox, romeoAndJulietQuotation, uiIcon) import Debug.Control as Control exposing (Control) +import Debug.Control.Extra as ControlExtra import Html.Styled as Html exposing (Html) import Html.Styled.Attributes as Attributes import Http @@ -110,3 +111,13 @@ uiIcon = ( name, Control.value ( "UiIcon." ++ name, value ) ) ) |> Control.choice + + +disabledListItem : String -> (Bool -> b) -> Control (List ( String, b )) -> Control (List ( String, b )) +disabledListItem moduleName f = + ControlExtra.optionalBoolListItem "disabled" + (\bool -> + ( moduleName ++ ".disabled True" + , f bool + ) + ) diff --git a/styleguide-app/Debug/Control/Extra.elm b/styleguide-app/Debug/Control/Extra.elm index 7934938d..89a9eb93 100644 --- a/styleguide-app/Debug/Control/Extra.elm +++ b/styleguide-app/Debug/Control/Extra.elm @@ -1,13 +1,13 @@ module Debug.Control.Extra exposing ( float, int - , list, listItem, optionalListItem + , list, listItem, optionalListItem, optionalBoolListItem , css ) {-| @docs float, int -@docs list, listItem, optionalListItem +@docs list, listItem, optionalListItem, optionalBoolListItem @docs css -} @@ -58,6 +58,23 @@ optionalListItem name accessor accumulator = (Control.map (++) accumulator) +{-| -} +optionalBoolListItem : String -> (Bool -> a) -> Control (List a) -> Control (List a) +optionalBoolListItem name f accumulator = + Control.field name + (Control.map + (\value -> + if value then + [ f value ] + + else + [] + ) + (Control.bool False) + ) + (Control.map (++) accumulator) + + {-| -} css : String -> Control (List Css.Style) css exampleCss = diff --git a/styleguide-app/Examples/ClickableSvg.elm b/styleguide-app/Examples/ClickableSvg.elm index 0917eeca..ceab0cd8 100644 --- a/styleguide-app/Examples/ClickableSvg.elm +++ b/styleguide-app/Examples/ClickableSvg.elm @@ -270,17 +270,15 @@ initSettings = |> Control.field "icon" CommonControls.uiIcon |> Control.field "attributes" (ControlExtra.list - |> ControlExtra.listItem "disabled" - (Control.map ClickableSvg.disabled (Control.bool False)) - |> ControlExtra.optionalListItem "exactSize" - (Control.map ClickableSvg.exactSize (ControlExtra.int 36)) - |> ControlExtra.optionalListItem "css" - (Control.map ClickableSvg.css (ControlExtra.css "border: 2px solid red;")) - |> ControlExtra.optionalListItem "mobileCss" - (Control.map ClickableSvg.mobileCss (ControlExtra.css "padding: 10px;")) - |> ControlExtra.optionalListItem "quizEngineMobileCss" - (Control.map ClickableSvg.quizEngineMobileCss (ControlExtra.css "")) - |> ControlExtra.optionalListItem "notMobileCss" - (Control.map ClickableSvg.notMobileCss (ControlExtra.css "")) - |> Control.map (List.map (\v -> ( Debug.toString v, v ))) + |> CommonControls.disabledListItem "ClickableSvg" ClickableSvg.disabled + --|> ControlExtra.optionalListItem "exactSize" + -- (Control.map ClickableSvg.exactSize (ControlExtra.int 36)) + --|> ControlExtra.optionalListItem "css" + -- (Control.map ClickableSvg.css (ControlExtra.css "border: 2px solid red;")) + --|> ControlExtra.optionalListItem "mobileCss" + -- (Control.map ClickableSvg.mobileCss (ControlExtra.css "padding: 10px;")) + --|> ControlExtra.optionalListItem "quizEngineMobileCss" + -- (Control.map ClickableSvg.quizEngineMobileCss (ControlExtra.css "")) + --|> ControlExtra.optionalListItem "notMobileCss" + -- (Control.map ClickableSvg.notMobileCss (ControlExtra.css "")) )