noredink-ui/styleguide-app/Debug/Control/Extra.elm

44 lines
998 B
Elm
Raw Normal View History

2021-10-22 03:20:29 +03:00
module Debug.Control.Extra exposing
( float
, list, listItem, optionalListItem
)
{-|
@docs float
@docs list, listItem, optionalListItem
-}
import Debug.Control as Control exposing (Control)
{-| -}
float : Float -> Control Float
float default =
Control.map (String.toFloat >> Maybe.withDefault default)
(Control.string (String.fromFloat default))
{-| Use with `listItem` and `optionalListItem`
-}
list : Control (List a)
list =
Control.record []
{-| -}
listItem : String -> Control a -> Control (List a) -> Control (List a)
listItem name accessor accumulator =
Control.field name
(Control.map List.singleton accessor)
(Control.map (++) accumulator)
{-| -}
2021-10-22 03:27:29 +03:00
optionalListItem : String -> Control a -> Control (List a) -> Control (List a)
2021-10-22 03:20:29 +03:00
optionalListItem name accessor accumulator =
Control.field name
2021-10-22 03:27:29 +03:00
(Control.map (List.singleton >> List.filterMap identity) (Control.maybe False accessor))
2021-10-22 03:20:29 +03:00
(Control.map (++) accumulator)