Adds common disabled helper

This commit is contained in:
Tessa Kelly 2022-03-04 13:51:31 -08:00
parent 06a5615959
commit 88cfb2453a
3 changed files with 42 additions and 16 deletions

View File

@ -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
)
)

View File

@ -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 =

View File

@ -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 ""))
)